Author: keith
Date: Thu Apr 24 22:45:33 2008
New Revision: 16130

Log:

Refractoring a couple of methods to smaller methods Mashup-771


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

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 22:45:33 2008
@@ -356,6 +356,9 @@
             // org.wso2.javascript.rhino.JavaScriptReceiver needs this to load 
the javascript file
             // in order to execute the relavant JavaScript function
             File file = currentFile.getFile();
+
+            File resourcesDir = createDefaultFolders(shortFileName, file);
+
             Parameter serviceJSParameter = new 
Parameter(JavaScriptEngineConstants.SERVICE_JS,
                                                          file);
             axisService.addParameter(serviceJSParameter);
@@ -371,19 +374,6 @@
                     new 
Parameter(MashupConstants.QUARTZ_FUNCTION_SCHEDULER_JOB_IDS, new HashMap());
             axisService.addParameter(jobIds);
 
-            // Creating the service.resources dir
-            // 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 + 
MashupConstants.RESOURCES);
-            resourcesDir.mkdir();
-
-            // creating _private folder in the resources folder to keep 
private stuff
-            // This folder can be used to keep information that the user does 
not want to share when
-            // a mashup is shared
-            File privatedir = new File(resourcesDir, 
MashupConstants.MASHUP_PRIVATE_FOLDER_NAME);
-            privatedir.mkdir();
-
             // Add a reference to the resources folder, as this is quite 
usefull in the runtime
             Parameter resourceFolderParameter = new Parameter(
                     JavaScriptEngineConstants.RESOURCES_FOLDER, resourcesDir);
@@ -469,32 +459,6 @@
             // control of the Axis2 binding hierarchy cause we need to speficy 
some HTTPBinding
             // properties such as httpMethod and httpLocation
 
-            // Create a default SOAP 1.1 Binding
-            soap11Binding = new AxisBinding();
-            soap11Binding.setName(new QName(name + 
Java2WSDLConstants.BINDING_NAME_SUFFIX));
-            soap11Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
-            soap11Binding
-                    .setProperty(WSDL2Constants.ATTR_WSOAP_PROTOCOL, 
WSDL2Constants.HTTP_PROTOCAL);
-            soap11Binding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
-                                      
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            soap11Binding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
-
-            // Create a default SOAP 1.2 Binding
-            soap12Binding = new AxisBinding();
-            soap12Binding.setName(new QName(name + 
Java2WSDLConstants.SOAP12BINDING_NAME_SUFFIX));
-            soap12Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
-            soap12Binding
-                    .setProperty(WSDL2Constants.ATTR_WSOAP_PROTOCOL, 
WSDL2Constants.HTTP_PROTOCAL);
-            soap12Binding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
-                                      
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            soap12Binding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
-
-            // Create a default HTTP Binding
-            httpBinding = new AxisBinding();
-            httpBinding.setName(new QName(name + 
Java2WSDLConstants.HTTP_BINDING));
-            httpBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
-            httpBinding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
-
             // Set a comparator so tha httpLocations are stored in decending 
order. We want the
             // HTTPLocationBasedDiapatcher to make the best match hence we 
need them in decending
             // order
@@ -504,65 +468,18 @@
                 }
             });
 
-            // Add this map to all bindings
-            httpBinding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
-            soap11Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
-            soap12Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+            // Create a default SOAP 1.1 Binding
+            createDefaultSOAP11Binding(name, interfaceName);
+
+            // Create a default SOAP 1.2 Binding
+            createDefaultSOAP12Binding(name, interfaceName);
+
+            // Create a default HTTP Binding
+            createDefaultHTTPBinding(name, interfaceName);
 
             // We need to get all transports from the axis2 engine and create 
endpoints for each of
             // those in here.
