Author: keith
Date: Thu Apr 24 05:43:44 2008
New Revision: 16108

Log:

Getting rid of inline strings and introducing constants as per the code review


Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Thu Apr 24 05:43:44 2008
@@ -78,6 +78,10 @@
     public static final String PROFILE_PATH = "profilePath";
     public static final String ALL_MASHUPS_PATH = "/mashups";
     public static final String QUERYSTORE_QUERY_PATH = "/querystore";
+    public static final String USERS_PATH = "/users";
+    public static final String SYSTEM_PATH = "/system";
+    public static final String SYSTEM__QUERIES_PATH = SYSTEM_PATH + "/queries";
+    public static final String PROFILES_PATH = USERS_PATH + "/profile";
     public static final String MY_MASHUPS_QUERY_PATH = QUERYSTORE_QUERY_PATH + 
"/mymashups";
     public static final String ALL_MASHUPS_QUERY_PATH = QUERYSTORE_QUERY_PATH 
+ "/allmashups";
     public static final String CUSTOM_QUERY_PATH = QUERYSTORE_QUERY_PATH + 
"/searchCustom";
@@ -117,6 +121,7 @@
 
     public static final String SEPARATOR_CHAR = "-";
     public static final String MASHUP_USER_ROLE = "mashup_user";
+    public static final String MASHUP_USER_ROLE_NAME = "Mashup User";
 
     public static final String SELF_REGISTRATION_ENABLED = 
"self_registration_enabled";
 
@@ -143,10 +148,19 @@
     public static String MASHUP_PRIVATE_FOLDER_NAME = "_private";
     public static String UNDISPATCHED_OPERATION = "undispatched";
     public static String TAGS_ELEMENT = "tag";
+
+    // The extention of the tags file used to hold the tags for masgups
     public static String TAGS_File = ".tags";
+
+    // The extention of the resources file created for each masgup
+    public static String RESOURCES = ".resources";
+
+
     public static String NAME = "name";
     public static String XSD = "xsd";
     public static String QUESTION_MARK = "?";
+    public static String FORWARD_SLASH = "/";
+    public static String DOT = ".";
 
     // The value that is used by the javascript init annotation. e.g this.init 
= function (){}
     public static String INIT_ANNOTATION = "init";

Modified: 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
==============================================================================
--- 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
   (original)
+++ 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
   Thu Apr 24 05:43:44 2008
@@ -124,6 +124,24 @@
     // httpLocationBasedDispatcher
     Map httpLocationTable;
 
+    // Used by the service name validator to genarate the error message on an 
invalid name
+    private final String SERVICE_NAME = "ServiceName";
+
+    // Used by the operation name validator to genarate the error message on 
an invalid name
+    private final String OPERATION_NAME = "OperationName";
+
+
+    private final String HTTP_TRANSPORT = "http";
+    private final String HTTPS_TRANSPORT = "https";
+    private final String SYSTEM_USER_NAME = "System";
+    private final String SYSTEM_USER_BIO = "System User";
+    private final String SAMPLES_USER_NAME = "Samples";
+    private final String SAMPLES_USER_BIO = "Samples User";
+    private final String ANNONYMOUS_USER_NAME = "Visitor";
+    private final String ANNONYMOUS_USER_BIO = "Annonymous User";
+    private final String ADMIN_USER_BIO = "System Administrator";
+    private final String NONE = "none";
+
     /**
      * Initialize the deployer.
      *
@@ -378,7 +396,7 @@
             // For more details see
             // 
http://www.wso2.org/wiki/display/mashup/scripts+folder+structure+and+deployment
             File parentDir = file.getParentFile();
-            File resourcesDir = new File(parentDir, shortFileName + 
".resources");
+            File resourcesDir = new File(parentDir, shortFileName + 
MashupConstants.RESOURCES);
             resourcesDir.mkdir();
 
             // creating _private folder in the resources folder to keep 
private stuff
@@ -432,7 +450,7 @@
 
             // Checks the validity of the serviceName. If the serviceName in 
invalid an exception is
             // thrown
-            MashupUtils.validateName(name, "ServiceName");
+            MashupUtils.validateName(name, SERVICE_NAME);
 
             UserRealm realm = (UserRealm) 
configCtx.getAxisConfiguration().getParameterValue(
                     RegistryConstants.REGISTRY_REALM);
@@ -525,21 +543,13 @@
                 String prefix = "";
                 TransportInDescription transportIn = (TransportInDescription) 
iterator.next();
                 String transportInName = transportIn.getName();
-                if (transportInName.equals("http")) {
+                if (HTTP_TRANSPORT.equalsIgnoreCase(transportInName)) {
                     needHttp = true;
-                    //todo
-                } else if (transportInName.equals("https")) {
+                } else if (HTTPS_TRANSPORT.equalsIgnoreCase(transportInName)) {
                     needHttp = true;
                     prefix = WSDL2Constants.DEFAULT_HTTPS_PREFIX;
-                } else if (transportInName.equals("jms")) {
-                    prefix = "JMS";
-                } else if (transportInName.equals("tcp")) {
-                    prefix = "TCP";
-                    //todo use toUpperCase
-                } else if (transportInName.equals("SMTP")) {
-                    prefix = "smtp";
-                } else if (transportInName.equals("XMPP")) {
-                    prefix = "XMPP";
+                } else if (transportInName != null) {
+                    prefix = transportInName.toUpperCase();
                 }
 
                 // Creates a default SOAP 1.1 endpoint
@@ -686,11 +696,12 @@
         not what we need to display in the WSDL. We need the function name as 
bar instead to be
         displayed in the WSDL. Hence we need to do something special here to 
get that to work.
         */
