You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ga...@apache.org on 2009/10/06 22:41:32 UTC
svn commit: r822489 [1/3] - in /incubator/aries/trunk/jndi-contrib:
jndi-core/src/main/java/org/apache/aries/jndi/
jndi-core/src/main/java/org/apache/aries/jndi/startup/
jndi-core/src/test/java/org/apache/aries/jndi/
jndi-url/src/main/java/org/apache/a...
Author: gawor
Date: Tue Oct 6 20:41:31 2009
New Revision: 822489
URL: http://svn.apache.org/viewvc?rev=822489&view=rev
Log:
set svn:eol-style property on all Java files
Modified:
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/Constants.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-core/src/test/java/org/apache/aries/jndi/ObjectFactoryTest.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/main/java/org/apache/aries/jndi/services/ServiceHelper.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/main/java/org/apache/aries/jndi/url/Activator.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/main/java/org/apache/aries/jndi/url/OsgiURLContextFactory.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryContext.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryName.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/main/java/org/apache/aries/jndi/url/ServiceRegistryNameParser.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceHelperTest.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryContextTest.java (contents, props changed)
incubator/aries/trunk/jndi-contrib/jndi-url/src/test/java/org/apache/aries/jndi/url/ServiceRegistryNameParserTest.java (contents, props changed)
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/Constants.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/Constants.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/Constants.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/Constants.java Tue Oct 6 20:41:31 2009
@@ -1,24 +1,24 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
-
-public class Constants {
- public static final String OSGI_JNDI_FILTER_NAME = "osgi.jndi.serviceName";
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
+
+public class Constants {
+ public static final String OSGI_JNDI_FILTER_NAME = "osgi.jndi.serviceName";
+
+}
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/Constants.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java Tue Oct 6 20:41:31 2009
@@ -1,252 +1,252 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.NoInitialContextException;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.InitialContextFactoryBuilder;
-import javax.naming.spi.ObjectFactory;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-/**
- * Provides helper methods for the DelegateContext. This provides the methods so
- * there can be many DelegateContexts, but few service trackers.
- */
-public final class ContextHelper
-{
- /** The bundle context we use for accessing the SR */
- private static BundleContext context;
-
- /** Ensure no one constructs us */
- private ContextHelper() { throw new RuntimeException(); }
-
- public static void setBundleContext(BundleContext ctx)
- {
- context = ctx;
- }
-
- /**
- * This class creates a Context from an InitialContextFactory that may be
- * named in the provided env. If no name is set the first InitialContextFactory
- * returned from the service registry is used.
- *
- * @param env
- * @return the context.
- * @throws NamingException
- */
- public static Context createContext(Hashtable<?,?> env)
- throws NamingException
- {
-
- InitialContextFactory icf = null;
- ServiceReference ref = null;
-
- String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
-
- boolean icfFactorySet = true;
-
- if (icfFactory == null) {
- icfFactory = InitialContextFactory.class.getName();
- icfFactorySet = false;
- }
-
- try {
- ServiceReference[] refs = context.getAllServiceReferences(icfFactory, null);
- if (refs != null) {
- ref = refs[0];
- icf = (InitialContextFactory) context.getService(ref);
- }
- } catch (InvalidSyntaxException e) {
- // TODO nls enable this.
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e);
-
- throw e4;
- }
-
- if (icf == null) {
- try {
- ServiceReference[] refs = context.getAllServiceReferences(InitialContextFactoryBuilder.class.getName(), null);
-
- if (refs != null) {
- for (ServiceReference icfbRef : refs) {
- InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(icfbRef);
-
- icf = builder.createInitialContextFactory(env);
-
- context.ungetService(icfbRef);
- if (icf != null) {
- break;
- }
- }
- }
- } catch (InvalidSyntaxException e) {
- // TODO nls enable this.
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e);
- throw e4;
- }
- }
-
- if (icf == null && icfFactorySet) {
- try {
- Class<?> clazz = Class.forName(icfFactory, true, null);
- icf = (InitialContextFactory) clazz.newInstance();
- } catch (ClassNotFoundException e11) {
- // TODO nls enable this.
- NamingException e = new NamingException("Argh this should never happen :)");
- e.initCause(e11);
- throw e;
- } catch (InstantiationException e2) {
- // TODO nls enable this.
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e2);
- throw e4;
- } catch (IllegalAccessException e1) {
- // TODO nls enable this.
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e1);
- throw e4;
- }
- }
-
- if (icf == null) {
-
- // TODO nls enable this.
- NamingException e3 = new NoInitialContextException("We could not find an InitialContextFactory to use");
-
- throw e3;
- }
-
- Context ctx = icf.getInitialContext(env);
-
- if (ref != null) context.ungetService(ref);
-
- if (ctx == null) {
- // TODO nls enable this
- NamingException e = new NamingException("The ICF returned a null context");
- throw e;
- }
-
- return ctx;
- }
-
-
- private static Context createIcfContext(Hashtable<?,?> env) throws NamingException
- {
- String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
- InitialContextFactory icf = null;
-
- if (icfFactory != null) {
- try {
- Class<?> clazz = Class.forName(icfFactory, true, Thread.currentThread()
- .getContextClassLoader());
- icf = (InitialContextFactory) clazz.newInstance();
-
- } catch (ClassNotFoundException e11) {
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e11);
- throw e4;
- } catch (InstantiationException e2) {
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e2);
- throw e4;
- } catch (IllegalAccessException e1) {
- NamingException e4 = new NamingException("Argh this should never happen :)");
- e4.initCause(e1);
- throw e4;
- }
- }
- Context ctx = null;
-
- if (icf != null) {
- ctx = icf.getInitialContext(env);
- }
-
- return ctx;
- }
-
- /**
- * This method is used to create a URL Context. It does this by looking for
- * the URL context's ObjectFactory in the service registry.
- *
- * @param urlScheme
- * @param env
- * @return a Context
- * @throws NamingException
- */
- public static Context createURLContext(String urlScheme, Hashtable<?, ?> env)
- throws NamingException
- {
- ObjectFactory factory = null;
- ServiceReference ref = null;
-
- Context ctx = null;
-
- try {
- ServiceReference[] services = context.getServiceReferences(ObjectFactory.class.getName(),
- "(|(osgi.jndi.urlScheme=" + urlScheme + ")(urlScheme=" + urlScheme + "))");
-
- if (services != null) {
- ref = services[0];
- factory = (ObjectFactory) context.getService(ref);
- }
- } catch (InvalidSyntaxException e1) {
- // TODO nls enable this.
- NamingException e = new NamingException("Argh this should never happen :)");
- e.initCause(e1);
- throw e;
- }
-
- if (factory != null) {
- try {
- ctx = (Context) factory.getObjectInstance(null, null, null, env);
- } catch (Exception e) {
- NamingException e2 = new NamingException();
- e2.initCause(e);
- throw e2;
- } finally {
- if (ref != null) context.ungetService(ref);
- }
- }
-
- // TODO: This works for WAS - we believe - but is incorrect behaviour. We should not use an icf to generate the URLContext.
- // Rather, the missing URLContext factories should be exported on behalf of WAS.
- if (ctx == null) {
- ctx = createIcfContext(env);
- }
-
- if (ctx == null && factory == null) {
- NamingException e = new NamingException("We could not find an ObjectFactory to use");
- throw e;
- } else if (ctx == null && factory != null) {
- NamingException e = new NamingException("The ICF returned a null context");
- throw e;
- }
-
- return ctx;
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.ObjectFactory;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Provides helper methods for the DelegateContext. This provides the methods so
+ * there can be many DelegateContexts, but few service trackers.
+ */
+public final class ContextHelper
+{
+ /** The bundle context we use for accessing the SR */
+ private static BundleContext context;
+
+ /** Ensure no one constructs us */
+ private ContextHelper() { throw new RuntimeException(); }
+
+ public static void setBundleContext(BundleContext ctx)
+ {
+ context = ctx;
+ }
+
+ /**
+ * This class creates a Context from an InitialContextFactory that may be
+ * named in the provided env. If no name is set the first InitialContextFactory
+ * returned from the service registry is used.
+ *
+ * @param env
+ * @return the context.
+ * @throws NamingException
+ */
+ public static Context createContext(Hashtable<?,?> env)
+ throws NamingException
+ {
+
+ InitialContextFactory icf = null;
+ ServiceReference ref = null;
+
+ String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
+
+ boolean icfFactorySet = true;
+
+ if (icfFactory == null) {
+ icfFactory = InitialContextFactory.class.getName();
+ icfFactorySet = false;
+ }
+
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(icfFactory, null);
+ if (refs != null) {
+ ref = refs[0];
+ icf = (InitialContextFactory) context.getService(ref);
+ }
+ } catch (InvalidSyntaxException e) {
+ // TODO nls enable this.
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e);
+
+ throw e4;
+ }
+
+ if (icf == null) {
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(InitialContextFactoryBuilder.class.getName(), null);
+
+ if (refs != null) {
+ for (ServiceReference icfbRef : refs) {
+ InitialContextFactoryBuilder builder = (InitialContextFactoryBuilder) context.getService(icfbRef);
+
+ icf = builder.createInitialContextFactory(env);
+
+ context.ungetService(icfbRef);
+ if (icf != null) {
+ break;
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // TODO nls enable this.
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e);
+ throw e4;
+ }
+ }
+
+ if (icf == null && icfFactorySet) {
+ try {
+ Class<?> clazz = Class.forName(icfFactory, true, null);
+ icf = (InitialContextFactory) clazz.newInstance();
+ } catch (ClassNotFoundException e11) {
+ // TODO nls enable this.
+ NamingException e = new NamingException("Argh this should never happen :)");
+ e.initCause(e11);
+ throw e;
+ } catch (InstantiationException e2) {
+ // TODO nls enable this.
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e2);
+ throw e4;
+ } catch (IllegalAccessException e1) {
+ // TODO nls enable this.
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e1);
+ throw e4;
+ }
+ }
+
+ if (icf == null) {
+
+ // TODO nls enable this.
+ NamingException e3 = new NoInitialContextException("We could not find an InitialContextFactory to use");
+
+ throw e3;
+ }
+
+ Context ctx = icf.getInitialContext(env);
+
+ if (ref != null) context.ungetService(ref);
+
+ if (ctx == null) {
+ // TODO nls enable this
+ NamingException e = new NamingException("The ICF returned a null context");
+ throw e;
+ }
+
+ return ctx;
+ }
+
+
+ private static Context createIcfContext(Hashtable<?,?> env) throws NamingException
+ {
+ String icfFactory = (String) env.get(Context.INITIAL_CONTEXT_FACTORY);
+ InitialContextFactory icf = null;
+
+ if (icfFactory != null) {
+ try {
+ Class<?> clazz = Class.forName(icfFactory, true, Thread.currentThread()
+ .getContextClassLoader());
+ icf = (InitialContextFactory) clazz.newInstance();
+
+ } catch (ClassNotFoundException e11) {
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e11);
+ throw e4;
+ } catch (InstantiationException e2) {
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e2);
+ throw e4;
+ } catch (IllegalAccessException e1) {
+ NamingException e4 = new NamingException("Argh this should never happen :)");
+ e4.initCause(e1);
+ throw e4;
+ }
+ }
+ Context ctx = null;
+
+ if (icf != null) {
+ ctx = icf.getInitialContext(env);
+ }
+
+ return ctx;
+ }
+
+ /**
+ * This method is used to create a URL Context. It does this by looking for
+ * the URL context's ObjectFactory in the service registry.
+ *
+ * @param urlScheme
+ * @param env
+ * @return a Context
+ * @throws NamingException
+ */
+ public static Context createURLContext(String urlScheme, Hashtable<?, ?> env)
+ throws NamingException
+ {
+ ObjectFactory factory = null;
+ ServiceReference ref = null;
+
+ Context ctx = null;
+
+ try {
+ ServiceReference[] services = context.getServiceReferences(ObjectFactory.class.getName(),
+ "(|(osgi.jndi.urlScheme=" + urlScheme + ")(urlScheme=" + urlScheme + "))");
+
+ if (services != null) {
+ ref = services[0];
+ factory = (ObjectFactory) context.getService(ref);
+ }
+ } catch (InvalidSyntaxException e1) {
+ // TODO nls enable this.
+ NamingException e = new NamingException("Argh this should never happen :)");
+ e.initCause(e1);
+ throw e;
+ }
+
+ if (factory != null) {
+ try {
+ ctx = (Context) factory.getObjectInstance(null, null, null, env);
+ } catch (Exception e) {
+ NamingException e2 = new NamingException();
+ e2.initCause(e);
+ throw e2;
+ } finally {
+ if (ref != null) context.ungetService(ref);
+ }
+ }
+
+ // TODO: This works for WAS - we believe - but is incorrect behaviour. We should not use an icf to generate the URLContext.
+ // Rather, the missing URLContext factories should be exported on behalf of WAS.
+ if (ctx == null) {
+ ctx = createIcfContext(env);
+ }
+
+ if (ctx == null && factory == null) {
+ NamingException e = new NamingException("We could not find an ObjectFactory to use");
+ throw e;
+ } else if (ctx == null && factory != null) {
+ NamingException e = new NamingException("The ICF returned a null context");
+ throw e;
+ }
+
+ return ctx;
+ }
}
\ No newline at end of file
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java Tue Oct 6 20:41:31 2009
@@ -1,396 +1,396 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
-
-import java.util.Hashtable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NameClassPair;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.ModificationItem;
-import javax.naming.directory.SearchControls;
-
-public class DelegateContext implements DirContext
-{
- private Hashtable<Object, Object> env = new Hashtable<Object, Object>();
- private Context defaultContext;
- private static ConcurrentMap<String, Context> urlContexts = new ConcurrentHashMap<String, Context>();
-
- public DelegateContext(Hashtable<?, ?> theEnv)
- {
- env.putAll(theEnv);
- }
-
- public DelegateContext(Context ctx) throws NamingException
- {
-
- defaultContext = ctx;
- env.putAll(ctx.getEnvironment());
-
- }
-
- public Object addToEnvironment(String propName, Object propVal) throws NamingException
- {
- Context ctx = getDefaultContext();
-
- if (ctx != null) ctx.addToEnvironment(propName, propVal);
-
- return env.put(propName, propVal);
- }
-
- public void bind(Name name, Object obj) throws NamingException
- {
- findContext(name).bind(name, obj);
- }
-
- public void bind(String name, Object obj) throws NamingException
- {
- findContext(name).bind(name, obj);
- }
-
- public void close() throws NamingException
- {
- if (defaultContext != null) defaultContext.close();
- env.clear();
- }
-
- public Name composeName(Name name, Name prefix) throws NamingException
- {
- return findContext(name).composeName(name, prefix);
- }
-
- public String composeName(String name, String prefix) throws NamingException
- {
- return findContext(name).composeName(name, prefix);
- }
-
- public Context createSubcontext(Name name) throws NamingException
- {
- return findContext(name).createSubcontext(name);
- }
-
- public Context createSubcontext(String name) throws NamingException
- {
- return findContext(name).createSubcontext(name);
- }
-
- public void destroySubcontext(Name name) throws NamingException
- {
- findContext(name).destroySubcontext(name);
- }
-
- public void destroySubcontext(String name) throws NamingException
- {
- findContext(name).destroySubcontext(name);
- }
-
- public Hashtable<?, ?> getEnvironment() throws NamingException
- {
- Hashtable<Object, Object> theEnv = new Hashtable<Object, Object>();
- theEnv.putAll(env);
- return theEnv;
- }
-
- public String getNameInNamespace() throws NamingException
- {
- return getDefaultContext().getNameInNamespace();
- }
-
- public NameParser getNameParser(Name name) throws NamingException
- {
- return findContext(name).getNameParser(name);
- }
-
- public NameParser getNameParser(String name) throws NamingException
- {
- return findContext(name).getNameParser(name);
- }
-
- public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
- {
- return findContext(name).list(name);
- }
-
- public NamingEnumeration<NameClassPair> list(String name) throws NamingException
- {
- return findContext(name).list(name);
- }
-
- public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
- {
- return findContext(name).listBindings(name);
- }
-
- public NamingEnumeration<Binding> listBindings(String name) throws NamingException
- {
- return findContext(name).listBindings(name);
- }
-
- public Object lookup(Name name) throws NamingException
- {
- return findContext(name).lookup(name);
- }
-
- public Object lookup(String name) throws NamingException
- {
- return findContext(name).lookup(name);
- }
-
- public Object lookupLink(Name name) throws NamingException
- {
- return findContext(name).lookupLink(name);
- }
-
- public Object lookupLink(String name) throws NamingException
- {
- return findContext(name).lookupLink(name);
- }
-
- public void rebind(Name name, Object obj) throws NamingException
- {
- findContext(name).rebind(name, obj);
- }
-
- public void rebind(String name, Object obj) throws NamingException
- {
- findContext(name).rebind(name, obj);
- }
-
- public Object removeFromEnvironment(String propName) throws NamingException
- {
- Context ctx = getDefaultContext();
-
- if (ctx != null) ctx.removeFromEnvironment(propName);
-
- return env.remove(propName);
- }
-
- public void rename(Name oldName, Name newName) throws NamingException
- {
- findContext(oldName).rename(oldName, newName);
- }
-
- public void rename(String oldName, String newName) throws NamingException
- {
- findContext(oldName).rename(oldName, newName);
- }
-
- public void unbind(Name name) throws NamingException
- {
- findContext(name).unbind(name);
- }
-
- public void unbind(String name) throws NamingException
- {
- findContext(name).unbind(name);
- }
-
- protected Context findContext(Name name) throws NamingException
- {
- return findContext(name.toString());
- }
-
-
- protected Context findContext(String name) throws NamingException
- {
- Context toReturn = null;
-
- if (name.contains(":")) {
- toReturn = getURLContext(name);
- } else {
- toReturn = getDefaultContext();
- }
-
- if (toReturn != null)
- {
- String packages = System.getProperty(Context.URL_PKG_PREFIXES, null);
-
- if (packages != null)
- {
- toReturn.addToEnvironment(Context.URL_PKG_PREFIXES, packages);
- }
- }
-
- return toReturn;
- }
-
- private Context getDefaultContext() throws NamingException
- {
- if (defaultContext == null) {
- defaultContext = ContextHelper.createContext(env);
- }
- return defaultContext;
- }
-
- private Context getURLContext(String name) throws NamingException
- {
- Context ctx = null;
-
- int index = name.indexOf(':');
-
- if (index != -1) {
- String scheme = name.substring(0, index);
-
- ctx = ContextHelper.createURLContext(scheme, env);
- }
-
- if (ctx == null) {
- ctx = getDefaultContext();
- }
-
- return ctx;
- }
-
- /**
- * This method allows the caller to set the default context if one is to hand.
- * Normally the context would be lazily constructed upon first use, but this
- * if one already exists when this is created it can be pushed in.
- *
- * @param ctx the context to use.
- */
- public void setDefaultContext(Context ctx)
- {
- defaultContext = ctx;
- }
-
- /**
- * This method allows URL contexts to be pushed in. We should probably be
- * pushing in references to the ObjectFactory for the url Object Factory, but
- * for now lets just push the context itself in.
- *
- * @param url
- * @param ctx
- */
- public void setURLContext(String url, Context ctx)
- {
- urlContexts.put(url, ctx);
- }
-
- public Attributes getAttributes(Name name) throws NamingException {
- return ((DirContext)findContext(name)).getAttributes(name);
- }
-
- public Attributes getAttributes(String name) throws NamingException {
- return ((DirContext)findContext(name)).getAttributes(name);
- }
-
- public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
- return ((DirContext)findContext(name)).getAttributes(name, attrIds);
- }
-
- public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
- return ((DirContext)findContext(name)).getAttributes(name, attrIds);
- }
-
- public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
- ((DirContext)findContext(name)).modifyAttributes(name, mod_op, attrs);
- }
-
- public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
- ((DirContext)findContext(name)).modifyAttributes(name, mod_op, attrs);
- }
-
- public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
- ((DirContext)findContext(name)).modifyAttributes(name, mods);
- }
-
- public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
- ((DirContext)findContext(name)).modifyAttributes(name, mods);
- }
-
- public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
- ((DirContext)findContext(name)).bind(name, obj, attrs);
- }
-
- public void bind(String name, Object obj, Attributes attrs) throws NamingException {
- ((DirContext)findContext(name)).bind(name, obj, attrs);
- }
-
- public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
- ((DirContext)findContext(name)).rebind(name, obj, attrs);
- }
-
- public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
- ((DirContext)findContext(name)).rebind(name, obj, attrs);
- }
-
- public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
- return ((DirContext)findContext(name)).createSubcontext(name, attrs);
- }
-
- public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
- return ((DirContext)findContext(name)).createSubcontext(name, attrs);
- }
-
- public DirContext getSchema(Name name) throws NamingException {
- return ((DirContext)findContext(name)).getSchema(name);
- }
-
- public DirContext getSchema(String name) throws NamingException {
- return ((DirContext)findContext(name)).getSchema(name);
- }
-
- public DirContext getSchemaClassDefinition(Name name) throws NamingException {
- return ((DirContext)findContext(name)).getSchemaClassDefinition(name);
- }
-
- public DirContext getSchemaClassDefinition(String name) throws NamingException {
- return ((DirContext)findContext(name)).getSchemaClassDefinition(name);
- }
-
- public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
- return ((DirContext)findContext(name)).search(name, matchingAttributes, attributesToReturn);
- }
-
- public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
- return ((DirContext)findContext(name)).search(name, matchingAttributes, attributesToReturn);
- }
-
- public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException {
- return ((DirContext)findContext(name)).search(name, matchingAttributes);
- }
-
- public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException {
- return ((DirContext)findContext(name)).search(name, matchingAttributes);
- }
-
- public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException {
- return ((DirContext)findContext(name)).search(name, filter, cons);
- }
-
- public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException {
- return ((DirContext)findContext(name)).search(name, filter, cons);
- }
-
- public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
- return ((DirContext)findContext(name)).search(name, filterExpr, filterArgs, cons);
- }
-
- public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
- return ((DirContext)findContext(name)).search(name, filterExpr, filterArgs, cons);
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
+
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+
+public class DelegateContext implements DirContext
+{
+ private Hashtable<Object, Object> env = new Hashtable<Object, Object>();
+ private Context defaultContext;
+ private static ConcurrentMap<String, Context> urlContexts = new ConcurrentHashMap<String, Context>();
+
+ public DelegateContext(Hashtable<?, ?> theEnv)
+ {
+ env.putAll(theEnv);
+ }
+
+ public DelegateContext(Context ctx) throws NamingException
+ {
+
+ defaultContext = ctx;
+ env.putAll(ctx.getEnvironment());
+
+ }
+
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException
+ {
+ Context ctx = getDefaultContext();
+
+ if (ctx != null) ctx.addToEnvironment(propName, propVal);
+
+ return env.put(propName, propVal);
+ }
+
+ public void bind(Name name, Object obj) throws NamingException
+ {
+ findContext(name).bind(name, obj);
+ }
+
+ public void bind(String name, Object obj) throws NamingException
+ {
+ findContext(name).bind(name, obj);
+ }
+
+ public void close() throws NamingException
+ {
+ if (defaultContext != null) defaultContext.close();
+ env.clear();
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException
+ {
+ return findContext(name).composeName(name, prefix);
+ }
+
+ public String composeName(String name, String prefix) throws NamingException
+ {
+ return findContext(name).composeName(name, prefix);
+ }
+
+ public Context createSubcontext(Name name) throws NamingException
+ {
+ return findContext(name).createSubcontext(name);
+ }
+
+ public Context createSubcontext(String name) throws NamingException
+ {
+ return findContext(name).createSubcontext(name);
+ }
+
+ public void destroySubcontext(Name name) throws NamingException
+ {
+ findContext(name).destroySubcontext(name);
+ }
+
+ public void destroySubcontext(String name) throws NamingException
+ {
+ findContext(name).destroySubcontext(name);
+ }
+
+ public Hashtable<?, ?> getEnvironment() throws NamingException
+ {
+ Hashtable<Object, Object> theEnv = new Hashtable<Object, Object>();
+ theEnv.putAll(env);
+ return theEnv;
+ }
+
+ public String getNameInNamespace() throws NamingException
+ {
+ return getDefaultContext().getNameInNamespace();
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException
+ {
+ return findContext(name).getNameParser(name);
+ }
+
+ public NameParser getNameParser(String name) throws NamingException
+ {
+ return findContext(name).getNameParser(name);
+ }
+
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
+ {
+ return findContext(name).list(name);
+ }
+
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException
+ {
+ return findContext(name).list(name);
+ }
+
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
+ {
+ return findContext(name).listBindings(name);
+ }
+
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException
+ {
+ return findContext(name).listBindings(name);
+ }
+
+ public Object lookup(Name name) throws NamingException
+ {
+ return findContext(name).lookup(name);
+ }
+
+ public Object lookup(String name) throws NamingException
+ {
+ return findContext(name).lookup(name);
+ }
+
+ public Object lookupLink(Name name) throws NamingException
+ {
+ return findContext(name).lookupLink(name);
+ }
+
+ public Object lookupLink(String name) throws NamingException
+ {
+ return findContext(name).lookupLink(name);
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException
+ {
+ findContext(name).rebind(name, obj);
+ }
+
+ public void rebind(String name, Object obj) throws NamingException
+ {
+ findContext(name).rebind(name, obj);
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException
+ {
+ Context ctx = getDefaultContext();
+
+ if (ctx != null) ctx.removeFromEnvironment(propName);
+
+ return env.remove(propName);
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException
+ {
+ findContext(oldName).rename(oldName, newName);
+ }
+
+ public void rename(String oldName, String newName) throws NamingException
+ {
+ findContext(oldName).rename(oldName, newName);
+ }
+
+ public void unbind(Name name) throws NamingException
+ {
+ findContext(name).unbind(name);
+ }
+
+ public void unbind(String name) throws NamingException
+ {
+ findContext(name).unbind(name);
+ }
+
+ protected Context findContext(Name name) throws NamingException
+ {
+ return findContext(name.toString());
+ }
+
+
+ protected Context findContext(String name) throws NamingException
+ {
+ Context toReturn = null;
+
+ if (name.contains(":")) {
+ toReturn = getURLContext(name);
+ } else {
+ toReturn = getDefaultContext();
+ }
+
+ if (toReturn != null)
+ {
+ String packages = System.getProperty(Context.URL_PKG_PREFIXES, null);
+
+ if (packages != null)
+ {
+ toReturn.addToEnvironment(Context.URL_PKG_PREFIXES, packages);
+ }
+ }
+
+ return toReturn;
+ }
+
+ private Context getDefaultContext() throws NamingException
+ {
+ if (defaultContext == null) {
+ defaultContext = ContextHelper.createContext(env);
+ }
+ return defaultContext;
+ }
+
+ private Context getURLContext(String name) throws NamingException
+ {
+ Context ctx = null;
+
+ int index = name.indexOf(':');
+
+ if (index != -1) {
+ String scheme = name.substring(0, index);
+
+ ctx = ContextHelper.createURLContext(scheme, env);
+ }
+
+ if (ctx == null) {
+ ctx = getDefaultContext();
+ }
+
+ return ctx;
+ }
+
+ /**
+ * This method allows the caller to set the default context if one is to hand.
+ * Normally the context would be lazily constructed upon first use, but this
+ * if one already exists when this is created it can be pushed in.
+ *
+ * @param ctx the context to use.
+ */
+ public void setDefaultContext(Context ctx)
+ {
+ defaultContext = ctx;
+ }
+
+ /**
+ * This method allows URL contexts to be pushed in. We should probably be
+ * pushing in references to the ObjectFactory for the url Object Factory, but
+ * for now lets just push the context itself in.
+ *
+ * @param url
+ * @param ctx
+ */
+ public void setURLContext(String url, Context ctx)
+ {
+ urlContexts.put(url, ctx);
+ }
+
+ public Attributes getAttributes(Name name) throws NamingException {
+ return ((DirContext)findContext(name)).getAttributes(name);
+ }
+
+ public Attributes getAttributes(String name) throws NamingException {
+ return ((DirContext)findContext(name)).getAttributes(name);
+ }
+
+ public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
+ return ((DirContext)findContext(name)).getAttributes(name, attrIds);
+ }
+
+ public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
+ return ((DirContext)findContext(name)).getAttributes(name, attrIds);
+ }
+
+ public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
+ ((DirContext)findContext(name)).modifyAttributes(name, mod_op, attrs);
+ }
+
+ public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
+ ((DirContext)findContext(name)).modifyAttributes(name, mod_op, attrs);
+ }
+
+ public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
+ ((DirContext)findContext(name)).modifyAttributes(name, mods);
+ }
+
+ public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
+ ((DirContext)findContext(name)).modifyAttributes(name, mods);
+ }
+
+ public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
+ ((DirContext)findContext(name)).bind(name, obj, attrs);
+ }
+
+ public void bind(String name, Object obj, Attributes attrs) throws NamingException {
+ ((DirContext)findContext(name)).bind(name, obj, attrs);
+ }
+
+ public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
+ ((DirContext)findContext(name)).rebind(name, obj, attrs);
+ }
+
+ public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
+ ((DirContext)findContext(name)).rebind(name, obj, attrs);
+ }
+
+ public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
+ return ((DirContext)findContext(name)).createSubcontext(name, attrs);
+ }
+
+ public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
+ return ((DirContext)findContext(name)).createSubcontext(name, attrs);
+ }
+
+ public DirContext getSchema(Name name) throws NamingException {
+ return ((DirContext)findContext(name)).getSchema(name);
+ }
+
+ public DirContext getSchema(String name) throws NamingException {
+ return ((DirContext)findContext(name)).getSchema(name);
+ }
+
+ public DirContext getSchemaClassDefinition(Name name) throws NamingException {
+ return ((DirContext)findContext(name)).getSchemaClassDefinition(name);
+ }
+
+ public DirContext getSchemaClassDefinition(String name) throws NamingException {
+ return ((DirContext)findContext(name)).getSchemaClassDefinition(name);
+ }
+
+ public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, matchingAttributes, attributesToReturn);
+ }
+
+ public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, matchingAttributes, attributesToReturn);
+ }
+
+ public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, matchingAttributes);
+ }
+
+ public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, matchingAttributes);
+ }
+
+ public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, filter, cons);
+ }
+
+ public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, filter, cons);
+ }
+
+ public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, filterExpr, filterArgs, cons);
+ }
+
+ public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
+ return ((DirContext)findContext(name)).search(name, filterExpr, filterArgs, cons);
+ }
}
\ No newline at end of file
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java Tue Oct 6 20:41:31 2009
@@ -1,28 +1,28 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-
-public interface DelegateContextFactory {
- public Context getInitialContext(Hashtable<?, ?> envmt) throws NamingException;
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+public interface DelegateContextFactory {
+ public Context getInitialContext(Hashtable<?, ?> envmt) throws NamingException;
+}
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/DelegateContextFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java Tue Oct 6 20:41:31 2009
@@ -1,74 +1,74 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
-
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.InitialContextFactoryBuilder;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-
-
-public class OSGiInitialContextFactoryBuilder implements InitialContextFactoryBuilder,
- InitialContextFactory
-{
- private BundleContext _context;
-
- public OSGiInitialContextFactoryBuilder(BundleContext context)
- {
- _context = context;
- }
-
- public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment)
- throws NamingException
- {
- return this;
- }
- public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException
- {
- Context toReturn = null;
-
- ServiceReference ref = _context.getServiceReference(DelegateContextFactory.class.getName());
-
- //TODO: is the custom interface DelegateContextFactory the right way to go about things
- // or is there a more generic way in RFC 142
- if (ref != null) {
- try {
- DelegateContextFactory dcf = (DelegateContextFactory) _context.getService(ref);
-
- if (dcf != null) {
- toReturn = dcf.getInitialContext(environment);
- }
- }
- finally {
- _context.ungetService(ref);
- }
- }
-
- if (toReturn == null) {
- toReturn = new DelegateContext(environment);
- }
-
- return toReturn;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.InitialContextFactoryBuilder;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+
+public class OSGiInitialContextFactoryBuilder implements InitialContextFactoryBuilder,
+ InitialContextFactory
+{
+ private BundleContext _context;
+
+ public OSGiInitialContextFactoryBuilder(BundleContext context)
+ {
+ _context = context;
+ }
+
+ public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment)
+ throws NamingException
+ {
+ return this;
+ }
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException
+ {
+ Context toReturn = null;
+
+ ServiceReference ref = _context.getServiceReference(DelegateContextFactory.class.getName());
+
+ //TODO: is the custom interface DelegateContextFactory the right way to go about things
+ // or is there a more generic way in RFC 142
+ if (ref != null) {
+ try {
+ DelegateContextFactory dcf = (DelegateContextFactory) _context.getService(ref);
+
+ if (dcf != null) {
+ toReturn = dcf.getInitialContext(environment);
+ }
+ }
+ finally {
+ _context.ungetService(ref);
+ }
+ }
+
+ if (toReturn == null) {
+ toReturn = new DelegateContext(environment);
+ }
+
+ return toReturn;
+ }
+}
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiInitialContextFactoryBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java Tue Oct 6 20:41:31 2009
@@ -1,246 +1,246 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.RefAddr;
-import javax.naming.Reference;
-import javax.naming.Referenceable;
-import javax.naming.StringRefAddr;
-import javax.naming.directory.Attributes;
-import javax.naming.spi.DirObjectFactory;
-import javax.naming.spi.ObjectFactory;
-import javax.naming.spi.ObjectFactoryBuilder;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-
-public class OSGiObjectFactoryBuilder implements ObjectFactoryBuilder, ObjectFactory, DirObjectFactory
-{
- /** The bundle context we use for accessing the SR */
- private static BundleContext context;
-
- public static void setBundleContext(BundleContext ctx)
- {
- context = ctx;
- }
-
- public ObjectFactory createObjectFactory(Object obj, Hashtable<?, ?> environment)
- throws NamingException
- {
- return this;
- }
-
- public Object getObjectInstance(Object obj, Name name, Context nameCtx,
- Hashtable<?, ?> environment) throws Exception
- {
-
- Reference ref = null;
-
- if (obj instanceof Reference) {
- ref = (Reference) obj;
- } else if (obj instanceof Referenceable) {
- ref = ((Referenceable)obj).getReference();
- }
-
- Object result = ref;
-
- if (ref != null) {
- String className = ref.getFactoryClassName();
-
- if (className != null) {
- result = getObjectInstanceUsingClassName(obj, className, obj, name, nameCtx, environment);
- } else {
- result = getObjectInstanceUsingRefAddress(ref.getAll(), obj, name, nameCtx, environment);
-
- if (result == null || result == obj) {
- result = getObjectInstanceUsingAllObjectFactories(obj, name, nameCtx, environment);
- }
- }
- }
-
- if (result == null) result = ref;
-
- return result;
- }
-
- private Object getObjectInstanceUsingAllObjectFactories(Object obj, Name name, Context nameCtx,
- Hashtable<?, ?> environment)
- {
- Object result = obj;
- try {
- ServiceReference[] refs = context.getAllServiceReferences(ObjectFactory.class.getName(), null);
-
- if (refs != null) {
- for (ServiceReference ref : refs) {
- ObjectFactory factory = (ObjectFactory) context.getService(ref);
-
- if (factory != null) {
- try {
- result = factory.getObjectInstance(obj, name, nameCtx, environment);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- context.ungetService(ref);
-
- // if the result comes back and is not null and not the reference
- // object then we should return the result, so break out of the
- // loop we are in.
- if (result != null && result != obj) break;
- }
- }
- }
- } catch (InvalidSyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- if (result == null) result = obj;
-
- return result;
- }
-
- private Object getObjectInstanceUsingRefAddress(Enumeration<RefAddr> addresses, Object obj, Name name,
- Context nameCtx, Hashtable<?, ?> environment)
- {
- Object result = obj;
-
- while (addresses.hasMoreElements()) {
- RefAddr address = addresses.nextElement();
- if (address instanceof StringRefAddr && "URL".equals(address.getType())) {
- String urlScheme = (String)address.getContent();
- ObjectFactory factory = null;
- ServiceReference ref = null;
- try {
- ServiceReference[] services = context.getServiceReferences(ObjectFactory.class.getName(), "(|(osgi.jndi.urlScheme=" + urlScheme + ")(urlScheme=" + urlScheme + "))");
-
- if (services != null) {
- ref = services[0];
- factory = (ObjectFactory) context.getService(ref);
- }
- } catch (InvalidSyntaxException e) {
- e.printStackTrace();
- }
-
- if (factory != null) {
- try {
- result = factory.getObjectInstance(obj, name, nameCtx, environment);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- if (ref != null) context.ungetService(ref);
-
- // if the result is not null and references a different object from
- // the obj then we have resolved the object, so we stop searching.
- if (result != null && result != obj) break;
- }
- }
-
- return result;
- }
-
- private Object getObjectInstanceUsingClassName(Object reference, String className, Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
- {
- Object result = obj;
-
- ObjectFactory factory = null;
- ServiceReference ref = null;
-
- if (className != null) {
- try {
- ServiceReference[] refs = context.getAllServiceReferences(className, null);
-
- if (refs != null) {
- for (ServiceReference ref1 : refs) {
- factory = (ObjectFactory) context.getService(ref1);
-
- if (factory != null) {
- ref = ref1;
- break;
- }
- }
- }
- } catch (InvalidSyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- if (factory == null) {
- try {
- ServiceReference[] refs = context.getServiceReferences(ObjectFactoryBuilder.class.getName(), null);
-
- if (refs != null) {
- for (ServiceReference ofRef : refs) {
- ObjectFactoryBuilder builder = (ObjectFactoryBuilder) context.getService(ofRef);
- try {
- factory = builder.createObjectFactory(reference, environment);
- } catch (NamingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- context.ungetService(ofRef);
- if (factory != null) {
- break;
- }
- }
- }
- } catch (InvalidSyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- if (factory != null) {
- try {
- result = factory.getObjectInstance(obj, name, nameCtx, environment);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (ref != null) context.ungetService(ref);
- }
- }
-
- return result;
- }
-
- /**
- * when we get called by DirectoryManager#getObjectInstance if we can't find the object
- * instance, we just need to return the passed in refInfo
- */
- public Object getObjectInstance(Object refInfo, Name name, Context nameCtx,
- Hashtable<?, ?> environment, Attributes attrs) throws Exception {
- Object result = getObjectInstance(refInfo, name, nameCtx, environment);
- return result == null ? refInfo : result;
- }
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+import javax.naming.directory.Attributes;
+import javax.naming.spi.DirObjectFactory;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.ObjectFactoryBuilder;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class OSGiObjectFactoryBuilder implements ObjectFactoryBuilder, ObjectFactory, DirObjectFactory
+{
+ /** The bundle context we use for accessing the SR */
+ private static BundleContext context;
+
+ public static void setBundleContext(BundleContext ctx)
+ {
+ context = ctx;
+ }
+
+ public ObjectFactory createObjectFactory(Object obj, Hashtable<?, ?> environment)
+ throws NamingException
+ {
+ return this;
+ }
+
+ public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+ Hashtable<?, ?> environment) throws Exception
+ {
+
+ Reference ref = null;
+
+ if (obj instanceof Reference) {
+ ref = (Reference) obj;
+ } else if (obj instanceof Referenceable) {
+ ref = ((Referenceable)obj).getReference();
+ }
+
+ Object result = ref;
+
+ if (ref != null) {
+ String className = ref.getFactoryClassName();
+
+ if (className != null) {
+ result = getObjectInstanceUsingClassName(obj, className, obj, name, nameCtx, environment);
+ } else {
+ result = getObjectInstanceUsingRefAddress(ref.getAll(), obj, name, nameCtx, environment);
+
+ if (result == null || result == obj) {
+ result = getObjectInstanceUsingAllObjectFactories(obj, name, nameCtx, environment);
+ }
+ }
+ }
+
+ if (result == null) result = ref;
+
+ return result;
+ }
+
+ private Object getObjectInstanceUsingAllObjectFactories(Object obj, Name name, Context nameCtx,
+ Hashtable<?, ?> environment)
+ {
+ Object result = obj;
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(ObjectFactory.class.getName(), null);
+
+ if (refs != null) {
+ for (ServiceReference ref : refs) {
+ ObjectFactory factory = (ObjectFactory) context.getService(ref);
+
+ if (factory != null) {
+ try {
+ result = factory.getObjectInstance(obj, name, nameCtx, environment);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ context.ungetService(ref);
+
+ // if the result comes back and is not null and not the reference
+ // object then we should return the result, so break out of the
+ // loop we are in.
+ if (result != null && result != obj) break;
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (result == null) result = obj;
+
+ return result;
+ }
+
+ private Object getObjectInstanceUsingRefAddress(Enumeration<RefAddr> addresses, Object obj, Name name,
+ Context nameCtx, Hashtable<?, ?> environment)
+ {
+ Object result = obj;
+
+ while (addresses.hasMoreElements()) {
+ RefAddr address = addresses.nextElement();
+ if (address instanceof StringRefAddr && "URL".equals(address.getType())) {
+ String urlScheme = (String)address.getContent();
+ ObjectFactory factory = null;
+ ServiceReference ref = null;
+ try {
+ ServiceReference[] services = context.getServiceReferences(ObjectFactory.class.getName(), "(|(osgi.jndi.urlScheme=" + urlScheme + ")(urlScheme=" + urlScheme + "))");
+
+ if (services != null) {
+ ref = services[0];
+ factory = (ObjectFactory) context.getService(ref);
+ }
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+
+ if (factory != null) {
+ try {
+ result = factory.getObjectInstance(obj, name, nameCtx, environment);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ if (ref != null) context.ungetService(ref);
+
+ // if the result is not null and references a different object from
+ // the obj then we have resolved the object, so we stop searching.
+ if (result != null && result != obj) break;
+ }
+ }
+
+ return result;
+ }
+
+ private Object getObjectInstanceUsingClassName(Object reference, String className, Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
+ {
+ Object result = obj;
+
+ ObjectFactory factory = null;
+ ServiceReference ref = null;
+
+ if (className != null) {
+ try {
+ ServiceReference[] refs = context.getAllServiceReferences(className, null);
+
+ if (refs != null) {
+ for (ServiceReference ref1 : refs) {
+ factory = (ObjectFactory) context.getService(ref1);
+
+ if (factory != null) {
+ ref = ref1;
+ break;
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ if (factory == null) {
+ try {
+ ServiceReference[] refs = context.getServiceReferences(ObjectFactoryBuilder.class.getName(), null);
+
+ if (refs != null) {
+ for (ServiceReference ofRef : refs) {
+ ObjectFactoryBuilder builder = (ObjectFactoryBuilder) context.getService(ofRef);
+ try {
+ factory = builder.createObjectFactory(reference, environment);
+ } catch (NamingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ context.ungetService(ofRef);
+ if (factory != null) {
+ break;
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ if (factory != null) {
+ try {
+ result = factory.getObjectInstance(obj, name, nameCtx, environment);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ if (ref != null) context.ungetService(ref);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * when we get called by DirectoryManager#getObjectInstance if we can't find the object
+ * instance, we just need to return the passed in refInfo
+ */
+ public Object getObjectInstance(Object refInfo, Name name, Context nameCtx,
+ Hashtable<?, ?> environment, Attributes attrs) throws Exception {
+ Object result = getObjectInstance(refInfo, name, nameCtx, environment);
+ return result == null ? refInfo : result;
+ }
+
}
\ No newline at end of file
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/OSGiObjectFactoryBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java?rev=822489&r1=822488&r2=822489&view=diff
==============================================================================
--- incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java (original)
+++ incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java Tue Oct 6 20:41:31 2009
@@ -1,62 +1,62 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi.startup;
-
-import javax.naming.NamingException;
-import javax.naming.spi.NamingManager;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-import org.apache.aries.jndi.ContextHelper;
-import org.apache.aries.jndi.OSGiInitialContextFactoryBuilder;
-import org.apache.aries.jndi.OSGiObjectFactoryBuilder;
-
-/**
- * The activator for this bundle makes sure the static classes in it are
- * driven so they can do their magic stuff properly.
- */
-public class Activator implements BundleActivator
-{
- public void start(BundleContext context)
- {
- ContextHelper.setBundleContext(context);
- OSGiObjectFactoryBuilder.setBundleContext(context);
-
- try {
- if (!!!NamingManager.hasInitialContextFactoryBuilder()) {
- NamingManager.setInitialContextFactoryBuilder(new OSGiInitialContextFactoryBuilder(context));
- }
- } catch (NamingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- try {
- NamingManager.setObjectFactoryBuilder(new OSGiObjectFactoryBuilder());
- } catch (NamingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalStateException e) {
- e.printStackTrace();
- }
- }
-
- public void stop(BundleContext context) {}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE 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 WARRANTIESOR 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.aries.jndi.startup;
+
+import javax.naming.NamingException;
+import javax.naming.spi.NamingManager;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import org.apache.aries.jndi.ContextHelper;
+import org.apache.aries.jndi.OSGiInitialContextFactoryBuilder;
+import org.apache.aries.jndi.OSGiObjectFactoryBuilder;
+
+/**
+ * The activator for this bundle makes sure the static classes in it are
+ * driven so they can do their magic stuff properly.
+ */
+public class Activator implements BundleActivator
+{
+ public void start(BundleContext context)
+ {
+ ContextHelper.setBundleContext(context);
+ OSGiObjectFactoryBuilder.setBundleContext(context);
+
+ try {
+ if (!!!NamingManager.hasInitialContextFactoryBuilder()) {
+ NamingManager.setInitialContextFactoryBuilder(new OSGiInitialContextFactoryBuilder(context));
+ }
+ } catch (NamingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ try {
+ NamingManager.setObjectFactoryBuilder(new OSGiObjectFactoryBuilder());
+ } catch (NamingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void stop(BundleContext context) {}
}
\ No newline at end of file
Propchange: incubator/aries/trunk/jndi-contrib/jndi-core/src/main/java/org/apache/aries/jndi/startup/Activator.java
------------------------------------------------------------------------------
svn:eol-style = native