-            HashMap transportsIn = axisConfig.getTransportsIn();
-            Iterator iterator = transportsIn.values().iterator();
-            while (iterator.hasNext()) {
-                // Used to indicate whather a HTTPEndpoint is needed. Http 
endpoint is needed only
-                // for http and https transports
-                boolean needHttp = false;
-
-                // The prefix is used to genarate endpoint names
-                String prefix = "";
-                TransportInDescription transportIn = (TransportInDescription) 
iterator.next();
-                String transportInName = transportIn.getName();
-                if (HTTP_TRANSPORT.equalsIgnoreCase(transportInName)) {
-                    needHttp = true;
-                } else if (HTTPS_TRANSPORT.equalsIgnoreCase(transportInName)) {
-                    needHttp = true;
-                    prefix = WSDL2Constants.DEFAULT_HTTPS_PREFIX;
-                } else if (transportInName != null) {
-                    prefix = transportInName.toUpperCase();
-                }
-
-                // Creates a default SOAP 1.1 endpoint
-                AxisEndpoint soap11Endpoint = new AxisEndpoint();
-                String soap11EndpointName =
-                        prefix + WSDL2Constants.DEFAULT_SOAP11_ENDPOINT_NAME;
-                soap11Endpoint.setName(soap11EndpointName);
-                soap11Endpoint.setBinding(soap11Binding);
-                soap11Endpoint.setParent(axisService);
-                soap11Endpoint.setTransportInDescription(transportInName);
-                axisService.addEndpoint(soap11EndpointName, soap11Endpoint);
-
-                // Creates a default SOAP 1.2 endpoint
-                AxisEndpoint soap12Endpoint = new AxisEndpoint();
-                String soap12EndpointName =
-                        prefix + WSDL2Constants.DEFAULT_SOAP12_ENDPOINT_NAME;
-                soap12Endpoint.setName(soap12EndpointName);
-                soap12Endpoint.setBinding(soap12Binding);
-                soap12Endpoint.setParent(axisService);
-                soap12Endpoint.setTransportInDescription(transportInName);
-                axisService.addEndpoint(soap12EndpointName, soap12Endpoint);
-
-                // Creates a HTTP endpoint if its http or https transport is 
used
-                if (needHttp) {
-                    AxisEndpoint httpEndpoint = new AxisEndpoint();
-                    String httpEndpointName =
-                            prefix + WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME;
-                    httpEndpoint.setName(httpEndpointName);
-                    httpEndpoint.setBinding(httpBinding);
-                    httpEndpoint.setParent(axisService);
-                    httpEndpoint.setTransportInDescription(transportInName);
-                    axisService.addEndpoint(httpEndpointName, httpEndpoint);
-                }
-            }
+            createDefaultEndpoints(axisService);
 
             // Obtain the list of functions in the java script service and 
process each one of them.
             Object[] ids = engine.getIds();
@@ -663,6 +580,109 @@
         }
     }
 