-        String funcName = (String) function.get("name", function);
+        String funcName = (String) function.get(MashupConstants.NAME, 
function);
         // In this case init or destroy is an annonymous function.
         // Hence we dont need to create an axisoperation for that.
         // e.g this.init= function (){};
-        if ("".equals(funcName) && ("init".equals(method) || 
"destroy".equals(method))) {
+        if ("".equals(funcName) && 
(MashupConstants.INIT_ANNOTATION.equals(method) ||
+                MashupConstants.DESTROY_ANNOTATION.equals(method))) {
             return;
         }
         Scriptable parent = function.getParentScope();
@@ -719,7 +730,7 @@
 
             // Checks the validity of the OperationName. If the OperationName 
in invalid an
             // exception is thrown
-            MashupUtils.validateName(name, "OperationName");
+            MashupUtils.validateName(name, OPERATION_NAME);
 
             AxisOperation operation = axisService.getOperation(new 
QName(name));
             if (operation != null) {
@@ -776,7 +787,7 @@
             // If the user did not specify a httpLocation default it to 
serviceName/operationName
             // cause this is the default that axis2 uses
             if (httpLocation == null) {
-                httpLocation = serviceName + "/" + name;
+                httpLocation = serviceName + MashupConstants.FORWARD_SLASH + 
name;
             }
 
             String httpMethod = annotationParser.getHttpMethod();
@@ -823,18 +834,18 @@
             soap12Binding.addChild(soap12BindingOperation.getName(), 
soap12BindingOperation);
             httpBinding.addChild(httpBindingOperation.getName(), 
httpBindingOperation);
 
-            if (!targetNamespace.endsWith("/")) {
-                targetNamespace = targetNamespace + "/";
+            if (!targetNamespace.endsWith(MashupConstants.FORWARD_SLASH)) {
+                targetNamespace = targetNamespace + 
MashupConstants.FORWARD_SLASH;
             }
 
             // Calculate the values for input and output actions according to
             // http://www.w3.org/TR/ws-addr-wsdl/#defactionwsdl20
             String inputAction =
-                    targetNamespace + WSDL2Constants.DEFAULT_INTERFACE_NAME + 
"/" + name +
-                            Java2WSDLConstants.REQUEST;
+                    targetNamespace + WSDL2Constants.DEFAULT_INTERFACE_NAME +
+                            MashupConstants.FORWARD_SLASH + name + 
Java2WSDLConstants.REQUEST;
             String outAction =
-                    targetNamespace + WSDL2Constants.DEFAULT_INTERFACE_NAME + 
"/" + name +
-                            Java2WSDLConstants.RESPONSE;
+                    targetNamespace + WSDL2Constants.DEFAULT_INTERFACE_NAME +
+                            MashupConstants.FORWARD_SLASH + name + 
Java2WSDLConstants.RESPONSE;
             axisOp.setSoapAction(inputAction);
             
soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, 
inputAction);
             
soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, 
inputAction);
@@ -923,17 +934,21 @@
 
         // Get the database connection details for the registry database from 
the server.xml
         String registryDriverClass = serverConfig
-                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + 
MashupConstants.DRIVER_CLASS);
+                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.DRIVER_CLASS);
         String registryUrl = serverConfig
-                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + MashupConstants.URL);
+                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.URL);
         String registryUsername = serverConfig
-                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + MashupConstants.USERNAME);
+                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.USERNAME);
         String registryPassword = serverConfig
-                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + MashupConstants.PASSWORD);
+                .getFirstProperty(MashupConstants.REGISTRY_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.PASSWORD);
 
         if (registryDriverClass == null || "".equals(registryDriverClass) ||
                 registryUrl == null || "".equals(registryUrl)) {
@@ -944,17 +959,21 @@
         // Get the database connection details for the usermanager database 
from the server.xml
         String usermanagerDriverClass = serverConfig
                 .getFirstProperty(
-                        MashupConstants.USERMANAGER_CONFIG + "." + 
MashupConstants
-                                .DATABASE_CONNECTION + "." + 
MashupConstants.DRIVER_CLASS);
+                        MashupConstants.USERMANAGER_CONFIG + 
MashupConstants.DOT + MashupConstants
+                                .DATABASE_CONNECTION + MashupConstants.DOT +
+                                MashupConstants.DRIVER_CLASS);
         String usermanagerUrl = serverConfig
