diff options
author | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-11-27 03:16:14 +0000 |
---|---|---|
committer | green <green@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-11-27 03:16:14 +0000 |
commit | c59e6378223eba3d47ebeb9d261e762322c2d661 (patch) | |
tree | fddd25f01c276e915b483a1138befefd75ad4852 /libjava/javax | |
parent | 378db68f2e728a6ea8e1a814dae2433b32ef65fa (diff) | |
download | gcc-c59e6378223eba3d47ebeb9d261e762322c2d661.tar.gz |
Initial jndi check-in
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37770 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/javax')
18 files changed, 658 insertions, 0 deletions
diff --git a/libjava/javax/naming/Context.java b/libjava/javax/naming/Context.java new file mode 100644 index 00000000000..d9f520477c3 --- /dev/null +++ b/libjava/javax/naming/Context.java @@ -0,0 +1,83 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +public interface Context +{ + // Property with name of the inital context factory to use + public static final String INITIAL_CONTEXT_FACTORY + = "java.naming.factory.initial"; + + // Property with colon-separated list of object factories to use. + public static final String OBJECT_FACTORIES + = "java.naming.factory.object"; + + // Property with colon-separated list of state factories to use. + public static final String STATE_FACTORIES + = "java.naming.factory.state"; + + // Property with colon-separated list of package prefixes to use. + public static final String URL_PKG_PREFIXES + = "java.naming.factory.url.pkgs"; + + // Property with URL specifying configuration for the service + // provider to use. + public static final String PROVIDER_URL + = "java.naming.provider.url"; + + // Property with the DNS host and domain names to use. + public static final String DNS_URL + = "java.naming.dns.url"; + + // Property with the authoritativeness of the service requested. + public static final String AUTHORITATIVE + = "java.naming.authoritative"; + + // Property with the batch size to use when returning data via the + // service's protocol. + public static final String BATCHSIZE + = "java.naming.batchsize"; + + // Property defining how referrals encountered by the service + // provider are to be processed. + public static final String REFERRAL + = "java.naming.referral"; + + // Property specifying the security protocol to use. + public static final String SECURITY_PROTOCOL + = "java.naming.security.protocol"; + + // Property specifying the security level to use. + public static final String SECURITY_AUTHENTICATION + = "java.naming.security.authentication"; + + // Property for the identity of the principal for authenticating + // the caller to the service. + public static final String SECURITY_PRINCIPAL + = "java.naming.security.principal"; + + // Property specifying the credentials of the principal for + // authenticating the caller to the service. + public static final String SECURITY_CREDENTIAL + = "java.naming.security.credentials"; + + // Property for specifying the preferred language to use with the + // service. + public static final String LANGUAGE + = "java.naming.language"; + + // Property for the initial context constructor to use when searching + // for other properties. + public static final String APPLET + = "java.naming.applet"; + + public void bind (Name name, Object obj) throws NamingException; + public void bind (String name, Object obj) throws NamingException; +} + diff --git a/libjava/javax/naming/InitialContext.java b/libjava/javax/naming/InitialContext.java new file mode 100644 index 00000000000..66454a53b6f --- /dev/null +++ b/libjava/javax/naming/InitialContext.java @@ -0,0 +1,197 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + + This software is copyrighted work licensed under the terms of the + Libgcj License. Please consult the file "LIBGCJ_LICENSE" for + details. */ + +package javax.naming; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; +import java.applet.Applet; +import java.util.Hashtable; +import javax.naming.spi.NamingManager; + + +public class InitialContext implements Context +{ + protected Context defaultInitCtx; + protected boolean gotDefault = false; + protected Hashtable myProps; + + InitialContext (Hashtable environment) + { + init (environment); + } + + protected InitialContext (boolean lazy) + { + if (! lazy) + init (null); + } + + InitialContext () + { + init (null); + } + + protected void init (Hashtable environment) + { + // FIXME: Is this enough? + final String[] properties = { + Context.DNS_URL, + Context.INITIAL_CONTEXT_FACTORY, + Context.OBJECT_FACTORIES, + Context.PROVIDER_URL, + Context.STATE_FACTORIES, + Context.URL_PKG_PREFIXES, + }; + + // Create myProps, cloning environment if needed. + if (environment != null) + myProps = (Hashtable) environment.clone (); + else + myProps = new Hashtable (); + + Applet napplet = (Applet) myProps.get (Context.APPLET); + + for (int i = properties.length - 1; i >= 0; i--) + { + Object o = myProps.get (properties[i]); + + if (o == null) + { + if (napplet != null) + o = napplet.getParameter (properties[i]); + if (o == null) + o = System.getProperty (properties[i]); + if (o != null) + myProps.put (properties[i], o); + } + } + + try + { + Enumeration ep = Thread.currentThread().getContextClassLoader().getResources("jndi.naming"); + while (ep.hasMoreElements ()) + { + URL url = (URL) ep.nextElement (); + Properties p = new Properties (); + + try { + InputStream is = url.openStream (); + p.load (is); + is.close (); + } catch (IOException e) {} + + merge (myProps, p); + } + } + catch (IOException e) {} + + String home = System.getProperty("java.home"); + if (home != null) + { + String fileName = home + File.separator + + "lib" + File.separator + "jndi.properties"; + Properties p = new Properties (); + + try { + InputStream is = new FileInputStream (fileName); + p.load (is); + is.close (); + } catch (IOException e) {} + + merge (myProps, p); + } + } + + // FIXME: Is this enough? + private static final String[] colon_list = + { + Context.OBJECT_FACTORIS, + Context.URL_PKG_PREFIXES, + Context.STATE_FACTORIES + }; + + private static void merge (Hashtable h1, Hashtable h2) + { + Enumeration e2 = h2.keys(); + + while (e2.hasMoreElements()) + { + String key2 = (String) e2.nextElement(); + Object value1 = h1.get(key2); + if (value1 == null) + h1.put(key2, h2.get(key2)); + else if (key2.compareTo(colon_list[0]) == 0 + || key2.compareTo(colon_list[1]) == 0 + || key2.compareTo(colon_list[2]) == 0 + || key2.compareTo(colon_list[3]) == 0) + { + String value2 = (String) h2.get(key2); + h1.put(key2, (String) value1 + ":" + value2); + } + } + } + + protected Context getDefaultInitCtx () throws NamingException + { + if (! gotDefault) + { + defaultInitCtx = NamingManager.getInitialContext (myProps); + gotDefault = true; + } + return defaultInitCtx; + } + + + protected Context getURLOrDefaultInitCtx (Name name) + throws NamingException + { + if (name.size () > 0) + return getURLOrDefaultInitCtx (name.get (0)); + else + return getDefaultInitCtx (); + } + + protected Context getURLOrDefaultInitCtx (String name) + throws NamingException + { + String scheme = null; + + 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(); + } + + public void bind (Name name, Object obj) throws NamingException + { + getURLOrDefaultInitCtx (name).bind (name, obj); + } + + public void bind (String name, Object obj) throws NamingException + { + getURLOrDefaultInitCtx (name).bind (name, obj); + } +} diff --git a/libjava/javax/naming/Name.java b/libjava/javax/naming/Name.java new file mode 100644 index 00000000000..d07995bc86e --- /dev/null +++ b/libjava/javax/naming/Name.java @@ -0,0 +1,17 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.io.Serializable; + +public interface Name extends Cloneable, Serializable +{ + public int size (); + public String get (int index); +} diff --git a/libjava/javax/naming/NamingEnumeration.java b/libjava/javax/naming/NamingEnumeration.java new file mode 100644 index 00000000000..aed4d76578f --- /dev/null +++ b/libjava/javax/naming/NamingEnumeration.java @@ -0,0 +1,18 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.util.Enumeration; + +public interface NamingEnumeration extends Enumeration +{ + public void close() throws NamingException; + public boolean hasMore() throws NamingException; + public Object next() throws NamingException; +} diff --git a/libjava/javax/naming/NamingException.java b/libjava/javax/naming/NamingException.java new file mode 100644 index 00000000000..4cd87061123 --- /dev/null +++ b/libjava/javax/naming/NamingException.java @@ -0,0 +1,36 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.lang.Exception; + +public class NamingException extends Exception +{ + protected Throwable rootException; + + public NamingException() + { + super(); + } + + public NamingException(String msg) + { + super(msg); + } + + public Throwable getRootCause () + { + return rootException; + } + + public void setRootCause (Throwable e) + { + rootException = e; + } +} diff --git a/libjava/javax/naming/NoInitialContextException.java b/libjava/javax/naming/NoInitialContextException.java new file mode 100644 index 00000000000..1d13939c210 --- /dev/null +++ b/libjava/javax/naming/NoInitialContextException.java @@ -0,0 +1,24 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.lang.Exception; + +public class NoInitialContextException extends NamingException +{ + public NoInitialContextException() + { + super(); + } + + public NoInitialContextException(String msg) + { + super(msg); + } +} diff --git a/libjava/javax/naming/RefAddr.java b/libjava/javax/naming/RefAddr.java new file mode 100644 index 00000000000..1973efba29e --- /dev/null +++ b/libjava/javax/naming/RefAddr.java @@ -0,0 +1,15 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.io.Serializable; + +public class RefAddr implements Serializable +{ +} diff --git a/libjava/javax/naming/Reference.java b/libjava/javax/naming/Reference.java new file mode 100644 index 00000000000..79cecc3d4ca --- /dev/null +++ b/libjava/javax/naming/Reference.java @@ -0,0 +1,36 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.io.Serializable; + +public class Reference implements Cloneable, Serializable +{ + public Reference (String className, String factory, String factoryLocation) + { + this.className = className; + } + + void add (RefAddr addr) + { + throw new Error ("javax.naming.Reference.add not implemented"); + } + + RefAddr get (String addrType) + { + throw new Error ("javax.naming.Reference.get not implemented"); + } + + public String getClassName () + { + return className; + } + + private String className; +} diff --git a/libjava/javax/naming/Referenceable.java b/libjava/javax/naming/Referenceable.java new file mode 100644 index 00000000000..feb97fc63c5 --- /dev/null +++ b/libjava/javax/naming/Referenceable.java @@ -0,0 +1,14 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +public interface Referenceable +{ + public Reference getReference() throws NamingException; +} diff --git a/libjava/javax/naming/StringRefAddr.java b/libjava/javax/naming/StringRefAddr.java new file mode 100644 index 00000000000..7ceffa34f74 --- /dev/null +++ b/libjava/javax/naming/StringRefAddr.java @@ -0,0 +1,24 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming; + +import java.io.Serializable; + +public class StringRefAddr extends RefAddr +{ + public StringRefAddr (String addrType, String addr) + { + throw new Error ("javax.naming.StringRefAddr not implemented"); + } + + public Object getContent () + { + throw new Error ("javax.naming.StringRefAddr.getContent not implemented"); + } +} diff --git a/libjava/javax/naming/directory/Attribute.java b/libjava/javax/naming/directory/Attribute.java new file mode 100644 index 00000000000..ec3861c55d5 --- /dev/null +++ b/libjava/javax/naming/directory/Attribute.java @@ -0,0 +1,20 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming.directory; + +import javax.naming.*; +import java.io.Serializable; + +public interface Attribute extends Cloneable, Serializable +{ + // FIXME + + NamingEnumeration getAll (); +} + diff --git a/libjava/javax/naming/directory/Attributes.java b/libjava/javax/naming/directory/Attributes.java new file mode 100644 index 00000000000..7d7c953a33f --- /dev/null +++ b/libjava/javax/naming/directory/Attributes.java @@ -0,0 +1,20 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming.directory; + +import javax.naming.*; +import java.io.Serializable; + +public interface Attributes extends Cloneable, Serializable +{ + // FIXME + + NamingEnumeration getAll (); +} + diff --git a/libjava/javax/naming/directory/DirContext.java b/libjava/javax/naming/directory/DirContext.java new file mode 100644 index 00000000000..50deca0e445 --- /dev/null +++ b/libjava/javax/naming/directory/DirContext.java @@ -0,0 +1,18 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming.directory; + +import javax.naming.*; + +public interface DirContext extends Context +{ + public Attributes getAttributes (String name); + public Attributes getAttributes (String name, String[] attrIds); +} + diff --git a/libjava/javax/naming/directory/InitialDirContext.java b/libjava/javax/naming/directory/InitialDirContext.java new file mode 100644 index 00000000000..2e8915066cc --- /dev/null +++ b/libjava/javax/naming/directory/InitialDirContext.java @@ -0,0 +1,20 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming.directory; + +import javax.naming.*; +import java.util.Hashtable; + +public class InitialDirContext extends InitialContext implements DirContext +{ + public InitialDirContext (Hashtable environment) + { + throw new Error ("javax.naming.directory.InitialDirContext not implemented"); + } +} diff --git a/libjava/javax/naming/spi/InitialContextFactory.java b/libjava/javax/naming/spi/InitialContextFactory.java new file mode 100644 index 00000000000..493b3f5234f --- /dev/null +++ b/libjava/javax/naming/spi/InitialContextFactory.java @@ -0,0 +1,18 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + + This software is copyrighted work licensed under the terms of the + Libgcj License. Please consult the file "LIBGCJ_LICENSE" for + details. */ + +package javax.naming.spi; + +import java.util.Hashtable; +import javax.naming.Context; +import javax.naming.NamingException; + +public interface InitialContextFactory +{ + public Context getInitialContext (Hashtable environment) throws NamingException; +} diff --git a/libjava/javax/naming/spi/InitialContextFactoryBuilder.java b/libjava/javax/naming/spi/InitialContextFactoryBuilder.java new file mode 100644 index 00000000000..e4ae85f7d3e --- /dev/null +++ b/libjava/javax/naming/spi/InitialContextFactoryBuilder.java @@ -0,0 +1,17 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + + This software is copyrighted work licensed under the terms of the + Libgcj License. Please consult the file "LIBGCJ_LICENSE" for + details. */ + +package javax.naming.spi; + +import java.util.Hashtable; +import javax.naming.NamingException; + +public interface InitialContextFactoryBuilder +{ + public InitialContextFactory createInitialContextFactory (Hashtable environment) throws NamingException; +} diff --git a/libjava/javax/naming/spi/NamingManager.java b/libjava/javax/naming/spi/NamingManager.java new file mode 100644 index 00000000000..9cb814e9e12 --- /dev/null +++ b/libjava/javax/naming/spi/NamingManager.java @@ -0,0 +1,57 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + + This software is copyrighted work licensed under the terms of the + Libgcj License. Please consult the file "LIBGCJ_LICENSE" for + details. */ + +package javax.naming.spi; + +import java.util.Hashtable; +import javax.naming.*; + +public class NamingManager +{ + private static InitialContextFactoryBuilder icfb = null; + + public static boolean hasInitialContextFactoryBuilder () + { + return icfb != null; + } + + public static Context getInitialContext (Hashtable environment) throws NamingException + { + InitialContextFactory icf = null; + + if (icfb != null) + icf = icfb.createInitialContextFactory(environment); + else + { + String java_naming_factory_initial = null; + if (environment != null) + java_naming_factory_initial + = (String) environment.get (Context.INITIAL_CONTEXT_FACTORY); + if (java_naming_factory_initial == null) + throw new NoInitialContextException ("Can't find property: " + Context.INITIAL_CONTEXT_FACTORY); + + try { + icf = (InitialContextFactory) Thread.currentThread().getContextClassLoader().loadClass(java_naming_factory_initial).newInstance(); + } catch (Exception exception) { + NoInitialContextException e + = new NoInitialContextException("Can't load InitialContextFactory class: " + java_naming_factory_initial); + e.setRootCause(exception); + throw e; + } + } + + return icf.getInitialContext (environment); + } + + public static Context getURLContext(String scheme, + Hashtable environment) + throws NamingException + { + throw new Error ("javax.naming.spi.NamingManager.getURLContext not implemented"); + } +} diff --git a/libjava/javax/naming/spi/ObjectFactory.java b/libjava/javax/naming/spi/ObjectFactory.java new file mode 100644 index 00000000000..760e5863be9 --- /dev/null +++ b/libjava/javax/naming/spi/ObjectFactory.java @@ -0,0 +1,24 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package javax.naming.spi; + +import java.util.Hashtable; +import javax.naming.*; + +public class ObjectFactory +{ + public Object getObjectInstance (Object obj, + Name name, + Context nameCtx, + Hashtable environment) + throws Exception + { + throw new Error ("javax.naming.spi.ObjectFactory.getObjectInstance not implemented"); + } +} |