+    private void createDefaultEndpoints(AxisService axisService) {
+        HashMap transportsIn = axisConfig.getTransportsIn();
+        Iterator iterator = transportsIn.values().iterator();
+        while (iterator.hasNext()) {
+            // Used to indicate whather a HTTPEndpoint is needed. Http 
endpoint is needed only
+            // for http and https transports
+            boolean needHttp = false;
+
+            // The prefix is used to genarate endpoint names
+            String prefix = "";
+            TransportInDescription transportIn = (TransportInDescription) 
iterator.next();
+            String transportInName = transportIn.getName();
+            if (HTTP_TRANSPORT.equalsIgnoreCase(transportInName)) {
+                needHttp = true;
+            } else if (HTTPS_TRANSPORT.equalsIgnoreCase(transportInName)) {
+                needHttp = true;
+                prefix = WSDL2Constants.DEFAULT_HTTPS_PREFIX;
+            } else if (transportInName != null) {
+                prefix = transportInName.toUpperCase();
+            }
+
+            // Creates a default SOAP 1.1 endpoint
+            AxisEndpoint soap11Endpoint = new AxisEndpoint();
+            String soap11EndpointName =
+                    prefix + WSDL2Constants.DEFAULT_SOAP11_ENDPOINT_NAME;
+            soap11Endpoint.setName(soap11EndpointName);
+            soap11Endpoint.setBinding(soap11Binding);
+            soap11Endpoint.setParent(axisService);
+            soap11Endpoint.setTransportInDescription(transportInName);
+            axisService.addEndpoint(soap11EndpointName, soap11Endpoint);
+
+            // Creates a default SOAP 1.2 endpoint
+            AxisEndpoint soap12Endpoint = new AxisEndpoint();
+            String soap12EndpointName =
+                    prefix + WSDL2Constants.DEFAULT_SOAP12_ENDPOINT_NAME;
+            soap12Endpoint.setName(soap12EndpointName);
+            soap12Endpoint.setBinding(soap12Binding);
+            soap12Endpoint.setParent(axisService);
+            soap12Endpoint.setTransportInDescription(transportInName);
+            axisService.addEndpoint(soap12EndpointName, soap12Endpoint);
+
+            // Creates a HTTP endpoint if its http or https transport is used
+            if (needHttp) {
+                AxisEndpoint httpEndpoint = new AxisEndpoint();
+                String httpEndpointName =
+                        prefix + WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME;
+                httpEndpoint.setName(httpEndpointName);
+                httpEndpoint.setBinding(httpBinding);
+                httpEndpoint.setParent(axisService);
+                httpEndpoint.setTransportInDescription(transportInName);
+                axisService.addEndpoint(httpEndpointName, httpEndpoint);
+            }
+        }
+    }
+
+    private void createDefaultHTTPBinding(String name, String interfaceName) {
+        httpBinding = new AxisBinding();
+        httpBinding.setName(new QName(name + Java2WSDLConstants.HTTP_BINDING));
+        httpBinding.setType(WSDL2Constants.URI_WSDL2_HTTP);
+        httpBinding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
+        httpBinding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+    }
+
+    private void createDefaultSOAP12Binding(String name, String interfaceName) 
{
+        soap12Binding = new AxisBinding();
+        soap12Binding.setName(new QName(name + 
Java2WSDLConstants.SOAP12BINDING_NAME_SUFFIX));
+        soap12Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
+        soap12Binding
+                    .setProperty(WSDL2Constants.ATTR_WSOAP_PROTOCOL, 
WSDL2Constants.HTTP_PROTOCAL);
+        soap12Binding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
+                                      
SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        soap12Binding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
+        soap12Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+    }
+
+    private void createDefaultSOAP11Binding(String name, String interfaceName) 
{
+        soap11Binding = new AxisBinding();
+        soap11Binding.setName(new QName(name + 
Java2WSDLConstants.BINDING_NAME_SUFFIX));
+        soap11Binding.setType(WSDL2Constants.URI_WSDL2_SOAP);
+        soap11Binding
+                    .setProperty(WSDL2Constants.ATTR_WSOAP_PROTOCOL, 
WSDL2Constants.HTTP_PROTOCAL);
+        soap11Binding.setProperty(WSDL2Constants.ATTR_WSOAP_VERSION,
+                                      
SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        soap11Binding.setProperty(WSDL2Constants.INTERFACE_LOCAL_NAME, 
interfaceName);
+        soap11Binding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, 
httpLocationTable);
+    }
+
+    private File createDefaultFolders(String shortFileName, File file) {
+        // Creating the service.resources dir
+        // 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 + 
MashupConstants.RESOURCES);
+        resourcesDir.mkdir();
+
+        // creating _private folder in the resources folder to keep private 
stuff
+        // This folder can be used to keep information that the user does not 
want to share when
+        // a mashup is shared
+        File privatedir = new File(resourcesDir, 
MashupConstants.MASHUP_PRIVATE_FOLDER_NAME);
+        privatedir.mkdir();
+        return resourcesDir;
+    }
+
     //processing the a function present in the deploying javascript file.
     private void processOperation(JavaScriptEngine engine, AxisService 
axisService, String method,
                                   Function function, SchemaGenerator 
schemaGenerator,
@@ -718,40 +738,6 @@
                         "annotation as) " + name + " already exists. ");
             }
 
