[jboss-cvs] JBossAS SVN: r98121 - in projects/reloaded/trunk/naming: src/main/java/org/jboss/reloaded/naming/service and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 22 11:11:22 EST 2009
Author: wolfc
Date: 2009-12-22 11:11:22 -0500 (Tue, 22 Dec 2009)
New Revision: 98121
Added:
projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/AppObjectFactory.java
projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ModuleObjectFactory.java
Modified:
projects/reloaded/trunk/naming/pom.xml
projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/NameSpaces.java
projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/common/AbstractNamingTestCase.java
projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/SimpleTestCase.java
Log:
RELOADED-9: Implemented java:global, java:app and java:module
Modified: projects/reloaded/trunk/naming/pom.xml
===================================================================
--- projects/reloaded/trunk/naming/pom.xml 2009-12-22 15:49:34 UTC (rev 98120)
+++ projects/reloaded/trunk/naming/pom.xml 2009-12-22 16:11:22 UTC (rev 98121)
@@ -17,6 +17,17 @@
<description>
</description>
+ <build>
+ <plugins>
+ <plugin>
+ <!-- else you might get the snapshot, which doesn't pick up the correct classes directory -->
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>emma-maven-plugin</artifactId>
+ <version>1.0-alpha-2</version>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
<!--
<dependency>
@@ -29,7 +40,7 @@
<dependency>
<groupId>org.jboss.naming</groupId>
<artifactId>jnpserver</artifactId>
- <version>5.0.3.GA</version>
+ <version>5.0.4.GA</version>
</dependency>
</dependencies>
</project>
Added: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/AppObjectFactory.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/AppObjectFactory.java (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/AppObjectFactory.java 2009-12-22 16:11:22 UTC (rev 98121)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.naming.service;
+
+import org.jboss.naming.ENCFactory;
+import org.jboss.reloaded.naming.CurrentComponent;
+import org.jboss.reloaded.naming.spi.JavaEEApplication;
+import org.jboss.reloaded.naming.spi.JavaEEComponent;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class AppObjectFactory implements ObjectFactory
+{
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
+ {
+ JavaEEComponent current = CurrentComponent.get();
+ Object currentLegacyId = ENCFactory.getCurrentId();
+ // if there is no current set or some legacy component has pushed another id
+ if(current == null || !currentLegacyId.equals(ComponentObjectFactory.id(current)))
+ {
+ // do legacy resolution
+ return null;
+ }
+ else
+ {
+ JavaEEApplication application = current.getModule().getApplication();
+ if(application == null)
+ return null;
+ return application.getContext();
+ }
+ }
+}
Property changes on: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/AppObjectFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ModuleObjectFactory.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ModuleObjectFactory.java (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ModuleObjectFactory.java 2009-12-22 16:11:22 UTC (rev 98121)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright (c) 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.reloaded.naming.service;
+
+import org.jboss.naming.ENCFactory;
+import org.jboss.reloaded.naming.CurrentComponent;
+import org.jboss.reloaded.naming.spi.JavaEEComponent;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class ModuleObjectFactory implements ObjectFactory
+{
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception
+ {
+ JavaEEComponent current = CurrentComponent.get();
+ Object currentLegacyId = ENCFactory.getCurrentId();
+ // if there is no current set or some legacy component has pushed another id
+ if(current == null || !currentLegacyId.equals(ComponentObjectFactory.id(current)))
+ {
+ // do legacy resolution
+ return null;
+ }
+ else
+ {
+ return current.getModule().getContext();
+ }
+ }
+}
Property changes on: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ModuleObjectFactory.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/NameSpaces.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/NameSpaces.java 2009-12-22 15:49:34 UTC (rev 98120)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/NameSpaces.java 2009-12-22 16:11:22 UTC (rev 98121)
@@ -21,12 +21,8 @@
*/
package org.jboss.reloaded.naming.service;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.StringRefAddr;
+import javax.naming.*;
+import javax.naming.spi.ObjectFactory;
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
@@ -35,14 +31,22 @@
public class NameSpaces
{
private InitialContext iniCtx;
-
+
+ protected Reference createRef(String nns, Class<? extends ObjectFactory> objectFactory)
+ {
+ RefAddr refAddr = new StringRefAddr("nns", nns);
+ Reference ref = new Reference("javax.naming.Context", refAddr, objectFactory.getName(), null);
+ return ref;
+ }
+
public void start() throws NamingException
{
iniCtx = new InitialContext();
- RefAddr refAddr = new StringRefAddr("nns", "ENC");
- Reference envRef = new Reference("javax.naming.Context", refAddr, ComponentObjectFactory.class.getName(), null);
- Context ctx = (Context) iniCtx.lookup("java:");
- ctx.rebind("comp", envRef);
+ Context javaContext = (Context) iniCtx.lookup("java:");
+ javaContext.rebind("comp", createRef("ENC", ComponentObjectFactory.class));
+ javaContext.rebind("module", createRef("MOD", ModuleObjectFactory.class));
+ javaContext.rebind("app", createRef("APP", AppObjectFactory.class));
+ javaContext.createSubcontext("global");
}
public void stop() throws NamingException
@@ -50,8 +54,11 @@
if(iniCtx == null)
return;
- Context ctx = (Context) iniCtx.lookup("java:");
- ctx.unbind("comp");
+ Context javaContext = (Context) iniCtx.lookup("java:");
+ javaContext.unbind("global");
+ javaContext.unbind("app");
+ javaContext.unbind("module");
+ javaContext.unbind("comp");
iniCtx.close();
}
Modified: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/common/AbstractNamingTestCase.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/common/AbstractNamingTestCase.java 2009-12-22 15:49:34 UTC (rev 98120)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/common/AbstractNamingTestCase.java 2009-12-22 16:11:22 UTC (rev 98121)
@@ -21,12 +21,6 @@
*/
package org.jboss.reloaded.naming.test.common;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
import org.jboss.reloaded.naming.service.NameSpaces;
import org.jnp.interfaces.NamingContext;
import org.jnp.server.NamingServer;
@@ -34,6 +28,11 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.Hashtable;
+
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
@@ -43,6 +42,7 @@
private static SingletonNamingServer server;
private static NameSpaces ns;
protected static InitialContext iniCtx;
+ protected static Context javaGlobal;
@AfterClass
public static void afterClass() throws NamingException
@@ -63,9 +63,11 @@
ns.start();
iniCtx = new InitialContext();
+
+ javaGlobal = (Context) iniCtx.lookup("java:global");
}
- protected Context createContext(Hashtable<?, ?> environment) throws NamingException
+ protected static Context createContext(Hashtable<?, ?> environment) throws NamingException
{
NamingServer srv = new NamingServer();
return new NamingContext(environment, null, srv);
Modified: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/SimpleTestCase.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/SimpleTestCase.java 2009-12-22 15:49:34 UTC (rev 98120)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/SimpleTestCase.java 2009-12-22 16:11:22 UTC (rev 98121)
@@ -21,31 +21,114 @@
*/
package org.jboss.reloaded.naming.test.simple.unit;
-import static junit.framework.Assert.assertEquals;
-
import org.jboss.reloaded.naming.CurrentComponent;
+import org.jboss.reloaded.naming.simple.SimpleJavaEEApplication;
import org.jboss.reloaded.naming.simple.SimpleJavaEEComponent;
import org.jboss.reloaded.naming.simple.SimpleJavaEEModule;
+import org.jboss.reloaded.naming.spi.JavaEEApplication;
import org.jboss.reloaded.naming.spi.JavaEEComponent;
import org.jboss.reloaded.naming.spi.JavaEEModule;
import org.jboss.reloaded.naming.test.common.AbstractNamingTestCase;
import org.jboss.util.naming.Util;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import static junit.framework.Assert.assertEquals;
+import static org.jboss.util.naming.Util.rebind;
+
/**
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
public class SimpleTestCase extends AbstractNamingTestCase
{
+ private JavaEEModule module;
+ private JavaEEComponent component;
+
+ protected static JavaEEApplication createApplication(String appName) throws NamingException
+ {
+ Context context = javaGlobal.createSubcontext(appName);
+ JavaEEApplication application = new SimpleJavaEEApplication(appName, context);
+ return application;
+ }
+
+ protected static JavaEEComponent createComponent(JavaEEModule module, String componentName) throws NamingException
+ {
+ Context context = createContext(module.getContext().getEnvironment());
+ JavaEEComponent component = new SimpleJavaEEComponent(componentName, context, module);
+ return component;
+ }
+
+ protected static JavaEEModule createModule(String moduleName) throws NamingException
+ {
+ Context context = javaGlobal.createSubcontext(moduleName);
+ JavaEEModule module = new SimpleJavaEEModule(moduleName, context, null);
+ return module;
+ }
+
+ protected static JavaEEModule createModule(JavaEEApplication app, String moduleName) throws NamingException
+ {
+ Context context = app.getContext().createSubcontext(moduleName);
+ JavaEEModule module = new SimpleJavaEEModule(moduleName, context, app);
+ return module;
+ }
+
+ @After
+ public void after() throws NamingException
+ {
+ javaGlobal.unbind("a_module");
+ }
+
+ @Before
+ public void before() throws NamingException
+ {
+ module = createModule("a_module");
+ component = createComponent(module, "a_component");
+
+ Util.rebind(component.getContext(), "env/value", "Hello world");
+ }
+
@Test
- public void test1() throws Exception
+ public void testApp() throws Exception
{
- JavaEEModule module = new SimpleJavaEEModule("module", createContext(iniCtx.getEnvironment()), null);
- JavaEEComponent component = new SimpleJavaEEComponent("component", createContext(iniCtx.getEnvironment()), module);
-
- Util.rebind(component.getContext(), "env/value", "Hello world");
-
+ JavaEEApplication app = createApplication("an_app");
+ JavaEEModule moduleB = createModule(app, "moduleB");
+ JavaEEComponent component1 = createComponent(moduleB, "component1");
+ JavaEEModule moduleC = createModule(app, "moduleC");
+ JavaEEComponent component2 = createComponent(moduleB, "component2");
+
+ rebind(app.getContext(), "env/value", "sharedInApp");
+
+ CurrentComponent.push(component1);
+ try
+ {
+ String value = (String) iniCtx.lookup("java:app/env/value");
+ assertEquals("sharedInApp", value);
+ }
+ finally
+ {
+ CurrentComponent.pop();
+ }
+
+ CurrentComponent.push(component2);
+ try
+ {
+ String value = (String) iniCtx.lookup("java:app/env/value");
+ assertEquals("sharedInApp", value);
+ }
+ finally
+ {
+ CurrentComponent.pop();
+ }
+ }
+
+ @Test
+ public void testComponent() throws Exception
+ {
CurrentComponent.push(component);
try
{
@@ -57,4 +140,42 @@
CurrentComponent.pop();
}
}
+
+ @Test
+ public void testGlobal() throws Exception
+ {
+ rebind(javaGlobal, "env/value", "testGlobal");
+ String value = (String) iniCtx.lookup("java:global/env/value");
+ assertEquals("testGlobal", value);
+ }
+
+ @Test
+ public void testModule() throws Exception
+ {
+ JavaEEComponent componentB = createComponent(module, "b_component");
+
+ rebind(module.getContext(), "env/value", "sharedInModule");
+
+ CurrentComponent.push(component);
+ try
+ {
+ String value = (String) iniCtx.lookup("java:module/env/value");
+ assertEquals("sharedInModule", value);
+ }
+ finally
+ {
+ CurrentComponent.pop();
+ }
+
+ CurrentComponent.push(componentB);
+ try
+ {
+ String value = (String) iniCtx.lookup("java:module/env/value");
+ assertEquals("sharedInModule", value);
+ }
+ finally
+ {
+ CurrentComponent.pop();
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list