[jboss-cvs] JBossAS SVN: r94146 - in projects/reloaded/trunk/naming: src/main/java/org/jboss/reloaded/naming and 17 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Sep 30 07:39:43 EDT 2009


Author: wolfc
Date: 2009-09-30 07:39:42 -0400 (Wed, 30 Sep 2009)
New Revision: 94146

Added:
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ComponentObjectFactory.java
   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/simple/
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEApplication.java
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEComponent.java
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEModule.java
   projects/reloaded/trunk/naming/src/test/java/org/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/common/
   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/interceptor/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/NamingInvocationHandler.java
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolder.java
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolderBean.java
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/unit/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/unit/InterceptorTestCase.java
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/legacy/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/legacy/unit/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/legacy/unit/LegacyTestCase.java
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/
   projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/SimpleTestCase.java
   projects/reloaded/trunk/naming/src/test/resources/jndi.properties
Modified:
   projects/reloaded/trunk/naming/
   projects/reloaded/trunk/naming/pom.xml
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/CurrentComponent.java
   projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/util/ThreadLocalStack.java
Log:
RELOADED-9: utility classes, backwards compatible and more tests


Property changes on: projects/reloaded/trunk/naming
___________________________________________________________________
Name: svn:ignore
   - eclipse-target

   + eclipse-target
target


Modified: projects/reloaded/trunk/naming/pom.xml
===================================================================
--- projects/reloaded/trunk/naming/pom.xml	2009-09-30 10:07:55 UTC (rev 94145)
+++ projects/reloaded/trunk/naming/pom.xml	2009-09-30 11:39:42 UTC (rev 94146)
@@ -26,5 +26,10 @@
       <scope>test</scope>
     </dependency>
     -->
+    <dependency>
+      <groupId>org.jboss.naming</groupId>
+      <artifactId>jnpserver</artifactId>
+      <version>5.0.3.GA</version>
+    </dependency>
   </dependencies>
 </project>

Modified: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/CurrentComponent.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/CurrentComponent.java	2009-09-30 10:07:55 UTC (rev 94145)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/CurrentComponent.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -21,6 +21,7 @@
  */
 package org.jboss.reloaded.naming;
 
+import org.jboss.naming.ENCFactory;
 import org.jboss.reloaded.naming.spi.JavaEEComponent;
 import org.jboss.reloaded.naming.util.ThreadLocalStack;
 
@@ -34,6 +35,9 @@
 {
    private static ThreadLocalStack<JavaEEComponent> stack = new ThreadLocalStack<JavaEEComponent>();
    
+   /**
+    * @return the current JavaEEComponent
+    */
    public static JavaEEComponent get()
    {
       return stack.get();
@@ -41,11 +45,19 @@
    
    public static JavaEEComponent pop()
    {
-      return stack.pop();
+      JavaEEComponent comp = stack.pop();
+      
+      // to enable legacy java:comp resolution we must also pop from ENCFactory
+      ENCFactory.popContextId();
+      
+      return comp;
    }
    
    public static void push(JavaEEComponent component)
    {
+      // to enable legacy java:comp resolution we must also push to ENCFactory
+      ENCFactory.pushContextId(component.getName());
+      
       stack.push(component);
    }
 }

Added: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ComponentObjectFactory.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ComponentObjectFactory.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/ComponentObjectFactory.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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 java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+
+import org.jboss.naming.ENCFactory;
+import org.jboss.reloaded.naming.CurrentComponent;
+import org.jboss.reloaded.naming.spi.JavaEEComponent;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ComponentObjectFactory implements ObjectFactory
+{
+   private ENCFactory legacy = new ENCFactory();
+   
+   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(id(current)))
+      {
+         // do legacy resolution
+         return legacy.getObjectInstance(obj, name, nameCtx, environment);
+      }
+      else
+      {
+         return current.getContext();
+      }
+   }
+   
+   public static Object id(JavaEEComponent component)
+   {
+      return component.getName();
+   }
+}

Added: 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	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/service/NameSpaces.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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 javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class NameSpaces
+{
+   private InitialContext iniCtx;
+   
+   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);
+   }
+   
+   public void stop() throws NamingException
+   {
+      if(iniCtx == null)
+         return;
+      
+      Context ctx = (Context) iniCtx.lookup("java:");
+      ctx.unbind("comp");
+      
+      iniCtx.close();
+   }
+}

