summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-04-03 08:18:49 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-04-03 08:18:49 +0000
commite416b6615af1bc2b2e52dc34b7bda7421b054de2 (patch)
treeb6aa9f8f1990961bd5fcbbc1a74c87dbb262216c /branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany
parent1f915fbf92c34559d73c5ee3d36b5239ab75c4c2 (diff)
TUSCANY-2878 - JavaScript Generator extension point. Used by implementation.widget to allow multiple implementations of js generator (e.g. tuscany specific and dojo based)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@761561 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGenerator.java59
-rw-r--r--branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGeneratorExtensionPoint.java56
-rw-r--r--branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/DefaultComponentJavaScriptGeneratorExtensionPoint.java148
3 files changed, 263 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGenerator.java b/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGenerator.java
new file mode 100644
index 0000000000..2f9ba42bc4
--- /dev/null
+++ b/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGenerator.java
@@ -0,0 +1,59 @@
+/*
+ * 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.core.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+
+/**
+ * Widget component script generator interface
+ * This generates the necessary JavaScript client code into a single JavaScript per component
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentJavaScriptGenerator {
+
+ /**
+ * Return the QName that identify the Component script generator
+ * This is used to identify different generators supporting different JavaScript frameworks
+ *
+ * @return The QName
+ */
+ QName getQName();
+
+ /**
+ * Generate the Java Script code for a given component
+ * - generate/append client proxyies as needed
+ * - generate tuscany namespace as needed
+ * - generate properties for JavaScript injection
+ * - generate references for JavaScript injection
+ *
+ * @param component The SCA Component to be used
+ * @param pw A Print Writer where the script should be written to
+ * @throws IOException
+ */
+ void generateJavaScriptCode(RuntimeComponent component, PrintWriter pw) throws IOException;
+
+}
diff --git a/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGeneratorExtensionPoint.java b/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGeneratorExtensionPoint.java
new file mode 100644
index 0000000000..c2cba59362
--- /dev/null
+++ b/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/ComponentJavaScriptGeneratorExtensionPoint.java
@@ -0,0 +1,56 @@
+/*
+ * 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.core.web;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Widget component script generator extension pointinterface
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentJavaScriptGeneratorExtensionPoint {
+
+ /**
+ * Add a component script generator
+ * @param componentScriptGenerator
+ */
+ void addComponentJavaScriptGenerator(ComponentJavaScriptGenerator componentScriptGenerator);
+
+ /**
+ * Remove a component script generator
+ * @param componentScriptGenerator
+ */
+ void removeComponentJavaScriptGenerator(ComponentJavaScriptGenerator componentScriptGenerator);
+
+ /**
+ * Get a component scrpt generator instance based on QName
+ * @param bindingName
+ * @return
+ */
+ ComponentJavaScriptGenerator getComponentJavaScriptGenerator(QName bindingName);
+
+ /**
+ * Get a list of component script generator instances
+ */
+ List<ComponentJavaScriptGenerator> getComponentJavaScriptGenerators();
+}
diff --git a/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/DefaultComponentJavaScriptGeneratorExtensionPoint.java b/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/DefaultComponentJavaScriptGeneratorExtensionPoint.java
new file mode 100644
index 0000000000..85b1a7aead
--- /dev/null
+++ b/branches/sca-java-1.x/modules/core-web/src/main/java/org/apache/tuscany/sca/core/web/DefaultComponentJavaScriptGeneratorExtensionPoint.java
@@ -0,0 +1,148 @@
+/*
+ * 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.core.web;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+public class DefaultComponentJavaScriptGeneratorExtensionPoint implements ComponentJavaScriptGeneratorExtensionPoint {
+ private final List<ComponentJavaScriptGenerator> generators = new ArrayList<ComponentJavaScriptGenerator>();
+ private final Map<QName, ComponentJavaScriptGenerator> generatorsByQName = new HashMap<QName, ComponentJavaScriptGenerator>();
+
+ private ExtensionPointRegistry extensionPoints;
+ private Monitor monitor = null;
+
+ private boolean loaded = false;
+
+ public DefaultComponentJavaScriptGeneratorExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ if (monitorFactory != null) {
+ this.monitor = monitorFactory.createMonitor();
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "core-web-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public void addComponentJavaScriptGenerator(ComponentJavaScriptGenerator componentScriptGenerator) {
+ if (componentScriptGenerator.getQName() != null) {
+ generatorsByQName.put(componentScriptGenerator.getQName(), componentScriptGenerator);
+ }
+
+ generators.add(componentScriptGenerator);
+ }
+
+ public void removeComponentJavaScriptGenerator(ComponentJavaScriptGenerator componentScriptGenerator) {
+ if (componentScriptGenerator.getQName() != null) {
+ generatorsByQName.remove(componentScriptGenerator.getQName());
+ }
+
+ generators.remove(componentScriptGenerator);
+ }
+
+
+ public ComponentJavaScriptGenerator getComponentJavaScriptGenerator(QName bindingName) {
+ loadFacories();
+ return generatorsByQName.get(bindingName);
+ }
+
+ public List<ComponentJavaScriptGenerator> getComponentJavaScriptGenerators() {
+ loadFacories();
+ return this.generators;
+ }
+
+ /**
+ * Private Utility methods
+ */
+
+
+ /**
+ * Lazily load artifact processors registered in the extension point.
+ */
+ @SuppressWarnings("unchecked")
+ private synchronized void loadFacories() {
+ if (loaded) {
+ return;
+ }
+
+ // Get the proxy factories declarations
+ Set<ServiceDeclaration> factoryDeclarations = null;
+ try {
+ factoryDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ComponentJavaScriptGenerator.class);
+ } catch (IOException e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", factoryDeclarations, ie);
+ throw ie;
+ }
+
+ for (ServiceDeclaration processorDeclaration : factoryDeclarations) {
+ // Create a factory, and register it
+ ComponentJavaScriptGenerator generator = null;
+ try {
+ Class generatorClass = processorDeclaration.loadClass();
+
+ Constructor<ComponentJavaScriptGenerator> constructor = generatorClass.getConstructor(ExtensionPointRegistry.class);
+ generator = constructor.newInstance(extensionPoints);
+
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", generator, ie);
+ throw ie;
+ }
+
+ addComponentJavaScriptGenerator(generator);
+ }
+
+ loaded = true;
+ }
+
+
+}