-            // In here we inject a special function into the JavaScript 
service that helps us
-            // convert a function to a string and get the full string 
corresponding to that
-            // function. We need that to get the order of the parameter names 
in that function.
-            // Rhino does not preserve the order of parameters as they are 
held in a map
-            String sourceStr = "function org_wso2_mashup_ConvertToString(){ " 
+ "var code = " +
-                    oriMethodName + ".toString();" + "return code;}";
-            engine.getCx().evaluateString(engine, sourceStr, "", 0, null);
-
-            // Get the function from the scope the javascript object is in
-            Object fObj = engine.get("org_wso2_mashup_ConvertToString", 
engine);
-            if (!(fObj instanceof Function) || (fObj == Scriptable.NOT_FOUND)) 
{
-                throw new DeploymentException("Method " + 
"org_wso2_mashup_ConvertToString"
-                        + " is undefined or not a function");
-            }
-
-            Object functionArgs[] = { };
-            Function f = (Function) fObj;
-
-            // Execute our org_wso2_mashup_ConvertToString function and get 
the function a string
-            Object args = f.call(engine.getCx(), engine, engine, functionArgs);
-            String[] params = null;
-            if (args instanceof String) {
-                String functionString = (String) args;
-                int paramStartIndex = functionString.indexOf('(');
-                int paramEndIndex = functionString.indexOf(')');
-
-                // Get the parameters of the function as a string. Parameters 
are always enclosed
-                // using braces
-                String paramString = functionString.substring(paramStartIndex 
+ 1, paramEndIndex);
-
-                // Get the paramer names by splitting them using ","
-                params = paramString.split(",");
-            }
-
             // We always assume that our operations are inout operations
             AxisOperation axisOp = new InOutAxisOperation(new QName(name));
 
@@ -781,38 +767,6 @@
                 }
             }
 
-            // Create a default SOAP 1.1 Binding operation
-            AxisBindingOperation soap11BindingOperation = new 
AxisBindingOperation();
-            soap11BindingOperation.setAxisOperation(axisOp);
-            soap11BindingOperation.setName(axisOp.getName());
-            soap11BindingOperation.setParent(soap11Binding);
-            
soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
-
-            // Create a default SOAP 1.2 Binding operation
-            AxisBindingOperation soap12BindingOperation = new 
AxisBindingOperation();
-            soap12BindingOperation.setAxisOperation(axisOp);
-            soap12BindingOperation.setName(axisOp.getName());
-            soap12BindingOperation.setParent(soap12Binding);
-            
soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
-
-            // Create a default HTTP Binding operation
-            AxisBindingOperation httpBindingOperation = new 
AxisBindingOperation();
-            httpBindingOperation.setAxisOperation(axisOp);
-            httpBindingOperation.setName(axisOp.getName());
-            httpBindingOperation.setParent(httpBinding);
-            
httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
-            httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, 
httpMethod);
-
-            // We need to extract a constant value from the httpLocation so 
that the
-            // httpLocationBasedDispatcher can use that value to dispatch to 
the correct operation
-            String httpLocationString =
-                    RESTUtil.getConstantFromHTTPLocation(httpLocation, 
httpMethod);
-            httpLocationTable.put(httpLocationString, axisOp);
-
-            soap11Binding.addChild(soap11BindingOperation.getName(), 
soap11BindingOperation);
-            soap12Binding.addChild(soap12BindingOperation.getName(), 
soap12BindingOperation);
-            httpBinding.addChild(httpBindingOperation.getName(), 
httpBindingOperation);
-
             if (!targetNamespace.endsWith(MashupConstants.FORWARD_SLASH)) {
                 targetNamespace = targetNamespace + 
MashupConstants.FORWARD_SLASH;
             }
@@ -826,10 +780,27 @@
                     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);
             axisOp.setOutputAction(outAction);
 