Added: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEApplication.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEApplication.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEApplication.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.simple;
+
+import javax.naming.Context;
+
+import org.jboss.reloaded.naming.spi.JavaEEApplication;
+
+/**
+ * A simple implementation of {@link JavaEEApplication}.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleJavaEEApplication implements JavaEEApplication
+{
+   private Context context;
+   private String name;
+
+   public SimpleJavaEEApplication(String name, Context context)
+   {
+      assert name != null : "name is null";
+      assert context != null : "context is null";
+      
+      this.name = name;
+      this.context = context;
+   }
+   
+   public Context getContext()
+   {
+      return context;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+}

Added: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEComponent.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEComponent.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEComponent.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.simple;
+
+import javax.naming.Context;
+
+import org.jboss.reloaded.naming.spi.JavaEEComponent;
+import org.jboss.reloaded.naming.spi.JavaEEModule;
+
+/**
+ * A simple implementation of {@link JavaEEComponent}.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleJavaEEComponent implements JavaEEComponent
+{
+   private Context context;
+   private JavaEEModule module;
+   private String name;
+
+   /**
+    * Instantiate a {@link SimpleJavaEEComponent}.
+    * 
+    * @param name the name of the component
+    * @param context the naming context of the component
+    * @param module the module of which this component is part
+    */
+   public SimpleJavaEEComponent(String name, Context context, JavaEEModule module)
+   {
+      assert name != null : "name is null";
+      assert context != null : "context is null";
+      assert module != null : "module is null";
+      
+      this.name = name;
+      this.context = context;
+      this.module = module;
+   }
+   
+   public Context getContext()
+   {
+      return context;
+   }
+
+   public JavaEEModule getModule()
+   {
+      return module;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+}

Added: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEModule.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEModule.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/simple/SimpleJavaEEModule.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.simple;
+
+import javax.naming.Context;
+
+import org.jboss.reloaded.naming.spi.JavaEEApplication;
+import org.jboss.reloaded.naming.spi.JavaEEModule;
+
+/**
+ * A simple implementation of {@link JavaEEModule}.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleJavaEEModule implements JavaEEModule
+{
+   private JavaEEApplication application;
+   private Context context;
+   private String name;
+
+   /**
+    * Instantiate a {@link SimpleJavaEEModule}.
+    * 
+    * @param name the name of the module
+    * @param context the naming context of the module
+    * @param application the application of which this module is part, or null if stand alone
+    */
+   public SimpleJavaEEModule(String name, Context context, JavaEEApplication application)
+   {
+      assert name != null : "name is null";
+      assert context != null : "context is null";
+      
+      this.name = name;
+      this.context = context;
+      this.application = application;
+   }
+   
+   public JavaEEApplication getApplication()
+   {
+      return application;
+   }
+
+   public Context getContext()
+   {
+      return context;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+}

