[mashup-dev] svn commit r1478 -
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino
svn at wso2.org
svn at wso2.org
Mon Mar 26 22:42:15 PDT 2007
Author: thilina
Date: Mon Mar 26 22:42:10 2007
New Revision: 1478
Added:
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JavaScriptOperationsAnnotationParser.java
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JavaScriptServiceAnnotationParser.java
Modified:
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JSDeployer.java
Log:
Adding operation level & service level java script annotation support as discussed in http://wso2.org/wiki/display/mashup/Generating+WSDL
Modified: trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JSDeployer.java
==============================================================================
--- trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JSDeployer.java (original)
+++ trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JSDeployer.java Mon Mar 26 22:42:10 2007
@@ -75,6 +75,153 @@
private ConfigurationContext configCtx;
+ /**
+ * @param filename
+ * @param axisServiceGroup
+ * @param extractService
+ * @param wsdls
+ * @param configCtx
+ * @return Returns ArrayList.
+ * @throws DeploymentException
+ */
+ public ArrayList processService(DeploymentFileData currentFile,
+ AxisServiceGroup axisServiceGroup, HashMap wsdls, ConfigurationContext configCtx)
+ throws AxisFault {
+ try {
+ String filename = currentFile.getAbsolutePath();
+ File file = new File(filename + ".xml");
+ String serviceName = DescriptionBuilder.getShortFileName(currentFile.getName());
+
+ /*
+ * Service level java script annotations processing
+ */
+ JavaScriptEngine engine = new JavaScriptEngine();
+ FileInputStream fileInputStream;
+ fileInputStream = new FileInputStream(currentFile.getFile());
+ engine.evaluate(new BufferedReader(new InputStreamReader(fileInputStream)));
+ JavaScriptServiceAnnotationParser serviceAnnotationParser = new JavaScriptServiceAnnotationParser(
+ engine, serviceName);
+ if (serviceAnnotationParser.isDisable()){
+ return null;
+ }
+ axisServiceGroup.setServiceGroupName(currentFile.getName());
+ AxisService axisService = null;
+ if (serviceName != null) {
+ axisService = (AxisService) wsdls.get(serviceName);
+ }
+ if (axisService == null) {
+ axisService = new AxisService();
+ }
+ // else {
+ // axisService.setWsdlFound(true);
+ // // axisService.setCustomWsld(true);
+ // }
+ axisService.setParent(axisServiceGroup);
+ axisService.setClassLoader(currentFile.getClassLoader());
+
+ if (file.exists()) {
+ axisService.setName(serviceName);
+ InputStream in = null;
+ try {
+ in = new FileInputStream(file);
+ DescriptionBuilder builder = new DescriptionBuilder(in, configCtx);
+ OMElement rootElement = builder.buildOM();
+ String elementName = rootElement.getLocalName();
+ if (TAG_SERVICE.equals(elementName)) {
+ populateService(axisService, rootElement);
+ } else {
+ throw new AxisFault("Invalid " + currentFile.getAbsolutePath()
+ + ".xml found");
+ }
+ } catch (FileNotFoundException e) {
+ throw new DeploymentException(Messages.getMessage(
+ DeploymentErrorMsgs.FILE_NOT_FOUND, e.getMessage()));
+ } catch (XMLStreamException e) {
+ throw new DeploymentException(Messages.getMessage(
+ DeploymentErrorMsgs.XML_STREAM_EXCEPTION, e.getMessage()));
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ log.info(Messages.getMessage("errorininputstreamclose"));
+ }
+ }
+ }
+ } else {
+ axisService.setName(serviceAnnotationParser.getServiceName());
+ axisService.setTargetNamespace(serviceAnnotationParser.getTargetNamespace());
+
+ // adding name spaces
+ NamespaceMap map = new NamespaceMap();
+ map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX, Java2WSDLConstants.AXIS2_XSD);
+ map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX,
+ Java2WSDLConstants.URI_2001_SCHEMA_XSD);
+ axisService.setNameSpacesMap(map);
+ String schemaTargetNamespace = serviceAnnotationParser.getSchemaTargetNamespace();
+ String schemaString = "<xs:schema targetNamespace=\""
+ + schemaTargetNamespace
+ + "\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">"
+ + " <xs:element name=\"jsParameter\" type=\"jsParamType\"/>"
+ + " <xs:complexType name=\"jsParamType\">" + " <xs:sequence>"
+ + " <xs:element name=\"in\" type=\"xs:anyType\"/>"
+ + " </xs:sequence>" + " </xs:complexType>" + "</xs:schema>";
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StringReader(schemaString), null);
+ axisService.addSchema(schema);
+ QName paramElementQname = new QName(schemaTargetNamespace, "jsParameter");
+
+ Object[] ids = engine.getIds();
+ for (int i = 0; i < ids.length; i++) {
+ String method = (String) ids[i];
+ Object object = engine.get(method, engine);
+ if (object instanceof Function) {
+ Function function = (Function) object;
+ JavaScriptOperationsAnnotationParser annotationParser = new JavaScriptOperationsAnnotationParser(
+ function, method);
+ if (annotationParser.isVisible()) {
+ AxisOperation axisOp = new InOutAxisOperation(new QName(
+ annotationParser.getOperationName()));
+ axisOp.setMessageReceiver(new JavaScriptReceiver());
+ axisOp.setStyle(WSDLConstants.STYLE_DOC);
+ axisService.addOperation(axisOp);
+
+ AxisMessage inMessage = axisOp
+ .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ if (inMessage != null) {
+ inMessage.setName(method + Java2WSDLConstants.MESSAGE_SUFFIX);
+ inMessage.setElementQName(paramElementQname);
+ }
+ AxisMessage outMessage = axisOp
+ .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
+
+ if (outMessage != null) {
+ outMessage.setName(method + Java2WSDLConstants.MESSAGE_SUFFIX);
+ outMessage.setElementQName(paramElementQname);
+ }
+ if (axisOp.getInputAction() == null) {
+ axisOp.setSoapAction("urn:" + method);
+ }
+ axisConfig.getPhasesInfo().setOperationPhases(axisOp);
+ }
+ }
+
+ }
+ }
+ Parameter parameter = new Parameter("ServiceJS", currentFile.getFile());
+ axisService.addParameter(parameter);
+ ArrayList serviceList = new ArrayList();
+ serviceList.add(axisService);
+ return serviceList;
+ } catch (FileNotFoundException e) {
+ throw new DeploymentException("JS Service File Not Found", e);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
// To initialize the deployer
public void init(ConfigurationContext configCtx) {
this.configCtx = configCtx;
@@ -92,10 +239,12 @@
serviceGroup.setServiceGroupClassLoader(deploymentFileData.getClassLoader());
ArrayList serviceList = processService(deploymentFileData, serviceGroup, wsdlservice,
configCtx);
- DeploymentEngine.addServiceGroup(serviceGroup, serviceList, deploymentFileData
- .getFile().toURL(), deploymentFileData, axisConfig);
- log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_WS, deploymentFileData
- .getName()));
+ if (serviceList != null) {
+ DeploymentEngine.addServiceGroup(serviceGroup, serviceList, deploymentFileData
+ .getFile().toURL(), deploymentFileData, axisConfig);
+ log.info(Messages.getMessage(DeploymentErrorMsgs.DEPLOYING_WS, deploymentFileData
+ .getName()));
+ }
} catch (DeploymentException de) {
de.printStackTrace();
log.error(Messages.getMessage(DeploymentErrorMsgs.INVALID_SERVICE, deploymentFileData
@@ -158,140 +307,6 @@
}
/**
- * @param filename
- * @param axisServiceGroup
- * @param extractService
- * @param wsdls
- * @param configCtx
- * @return Returns ArrayList.
- * @throws DeploymentException
- */
- public ArrayList processService(DeploymentFileData currentFile,
- AxisServiceGroup axisServiceGroup, HashMap wsdls, ConfigurationContext configCtx)
- throws AxisFault {
- String filename = currentFile.getAbsolutePath();
- File file = new File(filename + ".xml");
- axisServiceGroup.setServiceGroupName(currentFile.getName());
- AxisService axisService = null;
- String serviceName = DescriptionBuilder.getShortFileName(currentFile.getName());
- if (serviceName != null) {
- axisService = (AxisService) wsdls.get(serviceName);
- }
- if (axisService == null) {
- axisService = new AxisService();
- }
-// else {
-// axisService.setWsdlFound(true);
-//// axisService.setCustomWsld(true);
-// }
- axisService.setName(serviceName);
- axisService.setParent(axisServiceGroup);
- axisService.setClassLoader(currentFile.getClassLoader());
-
- if (file.exists()) {
- InputStream in = null;
- try {
- in = new FileInputStream(file);
- DescriptionBuilder builder = new DescriptionBuilder(in, configCtx);
- OMElement rootElement = builder.buildOM();
- String elementName = rootElement.getLocalName();
- if (TAG_SERVICE.equals(elementName)) {
- populateService(axisService, rootElement);
- } else {
- throw new AxisFault("Invalid " + currentFile.getAbsolutePath() + ".xml found");
- }
- } catch (FileNotFoundException e) {
- throw new DeploymentException(Messages.getMessage(
- DeploymentErrorMsgs.FILE_NOT_FOUND, e.getMessage()));
- } catch (XMLStreamException e) {
- throw new DeploymentException(Messages.getMessage(
- DeploymentErrorMsgs.XML_STREAM_EXCEPTION, e.getMessage()));
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- log.info(Messages.getMessage("errorininputstreamclose"));
- }
- }
- }
- } else {
- try {
- JavaScriptEngine engine = new JavaScriptEngine();
- FileInputStream fileInputStream;
- fileInputStream = new FileInputStream(currentFile.getFile());
- engine.evaluate(new BufferedReader(new InputStreamReader(fileInputStream)));
-
- // adding name spaces
- NamespaceMap map = new NamespaceMap();
- map.put(Java2WSDLConstants.AXIS2_NAMESPACE_PREFIX, Java2WSDLConstants.AXIS2_XSD);
- map.put(Java2WSDLConstants.DEFAULT_SCHEMA_NAMESPACE_PREFIX,
- Java2WSDLConstants.URI_2001_SCHEMA_XSD);
- axisService.setNameSpacesMap(map);
- String schemaTargetNamespace = "http://services.mashup.wso2.org/"+axisService.getName()+"?xsd";
- String schemaString =
- "<xs:schema targetNamespace=\""+schemaTargetNamespace+"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">" +
- " <xs:element name=\"jsParameter\" type=\"jsParamType\"/>"+
- " <xs:complexType name=\"jsParamType\">"+
- " <xs:sequence>"+
- " <xs:element name=\"in\" type=\"xs:anyType\"/>" +
- " </xs:sequence>" +
- " </xs:complexType>" +
- "</xs:schema>";
- XmlSchemaCollection schemaCol = new XmlSchemaCollection();
- XmlSchema schema = schemaCol.read(new StringReader(schemaString), null);
- axisService.addSchema(schema);
- QName paramElementQname = new QName(schemaTargetNamespace,"jsParameter");
-
- Object[] ids = engine.getIds();
- for (int i = 0; i < ids.length; i++) {
- String method = (String) ids[i];
- Object object = engine.get(method, engine);
- if (object instanceof Function) {
- AxisOperation axisOp = new InOutAxisOperation(new QName(method));
- axisOp.setMessageReceiver(new JavaScriptReceiver());
- axisOp.setStyle(WSDLConstants.STYLE_DOC);
- axisService.addOperation(axisOp);
-
- AxisMessage inMessage = axisOp
- .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
- if (inMessage != null) {
- inMessage.setName(method + Java2WSDLConstants.MESSAGE_SUFFIX);
- inMessage.setElementQName(paramElementQname);
- }
- AxisMessage outMessage = axisOp
- .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
-
- if (outMessage != null) {
- outMessage.setName(method + Java2WSDLConstants.MESSAGE_SUFFIX);
- outMessage.setElementQName(paramElementQname);
- }
- if (axisOp.getInputAction() == null) {
- axisOp.setSoapAction("urn:" + method);
- }
- axisConfig.getPhasesInfo().setOperationPhases(axisOp);
- }
-
- }
- } catch (FileNotFoundException e) {
- throw new DeploymentException("JS Service File Not Found", e);
- } catch (IOException e) {
- throw new DeploymentException(e);
- }
-
- }
- Parameter parameter = new Parameter("ServiceJS", currentFile.getFile());
- axisService.addParameter(parameter);
- ArrayList serviceList = new ArrayList();
- serviceList.add(axisService);
- return serviceList;
- }
-
- /***************************************************************************
- * Parts below this deals with Service Descriptor Based Deployment *
- **************************************************************************/
-
- /**
* Populates service from corresponding OM.
*/
public void populateService(AxisService service, OMElement service_element)
Added: trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JavaScriptOperationsAnnotationParser.java
==============================================================================
--- (empty file)
+++ trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JavaScriptOperationsAnnotationParser.java Mon Mar 26 22:42:10 2007
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.javascript.rhino;
+
+import org.mozilla.javascript.Function;
+
+public class JavaScriptOperationsAnnotationParser {
+ private boolean visible = true;
+
+ private String operationName = null;
+
+ public JavaScriptOperationsAnnotationParser(Function function, String functionName) {
+ Object visibleObject = function.get("visible", function);
+ if (visibleObject instanceof Boolean) {
+ visible = ((Boolean) visibleObject).booleanValue();
+ }
+ Object operationNameObject = function.get("operationName", function);
+ if (visibleObject instanceof String) {
+ operationName = (String) operationNameObject;
+ } else {
+ operationName = functionName;
+ }
+ }
+
+ public String getOperationName() {
+ return operationName;
+ }
+
+ public boolean isVisible() {
+ return visible;
+ }
+
+}
Added: trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JavaScriptServiceAnnotationParser.java
==============================================================================
--- (empty file)
+++ trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/javascript/rhino/JavaScriptServiceAnnotationParser.java Mon Mar 26 22:42:10 2007
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.javascript.rhino;
+
+import org.mozilla.javascript.Scriptable;
+
+public class JavaScriptServiceAnnotationParser {
+
+ private String targetNamespace = null;
+
+ private String schemaTargetNamespace = null;
+
+ private boolean disable = false;
+
+ private String serviceName;
+
+ public JavaScriptServiceAnnotationParser(Scriptable service, String serviceName) {
+
+ Object targetNamespaceObject = service.get("targetNamespace", service);
+ if (targetNamespaceObject instanceof String) {
+ targetNamespace = (String) targetNamespaceObject;
+ } else {
+ targetNamespace = "http://services.mashup.wso2.org/" + serviceName;
+ }
+
+ Object schemaTargetNamespaceObject = service.get("schemaTargetNamespace", service);
+ if (schemaTargetNamespaceObject instanceof String) {
+ schemaTargetNamespace = (String) schemaTargetNamespaceObject;
+ } else {
+ schemaTargetNamespace = "http://services.mashup.wso2.org/" + serviceName + "?xsd";
+ }
+
+ Object serviceDisableObject = service.get("disable", service);
+ if (serviceDisableObject instanceof Boolean) {
+ disable = ((Boolean) serviceDisableObject).booleanValue();
+ }
+
+ Object serviceNameObject = service.get("serviceName", service);
+ if (serviceNameObject instanceof String) {
+ this.serviceName = (String) serviceNameObject;
+ } else {
+ this.serviceName = serviceName;
+ }
+ }
+
+ public boolean isDisable() {
+ return disable;
+ }
+
+ public String getSchemaTargetNamespace() {
+ return schemaTargetNamespace;
+ }
+
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+}
More information about the Mashup-dev
mailing list