summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-web-runtime/src/main
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-02-18 15:44:46 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-02-18 15:44:46 +0000
commitc5fd4eb548af7ea52c8ee41ea050af847e88665f (patch)
treee2e65b06bf20764fecf113f815f8476ee2176b05 /java/sca/modules/implementation-web-runtime/src/main
parent14c196193898a76c0cc3b45c9388608d09d89390 (diff)
Start to get basic JSP references working
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@745542 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-web-runtime/src/main')
-rw-r--r--java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java53
-rw-r--r--java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java17
-rw-r--r--java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java43
3 files changed, 84 insertions, 29 deletions
diff --git a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java
new file mode 100644
index 0000000000..074f41453d
--- /dev/null
+++ b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java
@@ -0,0 +1,53 @@
+/*
+ * 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.web.runtime;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class InitServlet extends GenericServlet {
+ private static final long serialVersionUID = 1L;
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ public void init(ServletConfig config) throws ServletException {
+ ServletContext context = config.getServletContext();
+ for (String name : attributes.keySet()) {
+ context.setAttribute(name, attributes.get(name));
+ }
+ }
+
+ @Override
+ public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
+ throw new IllegalStateException();
+ }
+
+ public void setAttribute(String name, Object value) {
+ attributes.put(name, value);
+ }
+}
diff --git a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
index 06615178bf..6a43a4e8ab 100644
--- a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
+++ b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
@@ -18,7 +18,11 @@
*/
package org.apache.tuscany.sca.implementation.web.runtime;
+import java.util.List;
+
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
import org.apache.tuscany.sca.implementation.web.WebImplementation;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
@@ -29,12 +33,25 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
public class WebImplementationProviderFactory implements ImplementationProviderFactory<WebImplementation> {
+ private ServletHost servletHost;
+ private InitServlet servlet;
+
public WebImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
+ ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class);
+ List<ServletHost> hosts = servletHosts.getServletHosts();
+ if (!hosts.isEmpty()) {
+ this.servletHost = hosts.get(0);
+ }
+
+ servlet = new InitServlet();
}
public ImplementationProvider createImplementationProvider(RuntimeComponent component, WebImplementation implementation) {
+ servletHost.addServletMapping("org.apache.tuscany.sca.implementation.web.dummy", servlet);
+ servlet.setAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent", component);
return new ImplementationProvider() {
+
public Invoker createInvoker(RuntimeComponentService arg0, Operation arg1) {
throw new UnsupportedOperationException("Components using implementation.web have no services");
}
diff --git a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
index e56da99921..c46b507749 100644
--- a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
+++ b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
@@ -20,14 +20,13 @@
package org.apache.tuscany.sca.implementation.web.runtime.jsp;
import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
-import org.apache.tuscany.sca.host.webapp.WebAppServletHost;
-import org.apache.tuscany.sca.node.Node;
-import org.oasisopen.sca.ComponentContext;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.oasisopen.sca.ServiceReference;
/**
* Tag to handle SCA references
@@ -50,39 +49,25 @@ public class ReferenceTag extends TagSupport {
@Override
public int doEndTag() throws JspException {
- try {
- WebAppServletHost.getInstance().init(pageContext.getServletConfig());
- } catch (ServletException e) {
- throw new JspException("Exception initializing Tuscany webapp: " + e, e);
- }
-
ServletContext servletContext = pageContext.getServletContext();
- ComponentContext componentContext = (ComponentContext)servletContext.getAttribute("org.oasisopen.sca.ComponentContext");
- Node scaDomain = null;
- if (componentContext == null) {
- scaDomain = (Node)servletContext.getAttribute(WebAppServletHost.SCA_NODE_ATTRIBUTE);
- if (scaDomain == null) {
- throw new JspException("SCADomain is null. Check Tuscany configuration in web.xml");
- }
- }
-
- Class<?> typeClass;
+ RuntimeComponent component = (RuntimeComponent)servletContext.getAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent");
+
+ Class typeClass;
try {
typeClass = Class.forName(type, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new JspException("Reference '" + name + "' type class not found: " + type);
}
-
- Object o;
- try {
- if (componentContext != null) {
- o = componentContext.getService(typeClass, name);
- } else {
- o = scaDomain.getService(typeClass, name);
+
+ Object o = null;
+ for (ComponentReference ref : component.getReferences()) {
+ if (name.equals(ref.getName())) {
+ ServiceReference sr = component.getComponentContext().getServiceReference(typeClass, name);
+ o = sr.getService();
+ break;
}
- } catch (Exception e) {
- throw new JspException("Exception getting service for reference'" + name + "': " + e, e);
}
+
if (o == null) {
throw new JspException("Reference '" + name + "' not found");
}