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 2008/03/31 17:00:49 UTC

svn commit: r643015 - in /incubator/tuscany/java/sca/modules/host-webapp: ./ src/main/java/org/apache/tuscany/sca/host/webapp/ src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ src/main/resources/META-INF/

Author: antelder
Date: Mon Mar 31 08:00:46 2008
New Revision: 643015

URL: http://svn.apache.org/viewvc?rev=643015&view=rev
Log:
Add JSP taglib for using SCA references in JSPs as described in the SCA JEE spec draft

Added:
    incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/
    incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java   (with props)
    incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java   (with props)
    incubator/tuscany/java/sca/modules/host-webapp/src/main/resources/META-INF/sca.tld
Modified:
    incubator/tuscany/java/sca/modules/host-webapp/pom.xml
    incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java

Modified: incubator/tuscany/java/sca/modules/host-webapp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/pom.xml?rev=643015&r1=643014&r2=643015&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/host-webapp/pom.xml Mon Mar 31 08:00:46 2008
@@ -55,5 +55,12 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jsp_2.1_spec</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+
     </dependencies>
 </project>

Modified: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=643015&r1=643014&r2=643015&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java (original)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java Mon Mar 31 08:00:46 2008
@@ -205,20 +205,23 @@
     public void init(ServletConfig config) throws ServletException {
         ServletContext servletContext = config.getServletContext();
 
-        initContextPath(servletContext);
+        init(servletContext);
 
+        // Initialize the registered Servlets
+        for (Servlet servlet : servlets.values()) {
+            servlet.init(config);
+        }
+    }
+
+    public void init(ServletContext servletContext) throws ServletException {
         if (servletContext.getAttribute(SCA_DOMAIN_ATTRIBUTE) == null) {
+            initContextPath(servletContext);
             String domainURI = "http://localhost/" + contextPath;
             contributionRoot = getContributionRoot(servletContext);
             // logger.info("Contribution: " + contributionRoot);
             System.setProperty(SCADomain.class.getName(), WebSCADomain.class.getName());
             this.scaDomain = SCADomain.newInstance(domainURI, contributionRoot);
             servletContext.setAttribute(SCA_DOMAIN_ATTRIBUTE, scaDomain);
-        }
-
-        // Initialize the registered Servlets
-        for (Servlet servlet : servlets.values()) {
-            servlet.init(config);
         }
     }
 

Added: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java?rev=643015&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java (added)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java Mon Mar 31 08:00:46 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.host.webapp.jsp;
+
+import javax.servlet.jsp.tagext.TagData;
+import javax.servlet.jsp.tagext.TagExtraInfo;
+import javax.servlet.jsp.tagext.VariableInfo;
+
+/**
+ * TagExtraInfo class for the SCA reference tags
+ * <sca:reference name="service" type="test.MyService" scope="1" />
+ */
+public class ReferenceTEI extends TagExtraInfo {
+
+    public VariableInfo[] getVariableInfo(TagData data) {
+        VariableInfo info1
+           = new VariableInfo(
+              data.getAttributeString("name"),
+              data.getAttributeString("type"),
+              true,
+              VariableInfo.AT_END);
+        VariableInfo[] info = { info1 } ;
+        return info;
+     }
+}

Propchange: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTEI.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java?rev=643015&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java (added)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java Mon Mar 31 08:00:46 2008
@@ -0,0 +1,105 @@
+/*
+ * 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.host.webapp.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.embedded.SCADomain;
+import org.apache.tuscany.sca.host.webapp.WebAppServletHost;
+
+/**
+ * Tag to handle SCA references
+ * <sca:reference name="service" type="test.MyService" scope="1" />
+ */
+public class ReferenceTag extends TagSupport {
+    private static final long serialVersionUID = 1L;
+
+    protected String name;
+    protected String type;
+    protected Integer scope = PageContext.PAGE_SCOPE;
+
+    public int doStartTag() throws JspException {
+        return SKIP_BODY;
+    }
+
+    public int doEndTag() throws JspException {
+
+        ServletContext servletContext = pageContext.getServletContext();
+        try {
+            WebAppServletHost.getInstance().init(servletContext);
+        } catch (ServletException e) {
+            throw new JspException("Exception initializing Tuscany webapp: " + e, e);
+        }
+ 
+        SCADomain scaDomain = (SCADomain)servletContext.getAttribute(WebAppServletHost.SCA_DOMAIN_ATTRIBUTE);
+        if (scaDomain == null) {
+            throw new JspException("SCADomain is null. Check Tuscany configuration in web.xml");
+        }
+
+        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 {
+            o = scaDomain.getService(typeClass, name);
+        } catch (Exception e) {
+            throw new JspException("Exception getting service for reference'" + name + "': " + e, e);
+        }
+        if (o == null) {
+            throw new JspException("Reference '" + name + "' not found");
+        }
+
+        pageContext.setAttribute(name, o, scope);
+
+        return EVAL_PAGE;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getScope() {
+        return scope;
+    }
+
+    public void setScope(Integer scope) {
+        this.scope = scope;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+}

Propchange: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/jsp/ReferenceTag.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/modules/host-webapp/src/main/resources/META-INF/sca.tld
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/resources/META-INF/sca.tld?rev=643015&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/resources/META-INF/sca.tld (added)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/resources/META-INF/sca.tld Mon Mar 31 08:00:46 2008
@@ -0,0 +1,59 @@
+<?xml version = '1.0' encoding = 'ISO-8859-1'?>
+<!--
+ * 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.    
+ -->
+
+<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
+
+<taglib version="2.1">
+
+  <tlib-version>1.0</tlib-version>
+  <short-name>SCA-JSP</short-name>
+  <uri>http://www.osog.org/sca/sca.tld</uri>
+  <description>A tag library for integrating sca components with jsp</description>
+
+  <tag>
+
+    <name>reference</name>
+
+    <tag-class>org.apache.tuscany.sca.host.webapp.jsp.ReferenceTag</tag-class>
+    <tei-class>org.apache.tuscany.sca.host.webapp.jsp.ReferenceTEI</tei-class>
+    
+    <attribute>
+      <name>name</name>
+      <required>true</required>
+      <type>java.lang.String</type>
+    </attribute>
+
+    <attribute>
+      <name>type</name>
+      <required>true</required>
+      <type>java.lang.String</type>
+    </attribute>
+
+    <attribute>
+      <name>scope</name>
+      <required>false</required>
+      <type>java.lang.Integer</type>
+    </attribute>
+
+    <body-content>empty</body-content>
+
+  </tag>
+
+</taglib>



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