User: oberg
Date: 00/11/02 07:14:08
Modified: src/main/org/jnp/server NamingServer.java
Log:
Added support for listBindings.
Revision Changes Path
1.3 +60 -7 jnp/src/main/org/jnp/server/NamingServer.java
Index: NamingServer.java
===================================================================
RCS file: /products/cvs/ejboss/jnp/src/main/org/jnp/server/NamingServer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NamingServer.java 2000/10/25 08:59:12 1.2
+++ NamingServer.java 2000/11/02 15:14:07 1.3
@@ -7,10 +7,14 @@
*/
package org.jnp.server;
+import java.io.ObjectStreamException;
+import java.io.NotSerializableException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
+import java.rmi.server.RemoteObject;
import java.util.Enumeration;
import java.util.Collection;
+import java.util.Iterator;
import java.util.Hashtable;
import java.util.Vector;
@@ -36,7 +40,7 @@
*
* @see <related>
* @author $Author: oberg $
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class NamingServer
implements Naming, java.io.Serializable
@@ -241,9 +245,7 @@
if (name.isEmpty())
{
// Return this
- Name fullName = (Name)(prefix.clone());
- fullName.addAll(name);
- result = new NamingContext(null, fullName, getRoot());
+ result = new NamingContext(null, (Name)(prefix.clone()), getRoot());
} else if (name.size() > 1)
{
// Recurse to find correct context
@@ -309,7 +311,7 @@
String key = (String)keys.nextElement();
Binding b = getBinding(key);
- list.addElement(new NameClassPair(b.getName(),b.getClassName(),true));
// FIX to real name!
+ list.addElement(new NameClassPair(b.getName(),b.getClassName(),true));
}
return list;
} else
@@ -340,6 +342,57 @@
}
}
+ public Collection listBindings(Name name)
+ throws NamingException
+ {
+ if (name.isEmpty())
+ {
+ Collection bindings = table.values();
+ Collection newBindings = new Vector(bindings.size());
+ Iterator enum = bindings.iterator();
+ while (enum.hasNext())
+ {
+ Binding b = (Binding)enum.next();
+ if (b.getObject() instanceof NamingServer)
+ {
+ Name n = (Name)prefix.clone();
+ n.add(b.getName());
+ newBindings.add(new Binding(b.getName(),
+ b.getClassName(),
+ new NamingContext(null, n, getRoot())));
+ } else
+ {
+ newBindings.add(b);
+ }
+ }
+
+ return newBindings;
+ } else
+ {
+ Object ctx = getObject(name);
+ if (ctx instanceof NamingServer)
+ {
+ return ((NamingServer)ctx).listBindings(name.getSuffix(1));
+ } else if (ctx instanceof Reference)
+ {
+ // Federation
+ if (((Reference)ctx).get("nns") != null)
+ {
+ CannotProceedException cpe = new CannotProceedException();
+ cpe.setResolvedObj(ctx);
+ cpe.setRemainingName(name.getSuffix(1));
+ throw cpe;
+ } else
+ {
+ throw new NotContextException();
+ }
+ } else
+ {
+ throw new NotContextException();
+ }
+ }
+ }
+
public Context createSubcontext(Name name)
throws NamingException
{
@@ -384,7 +437,8 @@
// System.out.println("create subcontext "+name);
Name fullName = (Name)(prefix.clone());
fullName.addAll(name);
- setBinding(name, new NamingServer(fullName, this),
NamingContext.class.getName());
+ NamingServer subContext = new NamingServer(fullName, this);
+ setBinding(name, subContext, NamingContext.class.getName());
return new NamingContext(null, fullName, getRoot());
}
}
@@ -443,6 +497,5 @@
{
return parent;
}
-
// Inner classes -------------------------------------------------
}