You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/06/03 20:55:58 UTC

svn commit: r543962 - in /incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script: ScriptImplementation.java ScriptInvoker.java

Author: antelder
Date: Sun Jun  3 11:55:57 2007
New Revision: 543962

URL: http://svn.apache.org/viewvc?view=rev&rev=543962
Log:
Add missing classes

Added:
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java   (with props)
    incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java   (with props)

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java?view=auto&rev=543962
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java Sun Jun  3 11:55:57 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.tuscany.sca.implementation.script;
+
+import org.apache.tuscany.sca.spi.utils.DynamicImplementation;
+import org.apache.tuscany.sca.spi.utils.ResourceHelper;
+
+/**
+ * Represents a Script implementation.
+ */
+public class ScriptImplementation extends DynamicImplementation {
+
+    protected String scriptName;
+    protected String scriptSrc;
+    protected String scriptLanguage;
+
+    public void setScript(String scriptName) {
+        this.scriptName = scriptName;
+
+        // TODO: hack so the .componentType side file is found. how to do this?
+        setURI(Thread.currentThread().getContextClassLoader().getResource(scriptName).toString());
+    }
+
+    public void setLanguage(String language) {
+        this.scriptLanguage = language;
+    }
+
+    public void setElementText(String elementText) {
+        scriptSrc = elementText;
+    }
+
+    public String getScriptName() {
+        return scriptName;
+    }
+
+    public String getScriptLanguage() {
+        if (scriptLanguage == null || scriptLanguage.length() < 1) {
+            int i = scriptName.lastIndexOf('.');
+            if (i > 0) {
+                scriptLanguage = scriptName.substring(i + 1);
+            }
+        }
+        return scriptLanguage;
+    }
+
+    public String getScriptSrc() {
+        if (scriptSrc == null) {
+            if (scriptName == null) {
+                throw new IllegalArgumentException("script name is null and no inline source used");
+            }
+
+            // TODO: how should resources be read? Soould this use the contrabution sevrice?
+            scriptSrc = ResourceHelper.readResource(scriptName);
+        }
+        return scriptSrc;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java?view=auto&rev=543962
==============================================================================
--- incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java (added)
+++ incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java Sun Jun  3 11:55:57 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.tuscany.sca.implementation.script;
+
+import javax.script.Invocable;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.bsf.xml.XMLHelper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Perform the actual script invocation
+ */
+public class ScriptInvoker implements Invoker {
+
+    protected ScriptEngine scriptEngine;
+    protected XMLHelper xmlHelper;
+    protected Operation operation;
+
+    public ScriptInvoker(ScriptEngine scriptEngine, XMLHelper xmlHelper, Operation operation) {
+        this.scriptEngine = scriptEngine;
+        this.xmlHelper = xmlHelper;
+        this.operation = operation;
+    }
+
+    protected Object doInvoke(Object[] objects) throws ScriptException {
+        if (xmlHelper != null) {
+            objects[0] = xmlHelper.toScriptXML((OMElement)objects[0]);
+        }
+
+        Object response = ((Invocable)scriptEngine).invokeFunction(operation.getName(), objects);
+
+        if (xmlHelper != null) {
+            response = xmlHelper.toOMElement(response);
+        }
+
+        return response;
+    }
+
+    public Message invoke(Message msg) {
+        try {
+            Object resp = doInvoke((Object[])msg.getBody());
+            msg.setBody(resp);
+        } catch (ScriptException e) {
+            msg.setFaultBody(e.getCause());
+        }
+        return msg;
+    }
+
+}

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org