+            // Create a default SOAP 1.1 Binding operation
+            AxisBindingOperation soap11BindingOperation =
+                    createDefaultSOAP11BindingOperation(axisOp, httpLocation, 
inputAction);
+
+            // Create a default SOAP 1.2 Binding operation
+            AxisBindingOperation soap12BindingOperation =
+                    createDefaultSOAP12BindingOperation(axisOp, httpLocation, 
inputAction);
+
+            // Create a default HTTP Binding operation
+            AxisBindingOperation httpBindingOperation =
+                    createDefaultHTTPBindingOperation(axisOp, httpLocation, 
httpMethod);
+
+
+            // We need to extract a constant value from the httpLocation so 
that the
+            // httpLocationBasedDispatcher can use that value to dispatch to 
the correct operation
+            String httpLocationString =
+                    RESTUtil.getConstantFromHTTPLocation(httpLocation, 
httpMethod);
+            httpLocationTable.put(httpLocationString, axisOp);
+
             //set the org.wso2.javascript.rhino.JavaScriptReceiver as the 
MessageReceiver for this
             // operation
             axisOp.setMessageReceiver(new JavaScriptReceiver());
@@ -845,20 +816,17 @@
                     JavaScriptEngineConstants.JS_FUNCTION_NAME, oriMethodName);
             axisOp.addParameter(jsFunctionNameParamter);
 
+            String[] params = extractInputParameters(engine, oriMethodName);
+
             // Create the in and out axis messages for this operation
             AxisMessage inMessage = 
axisOp.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
-            Object inputTypes = annotationParser.getInputTypesNameObject();
+
             if (inMessage != null) {
+                Object inputTypes = annotationParser.getInputTypesNameObject();
                 inMessage.setName(method + Java2WSDLConstants.MESSAGE_SUFFIX);
                 AxisBindingMessage inBindingMessage = new AxisBindingMessage();
                 inBindingMessage.setName(inMessage.getName());
                 inBindingMessage.setAxisMessage(inMessage);
-                soap11BindingOperation
-                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
inBindingMessage);
-                soap12BindingOperation
-                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
inBindingMessage);
-                httpBindingOperation
-                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
inBindingMessage);
 
                 // Genarate the input element for the input message using the 
"inputTypes'
                 // annotation specified by the user
@@ -868,24 +836,25 @@
                 if (element != null) {
                     inMessage.setElementQName(new QName(schemaTargetNamespace, 
element.getName()));
                 }
+
+                soap11BindingOperation
+                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
inBindingMessage);
+                soap12BindingOperation
+                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
inBindingMessage);
+                httpBindingOperation
+                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
inBindingMessage);
             }
 
             AxisMessage outMessage = 
axisOp.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
             Object outputType = annotationParser.getOutputTypeNameObject();
+            params = new String[1];
+            params[0] = "return";
 
             if (outMessage != null) {
-                params = new String[1];
-                params[0] = "return";
                 outMessage.setName(method + 
Java2WSDLConstants.RESPONSE_MESSAGE);
                 AxisBindingMessage outBindingMessage = new 
AxisBindingMessage();
                 outBindingMessage.setName(outMessage.getName());
-                outBindingMessage.setAxisMessage(inMessage);
-                soap11BindingOperation
-                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
outBindingMessage);
-                soap12BindingOperation
-                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
outBindingMessage);
-                httpBindingOperation
-                        .addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, 
outBindingMessage);
+                outBindingMessage.setAxisMessage(outMessage);
 
                 // Genarate the output element for the input message using the 
"outputType'
                 // annotation specified by the user
@@ -895,9 +864,92 @@
                 if (element != null) {
                     outMessage.setElementQName(new 
QName(schemaTargetNamespace, element.getName()));
                 }
+                soap11BindingOperation
+                        .addChild(WSDLConstants.MESSAGE_LABEL_OUT_VALUE, 
outBindingMessage);
+                soap12BindingOperation
+                        .addChild(WSDLConstants.MESSAGE_LABEL_OUT_VALUE, 
outBindingMessage);
+                httpBindingOperation
+                        .addChild(WSDLConstants.MESSAGE_LABEL_OUT_VALUE, 
outBindingMessage);                 
             }
             axisService.addOperation(axisOp);
             axisConfig.getPhasesInfo().setOperationPhases(axisOp);
         }
     }
