Author: keith
Date: Thu Apr 24 05:09:41 2008
New Revision: 16106
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/JavaScriptServiceAnnotationParser.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:09:41 2008
@@ -144,4 +144,48 @@
public static String UNDISPATCHED_OPERATION = "undispatched";
public static String TAGS_ELEMENT = "tag";
public static String TAGS_File = ".tags";
+ public static String NAME = "name";
+ public static String XSD = "xsd";
+ public static String QUESTION_MARK = "?";
+
+ // The value that is used by the javascript init annotation. e.g this.init
= function (){}
+ public static String INIT_ANNOTATION = "init";
+
+ // The value that is used by the javascript destroy annotation.
+ // e.g this.destroy = function foo(){}
+ public static String DESTROY_ANNOTATION = "destroy";
+
+ // The value that is used by the javascript undispatched annotation.
+ // e.g this.undispatched = function foo(){}
+ public static String UNDISPATCHED_ANNOTATION = "undispatched";
+
+ // The value that is used by the javascript scope annotation. e.g
this.scope = "application";
+ public static String SCOPE_ANNOTATION = "scope";
+
+ // The value that is used by the javascript documentation annotation.
+ // e.g this.documentation = "documentation";
+ public static String DOCUMENTATION_ANNOTATION = "scope";
+
+ // The value that is used by the javascript targetNamespace annotation.
+ // e.g this.targetNamespace = "http://foo.com";
+ public static String TARGET_NAMESPACE_ANNOTATION = "targetNamespace";
+
+ // The value that is used by the javascript schemaTargetNamespace
annotation.
+ // e.g this.schemaTargetNamespace = "http://foo.com?xsd";
+ public static String SCHEMA_TARGET_NAMESPACE_ANNOTATION =
"schemaTargetNamespace";
+
+ // The value that is used by the javascript serviceName annotation.
+ // e.g this.serviceName = "serviceName";
+ public static String SERVICE_NAME_ANNOTATION = "serviceName";
+
+ // The value that is used by the javascript operationName annotation.
+ // e.g foo.operationName = "operationName";
+ // function foo () {}
+ public static String OPERATION_NAME_ANNOTATION = "operationName";
+
+ // The value that is used by the javascript deployer as the prefix for the
default target
+ // namespaces. The target namespace will be of the form
+ // "http://services.mashup.wso2.org/" + serviceName and the
schemaTargetNamespace will be of the
+ // form http://services.mashup.wso2.org/" + serviceName + "?xsd";
+ public static String TARGET_NAMESPACE_PREFIX =
"http://services.mashup.wso2.org/";
}
Modified:
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JavaScriptServiceAnnotationParser.java
==============================================================================
---
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JavaScriptServiceAnnotationParser.java
(original)
+++
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JavaScriptServiceAnnotationParser.java
Thu Apr 24 05:09:41 2008
@@ -23,6 +23,7 @@
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.wso2.javascript.xmlimpl.XML;
+import org.wso2.mashup.MashupConstants;
/**
* This extracts & processes the service level annotations when deploying the
@@ -115,15 +116,17 @@
// Check weather the user provided a schemaTargetNamespace. If its not
present use a default
// namespace
- Object schemaTargetNamespaceObject =
service.get("schemaTargetNamespace", service);
+ Object schemaTargetNamespaceObject =
+
service.get(MashupConstants.SCHEMA_TARGET_NAMESPACE_ANNOTATION, service);
if (schemaTargetNamespaceObject instanceof String) {
schemaTargetNamespace = (String) schemaTargetNamespaceObject;
} else {
- schemaTargetNamespace = "http://services.mashup.wso2.org/" +
serviceName + "?xsd";
+ schemaTargetNamespace = MashupConstants.TARGET_NAMESPACE_PREFIX +
serviceName +
+ MashupConstants.QUESTION_MARK + MashupConstants.XSD;
}
// Check weather the user provided a serviceName
- Object serviceNameObject = service.get("serviceName", service);
+ Object serviceNameObject =
service.get(MashupConstants.SERVICE_NAME_ANNOTATION, service);
if (serviceNameObject instanceof String) {
String serviceNameString = ((String) serviceNameObject).trim();
if (serviceNameString.indexOf(' ') > -1) {
@@ -137,15 +140,16 @@
// Check weather the user provided a targetNamespace. If its not
present use a default
// namespace
- Object targetNamespaceObject = service.get("targetNamespace", service);
+ Object targetNamespaceObject =
service.get(MashupConstants.TARGET_NAMESPACE_ANNOTATION,
+ service);
if (targetNamespaceObject instanceof String) {
targetNamespace = (String) targetNamespaceObject;
} else {
- targetNamespace = "http://services.mashup.wso2.org/" +
this.serviceName;
+ targetNamespace = MashupConstants.TARGET_NAMESPACE_PREFIX +
this.serviceName;
}
// Check weather the user provided a scope for the service
- Object serviceScopeObject = service.get("scope", service);
+ Object serviceScopeObject =
service.get(MashupConstants.SCOPE_ANNOTATION, service);
if (serviceScopeObject instanceof String) {
this.serviceScope = (String) serviceScopeObject;
}
@@ -153,7 +157,8 @@
// Check weather the user provided some service level documentation.
If the documentation is
// a String we wrap it as a OMText. Else if its an E4X XML object we
get the axiom from it
// and set that as the documentation.
- Object serviceDocumentationObject = service.get("documentation",
service);
+ Object serviceDocumentationObject =
service.get(MashupConstants.DOCUMENTATION_ANNOTATION,
+ service);
if (serviceDocumentationObject instanceof String) {
this.serviceDocumentation = omFactory.createOMText((String)
serviceDocumentationObject);
} else if (serviceDocumentationObject instanceof XML) {
@@ -163,24 +168,25 @@
// Check weather the user provided a init annotation. If it was
provided this function would
// be called on service Deployment
- Object initObject = service.get("init", service);
+ Object initObject = service.get(MashupConstants.INIT_ANNOTATION,
service);
if (initObject instanceof Function) {
this.init = (Function) initObject;
}
// Check weather the user provided a destroy annotation. If it was
provided this function
// would be called on service undeployment
- Object destroyObject = service.get("destroy", service);
+ Object destroyObject = service.get(MashupConstants.DESTROY_ANNOTATION,
service);
if (destroyObject instanceof Function) {
this.destroy = (Function) destroyObject;
}
// Check weather the user provided a undispatched annotation. If it
was provided any
// undispatched operations will be dispatched to this special function
- Object undispatchedOperation = service.get("undispatched", service);
+ Object undispatchedOperation =
+ service.get(MashupConstants.UNDISPATCHED_ANNOTATION, service);
if (undispatchedOperation instanceof Function) {
Scriptable scriptable = (Scriptable) undispatchedOperation;
- undispatched = (String) scriptable.get("name", scriptable);
+ undispatched = (String) scriptable.get(MashupConstants.NAME,
scriptable);
} else if (undispatchedOperation instanceof String) {
undispatched = (String) undispatchedOperation;
}
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev