Author: antelder
Date: Wed Feb 18 15:44:46 2009
New Revision: 745542
URL: http://svn.apache.org/viewvc?rev=745542&view=rev
Log:
Start to get basic JSP references working
Added:
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java
Modified:
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
Added:
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java?rev=745542&view=auto
==============================================================================
---
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java
(added)
+++
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/InitServlet.java
Wed Feb 18 15:44:46 2009
@@ -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);
+ }
+}
Modified:
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java?rev=745542&r1=745541&r2=745542&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
(original)
+++
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
Wed Feb 18 15:44:46 2009
@@ -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 @@
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");
}
Modified:
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java?rev=745542&r1=745541&r2=745542&view=diff
==============================================================================
---
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
(original)
+++
tuscany/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
Wed Feb 18 15:44:46 2009
@@ -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 @@
@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");
}