-                .getFirstProperty(MashupConstants.USERMANAGER_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + MashupConstants.URL);
+                .getFirstProperty(MashupConstants.USERMANAGER_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.URL);
         String usermanagerUsername = serverConfig
-                .getFirstProperty(MashupConstants.USERMANAGER_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + MashupConstants.USERNAME);
+                .getFirstProperty(MashupConstants.USERMANAGER_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.USERNAME);
         String usermanagerPassword = serverConfig
-                .getFirstProperty(MashupConstants.USERMANAGER_CONFIG + "." + 
MashupConstants
-                        .DATABASE_CONNECTION + "." + MashupConstants.PASSWORD);
+                .getFirstProperty(MashupConstants.USERMANAGER_CONFIG + 
MashupConstants.DOT +
+                        MashupConstants.DATABASE_CONNECTION + 
MashupConstants.DOT +
+                        MashupConstants.PASSWORD);
 
         if (usermanagerDriverClass == null || 
"".equals(usermanagerDriverClass) ||
                 usermanagerUrl == null || "".equals(usermanagerUrl)) {
@@ -977,7 +996,8 @@
                 }
             }
             if (!hasMashupUserRole) {
-                admin.addRole(MashupConstants.MASHUP_USER_ROLE, "Mashup User");
+                admin.addRole(MashupConstants.MASHUP_USER_ROLE,
+                              MashupConstants.MASHUP_USER_ROLE_NAME);
             }
 
             // We create a new WSASRegistryRealm here. The WSASRegistryRealm 
is specially designed
@@ -1182,23 +1202,23 @@
 
                 // Create a collection for users. All user related data will 
go in here
                 Collection usersCollection = systemRegistry.newCollection();
-                systemRegistry.put("/users", usersCollection);
+                systemRegistry.put(MashupConstants.USERS_PATH, 
usersCollection);
 
                 // Create a collection for profiles. All user profiles data 
will go in here
                 Collection profileCollection = systemRegistry.newCollection();
-                systemRegistry.put("/users/profile", profileCollection);
+                systemRegistry.put(MashupConstants.PROFILES_PATH, 
profileCollection);
 
                 // Create a collection for system. All system related data 
will go in here
                 Collection systemCollection = systemRegistry.newCollection();
-                systemRegistry.put("/system", systemCollection);
+                systemRegistry.put(MashupConstants.SYSTEM_PATH, 
systemCollection);
 
                 // Create a collection for /system/queries. All system queries 
will go in here
                 Collection queriesCollection = systemRegistry.newCollection();
-                systemRegistry.put("/system/queries", queriesCollection);
+                systemRegistry.put(MashupConstants.SYSTEM__QUERIES_PATH, 
queriesCollection);
 
                 // Create a collection for mashups. All mashup related data 
will go in here
                 Collection mashupsCollection = systemRegistry.newCollection();
-                systemRegistry.put("/mashups", mashupsCollection);
+                systemRegistry.put(MashupConstants.ALL_MASHUPS_PATH, 
mashupsCollection);
 
                 // This query accepts a resource path, a username, and a tag 
name, and returns the
                 // resource path if that user applied that tag to the resource.
@@ -1274,24 +1294,24 @@
 
                 // Create the anonymous user profile.
                 RegistryUtils.createUser(systemRegistry,
-                                         RegistryConstants.ANONYMOUS_USER, 
"Visitor", "none",
-                                         "Anonymous user");
+                                         RegistryConstants.ANONYMOUS_USER, 
ANNONYMOUS_USER_NAME, NONE,
+                                         ANNONYMOUS_USER_BIO);
 
                 // Create the system user profile.
                 RegistryUtils.createUser(systemRegistry, 
MashupConstants.SYSTEM_USER,
-                                         "System", "none", "System User");
+                                         SYSTEM_USER_NAME, NONE, 
SYSTEM_USER_BIO);
 
                 // Create the samples user and profile.
                 RegistryUtils.createUser(systemRegistry, 
MashupConstants.SAMPLES_USER,
-                                         "Samples", "none", "Samples User");
+                                         SAMPLES_USER_NAME, NONE, 
SAMPLES_USER_BIO);
             }
 
             // If primary user has not been created, do so.
             if (createPrimary && !MashupUtils.isInitialSetupComplete()) {
                 //Create the admin profile using information from a config 
file.
                 RegistryUtils
-                        .createUser(systemRegistry, primaryName, primaryName, 
"none",
-                                    "System Administrator");
+                        .createUser(systemRegistry, primaryName, primaryName, 
NONE,
+                                    ADMIN_USER_BIO);
                 // Assign system user the 'admin' role and make primary.
                 us.addUserToRole(primaryName, RegistryConstants.ADMIN_ROLE);
                 RegistryUtils.makeUserPrimary(realm, primaryName);

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to