You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ps...@apache.org on 2004/12/28 09:34:13 UTC

svn commit: r123481 - /incubator/directory/naming/trunk/core/src/java/org/apache/naming/NamingContextFactory.java /incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java

Author: psteitz
Date: Tue Dec 28 00:34:12 2004
New Revision: 123481

URL: http://svn.apache.org/viewcvs?view=rev&rev=123481
Log:
Added initial context factory to create NamingContext instances directly in naming-core.
Added:
   incubator/directory/naming/trunk/core/src/java/org/apache/naming/NamingContextFactory.java
Modified:
   incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java

Added: incubator/directory/naming/trunk/core/src/java/org/apache/naming/NamingContextFactory.java
Url: http://svn.apache.org/viewcvs/incubator/directory/naming/trunk/core/src/java/org/apache/naming/NamingContextFactory.java?view=auto&rev=123481
==============================================================================
--- (empty file)
+++ incubator/directory/naming/trunk/core/src/java/org/apache/naming/NamingContextFactory.java	Tue Dec 28 00:34:12 2004
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */ 
+
+package org.apache.naming;
+
+import java.util.Hashtable;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+/**
+ * Initial context factory returning {@link NamingContext} instances.
+ *
+ * @version $Revision$ $Date$
+ */
+public class NamingContextFactory implements InitialContextFactory {
+    
+    /**
+     * Get a new (writable) initial context.  Always returns a 
+     * {@link NamingContext}.  If
+     * {@link SynchronizedContext#isSynchronized} returns true for 
+     * <code>environment</code>  then the
+     * returned context is wrapped in a {@link SynchronizedContext}, so access
+     * to it will be synchronized.
+     * 
+     * @param environment  environment
+     * @return a new Context
+     * @exception NamingException if a naming exception is encountered
+     */
+    public Context getInitialContext(Hashtable environment)
+    throws NamingException {
+        Context ctx = new NamingContext(environment, "initialContext");
+        if (SynchronizedContext.isSynchronized(environment)) {
+            return new SynchronizedContext(ctx);
+        } else {
+            return ctx;
+        }
+    }
+}

Modified: incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java?view=diff&rev=123481&p1=incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java&r1=123480&p2=incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java&r2=123481
==============================================================================
--- incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java	(original)
+++ incubator/directory/naming/trunk/core/src/test/org/apache/naming/NamingContextTest.java	Tue Dec 28 00:34:12 2004
@@ -18,6 +18,7 @@
 import java.util.Hashtable;
 
 import javax.naming.Context;
+import javax.naming.InitialContext;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -47,7 +48,9 @@
     
     protected Context makeInitialContext() {
     	try {
-    		return new NamingContext(new Hashtable(), "root");
+            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, 
+                    "org.apache.naming.NamingContextFactory");
+    		return new InitialContext(new Hashtable());
     	} catch (Exception ex) {
     		fail("Failed to create NamingContext");
     	}