You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2004/02/12 21:38:19 UTC
cvs commit: incubator-geronimo/modules/naming/src/test-data jndi.properties
djencks 2004/02/12 12:38:19
Modified: modules/connector project.xml
modules/connector/src/java/org/apache/geronimo/connector/outbound
ManagedConnectionFactoryWrapper.java
modules/jetty project.xml
modules/jetty/src/java/org/apache/geronimo/jetty
JettyWebApplicationContext.java
Added: modules/naming project.xml
modules/naming/src/java/org/apache/geronimo/naming/geronimo
GeronimoContext.java GeronimoContextManager.java
GeronimoRootContext.java
geronimoURLContextFactory.java
modules/naming/src/java/org/apache/geronimo/naming/java
ComponentContextBuilder.java
ComponentContextInterceptor.java ProxyFactory.java
ReadOnlyContext.java RootContext.java
javaURLContextFactory.java
modules/naming/src/test/org/apache/geronimo/naming/geronimo
GeronimoContextTest.java
GeronimoRootContextTest.java
modules/naming/src/test/org/apache/geronimo/naming/java
AbstractContextTest.java BasicContextTest.java
ThreadContextTest.java
modules/naming/src/test/org/apache/geronimo/naming/jmx
TestObject.java
modules/naming/src/test-data jndi.properties
Removed: modules/core/src/java/org/apache/geronimo/naming/ger
GerContext.java GerContextManager.java
GerRootContext.java gerURLContextFactory.java
modules/core/src/java/org/apache/geronimo/naming/java
ComponentContextBuilder.java
ComponentContextInterceptor.java
ReadOnlyContext.java ReferenceFactory.java
RootContext.java javaURLContextFactory.java
modules/core/src/java/org/apache/geronimo/naming/jmx
JMXContext.java JMXReferenceFactory.java
jmxURLContextFactory.java
modules/core/src/test/org/apache/geronimo/naming/ger
GerContextTest.java GerRootContextTest.java
modules/core/src/test/org/apache/geronimo/naming/java
AbstractContextTest.java BasicContextTest.java
ThreadContextTest.java
modules/core/src/test/org/apache/geronimo/naming/jmx
TestObject.java
Log:
Move naming to its own module. Still some unimplemented parts for new proxy binding
Revision Changes Path
1.8 +2 -3 incubator-geronimo/modules/connector/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/project.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- project.xml 9 Feb 2004 05:52:01 -0000 1.7
+++ project.xml 12 Feb 2004 20:38:17 -0000 1.8
@@ -45,10 +45,9 @@
</properties>
</dependency>
- <!-- needed for GerContext. change to naming module when moved -->
<dependency>
<groupId>geronimo</groupId>
- <artifactId>geronimo-core</artifactId>
+ <artifactId>geronimo-naming</artifactId>
<version>DEV</version>
<properties>
</properties>
1.3 +4 -4 incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java
Index: ManagedConnectionFactoryWrapper.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/outbound/ManagedConnectionFactoryWrapper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ManagedConnectionFactoryWrapper.java 25 Jan 2004 21:07:03 -0000 1.2
+++ ManagedConnectionFactoryWrapper.java 12 Feb 2004 20:38:17 -0000 1.3
@@ -74,7 +74,7 @@
import org.apache.geronimo.gbean.GReferenceInfo;
import org.apache.geronimo.gbean.GOperationInfo;
import org.apache.geronimo.gbean.WaitingException;
-import org.apache.geronimo.naming.ger.GerContextManager;
+import org.apache.geronimo.naming.geronimo.GeronimoContextManager;
/**
*
@@ -210,7 +210,7 @@
connectionFactory = connectionManagerFactory.createConnectionFactory(managedConnectionFactory);
//If a globalJNDIName is supplied, bind it.
if (globalJNDIName != null) {
- GerContextManager.bind(globalJNDIName, connectionFactory);
+ GeronimoContextManager.bind(globalJNDIName, connectionFactory);
log.debug("Bound connection factory into global 'ger:' context at " + globalJNDIName);
}
@@ -224,7 +224,7 @@
connectionFactory = null;
if (globalJNDIName != null) {
try {
- GerContextManager.unbind(globalJNDIName);
+ GeronimoContextManager.unbind(globalJNDIName);
} catch (NamingException e) {
throw new RuntimeException(e);
}
1.13 +2 -2 incubator-geronimo/modules/jetty/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/project.xml,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- project.xml 6 Feb 2004 08:55:49 -0000 1.12
+++ project.xml 12 Feb 2004 20:38:18 -0000 1.13
@@ -61,7 +61,7 @@
<dependency>
<groupId>geronimo</groupId>
- <artifactId>geronimo-core</artifactId>
+ <artifactId>geronimo-naming</artifactId>
<version>DEV</version>
<properties>
</properties>
1.9 +10 -10 incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java
Index: JettyWebApplicationContext.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebApplicationContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JettyWebApplicationContext.java 5 Feb 2004 01:37:56 -0000 1.8
+++ JettyWebApplicationContext.java 12 Feb 2004 20:38:18 -0000 1.9
@@ -102,7 +102,7 @@
public class JettyWebApplicationContext extends WebApplicationContext implements GBean {
private static Log log = LogFactory.getLog(JettyWebApplicationContext.class);
-
+
private final ConfigurationParent config;
private final URI uri;
private final JettyContainer container;
@@ -137,9 +137,9 @@
this.associator = associator;
}
-
+
/** getContextPriorityClassLoader.
- * @return True if this context should give web application class in preference over the containers
+ * @return True if this context should give web application class in preference over the containers
* classes, as per the servlet specification recommendations.
*/
public boolean getContextPriorityClassLoader() {
@@ -147,18 +147,18 @@
}
/** setContextPriorityClassLoader.
- * @param b True if this context should give web application class in preference over the containers
+ * @param b True if this context should give web application class in preference over the containers
* classes, as per the servlet specification recommendations.
*/
public void setContextPriorityClassLoader(boolean b) {
contextPriorityClassLoader= b;
}
-
+
/**
- * init the classloader. Uses the value of contextPriorityClassLoader to
+ * init the classloader. Uses the value of contextPriorityClassLoader to
* determine if the context needs to create its own classloader.
*/
- protected void initClassLoader(boolean forceContextLoader)
+ protected void initClassLoader(boolean forceContextLoader)
throws MalformedURLException, IOException
{
setClassLoaderJava2Compliant(!contextPriorityClassLoader);
@@ -169,11 +169,11 @@
// setClassLoader(Thread.currentThread().getContextClassLoader());
}
super.initClassLoader(forceContextLoader);
-
+
if (log.isDebugEnabled())
log.debug("classloader for "+getContextPath()+": "+getClassLoader());
}
-
+
public void handle(String pathInContext,
String pathParams,
HttpRequest httpRequest,
1.1 incubator-geronimo/modules/naming/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $ -->
<project>
<pomVersion>3</pomVersion>
<extend>${basedir}/../../etc/project.xml</extend>
<!-- ===================== -->
<!-- Module Identification -->
<!-- ===================== -->
<name>Geronimo :: Naming</name>
<id>geronimo-naming</id>
<shortDescription>Geronimo Namin</shortDescription>
<description>Geronimo Namin</description>
<url>http://incubator.apache.org/projects/geronimo/naming/</url>
<siteDirectory>/www/incubator.apache.org/projects/geronimo/naming</siteDirectory>
<distributionDirectory>/www/incubator.apache.org/projects/geronimo/builds/naming</distributionDirectory>
<package>org.apache.geronimo.naming</package>
<currentVersion>DEV</currentVersion>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<!-- needed for xmlbeans runtime-->
<dependency>
<groupId>xmlbeans</groupId>
<artifactId>xbean-apache</artifactId>
<version>1.0-DEV</version>
<properties>
</properties>
</dependency>
<!-- Module Dependencies -->
<!-- only for ComponentContextInterceptor -->
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-core</artifactId>
<version>DEV</version>
<properties>
<module>true</module>
</properties>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-kernel</artifactId>
<version>DEV</version>
<properties>
<module>true</module>
</properties>
</dependency>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-deployment</artifactId>
<version>DEV</version>
<properties>
<module>true</module>
</properties>
</dependency>
<dependency>
<groupId>geronimo-spec</groupId>
<artifactId>geronimo-spec-j2eeschema</artifactId>
<version>DEV</version>
<properties>
</properties>
</dependency>
<dependency>
<groupId>geronimo-spec</groupId>
<artifactId>geronimo-spec-jta</artifactId>
<version>DEV</version>
<properties>
<module>true</module>
</properties>
</dependency>
<!-- Thirdparty Dependencies -->
<dependency>
<id>mx4j</id>
<version>SNAPSHOT</version>
<properties>
<runtime>false</runtime>
</properties>
</dependency>
</dependencies>
<build>
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
<resources>
<resource>
<directory>${basedir}/src/test-data</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</unitTest>
</build>
</project>
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/geronimo/GeronimoContext.java
Index: GeronimoContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.geronimo;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import org.apache.geronimo.naming.java.ReadOnlyContext;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*
* */
public class GeronimoContext extends ReadOnlyContext {
GeronimoContext() {
super();
}
GeronimoContext(GeronimoContext context, Hashtable environment) {
super(context, environment);
}
protected synchronized Map internalBind(String name, Object value) throws NamingException {
return super.internalBind(name, value);
}
protected ReadOnlyContext newContext() {
return new GeronimoContext();
}
protected synchronized Set internalUnbind(String name) throws NamingException {
assert name != null;
assert !name.equals("");
Set removeBindings = new HashSet();
int pos = name.indexOf('/');
if (pos == -1) {
if (treeBindings.remove(name) == null) {
throw new NamingException("Nothing was bound at " + name);
}
bindings.remove(name);
removeBindings.add(name);
} else {
String segment = name.substring(0, pos);
assert segment != null;
assert !segment.equals("");
Object o = treeBindings.get(segment);
if (o == null) {
throw new NamingException("No context was bound at " + name);
} else if (!(o instanceof GeronimoContext)) {
throw new NamingException("Something else bound where a subcontext should be " + o);
}
GeronimoContext gerContext = (GeronimoContext)o;
String remainder = name.substring(pos + 1);
Set subBindings = gerContext.internalUnbind(remainder);
for (Iterator iterator = subBindings.iterator(); iterator.hasNext();) {
String subName = segment + "/" + (String) iterator.next();
treeBindings.remove(subName);
removeBindings.add(subName);
}
if (gerContext.bindings.isEmpty()) {
bindings.remove(segment);
treeBindings.remove(segment);
removeBindings.add(segment);
}
}
return removeBindings;
}
public synchronized Object lookup(String name) throws NamingException {
return super.lookup(name);
}
public Object lookup(Name name) throws NamingException {
return super.lookup(name);
}
public synchronized Object lookupLink(String name) throws NamingException {
return super.lookupLink(name);
}
public synchronized Name composeName(Name name, Name prefix) throws NamingException {
return super.composeName(name, prefix);
}
public synchronized String composeName(String name, String prefix) throws NamingException {
return super.composeName(name, prefix);
}
public synchronized NamingEnumeration list(String name) throws NamingException {
return super.list(name);
}
public synchronized NamingEnumeration listBindings(String name) throws NamingException {
return super.listBindings(name);
}
public synchronized Object lookupLink(Name name) throws NamingException {
return super.lookupLink(name);
}
public synchronized NamingEnumeration list(Name name) throws NamingException {
return super.list(name);
}
public synchronized NamingEnumeration listBindings(Name name) throws NamingException {
return super.listBindings(name);
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/geronimo/GeronimoContextManager.java
Index: GeronimoContextManager.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.geronimo;
import javax.naming.NamingException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*
* */
public class GeronimoContextManager {
private GeronimoContextManager() {}
public static void bind(String name, Object value) throws NamingException {
GeronimoRootContext.rootContext.internalBind(name, value);
}
public static void unbind(String name) throws NamingException {
GeronimoRootContext.rootContext.internalUnbind(name);
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/geronimo/GeronimoRootContext.java
Index: GeronimoRootContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.geronimo;
import java.util.Hashtable;
import javax.naming.NamingException;
import org.apache.geronimo.naming.geronimo.GeronimoContext;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*
* */
public class GeronimoRootContext extends GeronimoContext {
private static final String PROTOCOL = "geronimo:";
private static final int PROTOCOL_LENGTH = PROTOCOL.length();
static final GeronimoRootContext rootContext = new GeronimoRootContext();
private GeronimoRootContext() {
super();
}
GeronimoRootContext(Hashtable environment) {
super(rootContext, environment);
}
public Object lookup(String name) throws NamingException {
if (name.startsWith(PROTOCOL)) {
name = name.substring(PROTOCOL_LENGTH);
if (name.length() == 0) {
return this;
}
}
return super.lookup(name);
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/geronimo/geronimoURLContextFactory.java
Index: geronimoURLContextFactory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.geronimo;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.OperationNotSupportedException;
import javax.naming.spi.ObjectFactory;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*
* */
public class geronimoURLContextFactory implements ObjectFactory {
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
Hashtable environment) throws Exception {
if (obj == null) {
return new GeronimoRootContext(environment);
} else {
throw new OperationNotSupportedException();
}
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextBuilder.java
Index: ComponentContextBuilder.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import java.net.MalformedURLException;
import java.net.URL;
import javax.naming.NamingException;
import javax.transaction.UserTransaction;
import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.xbeans.j2ee.EjbLocalRefType;
import org.apache.geronimo.xbeans.j2ee.EjbRefType;
import org.apache.geronimo.xbeans.j2ee.EnvEntryType;
import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*/
public class ComponentContextBuilder {
private final ProxyFactory proxyFactory;
private final UserTransaction userTransaction;
private static final String ENV = "env/";
public ComponentContextBuilder(ProxyFactory proxyFactory, UserTransaction userTransaction) {
this.userTransaction = userTransaction;
this.proxyFactory = proxyFactory;
}
/**
* Build a component context from definitions contained in POJOs read from
* a deployment descriptor.
* @return a Context that can be bound to java:comp
*/
public ReadOnlyContext buildContext(EjbRefType[] ejbRefs, EjbLocalRefType[] ejbLocalRefs, EnvEntryType[] envEntries, ResourceRefType[] resourceRefs) throws DeploymentException {
ReadOnlyContext readOnlyContext = new ReadOnlyContext();
buildEnvEntries(readOnlyContext, envEntries);
buildEJBRefs(readOnlyContext, ejbRefs);
buildEJBLocalRefs(readOnlyContext, ejbLocalRefs);
buildResourceRefs(readOnlyContext, resourceRefs);
if (userTransaction != null) {
try {
readOnlyContext.internalBind("UserTransaction", userTransaction);
} catch (NamingException e) {
throw new DeploymentException("could not bind UserTransaction", e);
}
}
return readOnlyContext;
}
private static void buildEnvEntries(ReadOnlyContext readOnlyContext, EnvEntryType[] envEntries) throws DeploymentException {
for (int i = 0; i < envEntries.length; i++) {
EnvEntryType entry = envEntries[i];
String name = entry.getEnvEntryName().getStringValue();
String type = entry.getEnvEntryType().getStringValue();
String value = entry.getEnvEntryValue().getStringValue();
Object mapEntry;
try {
if (value == null) {
mapEntry = null;
} else if ("java.lang.String".equals(type)) {
mapEntry = value;
} else if ("java.lang.Character".equals(type)) {
mapEntry = new Character(value.charAt(0));
} else if ("java.lang.Boolean".equals(type)) {
mapEntry = Boolean.valueOf(value);
} else if ("java.lang.Byte".equals(type)) {
mapEntry = Byte.valueOf(value);
} else if ("java.lang.Short".equals(type)) {
mapEntry = Short.valueOf(value);
} else if ("java.lang.Integer".equals(type)) {
mapEntry = Integer.valueOf(value);
} else if ("java.lang.Long".equals(type)) {
mapEntry = Long.valueOf(value);
} else if ("java.lang.Float".equals(type)) {
mapEntry = Float.valueOf(value);
} else if ("java.lang.Double".equals(type)) {
mapEntry = Double.valueOf(value);
} else {
throw new AssertionError("Invalid class for env-entry " + name + ", " + type);
}
} catch (NumberFormatException e) {
throw new DeploymentException("Invalid numeric value for env-entry " + name + ", value=" + value);
}
try {
readOnlyContext.internalBind(ENV + name, mapEntry);
} catch (NamingException e) {
throw new DeploymentException("Could not bind", e);
}
}
}
private void buildEJBRefs(ReadOnlyContext readOnlyContext, EjbRefType[] ejbRefs) throws DeploymentException {
for (int i = 0; i < ejbRefs.length; i++) {
EjbRefType ejbRef = ejbRefs[i];
String name = ejbRef.getEjbRefName().getStringValue();
Object proxy = null;
try {
proxy = proxyFactory.getProxy(loadClass(ejbRef.getHome().getStringValue()) ,loadClass(ejbRef.getRemote().getStringValue()), getLink(ejbRef.getEjbLink().getStringValue()));
} catch (NamingException e) {
throw new DeploymentException("Could not construct proxy for " + ejbRef + ", " + e.getMessage());
}
try {
readOnlyContext.internalBind(ENV + name, proxy);
} catch (NamingException e) {
throw new DeploymentException("could not bind", e);
}
}
}
private Object getLink(String link) {
return null;
}
private Class loadClass(String stringValue) {
return null;
}
private void buildEJBLocalRefs(ReadOnlyContext readOnlyContext, EjbLocalRefType[] ejbLocalRefs) throws DeploymentException {
for (int i = 0; i < ejbLocalRefs.length; i++) {
EjbLocalRefType ejbLocalRef = ejbLocalRefs[i];
String name = ejbLocalRef.getEjbRefName().getStringValue();
Object proxy = null;
try {
proxy = proxyFactory.getProxy(loadClass(ejbLocalRef.getLocalHome().getStringValue()), loadClass(ejbLocalRef.getLocal().getStringValue()), getLink(ejbLocalRef.toString()));
} catch (NamingException e) {
throw new DeploymentException("Could not construct reference to " + ejbLocalRef + ", " + e.getMessage());
}
try {
readOnlyContext.internalBind(ENV + name, proxy);
} catch (NamingException e) {
throw new DeploymentException("Could not bind", e);
}
}
}
private void buildResourceRefs(ReadOnlyContext readOnlyContext, ResourceRefType[] resRefs) throws DeploymentException {
for (int i=0; i < resRefs.length; i++) {
ResourceRefType resRef = resRefs[i];
String name = resRef.getResRefName().getStringValue();
String type = resRef.getResType().getStringValue();
Object ref;
if ("java.net.URL".equals(type)) {
try {
ref = new URL(null /*resRef.geturl().getStringValue()*/);
} catch (MalformedURLException e) {
throw new DeploymentException("Invalid URL for resource-ref "+name, e);
}
} else {
try {
ref = proxyFactory.getProxy(loadClass(resRef.getResType().getStringValue()), getLink(resRef.toString()));
} catch (NamingException e) {
throw new DeploymentException("Could not construct reference to " + resRef);
}
}
try {
readOnlyContext.internalBind(ENV + name, ref);
} catch (NamingException e) {
throw new DeploymentException("Could not bind", e);
}
}
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ComponentContextInterceptor.java
Index: ComponentContextInterceptor.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import org.apache.geronimo.core.service.Interceptor;
import org.apache.geronimo.core.service.Invocation;
import org.apache.geronimo.core.service.InvocationResult;
/**
* An interceptor that pushes the current component's java:comp context into
* the java: JNDI namespace
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*/
public class ComponentContextInterceptor implements Interceptor {
private final Interceptor next;
private final ReadOnlyContext compContext;
/**
* Constructor specifying the components JNDI Context (java:comp)
* @param compContext the component's JNDI Context
*/
public ComponentContextInterceptor(Interceptor next, ReadOnlyContext compContext) {
this.next = next;
this.compContext = compContext;
}
public InvocationResult invoke(Invocation invocation) throws Throwable {
ReadOnlyContext oldContext = RootContext.getComponentContext();
try {
RootContext.setComponentContext(compContext);
return next.invoke(invocation);
} finally {
RootContext.setComponentContext(oldContext);
}
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ProxyFactory.java
Index: ProxyFactory.java
===================================================================
package org.apache.geronimo.naming.java;
import javax.naming.NamingException;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*
* */
public interface ProxyFactory {
Object getProxy(Class homeInterface, Class remoteInterface, Object targetId) throws NamingException;
Object getProxy(Class interfaced, Object targetId) throws NamingException;
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/ReadOnlyContext.java
Index: ReadOnlyContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import javax.naming.Binding;
import javax.naming.CompositeName;
import javax.naming.Context;
import javax.naming.LinkRef;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NotContextException;
import javax.naming.OperationNotSupportedException;
import javax.naming.spi.NamingManager;
/**
* A read-only Context in the java: namespace.
* <p>
* This version assumes it and all its subcontext are read-only and any attempt
* to modify (e.g. through bind) will result in an OperationNotSupportedException.
* Each Context in the tree builds a cache of the entries in all sub-contexts
* to optimise the performance of lookup.
* </p>
* <p>This implementation is intended to optimise the performance of lookup(String)
* to about the level of a HashMap get. It has been observed that the scheme
* resolution phase performed by the JVM takes considerably longer, so for
* optimum performance lookups should be coded like:</p>
* <code>
* Context componentContext = (Context)new InitialContext().lookup("java:comp");
* String envEntry = (String) componentContext.lookup("env/myEntry");
* String envEntry2 = (String) componentContext.lookup("env/myEntry2");
* </code>
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*/
public class ReadOnlyContext implements Context {
protected final Hashtable env; // environment for this context
protected final Map bindings; // bindings at my level
protected final Map treeBindings; // all bindings under me
protected ReadOnlyContext() {
env = new Hashtable();
bindings = new HashMap();
treeBindings = new HashMap();
}
ReadOnlyContext(Hashtable env) {
if (env == null) {
this.env = new Hashtable();
} else {
this.env = new Hashtable(env);
}
this.bindings = Collections.EMPTY_MAP;
this.treeBindings = Collections.EMPTY_MAP;
}
protected ReadOnlyContext(ReadOnlyContext clone, Hashtable env) {
this.bindings = clone.bindings;
this.treeBindings = clone.treeBindings;
this.env = new Hashtable(env);
}
/**
* internalBind is intended for use only during setup or possibly by suitably synchronized superclasses.
* It binds every possible lookup into a map in each context. To do this, each context
* strips off one name segment and if necessary creates a new context for it. Then it asks that context
* to bind the remaining name. It returns a map containing all the bindings from the next context, plus
* the context it just created (if it in fact created it). (the names are suitably extended by the segment
* originally lopped off).
* @param name
* @param value
* @return
* @throws javax.naming.NamingException
*/
protected Map internalBind(String name, Object value) throws NamingException {
assert name != null;
assert !name.equals("");
Map newBindings = new HashMap();
int pos = name.indexOf('/');
if (pos == -1) {
if (treeBindings.put(name, value) != null) {
throw new NamingException("Something already bound at " + name);
}
bindings.put(name, value);
newBindings.put(name, value);
} else {
String segment = name.substring(0, pos);
assert segment != null;
assert !segment.equals("");
Object o = treeBindings.get(segment);
if (o == null) {
o = newContext();
treeBindings.put(segment, o);
bindings.put(segment, o);
newBindings.put(segment, o);
} else if (!(o instanceof ReadOnlyContext)) {
throw new NamingException("Something already bound where a subcontext should go");
}
ReadOnlyContext readOnlyContext = (ReadOnlyContext)o;
String remainder = name.substring(pos + 1);
Map subBindings = readOnlyContext.internalBind(remainder, value);
for (Iterator iterator = subBindings.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String subName = segment + "/" + (String)entry.getKey();
Object bound = entry.getValue();
treeBindings.put(subName, bound);
newBindings.put(subName, bound);
}
}
return newBindings;
}
protected ReadOnlyContext newContext() {
return new ReadOnlyContext();
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
return env.put(propName, propVal);
}
public Hashtable getEnvironment() throws NamingException {
return (Hashtable) env.clone();
}
public Object removeFromEnvironment(String propName) throws NamingException {
return env.remove(propName);
}
public Object lookup(String name) throws NamingException {
if (name.length() == 0) {
return this;
}
Object result = treeBindings.get(name);
if (result == null) {
int pos = name.indexOf(':');
if (pos > 0) {
String scheme = name.substring(0, pos);
Context ctx = NamingManager.getURLContext(scheme, env);
if (ctx == null) {
throw new NamingException("scheme " + scheme + " not recognized");
}
return ctx.lookup(name);
} else {
// Split out the first name of the path
// and look for it in the bindings map.
CompositeName path = new CompositeName(name);
if (path.size() == 0) {
return this;
} else {
Object obj = bindings.get(path.get(0));
if (obj == null){
throw new NameNotFoundException(name);
} else if (obj instanceof Context && path.size() > 1){
Context subContext = (Context) obj;
obj = subContext.lookup(path.getSuffix(1));
}
return obj;
}
}
}
if (result instanceof LinkRef) {
LinkRef ref = (LinkRef) result;
result = lookup(ref.getLinkName());
}
if (result instanceof ReadOnlyContext) {
result = new ReadOnlyContext((ReadOnlyContext) result, env);
}
return result;
}
public Object lookup(Name name) throws NamingException {
return lookup(name.toString());
}
public Object lookupLink(String name) throws NamingException {
return lookup(name);
}
public Name composeName(Name name, Name prefix) throws NamingException {
Name result = (Name) prefix.clone();
result.addAll(name);
return result;
}
public String composeName(String name, String prefix) throws NamingException {
CompositeName result = new CompositeName(prefix);
result.addAll(new CompositeName(name));
return result.toString();
}
public NamingEnumeration list(String name) throws NamingException {
Object o = lookup(name);
if (o == this) {
return new ListEnumeration();
} else if (o instanceof Context) {
return ((Context) o).list("");
} else {
throw new NotContextException();
}
}
public NamingEnumeration listBindings(String name) throws NamingException {
Object o = lookup(name);
if (o == this) {
return new ListBindingEnumeration();
} else if (o instanceof Context) {
return ((Context) o).listBindings("");
} else {
throw new NotContextException();
}
}
public Object lookupLink(Name name) throws NamingException {
return lookupLink(name.toString());
}
public NamingEnumeration list(Name name) throws NamingException {
return list(name.toString());
}
public NamingEnumeration listBindings(Name name) throws NamingException {
return listBindings(name.toString());
}
public void bind(Name name, Object obj) throws NamingException {
throw new OperationNotSupportedException();
}
public void bind(String name, Object obj) throws NamingException {
throw new OperationNotSupportedException();
}
public void close() throws NamingException {
throw new OperationNotSupportedException();
}
public Context createSubcontext(Name name) throws NamingException {
throw new OperationNotSupportedException();
}
public Context createSubcontext(String name) throws NamingException {
throw new OperationNotSupportedException();
}
public void destroySubcontext(Name name) throws NamingException {
throw new OperationNotSupportedException();
}
public void destroySubcontext(String name) throws NamingException {
throw new OperationNotSupportedException();
}
public String getNameInNamespace() throws NamingException {
throw new OperationNotSupportedException();
}
public NameParser getNameParser(Name name) throws NamingException {
throw new OperationNotSupportedException();
}
public NameParser getNameParser(String name) throws NamingException {
throw new OperationNotSupportedException();
}
public void rebind(Name name, Object obj) throws NamingException {
throw new OperationNotSupportedException();
}
public void rebind(String name, Object obj) throws NamingException {
throw new OperationNotSupportedException();
}
public void rename(Name oldName, Name newName) throws NamingException {
throw new OperationNotSupportedException();
}
public void rename(String oldName, String newName) throws NamingException {
throw new OperationNotSupportedException();
}
public void unbind(Name name) throws NamingException {
throw new OperationNotSupportedException();
}
public void unbind(String name) throws NamingException {
throw new OperationNotSupportedException();
}
private abstract class LocalNamingEnumeration implements NamingEnumeration {
private Iterator i = bindings.entrySet().iterator();
public boolean hasMore() throws NamingException {
return i.hasNext();
}
public boolean hasMoreElements() {
return i.hasNext();
}
protected Map.Entry getNext() {
return (Map.Entry) i.next();
}
public void close() throws NamingException {
}
}
private class ListEnumeration extends LocalNamingEnumeration {
public Object next() throws NamingException {
return nextElement();
}
public Object nextElement() {
Map.Entry entry = getNext();
return new NameClassPair((String) entry.getKey(), entry.getValue().getClass().getName());
}
}
private class ListBindingEnumeration extends LocalNamingEnumeration {
public Object next() throws NamingException {
return nextElement();
}
public Object nextElement() {
Map.Entry entry = getNext();
return new Binding((String) entry.getKey(), entry.getValue());
}
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/RootContext.java
Index: RootContext.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import java.util.Hashtable;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
/**
* The root context for the java: namespace.
* Automatically handles switching the "java:comp" sub-context to the
* appropriate one for the current thread.
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*/
public class RootContext extends ReadOnlyContext {
private static InheritableThreadLocal compContext = new InheritableThreadLocal();
RootContext(Hashtable env) {
super(env);
}
public Object lookup(String name) throws NamingException {
if (name.startsWith("java:")) {
name = name.substring(5);
if (name.length() == 0) {
return this;
}
ReadOnlyContext compCtx = (ReadOnlyContext) compContext.get();
if (compCtx == null) {
// the component context was not set for this thread
throw new NameNotFoundException();
}
compCtx = new ReadOnlyContext(compCtx, getEnvironment());
if ("comp".equals(name)) {
return compCtx;
} else if (name.startsWith("comp/")) {
return compCtx.lookup(name.substring(5));
} else {
throw new NameNotFoundException();
}
}
return super.lookup(name);
}
/**
* Set the component context for the current thread. This will be returned
* for all lookups of "java:comp"
* @param ctx the current components context
*/
public static void setComponentContext(ReadOnlyContext ctx) {
compContext.set(ctx);
}
/**
* Get the component context for the current thread.
* @return the current components context
*/
public static ReadOnlyContext getComponentContext() {
return (ReadOnlyContext) compContext.get();
}
}
1.1 incubator-geronimo/modules/naming/src/java/org/apache/geronimo/naming/java/javaURLContextFactory.java
Index: javaURLContextFactory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.OperationNotSupportedException;
import javax.naming.spi.ObjectFactory;
/**
* URLContextFactory for the java: JNDI namespace.
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:18 $
*/
public class javaURLContextFactory implements ObjectFactory {
/**
* Return a Context that is able to resolve names in the java: namespace.
* The root context, "java:" is always returned. This is a specific
* implementation of a URLContextFactory and not a general ObjectFactory.
* @param obj must be null
* @param name ignored
* @param nameCtx ignored
* @param environment ignored
* @return the Context for "java:"
* @throws javax.naming.OperationNotSupportedException if obj is not null
*/
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable environment) throws Exception {
if (obj == null) {
return new RootContext(environment);
} else {
throw new OperationNotSupportedException();
}
}
}
1.1 incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/geronimo/GeronimoContextTest.java
Index: GeronimoContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.geronimo;
import javax.naming.NamingException;
import junit.framework.TestCase;
import org.apache.geronimo.naming.geronimo.GeronimoContext;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
*
* */
public class GeronimoContextTest extends TestCase {
private GeronimoContext context;
protected void setUp() throws Exception {
context = new GeronimoContext();
context.internalBind("one", "one");
context.internalBind("this/is/a/compound/name", "two");
context.internalBind("this/is/another/compound/name", "three");
}
public void testLookup() throws Exception {
assertEquals(context.lookup("one"), "one");
assertEquals(context.lookup("this/is/a/compound/name"), "two");
assertEquals(context.lookup("this/is/another/compound/name"), "three");
}
public void testUnbind() throws Exception {
assertEquals(1, context.internalUnbind("one").size());
try {
context.lookup("one");
fail();
} catch (NamingException e) {
}
assertEquals(3, context.internalUnbind("this/is/a/compound/name").size());
try {
context.lookup("this/is/a/compound/name");
fail();
} catch (NamingException e) {
}
context.lookup("this/is");
assertEquals(5, context.internalUnbind("this/is/another/compound/name").size());
try {
context.lookup("this/is");
fail();
} catch (NamingException e) {
}
}
}
1.1 incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/geronimo/GeronimoRootContextTest.java
Index: GeronimoRootContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.geronimo;
import javax.naming.InitialContext;
import junit.framework.TestCase;
import org.apache.geronimo.naming.geronimo.GeronimoContextManager;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
*
* */
public class GeronimoRootContextTest extends TestCase {
protected void setUp() throws Exception {
GeronimoContextManager.bind("one", "one");
GeronimoContextManager.bind("this/is/a/compound/name", "two");
GeronimoContextManager.bind("this/is/another/compound/name", "three");
}
public void testLookup() throws Exception {
InitialContext context = new InitialContext();
assertEquals(context.lookup("geronimo:one"), "one");
assertEquals(context.lookup("geronimo:this/is/a/compound/name"), "two");
assertEquals(context.lookup("geronimo:this/is/another/compound/name"), "three");
}
}
1.1 incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java/AbstractContextTest.java
Index: AbstractContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.LinkRef;
import javax.naming.NamingException;
import junit.framework.TestCase;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.naming.jmx.TestObject;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
*
* */
public class AbstractContextTest extends TestCase {
protected ReadOnlyContext readOnlyContext;
protected Properties syntax;
protected Map envBinding;
protected Context initialContext;
protected Context compContext;
protected Context envContext;
public void testNothing() { }
protected void setUp() throws Exception {
initialContext = new InitialContext();
readOnlyContext = new ReadOnlyContext();
envBinding = new HashMap();
readOnlyContext.internalBind("env/hello", "Hello");
envBinding.put("hello", "Hello");
bind("env/world", "Hello World");
envBinding.put("world", "Hello World");
bind("env/here/there/anywhere", "long name");
envBinding.put("here", readOnlyContext.lookup("env/here"));
LinkRef link = new LinkRef("java:comp/env/hello");
bind("env/link", link);
envBinding.put("link", link);
RootContext.setComponentContext(readOnlyContext);
compContext = (Context) initialContext.lookup("java:comp");
envContext = (Context) initialContext.lookup("java:comp/env");
syntax = new Properties();
}
protected void bind(String name, Object value) throws NamingException {
readOnlyContext.internalBind(name, value);
}
public static TestObject registerTestObject(MBeanServer server, ObjectName objectName) throws Exception {
GBeanInfo gbeanInfo = TestObject.getGBeanInfo();
GBeanMBean gbean = new GBeanMBean(gbeanInfo);
server.registerMBean(gbean, objectName);
return (TestObject) gbean.getTarget();
}
}
1.1 incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java/BasicContextTest.java
Index: BasicContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.naming.Binding;
import javax.naming.CompositeName;
import javax.naming.CompoundName;
import javax.naming.Context;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
/**
* Unit tests for basic ops on an {@link javax.naming.InitialContext}.
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
*/
public class BasicContextTest extends AbstractContextTest {
public void testInitialContext() throws NamingException {
assertEquals("Hello", initialContext.lookup("java:comp/env/hello"));
assertEquals("Hello", initialContext.lookup(new CompositeName("java:comp/env/hello")));
}
public void testLookup() throws NamingException {
assertEquals("Hello", envContext.lookup("hello"));
assertEquals("Hello", compContext.lookup("env/hello"));
try {
envContext.lookup("foo");
fail();
} catch (NamingException e) {
// OK
}
assertEquals("Hello", envContext.lookup(new CompositeName("hello")));
assertEquals("Hello", compContext.lookup(new CompositeName("env/hello")));
assertEquals("Hello", envContext.lookup(new CompoundName("hello", syntax)));
assertEquals("Hello", compContext.lookup(new CompoundName("env/hello", syntax)));
assertEquals(envContext, envContext.lookup(""));
}
public void testSubContext() throws NamingException {
assertEquals("long name", initialContext.lookup("java:comp/env/here/there/anywhere"));
Context intermediate = (Context)initialContext.lookup("java:comp/env/here/there");
assertNotNull(intermediate);
assertEquals("long name", intermediate.lookup("anywhere"));
}
public void testSchemeLookup() throws NamingException {
// envContext.lookup("dns:apache.org");
assertEquals("Hello", envContext.lookup("java:comp/env/hello"));
assertEquals("Hello", compContext.lookup("java:comp/env/hello"));
}
public void testLookupLink() throws NamingException {
assertEquals("Hello", envContext.lookup("link"));
}
public void testComposeName() throws NamingException {
assertEquals("org/research/user/jane", envContext.composeName("user/jane", "org/research"));
assertEquals("research/user/jane", envContext.composeName("user/jane", "research"));
assertEquals(new CompositeName("org/research/user/jane"), envContext.composeName(new CompositeName("user/jane"), new CompositeName("org/research")));
assertEquals(new CompositeName("research/user/jane"), envContext.composeName(new CompositeName("user/jane"), new CompositeName("research")));
}
public void testList() throws NamingException {
NamingEnumeration enum;
Map expected;
Map result;
expected = new HashMap();
for (Iterator i = envBinding.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
expected.put(entry.getKey(), entry.getValue().getClass().getName());
}
enum = envContext.list("");
result = new HashMap();
while (enum.hasMore()) {
NameClassPair pair = (NameClassPair) enum.next();
result.put(pair.getName(), pair.getClassName());
}
assertEquals(expected, result);
try {
enum.next();
fail();
} catch (NoSuchElementException e) {
// ok
}
try {
enum.nextElement();
fail();
} catch (NoSuchElementException e) {
// ok
}
}
public void testListBindings() throws NamingException {
NamingEnumeration enum;
enum = envContext.listBindings("");
int count = 0;
while (enum.hasMore()) {
count ++;
Binding pair = (Binding) enum.next();
assertTrue(envBinding.containsKey(pair.getName()));
if (! (envBinding.get(pair.getName()) instanceof ReadOnlyContext)) {
assertEquals(pair.getObject(), envBinding.get(pair.getName()));
}
}
assertEquals(envBinding.size(), count);
try {
enum.next();
fail();
} catch (NoSuchElementException e) {
// ok
}
try {
enum.nextElement();
fail();
} catch (NoSuchElementException e) {
// ok
}
}
public void testSpeed() throws NamingException {
Context comp = (Context) initialContext.lookup("java:comp");
long start = System.currentTimeMillis();
for (int i=0; i < 1000000; i++) {
// initialContext.lookup("java:comp/hello"); // this is sloooow due to scheme resolution
// envContext.lookup("hello");
comp.lookup("env/hello");
}
long end = System.currentTimeMillis();
System.out.println("lookup(String) milliseconds: " + (end - start));
}
}
1.1 incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/java/ThreadContextTest.java
Index: ThreadContextTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.java;
import javax.naming.InitialContext;
import javax.naming.LinkRef;
import junit.framework.TestCase;
/**
* Test component context can be inherited by Threads spawned by
* a component. This is required for Application Client and Servlets;
* it is not applicable to EJBs as they are not allowed to create Threads.
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
*/
public class ThreadContextTest extends TestCase {
private Throwable failure = null;
public void testThreadInheritence() throws Throwable {
Thread worker = new Thread() {
public void run() {
try {
assertEquals("Hello", new InitialContext().lookup("java:comp/env/hello"));
} catch (Throwable e) {
failure = e;
}
}
};
worker.start();
worker.join();
if (failure != null) {
throw failure;
}
}
protected void setUp() throws Exception {
ReadOnlyContext readOnlyContext = new ReadOnlyContext();
readOnlyContext.internalBind("env/hello", "Hello");
readOnlyContext.internalBind("env/world", "Hello World");
readOnlyContext.internalBind("env/link", new LinkRef("java:comp/env/hello"));
RootContext.setComponentContext(readOnlyContext);
}
}
1.1 incubator-geronimo/modules/naming/src/test/org/apache/geronimo/naming/jmx/TestObject.java
Index: TestObject.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.naming.jmx;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.GOperationInfo;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
*
* */
public class TestObject {
private static final GBeanInfo GBEAN_INFO;
private Object home = new Object();
private Object local = new Object();
private Object cf = new Object();
public TestObject() {
}
public Object getEJBHome() {
return home;
}
public Object getEJBLocalHome() {
return local;
}
public Object getConnectionFactory() {
return cf;
}
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory(TestObject.class.getName());
infoFactory.addOperation(new GOperationInfo("getEJBHome"));
infoFactory.addOperation(new GOperationInfo("getEJBLocalHome"));
infoFactory.addOperation(new GOperationInfo("getConnectionFactory"));
GBEAN_INFO = infoFactory.getBeanInfo();
}
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
}
1.1 incubator-geronimo/modules/naming/src/test-data/jndi.properties
Index: jndi.properties
===================================================================
##
## Default JNDI Properties
##
## $Revision: 1.1 $ $Date: 2004/02/12 20:38:19 $
##
java.naming.factory.initial=com.sun.jndi.rmi.registry.RegistryContextFactory
java.naming.factory.url.pkgs=org.apache.geronimo.naming
java.naming.provider.url=rmi://localhost:1099