Commit 63c5d91a by Tom Tromey Committed by Tom Tromey

* javax/naming/InitialContext.java: Reindented.

From-SVN: r71535
parent 1eeae5c1
2003-09-18 Tom Tromey <tromey@redhat.com>
* javax/naming/InitialContext.java: Reindented.
2003-09-18 Dalibor Topic <robilad@kaffe.org>, 2003-09-18 Dalibor Topic <robilad@kaffe.org>,
Helmer Kraemer <hkraemer@freenet.de> Helmer Kraemer <hkraemer@freenet.de>
......
/* InitialContext.java -- /* InitialContext.java --
Copyright (C) 2000, 2002 Free Software Foundation, Inc. Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -57,170 +57,176 @@ public class InitialContext implements Context ...@@ -57,170 +57,176 @@ public class InitialContext implements Context
public InitialContext (Hashtable environment) public InitialContext (Hashtable environment)
throws NamingException throws NamingException
{ {
init (environment); init (environment);
} }
protected InitialContext (boolean lazy) protected InitialContext (boolean lazy)
throws NamingException throws NamingException
{ {
if (! lazy) if (! lazy)
init (null); init (null);
} }
public InitialContext () public InitialContext ()
throws NamingException throws NamingException
{ {
init (null); init (null);
} }
/** @since 1.3 */ /** @since 1.3 */
protected void init (Hashtable environment) protected void init (Hashtable environment)
throws NamingException throws NamingException
{ {
// FIXME: Is this enough? // FIXME: Is this enough?
final String[] properties = { final String[] properties = {
Context.DNS_URL, Context.DNS_URL,
Context.INITIAL_CONTEXT_FACTORY, Context.INITIAL_CONTEXT_FACTORY,
Context.OBJECT_FACTORIES, Context.OBJECT_FACTORIES,
Context.PROVIDER_URL, Context.PROVIDER_URL,
Context.STATE_FACTORIES, Context.STATE_FACTORIES,
Context.URL_PKG_PREFIXES, Context.URL_PKG_PREFIXES,
}; };
// Create myProps, cloning environment if needed. // Create myProps, cloning environment if needed.
if (environment != null) if (environment != null)
myProps = (Hashtable) environment.clone (); myProps = (Hashtable) environment.clone ();
else else
myProps = new Hashtable (); myProps = new Hashtable ();
Applet napplet = (Applet) myProps.get (Context.APPLET); Applet napplet = (Applet) myProps.get (Context.APPLET);
for (int i = properties.length - 1; i >= 0; i--) for (int i = properties.length - 1; i >= 0; i--)
{ {
Object o = myProps.get (properties[i]); Object o = myProps.get (properties[i]);
if (o == null) if (o == null)
{ {
if (napplet != null) if (napplet != null)
o = napplet.getParameter (properties[i]); o = napplet.getParameter (properties[i]);
if (o == null) if (o == null)
o = System.getProperty (properties[i]); o = System.getProperty (properties[i]);
if (o != null) if (o != null)
myProps.put (properties[i], o); myProps.put (properties[i], o);
} }
} }
try try
{ {
Enumeration ep = Thread.currentThread().getContextClassLoader().getResources("jndi.naming"); Enumeration ep = Thread.currentThread().getContextClassLoader().getResources("jndi.naming");
while (ep.hasMoreElements ()) while (ep.hasMoreElements ())
{ {
URL url = (URL) ep.nextElement (); URL url = (URL) ep.nextElement ();
Properties p = new Properties (); Properties p = new Properties ();
try { try
InputStream is = url.openStream (); {
p.load (is); InputStream is = url.openStream ();
is.close (); p.load (is);
} catch (IOException e) {} is.close ();
}
merge (myProps, p); catch (IOException e)
} {
} }
catch (IOException e) {}
merge (myProps, p);
String home = System.getProperty("gnu.classpath.home.url"); }
if (home != null) }
{ catch (IOException e)
String url = home + "/jndi.properties"; {
Properties p = new Properties (); }
String home = System.getProperty("gnu.classpath.home.url");
if (home != null)
{
String url = home + "/jndi.properties";
Properties p = new Properties ();
try try
{ {
InputStream is = new URL(url).openStream(); InputStream is = new URL(url).openStream();
p.load (is); p.load (is);
is.close (); is.close ();
} }
catch (IOException e) catch (IOException e)
{ {
// Ignore. // Ignore.
} }
merge (myProps, p); merge (myProps, p);
} }
} }
// FIXME: Is this enough? // FIXME: Is this enough?
private static final String[] colon_list = private static final String[] colon_list =
{ {
Context.OBJECT_FACTORIES, Context.OBJECT_FACTORIES,
Context.URL_PKG_PREFIXES, Context.URL_PKG_PREFIXES,
Context.STATE_FACTORIES Context.STATE_FACTORIES
}; };
private static void merge (Hashtable h1, Hashtable h2) private static void merge (Hashtable h1, Hashtable h2)
{ {
Enumeration e2 = h2.keys(); Enumeration e2 = h2.keys();
while (e2.hasMoreElements()) while (e2.hasMoreElements())
{ {
String key2 = (String) e2.nextElement(); String key2 = (String) e2.nextElement();
Object value1 = h1.get(key2); Object value1 = h1.get(key2);
if (value1 == null) if (value1 == null)
h1.put(key2, h2.get(key2)); h1.put(key2, h2.get(key2));
else if (key2.compareTo(colon_list[0]) == 0 else if (key2.compareTo(colon_list[0]) == 0
|| key2.compareTo(colon_list[1]) == 0 || key2.compareTo(colon_list[1]) == 0
|| key2.compareTo(colon_list[2]) == 0 || key2.compareTo(colon_list[2]) == 0
|| key2.compareTo(colon_list[3]) == 0) || key2.compareTo(colon_list[3]) == 0)
{ {
String value2 = (String) h2.get(key2); String value2 = (String) h2.get(key2);
h1.put(key2, (String) value1 + ":" + value2); h1.put(key2, (String) value1 + ":" + value2);
} }
} }
} }
protected Context getDefaultInitCtx () throws NamingException protected Context getDefaultInitCtx () throws NamingException
{ {
if (! gotDefault) if (! gotDefault)
{ {
defaultInitCtx = NamingManager.getInitialContext (myProps); defaultInitCtx = NamingManager.getInitialContext (myProps);
gotDefault = true; gotDefault = true;
} }
return defaultInitCtx; return defaultInitCtx;
} }
protected Context getURLOrDefaultInitCtx (Name name) protected Context getURLOrDefaultInitCtx (Name name)
throws NamingException throws NamingException
{ {
if (name.size () > 0) if (name.size () > 0)
return getURLOrDefaultInitCtx (name.get (0)); return getURLOrDefaultInitCtx (name.get (0));
else else
return getDefaultInitCtx (); return getDefaultInitCtx ();
} }
protected Context getURLOrDefaultInitCtx (String name) protected Context getURLOrDefaultInitCtx (String name)
throws NamingException throws NamingException
{ {
String scheme = null; String scheme = null;
if (NamingManager.hasInitialContextFactoryBuilder()) if (NamingManager.hasInitialContextFactoryBuilder())
return getDefaultInitCtx();
int colon = name.indexOf(':');
int slash = name.indexOf('/');
if (colon > 0 && (slash == -1 || colon < slash))
scheme = name.substring(0, colon);
if (scheme != null)
{
Context context =
NamingManager.getURLContext(scheme, myProps);
if (context != null)
return context;
}
return getDefaultInitCtx(); return getDefaultInitCtx();
} int colon = name.indexOf(':');
int slash = name.indexOf('/');
if (colon > 0 && (slash == -1 || colon < slash))
scheme = name.substring(0, colon);
if (scheme != null)
{
Context context =
NamingManager.getURLContext(scheme, myProps);
if (context != null)
return context;
}
return getDefaultInitCtx();
}
public void bind (Name name, Object obj) throws NamingException public void bind (Name name, Object obj) throws NamingException
{ {
...@@ -338,13 +344,13 @@ public class InitialContext implements Context ...@@ -338,13 +344,13 @@ public class InitialContext implements Context
} }
public String composeName (String name, public String composeName (String name,
String prefix) throws NamingException String prefix) throws NamingException
{ {
return getURLOrDefaultInitCtx (name).composeName (name, prefix); return getURLOrDefaultInitCtx (name).composeName (name, prefix);
} }
public Object addToEnvironment (String propName, public Object addToEnvironment (String propName,
Object propVal) throws NamingException Object propVal) throws NamingException
{ {
return myProps.put (propName, propVal); return myProps.put (propName, propVal);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment