fix context

git-svn-id: 
https://svn.apache.org/repos/asf/oodt/branches/dependency-update@1705319 
13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/365a241f
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/365a241f
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/365a241f

Branch: refs/heads/master
Commit: 365a241fc3d25f7bb4620ce07cb518ee9950c2f6
Parents: 62ef5c0
Author: Tom Barber <[email protected]>
Authored: Fri Sep 25 15:13:42 2015 +0000
Committer: Tom Barber <[email protected]>
Committed: Fri Sep 25 15:13:42 2015 +0000

----------------------------------------------------------------------
 .../commons/object/jndi/ObjectContextTest.java  |  14 +-
 .../oodt/commons/object/jndi/TContext.java      | 204 ++++++++++++++++++
 .../oodt/commons/object/jndi/TestContext.java   | 208 -------------------
 .../commons/object/jndi/TestContextTest.java    |   2 +-
 4 files changed, 212 insertions(+), 216 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/365a241f/commons/src/test/java/org/apache/oodt/commons/object/jndi/ObjectContextTest.java
----------------------------------------------------------------------
diff --git 
a/commons/src/test/java/org/apache/oodt/commons/object/jndi/ObjectContextTest.java
 
b/commons/src/test/java/org/apache/oodt/commons/object/jndi/ObjectContextTest.java
index e328afa..899c1e7 100644
--- 
a/commons/src/test/java/org/apache/oodt/commons/object/jndi/ObjectContextTest.java
+++ 
b/commons/src/test/java/org/apache/oodt/commons/object/jndi/ObjectContextTest.java
@@ -24,7 +24,7 @@ import javax.naming.Binding;
 import javax.naming.NameClassPair;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import org.apache.oodt.commons.object.jndi.ObjectContext;
+
 import junit.framework.TestCase;
 
 /**
@@ -54,9 +54,9 @@ public class ObjectContextTest extends TestCase {
                aliases.save(out, "Temporary properties");
                out.close();
 
-               a1 = new TestContext("urn:a");
-               a2 = new TestContext("urn:a");
-               b = new TestContext("urn:b");
+               a1 = new TContext("urn:a");
+               a2 = new TContext("urn:a");
+               b = new TContext("urn:b");
 
                oldValue = 
System.getProperty("org.apache.oodt.commons.object.jndi.aliases");
                
System.setProperty("org.apache.oodt.commons.object.jndi.aliases", 
aliasFile.toString());
@@ -184,13 +184,13 @@ public class ObjectContextTest extends TestCase {
        }
 
        /** First delegate context for "urn:a" namespace. */
-       private TestContext a1;
+       private TContext a1;
 
        /** Second delegate context for "urn:a" namespace. */
-       private TestContext a2;
+       private TContext a2;
 
        /** Delegate context for "urn:b" namespace. */
-       private TestContext b;
+       private TContext b;
 
        /** Test subject: the object context. */
        private ObjectContext context;