Modified: projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/util/ThreadLocalStack.java
===================================================================
--- projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/util/ThreadLocalStack.java	2009-09-30 10:07:55 UTC (rev 94145)
+++ projects/reloaded/trunk/naming/src/main/java/org/jboss/reloaded/naming/util/ThreadLocalStack.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -24,7 +24,7 @@
 import java.util.LinkedList;
 
 /**
- * Comment
+ * INTERNAL
  *
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
  * @version $Revision$

Added: 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	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/common/AbstractNamingTestCase.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.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;
+import org.jnp.server.SingletonNamingServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractNamingTestCase
+{
+   private static SingletonNamingServer server;
+   private static NameSpaces ns;
+   protected static InitialContext iniCtx;
+   
+   @AfterClass
+   public static void afterClass() throws NamingException
+   {
+      iniCtx.close();
+      
+      ns.stop();
+      
+      server.destroy();
+   }
+   
+   @BeforeClass
+   public static void beforeClass() throws NamingException
+   {
+      server = new SingletonNamingServer();
+      
+      ns = new NameSpaces();
+      ns.start();
+      
+      iniCtx = new InitialContext();
+   }
+   
+   protected Context createContext(Hashtable<?, ?> environment) throws NamingException
+   {
+      NamingServer srv = new NamingServer();
+      return new NamingContext(environment, null, srv);
+   }
+}

Added: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/NamingInvocationHandler.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/NamingInvocationHandler.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/NamingInvocationHandler.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.interceptor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.jboss.reloaded.naming.interceptor.AbstractNamingInterceptor;
+import org.jboss.reloaded.naming.spi.JavaEEComponent;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class NamingInvocationHandler extends AbstractNamingInterceptor<NamingInvocationHandler.InvocationContext> implements InvocationHandler
+{
+   public static class InvocationContext
+   {
+      Object target;
+      Method method;
+      Object parameters[];
+   }
+   
+   private JavaEEComponent component;
+   private Object target;
+   
+   public NamingInvocationHandler(JavaEEComponent component, Object target)
+   {
+      this.component = component;
+      this.target = target;
+   }
+   
+   public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+   {
+      InvocationContext context = new InvocationContext();
+      context.target = target;
+      context.method = method;
+      context.parameters = args;
+      return invoke(context);
+   }
+
+   @Override
+   protected JavaEEComponent getComponent()
+   {
+      return component;
+   }
+
+   @Override
+   protected Object proceed(NamingInvocationHandler.InvocationContext context) throws Throwable
+   {
+      return context.method.invoke(context.target, context.parameters);
+   }
+}

Added: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolder.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolder.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolder.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.interceptor;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface ValueHolder
+{
+   String getValue();
+}

Added: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolderBean.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolderBean.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/ValueHolderBean.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.interceptor;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ValueHolderBean implements ValueHolder
+{
+   public String getValue()
+   {
+      try
+      {
+         return (String) new InitialContext().lookup("java:comp/env/value");
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/unit/InterceptorTestCase.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/unit/InterceptorTestCase.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/interceptor/unit/InterceptorTestCase.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.interceptor.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+
+import javax.naming.NamingException;
+
+import org.jboss.reloaded.naming.simple.SimpleJavaEEComponent;
+import org.jboss.reloaded.naming.simple.SimpleJavaEEModule;
+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.reloaded.naming.test.interceptor.NamingInvocationHandler;
+import org.jboss.reloaded.naming.test.interceptor.ValueHolder;
+import org.jboss.reloaded.naming.test.interceptor.ValueHolderBean;
+import org.jboss.util.naming.Util;
+import org.junit.Test;
+
+/**
+ * Since we provide an abstract interceptor, might as well test it. :-)
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorTestCase extends AbstractNamingTestCase
+{
+   @Test
+   public void test1() throws NamingException
+   {
+      JavaEEModule module = new SimpleJavaEEModule("module", createContext(iniCtx.getEnvironment()), null);
+      JavaEEComponent component = new SimpleJavaEEComponent("intercepted", createContext(iniCtx.getEnvironment()), module);
+      
+      Util.rebind(component.getContext(), "env/value", "Hello intercepted");
+      
+      Object target = new ValueHolderBean();
+      
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      Class<?> interfaces[] = { ValueHolder.class };
+      InvocationHandler handler = new NamingInvocationHandler(component, target);
+      
+      ValueHolder ref = (ValueHolder) Proxy.newProxyInstance(loader, interfaces, handler);
+      
+      assertEquals("Hello intercepted", ref.getValue());
+   }
+}

Added: projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/legacy/unit/LegacyTestCase.java
===================================================================
--- projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/legacy/unit/LegacyTestCase.java	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/legacy/unit/LegacyTestCase.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.legacy.unit;
+
+import static junit.framework.Assert.assertEquals;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import junit.framework.Assert;
+
+import org.jboss.naming.ENCFactory;
+import org.jboss.reloaded.naming.CurrentComponent;
+import org.jboss.reloaded.naming.simple.SimpleJavaEEComponent;
+import org.jboss.reloaded.naming.simple.SimpleJavaEEModule;
+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.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class LegacyTestCase extends AbstractNamingTestCase
+{
+   @Test
+   public void test1() throws Exception
+   {
+      Context context;
+      ENCFactory.pushContextId("component");
+      try
+      {
+         context = (Context) iniCtx.lookup("java:comp");
+      }
+      finally
+      {
+         ENCFactory.popContextId();
+      }
+      Util.rebind(context, "env/value", "Hello LegacyTestCase");
+      
+      ENCFactory.pushContextId("component");
+      try
+      {
+         String value = (String) iniCtx.lookup("java:comp/env/value");
+         Assert.assertEquals("Hello LegacyTestCase", value);
+      }
+      finally
+      {
+         ENCFactory.popContextId();
+      }
+   }
+   
+   @Test
+   public void testLegacyCallingNew() throws NamingException
+   {
+      final String newValue = "testNewCallingLegacy new";
+      final String legacyValue = "testNewCallingLegacy legacy";
+      
+      JavaEEModule module = new SimpleJavaEEModule("module", createContext(iniCtx.getEnvironment()), null);
+      JavaEEComponent component = new SimpleJavaEEComponent("new", createContext(iniCtx.getEnvironment()), module);
+      
+      Util.rebind(component.getContext(), "env/value", newValue);
+
+      ENCFactory.pushContextId("legacy");
+      try
+      {
+         Context ctx = (Context) iniCtx.lookup("java:comp");
+         Util.rebind(ctx, "env/value", legacyValue);
+      }
+      finally
+      {
+         ENCFactory.popContextId();
+      }
+      
+      ENCFactory.pushContextId("legacy");
+      try
+      {
+         String value = (String) iniCtx.lookup("java:comp/env/value");
+         assertEquals(legacyValue, value);
+         
+         CurrentComponent.push(component);
+         try
+         {
+            value = (String) iniCtx.lookup("java:comp/env/value");
+            assertEquals(newValue, value);
+         }
+         finally
+         {
+            CurrentComponent.pop();
+         }
+         
+         value = (String) iniCtx.lookup("java:comp/env/value");
+         assertEquals(legacyValue, value);
+      }
+      finally
+      {
+         ENCFactory.popContextId();
+      }
+      
+   }
+   
+   @Test
+   public void testNewCallingLegacy() throws NamingException
+   {
+      final String newValue = "testNewCallingLegacy new";
+      final String legacyValue = "testNewCallingLegacy legacy";
+      
+      JavaEEModule module = new SimpleJavaEEModule("module", createContext(iniCtx.getEnvironment()), null);
+      JavaEEComponent component = new SimpleJavaEEComponent("new", createContext(iniCtx.getEnvironment()), module);
+      
+      Util.rebind(component.getContext(), "env/value", newValue);
+
+      ENCFactory.pushContextId("legacy");
+      try
+      {
+         Context ctx = (Context) iniCtx.lookup("java:comp");
+         Util.rebind(ctx, "env/value", legacyValue);
+      }
+      finally
+      {
+         ENCFactory.popContextId();
+      }
+      
+      CurrentComponent.push(component);
+      try
+      {
+         String value = (String) iniCtx.lookup("java:comp/env/value");
+         assertEquals(newValue, value);
+         
+         ENCFactory.pushContextId("legacy");
+         try
+         {
+            value = (String) iniCtx.lookup("java:comp/env/value");
+            assertEquals(legacyValue, value);
+         }
+         finally
+         {
+            ENCFactory.popContextId();
+         }
+         
+         value = (String) iniCtx.lookup("java:comp/env/value");
+         assertEquals(newValue, value);
+      }
+      finally
+      {
+         CurrentComponent.pop();
+      }
+   }
+}

Added: 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	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/java/org/jboss/reloaded/naming/test/simple/unit/SimpleTestCase.java	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.test.simple.unit;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.jboss.reloaded.naming.CurrentComponent;
+import org.jboss.reloaded.naming.simple.SimpleJavaEEComponent;
+import org.jboss.reloaded.naming.simple.SimpleJavaEEModule;
+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.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleTestCase extends AbstractNamingTestCase
+{
+   @Test
+   public void test1() 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");
+      
+      CurrentComponent.push(component);
+      try
+      {
+         String value = (String) iniCtx.lookup("java:comp/env/value");
+         assertEquals("Hello world", value);
+      }
+      finally
+      {
+         CurrentComponent.pop();
+      }
+   }
+}

Added: projects/reloaded/trunk/naming/src/test/resources/jndi.properties
===================================================================
--- projects/reloaded/trunk/naming/src/test/resources/jndi.properties	                        (rev 0)
+++ projects/reloaded/trunk/naming/src/test/resources/jndi.properties	2009-09-30 11:39:42 UTC (rev 94146)
@@ -0,0 +1,2 @@
+java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces




More information about the jboss-cvs-commits mailing list