geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r711405 - in /geronimo/plugins/tuscany/trunk: geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java tuscany-jetty/pom.xml tuscany-jetty/src/main/plan/plan.xml
Date Tue, 04 Nov 2008 21:05:00 GMT
Author: vamsic007
Date: Tue Nov  4 13:05:00 2008
New Revision: 711405

URL: http://svn.apache.org/viewvc?rev=711405&view=rev
Log:
Bind the SCADomain object into JNDI.

Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
    geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml
    geronimo/plugins/tuscany/trunk/tuscany-jetty/src/main/plan/plan.xml

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java?rev=711405&r1=711404&r2=711405&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
Tue Nov  4 13:05:00 2008
@@ -18,6 +18,11 @@
  */
 package org.apache.geronimo.tuscany;
 
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.gbean.AbstractName;
@@ -40,6 +45,7 @@
     private EmbeddedSCADomain scaDomain;
     private String domainUri;
     private ClassLoader runtimeClassLoader;
+    private String jndiName;
     
     public EmbeddedSCADomainGBean(AbstractName abstractName, ClassLoader runtimeClassLoader,
String domainUri) {
         this.abstractName = abstractName;
@@ -50,13 +56,40 @@
     public EmbeddedSCADomainGBean() {
     }
     
+    public void setJndiName(String jndiName) {
+        this.jndiName = jndiName;
+    }
+
+    public String getJndiName() {
+        return jndiName;
+    }
+
     public void doStart() throws Exception {
         scaDomain = new EmbeddedSCADomain(runtimeClassLoader, domainUri);
         scaDomain.start();
         log.debug("EmbeddedSCADomainGBean started. Name=" + abstractName);
+        String jndiName = getJndiName();
+        if (jndiName != null && jndiName.length() > 0) {
+            // get the initial context
+            Context context = new InitialContext();
+            Name parsedName = context.getNameParser("").parse(jndiName);
+
+            // create intermediate contexts
+            for (int i = 1; i < parsedName.size(); i++) {
+                Name contextName = parsedName.getPrefix(i);
+                if (!bindingExists(context, contextName)) {
+                    context.createSubcontext(contextName);
+                }
+            }
+
+            // bind
+            context.bind(jndiName, scaDomain);
+            log.info("SCADomain bound to " + jndiName);
+        }
     }
 
     public void doStop() throws Exception {
+        unbindScaDomain();
         if(scaDomain != null) {
             scaDomain.stop();
         }
@@ -65,10 +98,32 @@
     }
     
     public void doFail() {
+        unbindScaDomain();
         scaDomain = null;
         log.warn("EmbeddedSCADomainGBean failed. Name=" + abstractName);        
     }
 
+    private void unbindScaDomain() {
+        String jndiName = getJndiName();
+        if (jndiName != null && jndiName.length() > 0) {
+            try {
+                Context context = new InitialContext();
+                context.unbind(jndiName);
+                log.info("SCADomain unbound from " + jndiName);
+            } catch (NamingException e) {
+                // we tried... this is a common error which occurs during shutdown due to
ordering
+            }
+        }
+    }
+
+    private static boolean bindingExists(Context context, Name contextName) {
+        try {
+            return context.lookup(contextName) != null;
+        } catch (NamingException e) {
+        }
+        return false;
+    }
+
     public SCADomain getScaDomain() {
         return scaDomain;
     }
@@ -80,6 +135,7 @@
         infoFactory.addAttribute("abstractName", AbstractName.class, false);
         infoFactory.addAttribute("runtimeClassLoader", ClassLoader.class, false);
         infoFactory.addAttribute("domainUri", String.class, true, true);
+        infoFactory.addAttribute("jndiName", String.class, true);
         infoFactory.addInterface(SCADomainInterface.class);
         infoFactory.setConstructor(new String[]{"abstractName", "runtimeClassLoader", "domainUri"});
         GBEAN_INFO = infoFactory.getBeanInfo();

Modified: geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml?rev=711405&r1=711404&r2=711405&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml Tue Nov  4 13:05:00 2008
@@ -428,6 +428,7 @@
                                 </gbean>
                                 <gbean name="GeronimoSCADomain">
                                     <attribute name="domainUri">http://localhost</attribute>
+                                    <attribute name="jndiName">ger:/SCADomain</attribute>
                                 </gbean>
                             </config-xml-content>
                         </plugin-artifact>

Modified: geronimo/plugins/tuscany/trunk/tuscany-jetty/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/tuscany-jetty/src/main/plan/plan.xml?rev=711405&r1=711404&r2=711405&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/tuscany-jetty/src/main/plan/plan.xml (original)
+++ geronimo/plugins/tuscany/trunk/tuscany-jetty/src/main/plan/plan.xml Tue Nov  4 13:05:00
2008
@@ -53,5 +53,6 @@
     </gbean>
     <gbean name="GeronimoSCADomain" class="org.apache.geronimo.tuscany.EmbeddedSCADomainGBean">
         <attribute name="domainUri">http://localhost/</attribute>
+        <attribute name="jndiName">ger:/SCADomain</attribute>
     </gbean>
 </module>



Mime
View raw message