+
+    private String[] extractInputParameters(JavaScriptEngine engine, String 
oriMethodName)
+            throws DeploymentException {
+        // In here we inject a special function into the JavaScript service 
that helps us
+        // convert a function to a string and get the full string 
corresponding to that
+        // function. We need that to get the order of the parameter names in 
that function.
+        // Rhino does not preserve the order of parameters as they are held in 
a map
+        String sourceStr = "function org_wso2_mashup_ConvertToString(){ " + 
"var code = " +
+                oriMethodName + ".toString();" + "return code;}";
+        engine.getCx().evaluateString(engine, sourceStr, "", 0, null);
+
+        // Get the function from the scope the javascript object is in
+        Object fObj = engine.get("org_wso2_mashup_ConvertToString", engine);
+        if (!(fObj instanceof Function) || (fObj == Scriptable.NOT_FOUND)) {
+            throw new DeploymentException("Method " + 
"org_wso2_mashup_ConvertToString"
+                    + " is undefined or not a function");
+        }
+
+        Object functionArgs[] = { };
+        Function f = (Function) fObj;
+
+        // Execute our org_wso2_mashup_ConvertToString function and get the 
function a string
+        Object args = f.call(engine.getCx(), engine, engine, functionArgs);
+        String[] params = null;
+        if (args instanceof String) {
+            String functionString = (String) args;
+            int paramStartIndex = functionString.indexOf('(');
+            int paramEndIndex = functionString.indexOf(')');
+
+            // Get the parameters of the function as a string. Parameters are 
always enclosed
+            // using braces
+            String paramString = functionString.substring(paramStartIndex + 1, 
paramEndIndex);
+
+            // Get the paramer names by splitting them using ","
+            params = paramString.split(",");
+        }
+        return params;
+    }
+
+    private AxisBindingOperation 
createDefaultHTTPBindingOperation(AxisOperation axisOp,
+                                                                   String 
httpLocation,
+                                                                   String 
httpMethod) {
+        AxisBindingOperation httpBindingOperation = new AxisBindingOperation();
+        httpBindingOperation.setAxisOperation(axisOp);
+        httpBindingOperation.setName(axisOp.getName());
+        httpBindingOperation.setParent(httpBinding);
+        httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
+        httpBindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_METHOD, 
httpMethod);
+        httpBinding.addChild(httpBindingOperation.getName(), 
httpBindingOperation);
+        return httpBindingOperation;
+    }
+
+    private AxisBindingOperation 
createDefaultSOAP12BindingOperation(AxisOperation axisOp,
+                                                                     String 
httpLocation,
+                                                                     String 
inputAction) {
+        AxisBindingOperation soap12BindingOperation = new 
AxisBindingOperation();
+        soap12BindingOperation.setAxisOperation(axisOp);
+        soap12BindingOperation.setName(axisOp.getName());
+        soap12BindingOperation.setParent(soap12Binding);
+        soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
+        soap12Binding.addChild(soap12BindingOperation.getName(), 
soap12BindingOperation);
+        soap12BindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, 
inputAction);
+        return soap12BindingOperation;
+    }
+
+    private AxisBindingOperation 
createDefaultSOAP11BindingOperation(AxisOperation axisOp,
+                                                                     String 
httpLocation,
+                                                                     String 
inputAction) {
+        AxisBindingOperation soap11BindingOperation = new 
AxisBindingOperation();
+        soap11BindingOperation.setAxisOperation(axisOp);
+        soap11BindingOperation.setName(axisOp.getName());
+        soap11BindingOperation.setParent(soap11Binding);
+        soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
httpLocation);
+        soap11Binding.addChild(soap11BindingOperation.getName(), 
soap11BindingOperation);
+        soap11BindingOperation.setProperty(WSDL2Constants.ATTR_WSOAP_ACTION, 
inputAction);
+        return soap11BindingOperation;
+    }
 }
\ No newline at end of file

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

Reply via email to