summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly')
-rw-r--r--sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java28
-rw-r--r--sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java34
-rw-r--r--sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java33
-rw-r--r--sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java116
4 files changed, 211 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java
new file mode 100644
index 0000000000..0072bcdaa1
--- /dev/null
+++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptAssemblyFactory.java
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.apache.tuscany.container.js.assembly;
+
+import org.apache.tuscany.model.assembly.AssemblyFactory;
+
+public interface JavaScriptAssemblyFactory extends AssemblyFactory {
+
+ /**
+ * Returns a new object of class '<em>JavaScript Implementation</em>'.
+ */
+ JavaScriptImplementation createJavaScriptImplementation();
+
+}
diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java
new file mode 100644
index 0000000000..6edaf2b60a
--- /dev/null
+++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/JavaScriptImplementation.java
@@ -0,0 +1,34 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.apache.tuscany.container.js.assembly;
+
+import org.apache.tuscany.common.resource.ResourceLoader;
+import org.apache.tuscany.model.assembly.ComponentImplementation;
+
+/**
+ * A representation of a JavaScript component implementation type
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaScriptImplementation extends ComponentImplementation {
+
+ public ResourceLoader getResourceLoader();
+
+ public String getScriptFile();
+
+ public void setScriptFile(String fn);
+}
diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java
new file mode 100644
index 0000000000..21930d22ec
--- /dev/null
+++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptAssemblyFactoryImpl.java
@@ -0,0 +1,33 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.apache.tuscany.container.js.assembly.impl;
+
+import org.apache.tuscany.container.js.assembly.JavaScriptAssemblyFactory;
+import org.apache.tuscany.container.js.assembly.JavaScriptImplementation;
+import org.apache.tuscany.model.assembly.impl.AssemblyFactoryImpl;
+
+public class JavaScriptAssemblyFactoryImpl extends AssemblyFactoryImpl implements JavaScriptAssemblyFactory {
+
+ public JavaScriptAssemblyFactoryImpl() {
+ super();
+ }
+
+ public JavaScriptImplementation createJavaScriptImplementation() {
+ return new JavaScriptImplementationImpl();
+ }
+
+}
diff --git a/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java
new file mode 100644
index 0000000000..c6b58a25c6
--- /dev/null
+++ b/sca-java-1.x/tags/java-stable-20060304/sca/container.js/src/main/java/org/apache/tuscany/container/js/assembly/impl/JavaScriptImplementationImpl.java
@@ -0,0 +1,116 @@
+package org.apache.tuscany.container.js.assembly.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.tuscany.common.resource.ResourceLoader;
+import org.apache.tuscany.container.js.assembly.JavaScriptImplementation;
+import org.apache.tuscany.model.assembly.AssemblyModelContext;
+import org.apache.tuscany.model.assembly.ComponentType;
+import org.apache.tuscany.model.assembly.ModelInitException;
+import org.apache.tuscany.model.assembly.impl.ComponentImplementationImpl;
+
+/**
+ * Default implementation of a JavScript component implementation type
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaScriptImplementationImpl extends ComponentImplementationImpl implements JavaScriptImplementation {
+
+ private ResourceLoader resourceLoader;
+
+ public JavaScriptImplementationImpl() {
+ super();
+ }
+
+ public ResourceLoader getResourceLoader() {
+ return null;
+ }
+
+ public void initialize(AssemblyModelContext modelContext) throws ModelInitException {
+ if (isInitialized()) {
+ return;
+ }
+ this.resourceLoader = modelContext.getApplicationResourceLoader();
+ if(resourceLoader == null){
+ throw new ModelInitException("No resource loader set on model context");
+ }
+ getScriptFile();
+
+ // Initialize the component type
+ ComponentType componentType = getComponentType();
+ if (componentType == null) {
+ try {
+ componentType = createComponentType(modelContext);
+ } catch (IOException e) {
+ throw new ModelInitException("Error retrieving component type file",e);
+ }
+ setComponentType(componentType);
+ }
+
+ super.initialize(modelContext);
+
+ }
+
+ String script;
+
+ public String getScriptFile() {
+ return script;
+ }
+
+ public void setScriptFile(String fn) {
+ script = fn;
+ }
+
+ private String scriptCode;
+
+ public String getScript() throws ModelInitException {
+ if (scriptCode != null) {
+ return scriptCode;
+ }
+ try {
+ URL url = resourceLoader.getResource(getScriptFile());
+ if (url == null) {
+ ModelInitException ce = new ModelInitException("Script not found");
+ ce.setIdentifier(getScriptFile());
+ throw ce;
+ }
+ InputStream inputStream = url.openStream();
+ try {
+ StringBuffer sb = new StringBuffer();
+ int n = 0;
+ while ((n = inputStream.read()) != -1) {
+ sb.append((char) n);
+ }
+ scriptCode = sb.toString();
+ return scriptCode;
+ } finally {
+ inputStream.close();
+ }
+ } catch (IOException e) {
+ ModelInitException ce = new ModelInitException("Error reading script file",e);
+ ce.setIdentifier(getScriptFile());
+ throw ce;
+ }
+ }
+
+ /**
+ * Create the component type
+ *
+ * @param modelContext
+ * @param implementationClass
+ */
+ private ComponentType createComponentType(AssemblyModelContext modelContext) throws IOException{
+ String prefix = script.substring(0,script.lastIndexOf('.'));
+ URL componentTypeFile = resourceLoader.getResource(prefix + ".componentType");
+ if (componentTypeFile != null) {
+ return modelContext.getAssemblyLoader().loadComponentType(componentTypeFile.toString());
+ } else {
+ // TODO we could introspect the JavaScript source
+ return modelContext.getAssemblyFactory().createComponentType();
+ }
+ }
+
+
+}