http://git-wip-us.apache.org/repos/asf/oodt/blob/365a241f/commons/src/test/java/org/apache/oodt/commons/object/jndi/TContext.java
----------------------------------------------------------------------
diff --git 
a/commons/src/test/java/org/apache/oodt/commons/object/jndi/TContext.java 
b/commons/src/test/java/org/apache/oodt/commons/object/jndi/TContext.java
new file mode 100644
index 0000000..b5acdf6
--- /dev/null
+++ b/commons/src/test/java/org/apache/oodt/commons/object/jndi/TContext.java
@@ -0,0 +1,204 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt file distributed with this work for
+// additional information regarding copyright ownership.  The ASF licenses this
+// file to you 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.oodt.commons.object.jndi;
+
+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.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+
+/**
+ * A context for testing.  This context uses a simple {@link Map} to track 
bindings.
+ * Names must start with a given prefix string or they cause {@link
+ * InvalidNameException}s.
+ *
+ * @author Kelly
+ * @version $Revision: 1.1 $
+ */
+public class TContext implements Context {
+
+  /**
+        * Creates a new <code>TestContext</code> instance.
+        *
+        * @param prefix What every name must start with.
+        */
+       public TContext(String prefix) {
+               this.prefix = prefix;
+       }
+
+       public Object lookup(Name name) throws NamingException {
+               return lookup(name.toString());
+       }
+       public Object lookup(String name) throws NamingException {
+               Object rc = bindings.get(name);
+               if (rc == null)
+                       throw new NameNotFoundException(name);
+               return rc;
+       }
+       public void bind(Name name, Object obj) throws NamingException {
+               bind(name.toString(), obj);
+       }
+       public void bind(String name, Object obj) throws NamingException {
+               if (!name.startsWith(prefix)) throw new 
InvalidNameException("Name doesn't start with " + prefix);
+               if (bindings.containsKey(name))
+                       throw new NameAlreadyBoundException(name);
+               bindings.put(name, obj);
+       }
+       public void rebind(Name name, Object obj) throws NamingException {
+               rebind(name.toString(), obj);
+       }
+       public void rebind(String name, Object obj) throws NamingException {
+               if (!name.startsWith(prefix)) throw new 
InvalidNameException("Name doesn't start with " + prefix);
+               bindings.put(name, obj);
+       }
+       public void unbind(Name name) throws NamingException {
+               unbind(name.toString());
+       }
+       public void unbind(String name) throws NamingException {
+               if (bindings.remove(name) == null)
+                       throw new NameNotFoundException(name);
+       }
+       public void rename(Name oldName, Name newName) throws NamingException {
+               rename(oldName.toString(), newName.toString());
+       }
+       public void rename(String oldName, String newName) throws 
NamingException {
+               if (!bindings.containsKey(oldName))
+                       throw new NameNotFoundException(oldName);
+               if (bindings.containsKey(newName))
+                       throw new NameAlreadyBoundException(newName);
+               if (!newName.startsWith(prefix))
+                       throw new InvalidNameException("Name doesn't start with 
" + prefix);
+               bindings.put(newName, bindings.remove(oldName));
+       }
+       public NamingEnumeration list(Name name) throws NamingException {
+               return list(name.toString());
+       }
+       public NamingEnumeration list(String name) throws NamingException {
+               if (name.length() > 0)
+                       throw new OperationNotSupportedException("subcontexts 
not supported");
+               final Iterator i = bindings.entrySet().iterator();
+               return new NamingEnumeration() {
+                       public Object next() {
+                               Map.Entry e = (Map.Entry) i.next();
+                               return new NameClassPair((String) e.getKey(), 
e.getValue().getClass().getName());
+                       }
+                       public boolean hasMore() {
+                               return i.hasNext();
+                       }
+                       public void close() {}
+                       public boolean hasMoreElements() {
+                               return hasMore();
+                       }
+                       public Object nextElement() {
+                               return next();
+                       }
+               };
+       }
+       public NamingEnumeration listBindings(Name name) throws NamingException 
{
+               return listBindings(name.toString());
+       }
+       public NamingEnumeration listBindings(String name) throws 
NamingException {
+               if (name.length() > 0)
+                       throw new OperationNotSupportedException("subcontexts 
not supported");
+               final Iterator i = bindings.entrySet().iterator();
+               return new NamingEnumeration() {
+                       public Object next() {
+                               Map.Entry e = (Map.Entry) i.next();
+                               return new Binding((String) e.getKey(), 
e.getValue());
+                       }
+                       public boolean hasMore() {
+                               return i.hasNext();
+                       }
+                       public void close() {}
+                       public boolean hasMoreElements() {
+                               return hasMore();
+                       }
+                       public Object nextElement() {
+                               return next();
+                       }
+
+               };
+       }
+       public void destroySubcontext(Name name) throws NamingException {
+               destroySubcontext(name.toString());
+       }
+       public void destroySubcontext(String name) throws NamingException {
+               throw new OperationNotSupportedException("subcontexts not 
supported");
+       }
+       public Context createSubcontext(Name name) throws NamingException {
+               return createSubcontext(name.toString());
+       }
+       public Context createSubcontext(String name) throws NamingException {
+               throw new OperationNotSupportedException("subcontexts not 
supported");
+       }
+       public Object lookupLink(Name name) throws NamingException {
+               return lookupLink(name.toString());
+       }
+       public Object lookupLink(String name) throws NamingException {
+               return lookup(name);
+       }
+       public NameParser getNameParser(Name name) {
+               return getNameParser(name.toString());
+       }
+       public NameParser getNameParser(String name) {
+               return new ObjectNameParser();
+       }
+       public String composeName(String name, String prefix) throws 
NamingException {
+               return composeName(new CompositeName(name), new 
CompositeName(prefix)).toString();
+       }
+       public Name composeName(Name name, Name prefix) throws NamingException {
+               Name result = (Name) prefix.clone();
+               result.addAll(name);
+               return result;
+       }
+       public Object addToEnvironment(String key, Object val) {
+               if (environment == null) environment = new Hashtable();
+               return environment.put(key, val);
+       }
+       public Object removeFromEnvironment(String key) {
+               if (environment == null) environment = new Hashtable();
+               return environment.remove(key);
+       }
+       public Hashtable getEnvironment() {
+               if (environment == null) environment = new Hashtable();
+               return environment;
+       }
+       public void close() {}
+       public String getNameInNamespace() {
+               return "";
+       }
+
+       /** What holds the bindings.  Keys are {@link String}s, values are 
{@link Object}s. */
+       Map bindings = new HashMap();
+
+       /** What every key must start with. */
+       private String prefix;
+
+       /** Context's environment. */
+       private Hashtable environment;
+}

http://git-wip-us.apache.org/repos/asf/oodt/blob/365a241f/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContext.java
----------------------------------------------------------------------
diff --git 
a/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContext.java 
b/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContext.java
deleted file mode 100644
index 72711b0..0000000
--- a/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContext.java
+++ /dev/null
@@ -1,208 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
-// license agreements.  See the NOTICE.txt file distributed with this work for
-// additional information regarding copyright ownership.  The ASF licenses this
-// file to you 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.oodt.commons.object.jndi;
-
-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.InvalidNameException;
-import javax.naming.Name;
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NameClassPair;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
-
-/**
- * A context for testing.  This context uses a simple {@link Map} to track 
bindings.
- * Names must start with a given prefix string or they cause {@link
- * InvalidNameException}s.
- *
- * @author Kelly
- * @version $Revision: 1.1 $
- */
-public class TestContext implements Context {
-
-
-       public TestContext() {
-       }
-
-  /**
-        * Creates a new <code>TestContext</code> instance.
-        *
-        * @param prefix What every name must start with.
-        */
-       public TestContext(String prefix) {
-               this.prefix = prefix;
-       }
-
-       public Object lookup(Name name) throws NamingException {
-               return lookup(name.toString());
-       }
-       public Object lookup(String name) throws NamingException {
-               Object rc = bindings.get(name);
-               if (rc == null)
-                       throw new NameNotFoundException(name);
-               return rc;
-       }
-       public void bind(Name name, Object obj) throws NamingException {
-               bind(name.toString(), obj);
-       }
-       public void bind(String name, Object obj) throws NamingException {
-               if (!name.startsWith(prefix)) throw new 
InvalidNameException("Name doesn't start with " + prefix);
-               if (bindings.containsKey(name))
-                       throw new NameAlreadyBoundException(name);
-               bindings.put(name, obj);
-       }
-       public void rebind(Name name, Object obj) throws NamingException {
-               rebind(name.toString(), obj);
-       }
-       public void rebind(String name, Object obj) throws NamingException {
-               if (!name.startsWith(prefix)) throw new 
InvalidNameException("Name doesn't start with " + prefix);
-               bindings.put(name, obj);
-       }
-       public void unbind(Name name) throws NamingException {
-               unbind(name.toString());
-       }
-       public void unbind(String name) throws NamingException {
-               if (bindings.remove(name) == null)
-                       throw new NameNotFoundException(name);
-       }
-       public void rename(Name oldName, Name newName) throws NamingException {
-               rename(oldName.toString(), newName.toString());
-       }
-       public void rename(String oldName, String newName) throws 
NamingException {
-               if (!bindings.containsKey(oldName))
-                       throw new NameNotFoundException(oldName);
-               if (bindings.containsKey(newName))
-                       throw new NameAlreadyBoundException(newName);
-               if (!newName.startsWith(prefix))
-                       throw new InvalidNameException("Name doesn't start with 
" + prefix);
-               bindings.put(newName, bindings.remove(oldName));
-       }
-       public NamingEnumeration list(Name name) throws NamingException {
-               return list(name.toString());
-       }
-       public NamingEnumeration list(String name) throws NamingException {
-               if (name.length() > 0)
-                       throw new OperationNotSupportedException("subcontexts 
not supported");
-               final Iterator i = bindings.entrySet().iterator();
-               return new NamingEnumeration() {
-                       public Object next() {
-                               Map.Entry e = (Map.Entry) i.next();
-                               return new NameClassPair((String) e.getKey(), 
e.getValue().getClass().getName());
-                       }
-                       public boolean hasMore() {
-                               return i.hasNext();
-                       }
-                       public void close() {}
-                       public boolean hasMoreElements() {
-                               return hasMore();
-                       }
-                       public Object nextElement() {
-                               return next();
-                       }
-               };
-       }
-       public NamingEnumeration listBindings(Name name) throws NamingException 
{
-               return listBindings(name.toString());
-       }
-       public NamingEnumeration listBindings(String name) throws 
NamingException {
-               if (name.length() > 0)
-                       throw new OperationNotSupportedException("subcontexts 
not supported");
-               final Iterator i = bindings.entrySet().iterator();
-               return new NamingEnumeration() {
-                       public Object next() {
-                               Map.Entry e = (Map.Entry) i.next();
-                               return new Binding((String) e.getKey(), 
e.getValue());
-                       }
-                       public boolean hasMore() {
-                               return i.hasNext();
-                       }
-                       public void close() {}
-                       public boolean hasMoreElements() {
-                               return hasMore();
-                       }
-                       public Object nextElement() {
-                               return next();
-                       }
-
-               };
-       }
-       public void destroySubcontext(Name name) throws NamingException {
-               destroySubcontext(name.toString());
-       }
-       public void destroySubcontext(String name) throws NamingException {
-               throw new OperationNotSupportedException("subcontexts not 
supported");
-       }
-       public Context createSubcontext(Name name) throws NamingException {
-               return createSubcontext(name.toString());
-       }
-       public Context createSubcontext(String name) throws NamingException {
-               throw new OperationNotSupportedException("subcontexts not 
supported");
-       }
-       public Object lookupLink(Name name) throws NamingException {
-               return lookupLink(name.toString());
-       }
-       public Object lookupLink(String name) throws NamingException {
-               return lookup(name);
-       }
-       public NameParser getNameParser(Name name) {
-               return getNameParser(name.toString());
-       }
-       public NameParser getNameParser(String name) {
-               return new ObjectNameParser();
-       }
-       public String composeName(String name, String prefix) throws 
NamingException {
-               return composeName(new CompositeName(name), new 
CompositeName(prefix)).toString();
-       }
-       public Name composeName(Name name, Name prefix) throws NamingException {
-               Name result = (Name) prefix.clone();
-               result.addAll(name);
-               return result;
-       }
-       public Object addToEnvironment(String key, Object val) {
-               if (environment == null) environment = new Hashtable();
-               return environment.put(key, val);
-       }
-       public Object removeFromEnvironment(String key) {
-               if (environment == null) environment = new Hashtable();
-               return environment.remove(key);
-       }
-       public Hashtable getEnvironment() {
-               if (environment == null) environment = new Hashtable();
-               return environment;
-       }
-       public void close() {}
-       public String getNameInNamespace() {
-               return "";
-       }
-
-       /** What holds the bindings.  Keys are {@link String}s, values are 
{@link Object}s. */
-       Map bindings = new HashMap();
-
-       /** What every key must start with. */
-       private String prefix;
-
-       /** Context's environment. */
-       private Hashtable environment;
-}

http://git-wip-us.apache.org/repos/asf/oodt/blob/365a241f/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContextTest.java
----------------------------------------------------------------------
diff --git 
a/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContextTest.java
 
b/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContextTest.java
index acf195f..f433a1f 100644
--- 
a/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContextTest.java
+++ 
b/commons/src/test/java/org/apache/oodt/commons/object/jndi/TestContextTest.java
@@ -46,7 +46,7 @@ public class TestContextTest extends TestCase {
         * @throws NamingException if an error occurs.
         */
        public void testTestContext() throws NamingException {
-               TestContext ctx = new TestContext("urn:x:");                    
       // Make it
+               TContext ctx = new TContext("urn:x:");                         
// Make it
                try {
                        ctx.lookup("urn:x:y");                                  
       // Lookup a nonexistent binding
                        fail("Got a binding that doesn't exist");               
       // Got something?  Yikes.

Reply via email to