init
This commit is contained in:
87
java/org/apache/naming/AbstractRef.java
Normal file
87
java/org/apache/naming/AbstractRef.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
|
||||
public abstract class AbstractRef extends Reference {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public AbstractRef(String className) {
|
||||
super(className);
|
||||
}
|
||||
|
||||
|
||||
public AbstractRef(String className, String factory, String factoryLocation) {
|
||||
super(className, factory, factoryLocation);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the class name of the factory of the object to which this
|
||||
* reference refers.
|
||||
*/
|
||||
@Override
|
||||
public final String getFactoryClassName() {
|
||||
String factory = super.getFactoryClassName();
|
||||
if (factory != null) {
|
||||
return factory;
|
||||
} else {
|
||||
factory = System.getProperty(Context.OBJECT_FACTORIES);
|
||||
if (factory != null) {
|
||||
return null;
|
||||
} else {
|
||||
return getDefaultFactoryClassName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected abstract String getDefaultFactoryClassName();
|
||||
|
||||
|
||||
/**
|
||||
* Return a String rendering of this object.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
|
||||
sb.append("[className=");
|
||||
sb.append(getClassName());
|
||||
sb.append(",factoryClassLocation=");
|
||||
sb.append(getFactoryClassLocation());
|
||||
sb.append(",factoryClassName=");
|
||||
sb.append(getFactoryClassName());
|
||||
Enumeration<RefAddr> refAddrs = getAll();
|
||||
while (refAddrs.hasMoreElements()) {
|
||||
RefAddr refAddr = refAddrs.nextElement();
|
||||
sb.append(",{type=");
|
||||
sb.append(refAddr.getType());
|
||||
sb.append(",content=");
|
||||
sb.append(refAddr.getContent());
|
||||
sb.append("}");
|
||||
}
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
35
java/org/apache/naming/Constants.java
Normal file
35
java/org/apache/naming/Constants.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
|
||||
/**
|
||||
* Static constants for this package.
|
||||
*
|
||||
* @deprecated Unused. Will be removed in Tomcat 9.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class Constants {
|
||||
|
||||
public static final String Package = "org.apache.naming";
|
||||
|
||||
/**
|
||||
* Has security been turned on?
|
||||
*/
|
||||
public static final boolean IS_SECURITY_ENABLED =
|
||||
(System.getSecurityManager() != null);
|
||||
}
|
||||
126
java/org/apache/naming/ContextAccessController.java
Normal file
126
java/org/apache/naming/ContextAccessController.java
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Handles the access control on the JNDI contexts.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ContextAccessController {
|
||||
|
||||
// -------------------------------------------------------------- Variables
|
||||
|
||||
/**
|
||||
* Catalina context names on which writing is not allowed.
|
||||
*/
|
||||
private static final Hashtable<Object,Object> readOnlyContexts = new Hashtable<>();
|
||||
|
||||
|
||||
/**
|
||||
* Security tokens repository.
|
||||
*/
|
||||
private static final Hashtable<Object,Object> securityTokens = new Hashtable<>();
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Set a security token for a Catalina context. Can be set only once.
|
||||
*
|
||||
* @param name Name of the Catalina context
|
||||
* @param token Security token
|
||||
*/
|
||||
public static void setSecurityToken(Object name, Object token) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission(
|
||||
ContextAccessController.class.getName()
|
||||
+ ".setSecurityToken"));
|
||||
}
|
||||
if ((!securityTokens.containsKey(name)) && (token != null)) {
|
||||
securityTokens.put(name, token);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a security token for a context.
|
||||
*
|
||||
* @param name Name of the Catalina context
|
||||
* @param token Security token
|
||||
*/
|
||||
public static void unsetSecurityToken(Object name, Object token) {
|
||||
if (checkSecurityToken(name, token)) {
|
||||
securityTokens.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a submitted security token.
|
||||
*
|
||||
* @param name Name of the Catalina context
|
||||
* @param token Submitted security token
|
||||
*
|
||||
* @return <code>true</code> if the submitted token is equal to the token
|
||||
* in the repository or if no token is present in the repository.
|
||||
* Otherwise, <code>false</code>
|
||||
*/
|
||||
public static boolean checkSecurityToken
|
||||
(Object name, Object token) {
|
||||
Object refToken = securityTokens.get(name);
|
||||
return (refToken == null || refToken.equals(token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow writing to a context.
|
||||
*
|
||||
* @param name Name of the Catalina context
|
||||
* @param token Security token
|
||||
*/
|
||||
public static void setWritable(Object name, Object token) {
|
||||
if (checkSecurityToken(name, token))
|
||||
readOnlyContexts.remove(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set whether or not a Catalina context is writable.
|
||||
*
|
||||
* @param name Name of the Catalina context
|
||||
*/
|
||||
public static void setReadOnly(Object name) {
|
||||
readOnlyContexts.put(name, name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is the context is writable?
|
||||
*
|
||||
* @param name Name of the Catalina context
|
||||
*
|
||||
* @return <code>true</code> if it is writable, otherwise <code>false</code>
|
||||
*/
|
||||
public static boolean isWritable(Object name) {
|
||||
return !(readOnlyContexts.containsKey(name));
|
||||
}
|
||||
}
|
||||
|
||||
305
java/org/apache/naming/ContextBindings.java
Normal file
305
java/org/apache/naming/ContextBindings.java
Normal file
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Handles the associations :
|
||||
* <ul>
|
||||
* <li>Object with a NamingContext</li>
|
||||
* <li>Calling thread with a NamingContext</li>
|
||||
* <li>Calling thread with object bound to the same naming context</li>
|
||||
* <li>Thread context class loader with a NamingContext</li>
|
||||
* <li>Thread context class loader with object bound to the same
|
||||
* NamingContext</li>
|
||||
* </ul>
|
||||
* The objects are typically Catalina Server or Context objects.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ContextBindings {
|
||||
|
||||
// -------------------------------------------------------------- Variables
|
||||
|
||||
/**
|
||||
* Bindings object - naming context. Keyed by object.
|
||||
*/
|
||||
private static final Hashtable<Object,Context> objectBindings = new Hashtable<>();
|
||||
|
||||
|
||||
/**
|
||||
* Bindings thread - naming context. Keyed by thread.
|
||||
*/
|
||||
private static final Hashtable<Thread,Context> threadBindings = new Hashtable<>();
|
||||
|
||||
|
||||
/**
|
||||
* Bindings thread - object. Keyed by thread.
|
||||
*/
|
||||
private static final Hashtable<Thread,Object> threadObjectBindings = new Hashtable<>();
|
||||
|
||||
|
||||
/**
|
||||
* Bindings class loader - naming context. Keyed by class loader.
|
||||
*/
|
||||
private static final Hashtable<ClassLoader,Context> clBindings = new Hashtable<>();
|
||||
|
||||
|
||||
/**
|
||||
* Bindings class loader - object. Keyed by class loader.
|
||||
*/
|
||||
private static final Hashtable<ClassLoader,Object> clObjectBindings = new Hashtable<>();
|
||||
|
||||
|
||||
/**
|
||||
* The string manager for this package.
|
||||
*/
|
||||
protected static final StringManager sm = StringManager.getManager(ContextBindings.class);
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Binds an object and a naming context.
|
||||
*
|
||||
* @param obj Object to bind with naming context
|
||||
* @param context Associated naming context instance
|
||||
*/
|
||||
public static void bindContext(Object obj, Context context) {
|
||||
bindContext(obj, context, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds an object and a naming context.
|
||||
*
|
||||
* @param obj Object to bind with naming context
|
||||
* @param context Associated naming context instance
|
||||
* @param token Security token
|
||||
*/
|
||||
public static void bindContext(Object obj, Context context, Object token) {
|
||||
if (ContextAccessController.checkSecurityToken(obj, token)) {
|
||||
objectBindings.put(obj, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds an object and a naming context.
|
||||
*
|
||||
* @param obj Object to unbind
|
||||
* @param token Security token
|
||||
*/
|
||||
public static void unbindContext(Object obj, Object token) {
|
||||
if (ContextAccessController.checkSecurityToken(obj, token)) {
|
||||
objectBindings.remove(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a naming context.
|
||||
*
|
||||
* @param obj Object bound to the required naming context
|
||||
*/
|
||||
static Context getContext(Object obj) {
|
||||
return objectBindings.get(obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a naming context to a thread.
|
||||
*
|
||||
* @param obj Object bound to the required naming context
|
||||
* @param token Security token
|
||||
*
|
||||
* @throws NamingException If no naming context is bound to the provided
|
||||
* object
|
||||
*/
|
||||
public static void bindThread(Object obj, Object token) throws NamingException {
|
||||
if (ContextAccessController.checkSecurityToken(obj, token)) {
|
||||
Context context = objectBindings.get(obj);
|
||||
if (context == null) {
|
||||
throw new NamingException(
|
||||
sm.getString("contextBindings.unknownContext", obj));
|
||||
}
|
||||
threadBindings.put(Thread.currentThread(), context);
|
||||
threadObjectBindings.put(Thread.currentThread(), obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds a thread and a naming context.
|
||||
*
|
||||
* @param obj Object bound to the required naming context
|
||||
* @param token Security token
|
||||
*/
|
||||
public static void unbindThread(Object obj, Object token) {
|
||||
if (ContextAccessController.checkSecurityToken(obj, token)) {
|
||||
threadBindings.remove(Thread.currentThread());
|
||||
threadObjectBindings.remove(Thread.currentThread());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the naming context bound to the current thread.
|
||||
*
|
||||
* @return The naming context bound to the current thread.
|
||||
*
|
||||
* @throws NamingException If no naming context is bound to the current
|
||||
* thread
|
||||
*/
|
||||
public static Context getThread() throws NamingException {
|
||||
Context context = threadBindings.get(Thread.currentThread());
|
||||
if (context == null) {
|
||||
throw new NamingException
|
||||
(sm.getString("contextBindings.noContextBoundToThread"));
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the name of the object bound to the naming context that is also
|
||||
* bound to the current thread.
|
||||
*/
|
||||
static String getThreadName() throws NamingException {
|
||||
Object obj = threadObjectBindings.get(Thread.currentThread());
|
||||
if (obj == null) {
|
||||
throw new NamingException
|
||||
(sm.getString("contextBindings.noContextBoundToThread"));
|
||||
}
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if current thread is bound to a naming context.
|
||||
*
|
||||
* @return <code>true</code> if the current thread is bound to a naming
|
||||
* context, otherwise <code>false</code>
|
||||
*/
|
||||
public static boolean isThreadBound() {
|
||||
return threadBindings.containsKey(Thread.currentThread());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a naming context to a class loader.
|
||||
*
|
||||
* @param obj Object bound to the required naming context
|
||||
* @param token Security token
|
||||
* @param classLoader The class loader to bind to the naming context
|
||||
*
|
||||
* @throws NamingException If no naming context is bound to the provided
|
||||
* object
|
||||
*/
|
||||
public static void bindClassLoader(Object obj, Object token,
|
||||
ClassLoader classLoader) throws NamingException {
|
||||
if (ContextAccessController.checkSecurityToken(obj, token)) {
|
||||
Context context = objectBindings.get(obj);
|
||||
if (context == null) {
|
||||
throw new NamingException
|
||||
(sm.getString("contextBindings.unknownContext", obj));
|
||||
}
|
||||
clBindings.put(classLoader, context);
|
||||
clObjectBindings.put(classLoader, obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds a naming context and a class loader.
|
||||
*
|
||||
* @param obj Object bound to the required naming context
|
||||
* @param token Security token
|
||||
* @param classLoader The class loader bound to the naming context
|
||||
*/
|
||||
public static void unbindClassLoader(Object obj, Object token,
|
||||
ClassLoader classLoader) {
|
||||
if (ContextAccessController.checkSecurityToken(obj, token)) {
|
||||
Object o = clObjectBindings.get(classLoader);
|
||||
if (o == null || !o.equals(obj)) {
|
||||
return;
|
||||
}
|
||||
clBindings.remove(classLoader);
|
||||
clObjectBindings.remove(classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the naming context bound to a class loader.
|
||||
*
|
||||
* @return the naming context bound to current class loader or one of its
|
||||
* parents
|
||||
*
|
||||
* @throws NamingException If no naming context was bound
|
||||
*/
|
||||
public static Context getClassLoader() throws NamingException {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Context context = null;
|
||||
do {
|
||||
context = clBindings.get(cl);
|
||||
if (context != null) {
|
||||
return context;
|
||||
}
|
||||
} while ((cl = cl.getParent()) != null);
|
||||
throw new NamingException(sm.getString("contextBindings.noContextBoundToCL"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the name of the object bound to the naming context that is also
|
||||
* bound to the thread context class loader.
|
||||
*/
|
||||
static String getClassLoaderName() throws NamingException {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Object obj = null;
|
||||
do {
|
||||
obj = clObjectBindings.get(cl);
|
||||
if (obj != null) {
|
||||
return obj.toString();
|
||||
}
|
||||
} while ((cl = cl.getParent()) != null);
|
||||
throw new NamingException (sm.getString("contextBindings.noContextBoundToCL"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if the thread context class loader is bound to a context.
|
||||
*
|
||||
* @return <code>true</code> if the thread context class loader or one of
|
||||
* its parents is bound to a naming context, otherwise
|
||||
* <code>false</code>
|
||||
*/
|
||||
public static boolean isClassLoaderBound() {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
do {
|
||||
if (clBindings.containsKey(cl)) {
|
||||
return true;
|
||||
}
|
||||
} while ((cl = cl.getParent()) != null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
103
java/org/apache/naming/EjbRef.java
Normal file
103
java/org/apache/naming/EjbRef.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
/**
|
||||
* Represents a reference address to an EJB.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class EjbRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_EJB_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* EJB type address type.
|
||||
*/
|
||||
public static final String TYPE = "type";
|
||||
|
||||
|
||||
/**
|
||||
* Remote interface classname address type.
|
||||
*/
|
||||
public static final String REMOTE = "remote";
|
||||
|
||||
|
||||
/**
|
||||
* Link address type.
|
||||
*/
|
||||
public static final String LINK = "link";
|
||||
|
||||
|
||||
/**
|
||||
* EJB Reference.
|
||||
*
|
||||
* @param ejbType EJB type
|
||||
* @param home Home interface classname
|
||||
* @param remote Remote interface classname
|
||||
* @param link EJB link
|
||||
*/
|
||||
public EjbRef(String ejbType, String home, String remote, String link) {
|
||||
this(ejbType, home, remote, link, null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* EJB Reference.
|
||||
*
|
||||
* @param ejbType EJB type
|
||||
* @param home Home interface classname
|
||||
* @param remote Remote interface classname
|
||||
* @param link EJB link
|
||||
* @param factory The possibly null class name of the object's factory.
|
||||
* @param factoryLocation The possibly null location from which to load
|
||||
* the factory (e.g. URL)
|
||||
*/
|
||||
public EjbRef(String ejbType, String home, String remote, String link,
|
||||
String factory, String factoryLocation) {
|
||||
super(home, factory, factoryLocation);
|
||||
StringRefAddr refAddr = null;
|
||||
if (ejbType != null) {
|
||||
refAddr = new StringRefAddr(TYPE, ejbType);
|
||||
add(refAddr);
|
||||
}
|
||||
if (remote != null) {
|
||||
refAddr = new StringRefAddr(REMOTE, remote);
|
||||
add(refAddr);
|
||||
}
|
||||
if (link != null) {
|
||||
refAddr = new StringRefAddr(LINK, link);
|
||||
add(refAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
110
java/org/apache/naming/HandlerRef.java
Normal file
110
java/org/apache/naming/HandlerRef.java
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
/**
|
||||
* Represents a reference handler for a web service.
|
||||
*
|
||||
* @author Fabien Carrion
|
||||
*/
|
||||
public class HandlerRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_HANDLER_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* HandlerName address type.
|
||||
*/
|
||||
public static final String HANDLER_NAME = "handlername";
|
||||
|
||||
|
||||
/**
|
||||
* Handler Classname address type.
|
||||
*/
|
||||
public static final String HANDLER_CLASS = "handlerclass";
|
||||
|
||||
|
||||
/**
|
||||
* Handler Classname address type.
|
||||
*/
|
||||
public static final String HANDLER_LOCALPART = "handlerlocalpart";
|
||||
|
||||
|
||||
/**
|
||||
* Handler Classname address type.
|
||||
*/
|
||||
public static final String HANDLER_NAMESPACE = "handlernamespace";
|
||||
|
||||
|
||||
/**
|
||||
* Handler Classname address type.
|
||||
*/
|
||||
public static final String HANDLER_PARAMNAME = "handlerparamname";
|
||||
|
||||
|
||||
/**
|
||||
* Handler Classname address type.
|
||||
*/
|
||||
public static final String HANDLER_PARAMVALUE = "handlerparamvalue";
|
||||
|
||||
|
||||
/**
|
||||
* Handler SoapRole address type.
|
||||
*/
|
||||
public static final String HANDLER_SOAPROLE = "handlersoaprole";
|
||||
|
||||
|
||||
/**
|
||||
* Handler PortName address type.
|
||||
*/
|
||||
public static final String HANDLER_PORTNAME = "handlerportname";
|
||||
|
||||
|
||||
public HandlerRef(String refname, String handlerClass) {
|
||||
this(refname, handlerClass, null, null);
|
||||
}
|
||||
|
||||
|
||||
public HandlerRef(String refname, String handlerClass,
|
||||
String factory, String factoryLocation) {
|
||||
super(refname, factory, factoryLocation);
|
||||
StringRefAddr refAddr = null;
|
||||
if (refname != null) {
|
||||
refAddr = new StringRefAddr(HANDLER_NAME, refname);
|
||||
add(refAddr);
|
||||
}
|
||||
if (handlerClass != null) {
|
||||
refAddr = new StringRefAddr(HANDLER_CLASS, handlerClass);
|
||||
add(refAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
30
java/org/apache/naming/LocalStrings.properties
Normal file
30
java/org/apache/naming/LocalStrings.properties
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.noContextBoundToCL=No naming context bound to this class loader
|
||||
contextBindings.noContextBoundToThread=No naming context bound to this thread
|
||||
contextBindings.unknownContext=Unknown context name : [{0}]
|
||||
|
||||
namingContext.alreadyBound=Name [{0}] is already bound in this Context
|
||||
namingContext.contextExpected=Name is not bound to a Context
|
||||
namingContext.failResolvingReference=Unexpected exception resolving reference
|
||||
namingContext.invalidName=Name is not valid
|
||||
namingContext.nameNotBound=Name [{0}] is not bound in this Context. Unable to find [{1}].
|
||||
namingContext.noAbsoluteName=Cannot generate an absolute name for this namespace
|
||||
namingContext.readOnly=Context is read only
|
||||
|
||||
selectorContext.methodUsingName=Call to method [{0}] with a Name of [{1}]
|
||||
selectorContext.methodUsingString=Call to method [{0}] with a String of [{1}]
|
||||
selectorContext.noJavaUrl=This context must be accessed through a java: URL
|
||||
20
java/org/apache/naming/LocalStrings_de.properties
Normal file
20
java/org/apache/naming/LocalStrings_de.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.unknownContext=Unbekannter Kontext-Name: [{0}]
|
||||
|
||||
namingContext.contextExpected=Ein Name ist nicht an den Context gebunden
|
||||
|
||||
selectorContext.noJavaUrl=Auf diesen Kontext muss durch eine java:-URL zugegriffen werden
|
||||
30
java/org/apache/naming/LocalStrings_es.properties
Normal file
30
java/org/apache/naming/LocalStrings_es.properties
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.noContextBoundToCL=No hay contexto de nombres asociado a este cargador de clase
|
||||
contextBindings.noContextBoundToThread=No hay contexto de nombres asociado a este hilo
|
||||
contextBindings.unknownContext=Contexto [{0}] desconocido
|
||||
|
||||
namingContext.alreadyBound=El nombre [{0}] este ya asociado en este Contexto
|
||||
namingContext.contextExpected=El nombre no esta asociado a ningun Contexto
|
||||
namingContext.failResolvingReference=Excepción inesperada resolviendo referencia
|
||||
namingContext.invalidName=Nombre no valido
|
||||
namingContext.nameNotBound=El nombre [{0}] no este asociado a este contexto
|
||||
namingContext.noAbsoluteName=No se puede generar un nombre absoluto para este espacio de nombres
|
||||
namingContext.readOnly=El contexto es de solo lectura
|
||||
|
||||
selectorContext.methodUsingName=Llamada al método [{0}] con un Nombre de [{1}]
|
||||
selectorContext.methodUsingString=Llamada al método [{0}] con una Cadena de [{1}]
|
||||
selectorContext.noJavaUrl=Este contexto debe de ser accedido a traves de una URL de tipo java:
|
||||
30
java/org/apache/naming/LocalStrings_fr.properties
Normal file
30
java/org/apache/naming/LocalStrings_fr.properties
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.noContextBoundToCL=Aucun Contexte de nommage lié à ce chargeur de classes
|
||||
contextBindings.noContextBoundToThread=Aucun Contexte de nommage lié à ce thread
|
||||
contextBindings.unknownContext=Nom de Contexte inconnu : [{0}]
|
||||
|
||||
namingContext.alreadyBound=Le Nom [{0}] est déjà lié à ce Contexte
|
||||
namingContext.contextExpected=Le Nom n'est pas lié à un Contexte
|
||||
namingContext.failResolvingReference=Une erreur s est produite durant la résolution de la référence
|
||||
namingContext.invalidName=Le Nom est invalide
|
||||
namingContext.nameNotBound=Le Nom [{0}] n''est pas lié à ce Contexte
|
||||
namingContext.noAbsoluteName=Impossible de générer un nom absolu pour cet espace de nommage (namespace)
|
||||
namingContext.readOnly=Le Contexte est en lecture seule
|
||||
|
||||
selectorContext.methodUsingName=Appel de la méthode [{0}] avec le nom [{1}]
|
||||
selectorContext.methodUsingString=Appel de la méthode [{0}] avec la String [{1}]
|
||||
selectorContext.noJavaUrl=Ce Contexte doit être accédé par une URL commençant par 'java:'
|
||||
30
java/org/apache/naming/LocalStrings_ja.properties
Normal file
30
java/org/apache/naming/LocalStrings_ja.properties
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.noContextBoundToCL=Naming Contextはこのクラスローダにバインドされていません
|
||||
contextBindings.noContextBoundToThread=名前付けコンテキストはこのスレッドにバインドされていません
|
||||
contextBindings.unknownContext=未知のコンテキスト名です: [{0}]
|
||||
|
||||
namingContext.alreadyBound=名前 [{0}] は既にこのコンテキストにバインドされています
|
||||
namingContext.contextExpected=名前がコンテキストにバインドされていません
|
||||
namingContext.failResolvingReference=参照の解決中に予測しない例外が発生しました
|
||||
namingContext.invalidName=名前は無効です
|
||||
namingContext.nameNotBound=名前 [{0}] はこのコンテキストにバインドされていません
|
||||
namingContext.noAbsoluteName=この名前空間に絶対名を生成できません
|
||||
namingContext.readOnly=コンテキストはリードオンリーです
|
||||
|
||||
selectorContext.methodUsingName=オブジェクト名 [{1}] に対してメソッド [{0}] を呼び出します。
|
||||
selectorContext.methodUsingString=メソッド[{0}]を[{1}]の文字列で呼び出します。
|
||||
selectorContext.noJavaUrl=このコンテキストにはjava: URLを用いてアクセスされねばいけません
|
||||
30
java/org/apache/naming/LocalStrings_ko.properties
Normal file
30
java/org/apache/naming/LocalStrings_ko.properties
Normal file
@@ -0,0 +1,30 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.noContextBoundToCL=Naming 컨텍스트가 이 클래스로더에 바인딩되지 않았습니다.
|
||||
contextBindings.noContextBoundToThread=이 쓰레드에 Naming 컨텍스트가 바인딩되지 않았습니다.
|
||||
contextBindings.unknownContext=알 수 없는 컨텍스트 이름: [{0}]
|
||||
|
||||
namingContext.alreadyBound=Name [{0}]이(가) 이미 이 컨텍스트에 바인딩 되어 있습니다.
|
||||
namingContext.contextExpected=Name이 컨텍스트에 바인딩 되지 않았습니다.
|
||||
namingContext.failResolvingReference=참조를 결정하는 중 예기치 않은 예외 발생
|
||||
namingContext.invalidName=Name이 유효하지 않습니다.
|
||||
namingContext.nameNotBound=Name [{0}]은(는) 이 컨텍스트에 바인딩되지 않았습니다. [{1}]을(를) 찾을 수 없습니다.
|
||||
namingContext.noAbsoluteName=이 네임스페이스를 위한 절대 이름을 생성할 수 없습니다.
|
||||
namingContext.readOnly=컨텍스트가 읽기 전용입니다.
|
||||
|
||||
selectorContext.methodUsingName=Name [{1}]을(를) 사용하여 메소드 [{0}]을(를) 호출합니다.
|
||||
selectorContext.methodUsingString=문자열 [{1}]을(를) 사용하여 메소드 [{0}]을(를) 호출합니다.
|
||||
selectorContext.noJavaUrl=이 컨텍스트는 반드시 java: URL을 통해 접근되어야 합니다.
|
||||
25
java/org/apache/naming/LocalStrings_zh_CN.properties
Normal file
25
java/org/apache/naming/LocalStrings_zh_CN.properties
Normal file
@@ -0,0 +1,25 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
contextBindings.noContextBoundToCL=没有绑定到此类加载器的命名上下文
|
||||
contextBindings.noContextBoundToThread=没有绑定到此线程的命名上下文
|
||||
contextBindings.unknownContext=未知.上下文名:[{0}]
|
||||
|
||||
namingContext.contextExpected=上下文Context未绑定名称name
|
||||
namingContext.failResolvingReference=解析引用时意外异常
|
||||
|
||||
selectorContext.methodUsingName=用[{1}]的name属性调用方法[{0}]
|
||||
selectorContext.methodUsingString=使用字符串[{1}]调用方法[{0}]
|
||||
selectorContext.noJavaUrl=必须通过java:url访问此上下文
|
||||
53
java/org/apache/naming/LookupRef.java
Normal file
53
java/org/apache/naming/LookupRef.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
/**
|
||||
* Represents a reference to lookup.
|
||||
*/
|
||||
public class LookupRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* JNDI name for the lookup
|
||||
*/
|
||||
public static final String LOOKUP_NAME = "lookup-name";
|
||||
|
||||
|
||||
public LookupRef(String resourceType, String lookupName) {
|
||||
this(resourceType, null, null, lookupName);
|
||||
}
|
||||
|
||||
|
||||
public LookupRef(String resourceType, String factory, String factoryLocation, String lookupName) {
|
||||
super(resourceType, factory, factoryLocation);
|
||||
if (lookupName != null && !lookupName.equals("")) {
|
||||
RefAddr ref = new StringRefAddr(LOOKUP_NAME, lookupName);
|
||||
add(ref);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return org.apache.naming.factory.Constants.DEFAULT_LOOKUP_JNDI_FACTORY;
|
||||
}
|
||||
}
|
||||
56
java/org/apache/naming/NameParserImpl.java
Normal file
56
java/org/apache/naming/NameParserImpl.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming;
|
||||
|
||||
import javax.naming.CompositeName;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Parses names.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class NameParserImpl
|
||||
implements NameParser {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
// ----------------------------------------------------- NameParser Methods
|
||||
|
||||
|
||||
/**
|
||||
* Parses a name into its components.
|
||||
*
|
||||
* @param name The non-null string name to parse
|
||||
* @return A non-null parsed form of the name using the naming convention
|
||||
* of this parser.
|
||||
*/
|
||||
@Override
|
||||
public Name parse(String name)
|
||||
throws NamingException {
|
||||
return new CompositeName(name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
970
java/org/apache/naming/NamingContext.java
Normal file
970
java/org/apache/naming/NamingContext.java
Normal file
@@ -0,0 +1,970 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.CompositeName;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.LinkRef;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameAlreadyBoundException;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.NotContextException;
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.Referenceable;
|
||||
import javax.naming.spi.NamingManager;
|
||||
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Catalina JNDI Context implementation.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class NamingContext implements Context {
|
||||
|
||||
|
||||
// -------------------------------------------------------------- Constants
|
||||
|
||||
|
||||
/**
|
||||
* Name parser for this context.
|
||||
*/
|
||||
protected static final NameParser nameParser = new NameParserImpl();
|
||||
|
||||
|
||||
private static final Log log = LogFactory.getLog(NamingContext.class);
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
/**
|
||||
* Builds a naming context.
|
||||
*
|
||||
* @param env The environment to use to construct the naming context
|
||||
* @param name The name of the associated Catalina Context
|
||||
*/
|
||||
public NamingContext(Hashtable<String,Object> env, String name) {
|
||||
this(env, name, new HashMap<String,NamingEntry>());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds a naming context.
|
||||
*
|
||||
* @param env The environment to use to construct the naming context
|
||||
* @param name The name of the associated Catalina Context
|
||||
* @param bindings The initial bindings for the naming context
|
||||
*/
|
||||
public NamingContext(Hashtable<String,Object> env, String name,
|
||||
HashMap<String,NamingEntry> bindings) {
|
||||
|
||||
this.env = new Hashtable<>();
|
||||
this.name = name;
|
||||
// Populating the environment hashtable
|
||||
if (env != null ) {
|
||||
Enumeration<String> envEntries = env.keys();
|
||||
while (envEntries.hasMoreElements()) {
|
||||
String entryName = envEntries.nextElement();
|
||||
addToEnvironment(entryName, env.get(entryName));
|
||||
}
|
||||
}
|
||||
this.bindings = bindings;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* Environment.
|
||||
*/
|
||||
protected final Hashtable<String,Object> env;
|
||||
|
||||
|
||||
/**
|
||||
* The string manager for this package.
|
||||
*/
|
||||
protected static final StringManager sm = StringManager.getManager(NamingContext.class);
|
||||
|
||||
|
||||
/**
|
||||
* Bindings in this Context.
|
||||
*/
|
||||
protected final HashMap<String,NamingEntry> bindings;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the associated Catalina Context.
|
||||
*/
|
||||
protected final String name;
|
||||
|
||||
|
||||
/**
|
||||
* Determines if an attempt to write to a read-only context results in an
|
||||
* exception or if the request is ignored.
|
||||
*/
|
||||
private boolean exceptionOnFailedWrite = true;
|
||||
public boolean getExceptionOnFailedWrite() {
|
||||
return exceptionOnFailedWrite;
|
||||
}
|
||||
public void setExceptionOnFailedWrite(boolean exceptionOnFailedWrite) {
|
||||
this.exceptionOnFailedWrite = exceptionOnFailedWrite;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------- Context Methods
|
||||
|
||||
/**
|
||||
* Retrieves the named object. If name is empty, returns a new instance
|
||||
* of this context (which represents the same naming context as this
|
||||
* context, but its environment may be modified independently and it may
|
||||
* be accessed concurrently).
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookup(Name name)
|
||||
throws NamingException {
|
||||
return lookup(name, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookup(String name)
|
||||
throws NamingException {
|
||||
return lookup(new CompositeName(name), true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object. All intermediate contexts and the target
|
||||
* context (that named by all but terminal atomic component of the name)
|
||||
* must already exist.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @exception NameAlreadyBoundException if name is already bound
|
||||
* @exception javax.naming.directory.InvalidAttributesException if object
|
||||
* did not supply all mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void bind(Name name, Object obj)
|
||||
throws NamingException {
|
||||
bind(name, obj, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @exception NameAlreadyBoundException if name is already bound
|
||||
* @exception javax.naming.directory.InvalidAttributesException if object
|
||||
* did not supply all mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void bind(String name, Object obj)
|
||||
throws NamingException {
|
||||
bind(new CompositeName(name), obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object, overwriting any existing binding. All
|
||||
* intermediate contexts and the target context (that named by all but
|
||||
* terminal atomic component of the name) must already exist.
|
||||
* <p>
|
||||
* If the object is a DirContext, any existing attributes associated with
|
||||
* the name are replaced with those of the object. Otherwise, any
|
||||
* existing attributes associated with the name remain unchanged.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @exception javax.naming.directory.InvalidAttributesException if object
|
||||
* did not supply all mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rebind(Name name, Object obj)
|
||||
throws NamingException {
|
||||
bind(name, obj, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object, overwriting any existing binding.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @exception javax.naming.directory.InvalidAttributesException if object
|
||||
* did not supply all mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rebind(String name, Object obj)
|
||||
throws NamingException {
|
||||
rebind(new CompositeName(name), obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds the named object. Removes the terminal atomic name in name
|
||||
* from the target context--that named by all but the terminal atomic
|
||||
* part of name.
|
||||
* <p>
|
||||
* This method is idempotent. It succeeds even if the terminal atomic
|
||||
* name is not bound in the target context, but throws
|
||||
* NameNotFoundException if any of the intermediate contexts do not exist.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @exception NameNotFoundException if an intermediate context does not
|
||||
* exist
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void unbind(Name name) throws NamingException {
|
||||
|
||||
if (!checkWritable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty())
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.invalidName"));
|
||||
|
||||
NamingEntry entry = bindings.get(name.get(0));
|
||||
|
||||
if (entry == null) {
|
||||
throw new NameNotFoundException
|
||||
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
|
||||
}
|
||||
|
||||
if (name.size() > 1) {
|
||||
if (entry.type == NamingEntry.CONTEXT) {
|
||||
((Context) entry.value).unbind(name.getSuffix(1));
|
||||
} else {
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
} else {
|
||||
bindings.remove(name.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds the named object.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @exception NameNotFoundException if an intermediate context does not
|
||||
* exist
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void unbind(String name)
|
||||
throws NamingException {
|
||||
unbind(new CompositeName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a new name to the object bound to an old name, and unbinds the
|
||||
* old name. Both names are relative to this context. Any attributes
|
||||
* associated with the old name become associated with the new name.
|
||||
* Intermediate contexts of the old name are not changed.
|
||||
*
|
||||
* @param oldName the name of the existing binding; may not be empty
|
||||
* @param newName the name of the new binding; may not be empty
|
||||
* @exception NameAlreadyBoundException if newName is already bound
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rename(Name oldName, Name newName)
|
||||
throws NamingException {
|
||||
Object value = lookup(oldName);
|
||||
bind(newName, value);
|
||||
unbind(oldName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a new name to the object bound to an old name, and unbinds the
|
||||
* old name.
|
||||
*
|
||||
* @param oldName the name of the existing binding; may not be empty
|
||||
* @param newName the name of the new binding; may not be empty
|
||||
* @exception NameAlreadyBoundException if newName is already bound
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rename(String oldName, String newName)
|
||||
throws NamingException {
|
||||
rename(new CompositeName(oldName), new CompositeName(newName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the class
|
||||
* names of objects bound to them. The contents of any subcontexts are
|
||||
* not included.
|
||||
* <p>
|
||||
* If a binding is added to or removed from this context, its effect on
|
||||
* an enumeration previously returned is undefined.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the names and class names of the bindings in
|
||||
* this context. Each element of the enumeration is of type NameClassPair.
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
// Removing empty parts
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty()) {
|
||||
return new NamingContextEnumeration(bindings.values().iterator());
|
||||
}
|
||||
|
||||
NamingEntry entry = bindings.get(name.get(0));
|
||||
|
||||
if (entry == null) {
|
||||
throw new NameNotFoundException
|
||||
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
|
||||
}
|
||||
|
||||
if (entry.type != NamingEntry.CONTEXT) {
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
return ((Context) entry.value).list(name.getSuffix(1));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the class
|
||||
* names of objects bound to them.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the names and class names of the bindings in
|
||||
* this context. Each element of the enumeration is of type NameClassPair.
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
return list(new CompositeName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the
|
||||
* objects bound to them. The contents of any subcontexts are not
|
||||
* included.
|
||||
* <p>
|
||||
* If a binding is added to or removed from this context, its effect on
|
||||
* an enumeration previously returned is undefined.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the bindings in this context.
|
||||
* Each element of the enumeration is of type Binding.
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
// Removing empty parts
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty()) {
|
||||
return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
|
||||
}
|
||||
|
||||
NamingEntry entry = bindings.get(name.get(0));
|
||||
|
||||
if (entry == null) {
|
||||
throw new NameNotFoundException
|
||||
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
|
||||
}
|
||||
|
||||
if (entry.type != NamingEntry.CONTEXT) {
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
return ((Context) entry.value).listBindings(name.getSuffix(1));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the
|
||||
* objects bound to them.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the bindings in this context.
|
||||
* Each element of the enumeration is of type Binding.
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
return listBindings(new CompositeName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the named context and removes it from the namespace. Any
|
||||
* attributes associated with the name are also removed. Intermediate
|
||||
* contexts are not destroyed.
|
||||
* <p>
|
||||
* This method is idempotent. It succeeds even if the terminal atomic
|
||||
* name is not bound in the target context, but throws
|
||||
* NameNotFoundException if any of the intermediate contexts do not exist.
|
||||
*
|
||||
* In a federated naming system, a context from one naming system may be
|
||||
* bound to a name in another. One can subsequently look up and perform
|
||||
* operations on the foreign context using a composite name. However, an
|
||||
* attempt destroy the context using this composite name will fail with
|
||||
* NotContextException, because the foreign context is not a "subcontext"
|
||||
* of the context in which it is bound. Instead, use unbind() to remove
|
||||
* the binding of the foreign context. Destroying the foreign context
|
||||
* requires that the destroySubcontext() be performed on a context from
|
||||
* the foreign context's "native" naming system.
|
||||
*
|
||||
* @param name the name of the context to be destroyed; may not be empty
|
||||
* @exception NameNotFoundException if an intermediate context does not
|
||||
* exist
|
||||
* @exception NotContextException if the name is bound but does not name
|
||||
* a context, or does not name a context of the appropriate type
|
||||
*/
|
||||
@Override
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
|
||||
if (!checkWritable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty())
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.invalidName"));
|
||||
|
||||
NamingEntry entry = bindings.get(name.get(0));
|
||||
|
||||
if (entry == null) {
|
||||
throw new NameNotFoundException
|
||||
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
|
||||
}
|
||||
|
||||
if (name.size() > 1) {
|
||||
if (entry.type == NamingEntry.CONTEXT) {
|
||||
((Context) entry.value).destroySubcontext(name.getSuffix(1));
|
||||
} else {
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
} else {
|
||||
if (entry.type == NamingEntry.CONTEXT) {
|
||||
((Context) entry.value).close();
|
||||
bindings.remove(name.get(0));
|
||||
} else {
|
||||
throw new NotContextException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the named context and removes it from the namespace.
|
||||
*
|
||||
* @param name the name of the context to be destroyed; may not be empty
|
||||
* @exception NameNotFoundException if an intermediate context does not
|
||||
* exist
|
||||
* @exception NotContextException if the name is bound but does not name
|
||||
* a context, or does not name a context of the appropriate type
|
||||
*/
|
||||
@Override
|
||||
public void destroySubcontext(String name)
|
||||
throws NamingException {
|
||||
destroySubcontext(new CompositeName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and binds a new context. Creates a new context with the given
|
||||
* name and binds it in the target context (that named by all but
|
||||
* terminal atomic component of the name). All intermediate contexts and
|
||||
* the target context must already exist.
|
||||
*
|
||||
* @param name the name of the context to create; may not be empty
|
||||
* @return the newly created context
|
||||
* @exception NameAlreadyBoundException if name is already bound
|
||||
* @exception javax.naming.directory.InvalidAttributesException if creation
|
||||
* of the sub-context requires specification of mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
if (!checkWritable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
NamingContext newContext = new NamingContext(env, this.name);
|
||||
bind(name, newContext);
|
||||
|
||||
newContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite());
|
||||
|
||||
return newContext;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and binds a new context.
|
||||
*
|
||||
* @param name the name of the context to create; may not be empty
|
||||
* @return the newly created context
|
||||
* @exception NameAlreadyBoundException if name is already bound
|
||||
* @exception javax.naming.directory.InvalidAttributesException if creation
|
||||
* of the sub-context requires specification of mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Context createSubcontext(String name)
|
||||
throws NamingException {
|
||||
return createSubcontext(new CompositeName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object, following links except for the terminal
|
||||
* atomic component of the name. If the object bound to name is not a
|
||||
* link, returns the object itself.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name, not following the terminal link
|
||||
* (if any).
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookupLink(Name name)
|
||||
throws NamingException {
|
||||
return lookup(name, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object, following links except for the terminal
|
||||
* atomic component of the name.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name, not following the terminal link
|
||||
* (if any).
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookupLink(String name)
|
||||
throws NamingException {
|
||||
return lookup(new CompositeName(name), false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the parser associated with the named context. In a
|
||||
* federation of namespaces, different naming systems will parse names
|
||||
* differently. This method allows an application to get a parser for
|
||||
* parsing names into their atomic components using the naming convention
|
||||
* of a particular naming system. Within any single naming system,
|
||||
* NameParser objects returned by this method must be equal (using the
|
||||
* equals() test).
|
||||
*
|
||||
* @param name the name of the context from which to get the parser
|
||||
* @return a name parser that can parse compound names into their atomic
|
||||
* components
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NameParser getNameParser(Name name)
|
||||
throws NamingException {
|
||||
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty())
|
||||
return nameParser;
|
||||
|
||||
if (name.size() > 1) {
|
||||
Object obj = bindings.get(name.get(0));
|
||||
if (obj instanceof Context) {
|
||||
return ((Context) obj).getNameParser(name.getSuffix(1));
|
||||
} else {
|
||||
throw new NotContextException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
}
|
||||
|
||||
return nameParser;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the parser associated with the named context.
|
||||
*
|
||||
* @param name the name of the context from which to get the parser
|
||||
* @return a name parser that can parse compound names into their atomic
|
||||
* components
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NameParser getNameParser(String name)
|
||||
throws NamingException {
|
||||
return getNameParser(new CompositeName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Composes the name of this context with a name relative to this context.
|
||||
* <p>
|
||||
* Given a name (name) relative to this context, and the name (prefix)
|
||||
* of this context relative to one of its ancestors, this method returns
|
||||
* the composition of the two names using the syntax appropriate for the
|
||||
* naming system(s) involved. That is, if name names an object relative
|
||||
* to this context, the result is the name of the same object, but
|
||||
* relative to the ancestor context. None of the names may be null.
|
||||
*
|
||||
* @param name a name relative to this context
|
||||
* @param prefix the name of this context relative to one of its ancestors
|
||||
* @return the composition of prefix and name
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
prefix = (Name) prefix.clone();
|
||||
return prefix.addAll(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Composes the name of this context with a name relative to this context.
|
||||
*
|
||||
* @param name a name relative to this context
|
||||
* @param prefix the name of this context relative to one of its ancestors
|
||||
* @return the composition of prefix and name
|
||||
*/
|
||||
@Override
|
||||
public String composeName(String name, String prefix) {
|
||||
return prefix + "/" + name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new environment property to the environment of this context. If
|
||||
* the property already exists, its value is overwritten.
|
||||
*
|
||||
* @param propName the name of the environment property to add; may not
|
||||
* be null
|
||||
* @param propVal the value of the property to add; may not be null
|
||||
*/
|
||||
@Override
|
||||
public Object addToEnvironment(String propName, Object propVal) {
|
||||
return env.put(propName, propVal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an environment property from the environment of this context.
|
||||
*
|
||||
* @param propName the name of the environment property to remove;
|
||||
* may not be null
|
||||
*/
|
||||
@Override
|
||||
public Object removeFromEnvironment(String propName){
|
||||
return env.remove(propName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the environment in effect for this context. See class
|
||||
* description for more details on environment properties.
|
||||
* The caller should not make any changes to the object returned: their
|
||||
* effect on the context is undefined. The environment of this context
|
||||
* may be changed using addToEnvironment() and removeFromEnvironment().
|
||||
*
|
||||
* @return the environment of this context; never null
|
||||
*/
|
||||
@Override
|
||||
public Hashtable<?,?> getEnvironment() {
|
||||
return env;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes this context. This method releases this context's resources
|
||||
* immediately, instead of waiting for them to be released automatically
|
||||
* by the garbage collector.
|
||||
* This method is idempotent: invoking it on a context that has already
|
||||
* been closed has no effect. Invoking any other method on a closed
|
||||
* context is not allowed, and results in undefined behaviour.
|
||||
*
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void close() throws NamingException {
|
||||
if (!checkWritable()) {
|
||||
return;
|
||||
}
|
||||
env.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the full name of this context within its own namespace.
|
||||
* <p>
|
||||
* Many naming services have a notion of a "full name" for objects in
|
||||
* their respective namespaces. For example, an LDAP entry has a
|
||||
* distinguished name, and a DNS record has a fully qualified name. This
|
||||
* method allows the client application to retrieve this name. The string
|
||||
* returned by this method is not a JNDI composite name and should not be
|
||||
* passed directly to context methods. In naming systems for which the
|
||||
* notion of full name does not make sense,
|
||||
* OperationNotSupportedException is thrown.
|
||||
*
|
||||
* @return this context's name in its own namespace; never null
|
||||
* @exception OperationNotSupportedException if the naming system does
|
||||
* not have the notion of a full name
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public String getNameInNamespace()
|
||||
throws NamingException {
|
||||
throw new OperationNotSupportedException
|
||||
(sm.getString("namingContext.noAbsoluteName"));
|
||||
//FIXME ?
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------ Protected Methods
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @param resolveLinks If true, the links will be resolved
|
||||
* @return the object bound to name
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
protected Object lookup(Name name, boolean resolveLinks)
|
||||
throws NamingException {
|
||||
|
||||
// Removing empty parts
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty()) {
|
||||
// If name is empty, a newly allocated naming context is returned
|
||||
return new NamingContext(env, this.name, bindings);
|
||||
}
|
||||
|
||||
NamingEntry entry = bindings.get(name.get(0));
|
||||
|
||||
if (entry == null) {
|
||||
throw new NameNotFoundException
|
||||
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
|
||||
}
|
||||
|
||||
if (name.size() > 1) {
|
||||
// If the size of the name is greater that 1, then we go through a
|
||||
// number of subcontexts.
|
||||
if (entry.type != NamingEntry.CONTEXT) {
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
return ((Context) entry.value).lookup(name.getSuffix(1));
|
||||
} else {
|
||||
if ((resolveLinks) && (entry.type == NamingEntry.LINK_REF)) {
|
||||
String link = ((LinkRef) entry.value).getLinkName();
|
||||
if (link.startsWith(".")) {
|
||||
// Link relative to this context
|
||||
return lookup(link.substring(1));
|
||||
} else {
|
||||
return new InitialContext(env).lookup(link);
|
||||
}
|
||||
} else if (entry.type == NamingEntry.REFERENCE) {
|
||||
try {
|
||||
Object obj = NamingManager.getObjectInstance
|
||||
(entry.value, name, this, env);
|
||||
if(entry.value instanceof ResourceRef) {
|
||||
boolean singleton = Boolean.parseBoolean(
|
||||
(String) ((ResourceRef) entry.value).get(
|
||||
"singleton").getContent());
|
||||
if (singleton) {
|
||||
entry.type = NamingEntry.ENTRY;
|
||||
entry.value = obj;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
} catch (NamingException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
String msg = sm.getString("namingContext.failResolvingReference");
|
||||
log.warn(msg, e);
|
||||
NamingException ne = new NamingException(msg);
|
||||
ne.initCause(e);
|
||||
throw ne;
|
||||
}
|
||||
} else {
|
||||
return entry.value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object. All intermediate contexts and the target
|
||||
* context (that named by all but terminal atomic component of the name)
|
||||
* must already exist.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @param rebind if true, then perform a rebind (ie, overwrite)
|
||||
* @exception NameAlreadyBoundException if name is already bound
|
||||
* @exception javax.naming.directory.InvalidAttributesException if object
|
||||
* did not supply all mandatory attributes
|
||||
* @exception NamingException if a naming exception is encountered
|
||||
*/
|
||||
protected void bind(Name name, Object obj, boolean rebind)
|
||||
throws NamingException {
|
||||
|
||||
if (!checkWritable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((!name.isEmpty()) && (name.get(0).length() == 0))
|
||||
name = name.getSuffix(1);
|
||||
if (name.isEmpty())
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.invalidName"));
|
||||
|
||||
NamingEntry entry = bindings.get(name.get(0));
|
||||
|
||||
if (name.size() > 1) {
|
||||
if (entry == null) {
|
||||
throw new NameNotFoundException(sm.getString(
|
||||
"namingContext.nameNotBound", name, name.get(0)));
|
||||
}
|
||||
if (entry.type == NamingEntry.CONTEXT) {
|
||||
if (rebind) {
|
||||
((Context) entry.value).rebind(name.getSuffix(1), obj);
|
||||
} else {
|
||||
((Context) entry.value).bind(name.getSuffix(1), obj);
|
||||
}
|
||||
} else {
|
||||
throw new NamingException
|
||||
(sm.getString("namingContext.contextExpected"));
|
||||
}
|
||||
} else {
|
||||
if ((!rebind) && (entry != null)) {
|
||||
throw new NameAlreadyBoundException
|
||||
(sm.getString("namingContext.alreadyBound", name.get(0)));
|
||||
} else {
|
||||
// Getting the type of the object and wrapping it within a new
|
||||
// NamingEntry
|
||||
Object toBind =
|
||||
NamingManager.getStateToBind(obj, name, this, env);
|
||||
if (toBind instanceof Context) {
|
||||
entry = new NamingEntry(name.get(0), toBind,
|
||||
NamingEntry.CONTEXT);
|
||||
} else if (toBind instanceof LinkRef) {
|
||||
entry = new NamingEntry(name.get(0), toBind,
|
||||
NamingEntry.LINK_REF);
|
||||
} else if (toBind instanceof Reference) {
|
||||
entry = new NamingEntry(name.get(0), toBind,
|
||||
NamingEntry.REFERENCE);
|
||||
} else if (toBind instanceof Referenceable) {
|
||||
toBind = ((Referenceable) toBind).getReference();
|
||||
entry = new NamingEntry(name.get(0), toBind,
|
||||
NamingEntry.REFERENCE);
|
||||
} else {
|
||||
entry = new NamingEntry(name.get(0), toBind,
|
||||
NamingEntry.ENTRY);
|
||||
}
|
||||
bindings.put(name.get(0), entry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if writing is allowed on this context.
|
||||
*/
|
||||
protected boolean isWritable() {
|
||||
return ContextAccessController.isWritable(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws a naming exception is Context is not writable.
|
||||
* @return <code>true</code> if the Context is writable
|
||||
* @throws NamingException if the Context is not writable and
|
||||
* <code>exceptionOnFailedWrite</code> is <code>true</code>
|
||||
*/
|
||||
protected boolean checkWritable() throws NamingException {
|
||||
if (isWritable()) {
|
||||
return true;
|
||||
} else {
|
||||
if (exceptionOnFailedWrite) {
|
||||
throw new javax.naming.OperationNotSupportedException(
|
||||
sm.getString("namingContext.readOnly"));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
132
java/org/apache/naming/NamingContextBindingsEnumeration.java
Normal file
132
java/org/apache/naming/NamingContextBindingsEnumeration.java
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.CompositeName;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Naming enumeration implementation.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class NamingContextBindingsEnumeration
|
||||
implements NamingEnumeration<Binding> {
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
public NamingContextBindingsEnumeration(Iterator<NamingEntry> entries,
|
||||
Context ctx) {
|
||||
iterator = entries;
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- Variables
|
||||
|
||||
|
||||
/**
|
||||
* Underlying enumeration.
|
||||
*/
|
||||
protected final Iterator<NamingEntry> iterator;
|
||||
|
||||
|
||||
/**
|
||||
* The context for which this enumeration is being generated.
|
||||
*/
|
||||
private final Context ctx;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the next element in the enumeration.
|
||||
*/
|
||||
@Override
|
||||
public Binding next()
|
||||
throws NamingException {
|
||||
return nextElementInternal();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether there are any more elements in the enumeration.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasMore()
|
||||
throws NamingException {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes this enumeration.
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
throws NamingException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Binding nextElement() {
|
||||
try {
|
||||
return nextElementInternal();
|
||||
} catch (NamingException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Binding nextElementInternal() throws NamingException {
|
||||
NamingEntry entry = iterator.next();
|
||||
Object value;
|
||||
|
||||
// If the entry is a reference, resolve it
|
||||
if (entry.type == NamingEntry.REFERENCE
|
||||
|| entry.type == NamingEntry.LINK_REF) {
|
||||
try {
|
||||
value = ctx.lookup(new CompositeName(entry.name));
|
||||
} catch (NamingException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
NamingException ne = new NamingException(e.getMessage());
|
||||
ne.initCause(e);
|
||||
throw ne;
|
||||
}
|
||||
} else {
|
||||
value = entry.value;
|
||||
}
|
||||
|
||||
return new Binding(entry.name, value.getClass().getName(), value, true);
|
||||
}
|
||||
}
|
||||
|
||||
99
java/org/apache/naming/NamingContextEnumeration.java
Normal file
99
java/org/apache/naming/NamingContextEnumeration.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Naming enumeration implementation.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class NamingContextEnumeration
|
||||
implements NamingEnumeration<NameClassPair> {
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
public NamingContextEnumeration(Iterator<NamingEntry> entries) {
|
||||
iterator = entries;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------- Variables
|
||||
|
||||
|
||||
/**
|
||||
* Underlying enumeration.
|
||||
*/
|
||||
protected final Iterator<NamingEntry> iterator;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the next element in the enumeration.
|
||||
*/
|
||||
@Override
|
||||
public NameClassPair next()
|
||||
throws NamingException {
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether there are any more elements in the enumeration.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasMore()
|
||||
throws NamingException {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes this enumeration.
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
throws NamingException {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NameClassPair nextElement() {
|
||||
NamingEntry entry = iterator.next();
|
||||
return new NameClassPair(entry.name, entry.value.getClass().getName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
63
java/org/apache/naming/NamingEntry.java
Normal file
63
java/org/apache/naming/NamingEntry.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a binding in a NamingContext.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class NamingEntry {
|
||||
|
||||
public static final int ENTRY = 0;
|
||||
public static final int LINK_REF = 1;
|
||||
public static final int REFERENCE = 2;
|
||||
public static final int CONTEXT = 10;
|
||||
|
||||
|
||||
public NamingEntry(String name, Object value, int type) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The type instance variable is used to avoid using RTTI when doing
|
||||
* lookups.
|
||||
*/
|
||||
public int type;
|
||||
public final String name;
|
||||
public Object value;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NamingEntry) {
|
||||
return name.equals(((NamingEntry) obj).name);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
}
|
||||
50
java/org/apache/naming/ResourceEnvRef.java
Normal file
50
java/org/apache/naming/ResourceEnvRef.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
/**
|
||||
* Represents a reference address to a resource environment.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ResourceEnvRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_RESOURCE_ENV_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* Resource env reference.
|
||||
*
|
||||
* @param resourceType Type
|
||||
*/
|
||||
public ResourceEnvRef(String resourceType) {
|
||||
super(resourceType);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
68
java/org/apache/naming/ResourceLinkRef.java
Normal file
68
java/org/apache/naming/ResourceLinkRef.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
/**
|
||||
* Represents a reference address to a resource.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ResourceLinkRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_RESOURCE_LINK_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* Description address type.
|
||||
*/
|
||||
public static final String GLOBALNAME = "globalName";
|
||||
|
||||
|
||||
/**
|
||||
* ResourceLink Reference.
|
||||
*
|
||||
* @param resourceClass Resource class
|
||||
* @param globalName Global name
|
||||
* @param factory The possibly null class name of the object's factory.
|
||||
* @param factoryLocation The possibly null location from which to load the
|
||||
* factory (e.g. URL)
|
||||
*/
|
||||
public ResourceLinkRef(String resourceClass, String globalName,
|
||||
String factory, String factoryLocation) {
|
||||
super(resourceClass, factory, factoryLocation);
|
||||
StringRefAddr refAddr = null;
|
||||
if (globalName != null) {
|
||||
refAddr = new StringRefAddr(GLOBALNAME, globalName);
|
||||
add(refAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
118
java/org/apache/naming/ResourceRef.java
Normal file
118
java/org/apache/naming/ResourceRef.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
/**
|
||||
* Represents a reference address to a resource.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ResourceRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_RESOURCE_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* Description address type.
|
||||
*/
|
||||
public static final String DESCRIPTION = "description";
|
||||
|
||||
|
||||
/**
|
||||
* Scope address type.
|
||||
*/
|
||||
public static final String SCOPE = "scope";
|
||||
|
||||
|
||||
/**
|
||||
* Auth address type.
|
||||
*/
|
||||
public static final String AUTH = "auth";
|
||||
|
||||
|
||||
/**
|
||||
* Is this resource a singleton
|
||||
*/
|
||||
public static final String SINGLETON = "singleton";
|
||||
|
||||
|
||||
/**
|
||||
* Resource Reference.
|
||||
*
|
||||
* @param resourceClass Resource class
|
||||
* @param description Description of the resource
|
||||
* @param scope Resource scope
|
||||
* @param auth Resource authentication
|
||||
* @param singleton Is this resource a singleton (every lookup should return
|
||||
* the same instance rather than a new instance)?
|
||||
*/
|
||||
public ResourceRef(String resourceClass, String description,
|
||||
String scope, String auth, boolean singleton) {
|
||||
this(resourceClass, description, scope, auth, singleton, null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resource Reference.
|
||||
*
|
||||
* @param resourceClass Resource class
|
||||
* @param description Description of the resource
|
||||
* @param scope Resource scope
|
||||
* @param auth Resource authentication
|
||||
* @param singleton Is this resource a singleton (every lookup should return
|
||||
* the same instance rather than a new instance)?
|
||||
* @param factory The possibly null class name of the object's factory.
|
||||
* @param factoryLocation The possibly null location from which to load the
|
||||
* factory (e.g. URL)
|
||||
*/
|
||||
public ResourceRef(String resourceClass, String description,
|
||||
String scope, String auth, boolean singleton,
|
||||
String factory, String factoryLocation) {
|
||||
super(resourceClass, factory, factoryLocation);
|
||||
StringRefAddr refAddr = null;
|
||||
if (description != null) {
|
||||
refAddr = new StringRefAddr(DESCRIPTION, description);
|
||||
add(refAddr);
|
||||
}
|
||||
if (scope != null) {
|
||||
refAddr = new StringRefAddr(SCOPE, scope);
|
||||
add(refAddr);
|
||||
}
|
||||
if (auth != null) {
|
||||
refAddr = new StringRefAddr(AUTH, auth);
|
||||
add(refAddr);
|
||||
}
|
||||
// singleton is a boolean so slightly different handling
|
||||
refAddr = new StringRefAddr(SINGLETON, Boolean.toString(singleton));
|
||||
add(refAddr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
799
java/org/apache/naming/SelectorContext.java
Normal file
799
java/org/apache/naming/SelectorContext.java
Normal file
@@ -0,0 +1,799 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
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 org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Catalina JNDI Context implementation.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class SelectorContext implements Context {
|
||||
|
||||
|
||||
// -------------------------------------------------------------- Constants
|
||||
|
||||
|
||||
/**
|
||||
* Namespace URL.
|
||||
*/
|
||||
public static final String prefix = "java:";
|
||||
|
||||
|
||||
/**
|
||||
* Namespace URL length.
|
||||
*/
|
||||
public static final int prefixLength = prefix.length();
|
||||
|
||||
|
||||
/**
|
||||
* Initial context prefix.
|
||||
*/
|
||||
public static final String IC_PREFIX = "IC_";
|
||||
|
||||
|
||||
private static final Log log = LogFactory.getLog(SelectorContext.class);
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
/**
|
||||
* Builds a Catalina selector context using the given environment.
|
||||
* @param env The environment
|
||||
*/
|
||||
public SelectorContext(Hashtable<String,Object> env) {
|
||||
this.env = env;
|
||||
this.initialContext = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds a Catalina selector context using the given environment.
|
||||
* @param env The environment
|
||||
* @param initialContext <code>true</code> if this is the main
|
||||
* initial context
|
||||
*/
|
||||
public SelectorContext(Hashtable<String,Object> env,
|
||||
boolean initialContext) {
|
||||
this.env = env;
|
||||
this.initialContext = initialContext;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* Environment.
|
||||
*/
|
||||
protected final Hashtable<String,Object> env;
|
||||
|
||||
|
||||
/**
|
||||
* The string manager for this package.
|
||||
*/
|
||||
protected static final StringManager sm = StringManager.getManager(SelectorContext.class);
|
||||
|
||||
|
||||
/**
|
||||
* Request for an initial context.
|
||||
*/
|
||||
protected final boolean initialContext;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
// -------------------------------------------------------- Context Methods
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object. If name is empty, returns a new instance
|
||||
* of this context (which represents the same naming context as this
|
||||
* context, but its environment may be modified independently and it may
|
||||
* be accessed concurrently).
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookup(Name name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingName", "lookup",
|
||||
name));
|
||||
}
|
||||
|
||||
// Strip the URL header
|
||||
// Find the appropriate NamingContext according to the current bindings
|
||||
// Execute the lookup on that context
|
||||
return getBoundContext().lookup(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookup(String name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingString", "lookup",
|
||||
name));
|
||||
}
|
||||
|
||||
// Strip the URL header
|
||||
// Find the appropriate NamingContext according to the current bindings
|
||||
// Execute the lookup on that context
|
||||
return getBoundContext().lookup(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object. All intermediate contexts and the target
|
||||
* context (that named by all but terminal atomic component of the name)
|
||||
* must already exist.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @throws javax.naming.NameAlreadyBoundException if name is already
|
||||
* bound
|
||||
* @throws javax.naming.directory.InvalidAttributesException if object did not
|
||||
* supply all mandatory attributes
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void bind(Name name, Object obj)
|
||||
throws NamingException {
|
||||
getBoundContext().bind(parseName(name), obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @throws javax.naming.NameAlreadyBoundException if name is already
|
||||
* bound
|
||||
* @throws javax.naming.directory.InvalidAttributesException if object did not
|
||||
* supply all mandatory attributes
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void bind(String name, Object obj)
|
||||
throws NamingException {
|
||||
getBoundContext().bind(parseName(name), obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object, overwriting any existing binding. All
|
||||
* intermediate contexts and the target context (that named by all but
|
||||
* terminal atomic component of the name) must already exist.
|
||||
* <p>
|
||||
* If the object is a DirContext, any existing attributes associated with
|
||||
* the name are replaced with those of the object. Otherwise, any
|
||||
* existing attributes associated with the name remain unchanged.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @throws javax.naming.directory.InvalidAttributesException if object did not
|
||||
* supply all mandatory attributes
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rebind(Name name, Object obj)
|
||||
throws NamingException {
|
||||
getBoundContext().rebind(parseName(name), obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a name to an object, overwriting any existing binding.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @param obj the object to bind; possibly null
|
||||
* @throws javax.naming.directory.InvalidAttributesException if object did not
|
||||
* supply all mandatory attributes
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rebind(String name, Object obj)
|
||||
throws NamingException {
|
||||
getBoundContext().rebind(parseName(name), obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds the named object. Removes the terminal atomic name in name
|
||||
* from the target context--that named by all but the terminal atomic
|
||||
* part of name.
|
||||
* <p>
|
||||
* This method is idempotent. It succeeds even if the terminal atomic
|
||||
* name is not bound in the target context, but throws
|
||||
* NameNotFoundException if any of the intermediate contexts do not exist.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @throws javax.naming.NameNotFoundException if an intermediate context
|
||||
* does not exist
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void unbind(Name name)
|
||||
throws NamingException {
|
||||
getBoundContext().unbind(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unbinds the named object.
|
||||
*
|
||||
* @param name the name to bind; may not be empty
|
||||
* @throws javax.naming.NameNotFoundException if an intermediate context
|
||||
* does not exist
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void unbind(String name)
|
||||
throws NamingException {
|
||||
getBoundContext().unbind(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a new name to the object bound to an old name, and unbinds the
|
||||
* old name. Both names are relative to this context. Any attributes
|
||||
* associated with the old name become associated with the new name.
|
||||
* Intermediate contexts of the old name are not changed.
|
||||
*
|
||||
* @param oldName the name of the existing binding; may not be empty
|
||||
* @param newName the name of the new binding; may not be empty
|
||||
* @throws javax.naming.NameAlreadyBoundException if name is already
|
||||
* bound
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rename(Name oldName, Name newName)
|
||||
throws NamingException {
|
||||
getBoundContext().rename(parseName(oldName), parseName(newName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Binds a new name to the object bound to an old name, and unbinds the
|
||||
* old name.
|
||||
*
|
||||
* @param oldName the name of the existing binding; may not be empty
|
||||
* @param newName the name of the new binding; may not be empty
|
||||
* @throws javax.naming.NameAlreadyBoundException if name is already
|
||||
* bound
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void rename(String oldName, String newName)
|
||||
throws NamingException {
|
||||
getBoundContext().rename(parseName(oldName), parseName(newName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the class
|
||||
* names of objects bound to them. The contents of any subcontexts are
|
||||
* not included.
|
||||
* <p>
|
||||
* If a binding is added to or removed from this context, its effect on
|
||||
* an enumeration previously returned is undefined.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the names and class names of the bindings in
|
||||
* this context. Each element of the enumeration is of type NameClassPair.
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingName", "list",
|
||||
name));
|
||||
}
|
||||
|
||||
return getBoundContext().list(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the class
|
||||
* names of objects bound to them.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the names and class names of the bindings in
|
||||
* this context. Each element of the enumeration is of type NameClassPair.
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingString", "list",
|
||||
name));
|
||||
}
|
||||
|
||||
return getBoundContext().list(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the
|
||||
* objects bound to them. The contents of any subcontexts are not
|
||||
* included.
|
||||
* <p>
|
||||
* If a binding is added to or removed from this context, its effect on
|
||||
* an enumeration previously returned is undefined.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the bindings in this context.
|
||||
* Each element of the enumeration is of type Binding.
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingName",
|
||||
"listBindings", name));
|
||||
}
|
||||
|
||||
return getBoundContext().listBindings(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enumerates the names bound in the named context, along with the
|
||||
* objects bound to them.
|
||||
*
|
||||
* @param name the name of the context to list
|
||||
* @return an enumeration of the bindings in this context.
|
||||
* Each element of the enumeration is of type Binding.
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingString",
|
||||
"listBindings", name));
|
||||
}
|
||||
|
||||
return getBoundContext().listBindings(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the named context and removes it from the namespace. Any
|
||||
* attributes associated with the name are also removed. Intermediate
|
||||
* contexts are not destroyed.
|
||||
* <p>
|
||||
* This method is idempotent. It succeeds even if the terminal atomic
|
||||
* name is not bound in the target context, but throws
|
||||
* NameNotFoundException if any of the intermediate contexts do not exist.
|
||||
*
|
||||
* In a federated naming system, a context from one naming system may be
|
||||
* bound to a name in another. One can subsequently look up and perform
|
||||
* operations on the foreign context using a composite name. However, an
|
||||
* attempt destroy the context using this composite name will fail with
|
||||
* NotContextException, because the foreign context is not a "subcontext"
|
||||
* of the context in which it is bound. Instead, use unbind() to remove
|
||||
* the binding of the foreign context. Destroying the foreign context
|
||||
* requires that the destroySubcontext() be performed on a context from
|
||||
* the foreign context's "native" naming system.
|
||||
*
|
||||
* @param name the name of the context to be destroyed; may not be empty
|
||||
* @throws javax.naming.NameNotFoundException if an intermediate context
|
||||
* does not exist
|
||||
* @throws javax.naming.NotContextException if the name is bound but does
|
||||
* not name a context, or does not name a context of the appropriate type
|
||||
*/
|
||||
@Override
|
||||
public void destroySubcontext(Name name)
|
||||
throws NamingException {
|
||||
getBoundContext().destroySubcontext(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the named context and removes it from the namespace.
|
||||
*
|
||||
* @param name the name of the context to be destroyed; may not be empty
|
||||
* @throws javax.naming.NameNotFoundException if an intermediate context
|
||||
* does not exist
|
||||
* @throws javax.naming.NotContextException if the name is bound but does
|
||||
* not name a context, or does not name a context of the appropriate type
|
||||
*/
|
||||
@Override
|
||||
public void destroySubcontext(String name)
|
||||
throws NamingException {
|
||||
getBoundContext().destroySubcontext(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and binds a new context. Creates a new context with the given
|
||||
* name and binds it in the target context (that named by all but
|
||||
* terminal atomic component of the name). All intermediate contexts and
|
||||
* the target context must already exist.
|
||||
*
|
||||
* @param name the name of the context to create; may not be empty
|
||||
* @return the newly created context
|
||||
* @throws javax.naming.NameAlreadyBoundException if name is already
|
||||
* bound
|
||||
* @throws javax.naming.directory.InvalidAttributesException if creation of the
|
||||
* sub-context requires specification of mandatory attributes
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Context createSubcontext(Name name)
|
||||
throws NamingException {
|
||||
return getBoundContext().createSubcontext(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates and binds a new context.
|
||||
*
|
||||
* @param name the name of the context to create; may not be empty
|
||||
* @return the newly created context
|
||||
* @throws javax.naming.NameAlreadyBoundException if name is already
|
||||
* bound
|
||||
* @throws javax.naming.directory.InvalidAttributesException if creation of the
|
||||
* sub-context requires specification of mandatory attributes
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Context createSubcontext(String name)
|
||||
throws NamingException {
|
||||
return getBoundContext().createSubcontext(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object, following links except for the terminal
|
||||
* atomic component of the name. If the object bound to name is not a
|
||||
* link, returns the object itself.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name, not following the terminal link
|
||||
* (if any).
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookupLink(Name name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingName",
|
||||
"lookupLink", name));
|
||||
}
|
||||
|
||||
return getBoundContext().lookupLink(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the named object, following links except for the terminal
|
||||
* atomic component of the name.
|
||||
*
|
||||
* @param name the name of the object to look up
|
||||
* @return the object bound to name, not following the terminal link
|
||||
* (if any).
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object lookupLink(String name)
|
||||
throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(sm.getString("selectorContext.methodUsingString",
|
||||
"lookupLink", name));
|
||||
}
|
||||
|
||||
return getBoundContext().lookupLink(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the parser associated with the named context. In a
|
||||
* federation of namespaces, different naming systems will parse names
|
||||
* differently. This method allows an application to get a parser for
|
||||
* parsing names into their atomic components using the naming convention
|
||||
* of a particular naming system. Within any single naming system,
|
||||
* NameParser objects returned by this method must be equal (using the
|
||||
* equals() test).
|
||||
*
|
||||
* @param name the name of the context from which to get the parser
|
||||
* @return a name parser that can parse compound names into their atomic
|
||||
* components
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NameParser getNameParser(Name name)
|
||||
throws NamingException {
|
||||
return getBoundContext().getNameParser(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the parser associated with the named context.
|
||||
*
|
||||
* @param name the name of the context from which to get the parser
|
||||
* @return a name parser that can parse compound names into their atomic
|
||||
* components
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public NameParser getNameParser(String name)
|
||||
throws NamingException {
|
||||
return getBoundContext().getNameParser(parseName(name));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Composes the name of this context with a name relative to this context.
|
||||
* <p>
|
||||
* Given a name (name) relative to this context, and the name (prefix)
|
||||
* of this context relative to one of its ancestors, this method returns
|
||||
* the composition of the two names using the syntax appropriate for the
|
||||
* naming system(s) involved. That is, if name names an object relative
|
||||
* to this context, the result is the name of the same object, but
|
||||
* relative to the ancestor context. None of the names may be null.
|
||||
*
|
||||
* @param name a name relative to this context
|
||||
* @param prefix the name of this context relative to one of its ancestors
|
||||
* @return the composition of prefix and name
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Name composeName(Name name, Name prefix)
|
||||
throws NamingException {
|
||||
Name prefixClone = (Name) prefix.clone();
|
||||
return prefixClone.addAll(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Composes the name of this context with a name relative to this context.
|
||||
*
|
||||
* @param name a name relative to this context
|
||||
* @param prefix the name of this context relative to one of its ancestors
|
||||
* @return the composition of prefix and name
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException {
|
||||
return prefix + "/" + name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new environment property to the environment of this context. If
|
||||
* the property already exists, its value is overwritten.
|
||||
*
|
||||
* @param propName the name of the environment property to add; may not
|
||||
* be null
|
||||
* @param propVal the value of the property to add; may not be null
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object addToEnvironment(String propName, Object propVal)
|
||||
throws NamingException {
|
||||
return getBoundContext().addToEnvironment(propName, propVal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes an environment property from the environment of this context.
|
||||
*
|
||||
* @param propName the name of the environment property to remove;
|
||||
* may not be null
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Object removeFromEnvironment(String propName)
|
||||
throws NamingException {
|
||||
return getBoundContext().removeFromEnvironment(propName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the environment in effect for this context. See class
|
||||
* description for more details on environment properties.
|
||||
* The caller should not make any changes to the object returned: their
|
||||
* effect on the context is undefined. The environment of this context
|
||||
* may be changed using addToEnvironment() and removeFromEnvironment().
|
||||
*
|
||||
* @return the environment of this context; never null
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public Hashtable<?,?> getEnvironment()
|
||||
throws NamingException {
|
||||
return getBoundContext().getEnvironment();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes this context. This method releases this context's resources
|
||||
* immediately, instead of waiting for them to be released automatically
|
||||
* by the garbage collector.
|
||||
* This method is idempotent: invoking it on a context that has already
|
||||
* been closed has no effect. Invoking any other method on a closed
|
||||
* context is not allowed, and results in undefined behaviour.
|
||||
*
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
throws NamingException {
|
||||
getBoundContext().close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the full name of this context within its own namespace.
|
||||
* <p>
|
||||
* Many naming services have a notion of a "full name" for objects in
|
||||
* their respective namespaces. For example, an LDAP entry has a
|
||||
* distinguished name, and a DNS record has a fully qualified name. This
|
||||
* method allows the client application to retrieve this name. The string
|
||||
* returned by this method is not a JNDI composite name and should not be
|
||||
* passed directly to context methods. In naming systems for which the
|
||||
* notion of full name does not make sense,
|
||||
* OperationNotSupportedException is thrown.
|
||||
*
|
||||
* @return this context's name in its own namespace; never null
|
||||
* @throws javax.naming.OperationNotSupportedException if the naming
|
||||
* system does not have the notion of a full name
|
||||
* @throws NamingException if a naming exception is encountered
|
||||
*/
|
||||
@Override
|
||||
public String getNameInNamespace()
|
||||
throws NamingException {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------ Protected Methods
|
||||
|
||||
|
||||
/**
|
||||
* Get the bound context.
|
||||
* @return the Context bound with either the current thread or
|
||||
* the current classloader
|
||||
* @throws NamingException Bindings exception
|
||||
*/
|
||||
protected Context getBoundContext()
|
||||
throws NamingException {
|
||||
|
||||
if (initialContext) {
|
||||
String ICName = IC_PREFIX;
|
||||
if (ContextBindings.isThreadBound()) {
|
||||
ICName += ContextBindings.getThreadName();
|
||||
} else if (ContextBindings.isClassLoaderBound()) {
|
||||
ICName += ContextBindings.getClassLoaderName();
|
||||
}
|
||||
Context initialContext = ContextBindings.getContext(ICName);
|
||||
if (initialContext == null) {
|
||||
// Allocating a new context and binding it to the appropriate
|
||||
// name
|
||||
initialContext = new NamingContext(env, ICName);
|
||||
ContextBindings.bindContext(ICName, initialContext);
|
||||
}
|
||||
return initialContext;
|
||||
} else {
|
||||
if (ContextBindings.isThreadBound()) {
|
||||
return ContextBindings.getThread();
|
||||
} else {
|
||||
return ContextBindings.getClassLoader();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strips the URL header.
|
||||
* @param name The name
|
||||
* @return the parsed name
|
||||
* @throws NamingException if there is no "java:" header or if no
|
||||
* naming context has been bound to this thread
|
||||
*/
|
||||
protected String parseName(String name)
|
||||
throws NamingException {
|
||||
|
||||
if ((!initialContext) && (name.startsWith(prefix))) {
|
||||
return name.substring(prefixLength);
|
||||
} else {
|
||||
if (initialContext) {
|
||||
return name;
|
||||
} else {
|
||||
throw new NamingException
|
||||
(sm.getString("selectorContext.noJavaUrl"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Strips the URL header.
|
||||
* @param name The name
|
||||
* @return the parsed name
|
||||
* @throws NamingException if there is no "java:" header or if no
|
||||
* naming context has been bound to this thread
|
||||
*/
|
||||
protected Name parseName(Name name)
|
||||
throws NamingException {
|
||||
|
||||
if (!initialContext && !name.isEmpty() &&
|
||||
name.get(0).startsWith(prefix)) {
|
||||
if (name.get(0).equals(prefix)) {
|
||||
return name.getSuffix(1);
|
||||
} else {
|
||||
Name result = name.getSuffix(1);
|
||||
result.add(0, name.get(0).substring(prefixLength));
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
if (initialContext) {
|
||||
return name;
|
||||
} else {
|
||||
throw new NamingException(
|
||||
sm.getString("selectorContext.noJavaUrl"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
143
java/org/apache/naming/ServiceRef.java
Normal file
143
java/org/apache/naming/ServiceRef.java
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
/**
|
||||
* Represents a reference web service.
|
||||
*
|
||||
* @author Fabien Carrion
|
||||
*/
|
||||
public class ServiceRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_SERVICE_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* Service Classname address type.
|
||||
*/
|
||||
public static final String SERVICE_INTERFACE = "serviceInterface";
|
||||
|
||||
|
||||
/**
|
||||
* ServiceQname address type.
|
||||
*/
|
||||
public static final String SERVICE_NAMESPACE = "service namespace";
|
||||
public static final String SERVICE_LOCAL_PART = "service local part";
|
||||
|
||||
|
||||
/**
|
||||
* Wsdl Location address type.
|
||||
*/
|
||||
public static final String WSDL = "wsdl";
|
||||
|
||||
|
||||
/**
|
||||
* Jaxrpcmapping address type.
|
||||
*/
|
||||
public static final String JAXRPCMAPPING = "jaxrpcmapping";
|
||||
|
||||
|
||||
/**
|
||||
* port-component-ref/port-component-link address type.
|
||||
*/
|
||||
public static final String PORTCOMPONENTLINK = "portcomponentlink";
|
||||
|
||||
|
||||
/**
|
||||
* port-component-ref/service-endpoint-interface address type.
|
||||
*/
|
||||
public static final String SERVICEENDPOINTINTERFACE = "serviceendpointinterface";
|
||||
|
||||
|
||||
/**
|
||||
* The vector to save the handler Reference objects, because they can't be
|
||||
* saved in the addrs vector.
|
||||
*/
|
||||
private final Vector<HandlerRef> handlers = new Vector<>();
|
||||
|
||||
|
||||
public ServiceRef(String refname, String serviceInterface, String[] serviceQname,
|
||||
String wsdl, String jaxrpcmapping) {
|
||||
this(refname, serviceInterface, serviceQname, wsdl, jaxrpcmapping,
|
||||
null, null);
|
||||
}
|
||||
|
||||
|
||||
public ServiceRef(@SuppressWarnings("unused") String refname,
|
||||
String serviceInterface, String[] serviceQname,
|
||||
String wsdl, String jaxrpcmapping,
|
||||
String factory, String factoryLocation) {
|
||||
super(serviceInterface, factory, factoryLocation);
|
||||
StringRefAddr refAddr = null;
|
||||
if (serviceInterface != null) {
|
||||
refAddr = new StringRefAddr(SERVICE_INTERFACE, serviceInterface);
|
||||
add(refAddr);
|
||||
}
|
||||
if (serviceQname[0] != null) {
|
||||
refAddr = new StringRefAddr(SERVICE_NAMESPACE, serviceQname[0]);
|
||||
add(refAddr);
|
||||
}
|
||||
if (serviceQname[1] != null) {
|
||||
refAddr = new StringRefAddr(SERVICE_LOCAL_PART, serviceQname[1]);
|
||||
add(refAddr);
|
||||
}
|
||||
if (wsdl != null) {
|
||||
refAddr = new StringRefAddr(WSDL, wsdl);
|
||||
add(refAddr);
|
||||
}
|
||||
if (jaxrpcmapping != null) {
|
||||
refAddr = new StringRefAddr(JAXRPCMAPPING, jaxrpcmapping);
|
||||
add(refAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add and Get Handlers classes.
|
||||
* @return the handler
|
||||
*/
|
||||
public HandlerRef getHandler() {
|
||||
return handlers.remove(0);
|
||||
}
|
||||
|
||||
|
||||
public int getHandlersSize() {
|
||||
return handlers.size();
|
||||
}
|
||||
|
||||
|
||||
public void addHandler(HandlerRef handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
184
java/org/apache/naming/StringManager.java
Normal file
184
java/org/apache/naming/StringManager.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.naming;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* An internationalization / localization helper class which reduces
|
||||
* the bother of handling ResourceBundles and takes care of the
|
||||
* common cases of message formating which otherwise require the
|
||||
* creation of Object arrays and such.
|
||||
*
|
||||
* <p>The StringManager operates on a package basis. One StringManager
|
||||
* per package can be created and accessed via the getManager method
|
||||
* call.
|
||||
*
|
||||
* <p>The StringManager will look for a ResourceBundle named by
|
||||
* the package name given plus the suffix of "LocalStrings". In
|
||||
* practice, this means that the localized information will be contained
|
||||
* in a LocalStrings.properties file located in the package
|
||||
* directory of the classpath.
|
||||
*
|
||||
* <p>Please see the documentation for java.util.ResourceBundle for
|
||||
* more information.
|
||||
*
|
||||
* @author James Duncan Davidson [duncan@eng.sun.com]
|
||||
* @author James Todd [gonzo@eng.sun.com]
|
||||
* @author Mel Martinez [mmartinez@g1440.com]
|
||||
* @see java.util.ResourceBundle
|
||||
*/
|
||||
public class StringManager {
|
||||
|
||||
/**
|
||||
* The ResourceBundle for this StringManager.
|
||||
*/
|
||||
private final ResourceBundle bundle;
|
||||
private final Locale locale;
|
||||
|
||||
/**
|
||||
* Creates a new StringManager for a given package. This is a
|
||||
* private method and all access to it is arbitrated by the
|
||||
* static getManager method call so that only one StringManager
|
||||
* per package will be created.
|
||||
*
|
||||
* @param packageName Name of package to create StringManager for.
|
||||
*/
|
||||
private StringManager(String packageName) {
|
||||
String bundleName = packageName + ".LocalStrings";
|
||||
ResourceBundle tempBundle = null;
|
||||
try {
|
||||
tempBundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
|
||||
} catch( MissingResourceException ex ) {
|
||||
// Try from the current loader (that's the case for trusted apps)
|
||||
// Should only be required if using a TC5 style classloader structure
|
||||
// where common != shared != server
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if( cl != null ) {
|
||||
try {
|
||||
tempBundle = ResourceBundle.getBundle(
|
||||
bundleName, Locale.getDefault(), cl);
|
||||
} catch(MissingResourceException ex2) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get the actual locale, which may be different from the requested one
|
||||
if (tempBundle != null) {
|
||||
locale = tempBundle.getLocale();
|
||||
} else {
|
||||
locale = null;
|
||||
}
|
||||
bundle = tempBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
Get a string from the underlying resource bundle or return
|
||||
null if the String is not found.
|
||||
|
||||
@param key to desired resource String
|
||||
@return resource String matching <i>key</i> from underlying
|
||||
bundle or null if not found.
|
||||
@throws IllegalArgumentException if <i>key</i> is null.
|
||||
*/
|
||||
public String getString(String key) {
|
||||
if(key == null){
|
||||
String msg = "key may not have a null value";
|
||||
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
|
||||
String str = null;
|
||||
|
||||
try {
|
||||
// Avoid NPE if bundle is null and treat it like an MRE
|
||||
if (bundle != null) {
|
||||
str = bundle.getString(key);
|
||||
}
|
||||
} catch(MissingResourceException mre) {
|
||||
//bad: shouldn't mask an exception the following way:
|
||||
// str = "[cannot find message associated with key '" + key + "' due to " + mre + "]";
|
||||
// because it hides the fact that the String was missing
|
||||
// from the calling code.
|
||||
//good: could just throw the exception (or wrap it in another)
|
||||
// but that would probably cause much havoc on existing
|
||||
// code.
|
||||
//better: consistent with container pattern to
|
||||
// simply return null. Calling code can then do
|
||||
// a null check.
|
||||
str = null;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string from the underlying resource bundle and format
|
||||
* it with the given set of arguments.
|
||||
*
|
||||
* @param key The key for the required message
|
||||
* @param args The values to insert into the message
|
||||
*
|
||||
* @return The request string formatted with the provided arguments or the
|
||||
* key if the key was not found.
|
||||
*/
|
||||
public String getString(final String key, final Object... args) {
|
||||
String value = getString(key);
|
||||
if (value == null) {
|
||||
value = key;
|
||||
}
|
||||
|
||||
MessageFormat mf = new MessageFormat(value);
|
||||
mf.setLocale(locale);
|
||||
return mf.format(args, new StringBuffer(), null).toString();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// STATIC SUPPORT METHODS
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private static final Hashtable<String, StringManager> managers =
|
||||
new Hashtable<>();
|
||||
|
||||
/**
|
||||
* Get the StringManager for a particular package. If a manager for
|
||||
* a package already exists, it will be reused, else a new
|
||||
* StringManager will be created and returned.
|
||||
*
|
||||
* @param packageName The package name
|
||||
*
|
||||
* @return The instance associated with the given package
|
||||
*/
|
||||
public static final synchronized StringManager getManager(String packageName) {
|
||||
StringManager mgr = managers.get(packageName);
|
||||
if (mgr == null) {
|
||||
mgr = new StringManager(packageName);
|
||||
managers.put(packageName, mgr);
|
||||
}
|
||||
return mgr;
|
||||
}
|
||||
|
||||
|
||||
public static final StringManager getManager(Class<?> clazz) {
|
||||
return getManager(clazz.getPackage().getName());
|
||||
}
|
||||
}
|
||||
59
java/org/apache/naming/TransactionRef.java
Normal file
59
java/org/apache/naming/TransactionRef.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming;
|
||||
|
||||
/**
|
||||
* Represents a reference address to a transaction.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class TransactionRef extends AbstractRef {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* Default factory for this reference.
|
||||
*/
|
||||
public static final String DEFAULT_FACTORY =
|
||||
org.apache.naming.factory.Constants.DEFAULT_TRANSACTION_FACTORY;
|
||||
|
||||
|
||||
/**
|
||||
* Resource Reference.
|
||||
*/
|
||||
public TransactionRef() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resource Reference.
|
||||
*
|
||||
* @param factory The factory class
|
||||
* @param factoryLocation The factory location
|
||||
*/
|
||||
public TransactionRef(String factory, String factoryLocation) {
|
||||
super("javax.transaction.UserTransaction", factory, factoryLocation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getDefaultFactoryClassName() {
|
||||
return DEFAULT_FACTORY;
|
||||
}
|
||||
}
|
||||
309
java/org/apache/naming/factory/BeanFactory.java
Normal file
309
java/org/apache/naming/factory/BeanFactory.java
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.ResourceRef;
|
||||
|
||||
/**
|
||||
* Object factory for any Resource conforming to the JavaBean spec.
|
||||
*
|
||||
* <p>This factory can be configured in a <code><Context></code> element
|
||||
* in your <code>conf/server.xml</code>
|
||||
* configuration file. An example of factory configuration is:</p>
|
||||
* <pre>
|
||||
* <Resource name="jdbc/myDataSource" auth="SERVLET"
|
||||
* type="oracle.jdbc.pool.OracleConnectionCacheImpl"/>
|
||||
* <ResourceParams name="jdbc/myDataSource">
|
||||
* <parameter>
|
||||
* <name>factory</name>
|
||||
* <value>org.apache.naming.factory.BeanFactory</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>driverType</name>
|
||||
* <value>thin</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>serverName</name>
|
||||
* <value>hue</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>networkProtocol</name>
|
||||
* <value>tcp</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>databaseName</name>
|
||||
* <value>XXXX</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>portNumber</name>
|
||||
* <value>NNNN</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>user</name>
|
||||
* <value>XXXX</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>password</name>
|
||||
* <value>XXXX</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>maxLimit</name>
|
||||
* <value>5</value>
|
||||
* </parameter>
|
||||
* </ResourceParams>
|
||||
* </pre>
|
||||
*
|
||||
* @author Aner Perez [aner at ncstech.com]
|
||||
*/
|
||||
public class BeanFactory
|
||||
implements ObjectFactory {
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
// -------------------------------------------------------------- Constants
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
// -------------------------------------------------- ObjectFactory Methods
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Bean instance.
|
||||
*
|
||||
* @param obj The reference object describing the Bean
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?,?> environment)
|
||||
throws NamingException {
|
||||
|
||||
if (obj instanceof ResourceRef) {
|
||||
|
||||
try {
|
||||
|
||||
Reference ref = (Reference) obj;
|
||||
String beanClassName = ref.getClassName();
|
||||
Class<?> beanClass = null;
|
||||
ClassLoader tcl =
|
||||
Thread.currentThread().getContextClassLoader();
|
||||
if (tcl != null) {
|
||||
try {
|
||||
beanClass = tcl.loadClass(beanClassName);
|
||||
} catch(ClassNotFoundException e) {
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
beanClass = Class.forName(beanClassName);
|
||||
} catch(ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (beanClass == null) {
|
||||
throw new NamingException
|
||||
("Class not found: " + beanClassName);
|
||||
}
|
||||
|
||||
BeanInfo bi = Introspector.getBeanInfo(beanClass);
|
||||
PropertyDescriptor[] pda = bi.getPropertyDescriptors();
|
||||
|
||||
Object bean = beanClass.getConstructor().newInstance();
|
||||
|
||||
/* Look for properties with explicitly configured setter */
|
||||
RefAddr ra = ref.get("forceString");
|
||||
Map<String, Method> forced = new HashMap<>();
|
||||
String value;
|
||||
|
||||
if (ra != null) {
|
||||
value = (String)ra.getContent();
|
||||
Class<?> paramTypes[] = new Class[1];
|
||||
paramTypes[0] = String.class;
|
||||
String setterName;
|
||||
int index;
|
||||
|
||||
/* Items are given as comma separated list */
|
||||
for (String param: value.split(",")) {
|
||||
param = param.trim();
|
||||
/* A single item can either be of the form name=method
|
||||
* or just a property name (and we will use a standard
|
||||
* setter) */
|
||||
index = param.indexOf('=');
|
||||
if (index >= 0) {
|
||||
setterName = param.substring(index + 1).trim();
|
||||
param = param.substring(0, index).trim();
|
||||
} else {
|
||||
setterName = "set" +
|
||||
param.substring(0, 1).toUpperCase(Locale.ENGLISH) +
|
||||
param.substring(1);
|
||||
}
|
||||
try {
|
||||
forced.put(param,
|
||||
beanClass.getMethod(setterName, paramTypes));
|
||||
} catch (NoSuchMethodException|SecurityException ex) {
|
||||
throw new NamingException
|
||||
("Forced String setter " + setterName +
|
||||
" not found for property " + param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Enumeration<RefAddr> e = ref.getAll();
|
||||
|
||||
while (e.hasMoreElements()) {
|
||||
|
||||
ra = e.nextElement();
|
||||
String propName = ra.getType();
|
||||
|
||||
if (propName.equals(Constants.FACTORY) ||
|
||||
propName.equals("scope") || propName.equals("auth") ||
|
||||
propName.equals("forceString") ||
|
||||
propName.equals("singleton")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value = (String)ra.getContent();
|
||||
|
||||
Object[] valueArray = new Object[1];
|
||||
|
||||
/* Shortcut for properties with explicitly configured setter */
|
||||
Method method = forced.get(propName);
|
||||
if (method != null) {
|
||||
valueArray[0] = value;
|
||||
try {
|
||||
method.invoke(bean, valueArray);
|
||||
} catch (IllegalAccessException|
|
||||
IllegalArgumentException|
|
||||
InvocationTargetException ex) {
|
||||
throw new NamingException
|
||||
("Forced String setter " + method.getName() +
|
||||
" threw exception for property " + propName);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i<pda.length; i++) {
|
||||
|
||||
if (pda[i].getName().equals(propName)) {
|
||||
|
||||
Class<?> propType = pda[i].getPropertyType();
|
||||
|
||||
if (propType.equals(String.class)) {
|
||||
valueArray[0] = value;
|
||||
} else if (propType.equals(Character.class)
|
||||
|| propType.equals(char.class)) {
|
||||
valueArray[0] =
|
||||
Character.valueOf(value.charAt(0));
|
||||
} else if (propType.equals(Byte.class)
|
||||
|| propType.equals(byte.class)) {
|
||||
valueArray[0] = Byte.valueOf(value);
|
||||
} else if (propType.equals(Short.class)
|
||||
|| propType.equals(short.class)) {
|
||||
valueArray[0] = Short.valueOf(value);
|
||||
} else if (propType.equals(Integer.class)
|
||||
|| propType.equals(int.class)) {
|
||||
valueArray[0] = Integer.valueOf(value);
|
||||
} else if (propType.equals(Long.class)
|
||||
|| propType.equals(long.class)) {
|
||||
valueArray[0] = Long.valueOf(value);
|
||||
} else if (propType.equals(Float.class)
|
||||
|| propType.equals(float.class)) {
|
||||
valueArray[0] = Float.valueOf(value);
|
||||
} else if (propType.equals(Double.class)
|
||||
|| propType.equals(double.class)) {
|
||||
valueArray[0] = Double.valueOf(value);
|
||||
} else if (propType.equals(Boolean.class)
|
||||
|| propType.equals(boolean.class)) {
|
||||
valueArray[0] = Boolean.valueOf(value);
|
||||
} else {
|
||||
throw new NamingException
|
||||
("String conversion for property " + propName +
|
||||
" of type '" + propType.getName() +
|
||||
"' not available");
|
||||
}
|
||||
|
||||
Method setProp = pda[i].getWriteMethod();
|
||||
if (setProp != null) {
|
||||
setProp.invoke(bean, valueArray);
|
||||
} else {
|
||||
throw new NamingException
|
||||
("Write not allowed for property: "
|
||||
+ propName);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (i == pda.length) {
|
||||
throw new NamingException
|
||||
("No set method found for property: " + propName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return bean;
|
||||
|
||||
} catch (java.beans.IntrospectionException ie) {
|
||||
NamingException ne = new NamingException(ie.getMessage());
|
||||
ne.setRootCause(ie);
|
||||
throw ne;
|
||||
} catch (java.lang.ReflectiveOperationException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) cause;
|
||||
}
|
||||
if (cause instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) cause;
|
||||
}
|
||||
NamingException ne = new NamingException(e.getMessage());
|
||||
ne.setRootCause(e);
|
||||
throw ne;
|
||||
}
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
48
java/org/apache/naming/factory/Constants.java
Normal file
48
java/org/apache/naming/factory/Constants.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
/**
|
||||
* Static constants for this package.
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
public static final String Package = "org.apache.naming.factory";
|
||||
|
||||
public static final String DEFAULT_RESOURCE_FACTORY = Package + ".ResourceFactory";
|
||||
|
||||
public static final String DEFAULT_RESOURCE_LINK_FACTORY = Package + ".ResourceLinkFactory";
|
||||
|
||||
public static final String DEFAULT_TRANSACTION_FACTORY = Package + ".TransactionFactory";
|
||||
|
||||
public static final String DEFAULT_RESOURCE_ENV_FACTORY = Package + ".ResourceEnvFactory";
|
||||
|
||||
public static final String DEFAULT_EJB_FACTORY = Package + ".EjbFactory";
|
||||
|
||||
public static final String DEFAULT_SERVICE_FACTORY = Package + ".webservices.ServiceRefFactory";
|
||||
|
||||
public static final String DEFAULT_HANDLER_FACTORY = Package + ".HandlerFactory";
|
||||
|
||||
public static final String DBCP_DATASOURCE_FACTORY =
|
||||
"org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory";
|
||||
|
||||
public static final String OPENEJB_EJB_FACTORY = Package + ".OpenEjbFactory";
|
||||
|
||||
public static final String DEFAULT_LOOKUP_JNDI_FACTORY = Package + ".LookupFactory";
|
||||
|
||||
public static final String FACTORY = "factory";
|
||||
}
|
||||
150
java/org/apache/naming/factory/DataSourceLinkFactory.java
Normal file
150
java/org/apache/naming/factory/DataSourceLinkFactory.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.sql.SQLException;
|
||||
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.sql.DataSource;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Object factory for resource links for shared data sources.</p>
|
||||
*
|
||||
*/
|
||||
public class DataSourceLinkFactory extends ResourceLinkFactory {
|
||||
|
||||
public static void setGlobalContext(Context newGlobalContext) {
|
||||
ResourceLinkFactory.setGlobalContext(newGlobalContext);
|
||||
}
|
||||
// ------------------------------------------------- ObjectFactory Methods
|
||||
|
||||
|
||||
/**
|
||||
* Create a new DataSource instance.
|
||||
*
|
||||
* @param obj The reference object describing the DataSource
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment)
|
||||
throws NamingException {
|
||||
Object result = super.getObjectInstance(obj, name, nameCtx, environment);
|
||||
// Can we process this request?
|
||||
if (result!=null) {
|
||||
Reference ref = (Reference) obj;
|
||||
RefAddr userAttr = ref.get("username");
|
||||
RefAddr passAttr = ref.get("password");
|
||||
if (userAttr.getContent()!=null && passAttr.getContent()!=null) {
|
||||
result = wrapDataSource(result,userAttr.getContent().toString(), passAttr.getContent().toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Object wrapDataSource(Object datasource, String username, String password) throws NamingException {
|
||||
try {
|
||||
DataSourceHandler handler =
|
||||
new DataSourceHandler((DataSource)datasource, username, password);
|
||||
return Proxy.newProxyInstance(datasource.getClass().getClassLoader(),
|
||||
datasource.getClass().getInterfaces(), handler);
|
||||
}catch (Exception x) {
|
||||
if (x instanceof InvocationTargetException) {
|
||||
Throwable cause = x.getCause();
|
||||
if (cause instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) cause;
|
||||
}
|
||||
if (cause instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) cause;
|
||||
}
|
||||
if (cause instanceof Exception) {
|
||||
x = (Exception) cause;
|
||||
}
|
||||
}
|
||||
if (x instanceof NamingException) throw (NamingException)x;
|
||||
else {
|
||||
NamingException nx = new NamingException(x.getMessage());
|
||||
nx.initCause(x);
|
||||
throw nx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple wrapper class that will allow a user to configure a ResourceLink for a data source
|
||||
* so that when {@link javax.sql.DataSource#getConnection()} is called, it will invoke
|
||||
* {@link javax.sql.DataSource#getConnection(String, String)} with the preconfigured username and password.
|
||||
*/
|
||||
public static class DataSourceHandler implements InvocationHandler {
|
||||
private final DataSource ds;
|
||||
private final String username;
|
||||
private final String password;
|
||||
private final Method getConnection;
|
||||
public DataSourceHandler(DataSource ds, String username, String password) throws Exception {
|
||||
this.ds = ds;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
getConnection = ds.getClass().getMethod("getConnection", String.class, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
|
||||
if ("getConnection".equals(method.getName()) && (args==null || args.length==0)) {
|
||||
args = new String[] {username,password};
|
||||
method = getConnection;
|
||||
} else if ("unwrap".equals(method.getName())) {
|
||||
return unwrap((Class<?>)args[0]);
|
||||
}
|
||||
try {
|
||||
return method.invoke(ds,args);
|
||||
}catch (Throwable t) {
|
||||
if (t instanceof InvocationTargetException
|
||||
&& t.getCause() != null) {
|
||||
throw t.getCause();
|
||||
} else {
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object unwrap(Class<?> iface) throws SQLException {
|
||||
if (iface == DataSource.class) {
|
||||
return ds;
|
||||
} else {
|
||||
throw new SQLException(sm.getString("dataSourceLinkFactory.badWrapper", iface.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
78
java/org/apache/naming/factory/EjbFactory.java
Normal file
78
java/org/apache/naming/factory/EjbFactory.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.EjbRef;
|
||||
|
||||
/**
|
||||
* Object factory for EJBs.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class EjbFactory extends FactoryBase {
|
||||
|
||||
@Override
|
||||
protected boolean isReferenceTypeSupported(Object obj) {
|
||||
return obj instanceof EjbRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectFactory getDefaultFactory(Reference ref) throws NamingException {
|
||||
|
||||
ObjectFactory factory;
|
||||
String javaxEjbFactoryClassName = System.getProperty(
|
||||
"javax.ejb.Factory", Constants.OPENEJB_EJB_FACTORY);
|
||||
try {
|
||||
factory = (ObjectFactory)
|
||||
Class.forName(javaxEjbFactoryClassName).getConstructor().newInstance();
|
||||
} catch(Throwable t) {
|
||||
if (t instanceof NamingException) {
|
||||
throw (NamingException) t;
|
||||
}
|
||||
if (t instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) t;
|
||||
}
|
||||
if (t instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) t;
|
||||
}
|
||||
NamingException ex = new NamingException
|
||||
("Could not create resource factory instance");
|
||||
ex.initCause(t);
|
||||
throw ex;
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getLinked(Reference ref) throws NamingException {
|
||||
// If ejb-link has been specified, resolving the link using JNDI
|
||||
RefAddr linkRefAddr = ref.get(EjbRef.LINK);
|
||||
if (linkRefAddr != null) {
|
||||
// Retrieving the EJB link
|
||||
String ejbLink = linkRefAddr.getContent().toString();
|
||||
Object beanObj = (new InitialContext()).lookup(ejbLink);
|
||||
return beanObj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
141
java/org/apache/naming/factory/FactoryBase.java
Normal file
141
java/org/apache/naming/factory/FactoryBase.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
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.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.StringManager;
|
||||
|
||||
/**
|
||||
* Abstract base class that provides common functionality required by
|
||||
* sub-classes. This class exists primarily to reduce code duplication.
|
||||
*/
|
||||
public abstract class FactoryBase implements ObjectFactory {
|
||||
|
||||
private static final StringManager sm = StringManager.getManager(FactoryBase.class);
|
||||
|
||||
/**
|
||||
* Creates a new object instance.
|
||||
*
|
||||
* @param obj The reference object describing the object to create
|
||||
*/
|
||||
@Override
|
||||
public final Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?,?> environment) throws Exception {
|
||||
|
||||
if (isReferenceTypeSupported(obj)) {
|
||||
Reference ref = (Reference) obj;
|
||||
|
||||
Object linked = getLinked(ref);
|
||||
if (linked != null) {
|
||||
return linked;
|
||||
}
|
||||
|
||||
ObjectFactory factory = null;
|
||||
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
|
||||
if (factoryRefAddr != null) {
|
||||
// Using the specified factory
|
||||
String factoryClassName = factoryRefAddr.getContent().toString();
|
||||
// Loading factory
|
||||
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
|
||||
Class<?> factoryClass = null;
|
||||
try {
|
||||
if (tcl != null) {
|
||||
factoryClass = tcl.loadClass(factoryClassName);
|
||||
} else {
|
||||
factoryClass = Class.forName(factoryClassName);
|
||||
}
|
||||
} catch(ClassNotFoundException e) {
|
||||
NamingException ex = new NamingException(sm.getString("factoryBase.factoryClassError"));
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
try {
|
||||
factory = (ObjectFactory) factoryClass.getConstructor().newInstance();
|
||||
} catch(Throwable t) {
|
||||
if (t instanceof NamingException) {
|
||||
throw (NamingException) t;
|
||||
}
|
||||
if (t instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) t;
|
||||
}
|
||||
if (t instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) t;
|
||||
}
|
||||
NamingException ex = new NamingException(sm.getString("factoryBase.factoryCreationError"));
|
||||
ex.initCause(t);
|
||||
throw ex;
|
||||
}
|
||||
} else {
|
||||
// Check for a default factory
|
||||
factory = getDefaultFactory(ref);
|
||||
}
|
||||
|
||||
if (factory != null) {
|
||||
return factory.getObjectInstance(obj, name, nameCtx, environment);
|
||||
} else {
|
||||
throw new NamingException(sm.getString("factoryBase.instanceCreationError"));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if this factory supports processing the provided reference
|
||||
* object.
|
||||
*
|
||||
* @param obj The object to be processed
|
||||
*
|
||||
* @return <code>true</code> if this factory can process the object,
|
||||
* otherwise <code>false</code>
|
||||
*/
|
||||
protected abstract boolean isReferenceTypeSupported(Object obj);
|
||||
|
||||
/**
|
||||
* If a default factory is available for the given reference type, create
|
||||
* the default factory.
|
||||
*
|
||||
* @param ref The reference object to be processed
|
||||
*
|
||||
* @return The default factory for the given reference object or
|
||||
* <code>null</code> if no default factory exists.
|
||||
*
|
||||
* @throws NamingException If the default factory cannot be created
|
||||
*/
|
||||
protected abstract ObjectFactory getDefaultFactory(Reference ref)
|
||||
throws NamingException;
|
||||
|
||||
/**
|
||||
* If this reference is a link to another JNDI object, obtain that object.
|
||||
*
|
||||
* @param ref The reference object to be processed
|
||||
*
|
||||
* @return The linked object or <code>null</code> if linked objects are
|
||||
* not supported by or not configured for this reference object
|
||||
* @throws NamingException Error accessing linked object
|
||||
*/
|
||||
protected abstract Object getLinked(Reference ref) throws NamingException;
|
||||
}
|
||||
32
java/org/apache/naming/factory/LocalStrings.properties
Normal file
32
java/org/apache/naming/factory/LocalStrings.properties
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
dataSourceLinkFactory.badWrapper=Not a wrapper for type [{0}]
|
||||
|
||||
factoryBase.factoryClassError=Could not load resource factory class
|
||||
factoryBase.factoryCreationError=Could not create resource factory instance
|
||||
factoryBase.instanceCreationError=Could not create resource instance
|
||||
|
||||
lookupFactory.circularReference=Found a circular reference involving [{0}]
|
||||
lookupFactory.createFailed=Could not create instance of JNDI lookup factory class
|
||||
lookupFactory.loadFailed=Could not load JNDI lookup factory class
|
||||
lookupFactory.typeMismatch=The JNDI reference [{0}] was expected to be of type [{1}] but the lookup [{2}] return an object of type [{3}]
|
||||
|
||||
resourceFactory.factoryCreationError=Could not create resource factory instance
|
||||
|
||||
resourceLinkFactory.invalidGlobalContext=Caller provided invalid global context
|
||||
resourceLinkFactory.nullType=The local resource link [{0}] that refers to global resource [{1}] does not specify the required attribute type
|
||||
resourceLinkFactory.unknownType=The local resource link [{0}] that refers to global resource [{1}] specified the unknown type [{2}]
|
||||
resourceLinkFactory.wrongType=The local resource link [{0}] that refers to global resource [{1}] was expected to return an instance of [{2}] but returned an instance of [{3}]
|
||||
20
java/org/apache/naming/factory/LocalStrings_es.properties
Normal file
20
java/org/apache/naming/factory/LocalStrings_es.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
lookupFactory.createFailed=No se pudo crear una instancia de la clase de fábrica JNDI lookup\n
|
||||
lookupFactory.typeMismatch=La referencia JNDI [{0}] se esperaba que fuera de tipo [{1}] pero la búsqueda [{2}] devolvió un objeto tipo [{3}]
|
||||
|
||||
resourceLinkFactory.nullType=El enlace del recurso local [{0}] que se refiere al recurso global [{1}] no especifica el atributo obligatorio "type"
|
||||
resourceLinkFactory.unknownType=El enlace del recurso local [{0}] que apunta al recurso global especificado [{1}] de tipo desconocido [{2}]\n
|
||||
32
java/org/apache/naming/factory/LocalStrings_fr.properties
Normal file
32
java/org/apache/naming/factory/LocalStrings_fr.properties
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
dataSourceLinkFactory.badWrapper=Pas un enrobeur pour le type [{0}]
|
||||
|
||||
factoryBase.factoryClassError=Impossible de charger la classe de la fabrique de ressources
|
||||
factoryBase.factoryCreationError=Impossible de créer l'instance de la fabrique de ressources
|
||||
factoryBase.instanceCreationError=Impossible de créer l'instance de la ressource
|
||||
|
||||
lookupFactory.circularReference=Trouvé une référence circulaire avec [{0}]
|
||||
lookupFactory.createFailed=Echec de création de l'instance de la classe de fabrique de recherche JNDI
|
||||
lookupFactory.loadFailed=Echec de chargement de la classe de fabrique de recherche JNDI
|
||||
lookupFactory.typeMismatch=La référence JNDI [{0}] devrait être de type [{1}] mais la recherche [{2}] retourne un objet de type [{3}]
|
||||
|
||||
resourceFactory.factoryCreationError=Impossible de créer une instance de la fabrique de ressources
|
||||
|
||||
resourceLinkFactory.invalidGlobalContext=L'appelant a fourni un contexte global invalide
|
||||
resourceLinkFactory.nullType=Le lien local de resource [{0}] qui se réfère à la resource globale [{1}] ne spécifie pas le type d''attribut requis
|
||||
resourceLinkFactory.unknownType=Le lien local de resource [{0}] qui se réfère à la resource globale [{1}] a spécifié le type inconnu [{2}]
|
||||
resourceLinkFactory.wrongType=Le lien de ressource local [{0}] qui se réfère à la ressource globale [{1}] devait renvoyer une instance de [{2}] mais à renvoyé une instance de [{3}]
|
||||
28
java/org/apache/naming/factory/LocalStrings_ja.properties
Normal file
28
java/org/apache/naming/factory/LocalStrings_ja.properties
Normal file
@@ -0,0 +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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
dataSourceLinkFactory.badWrapper=クラス[{0}]のラッパーではありません。
|
||||
|
||||
lookupFactory.circularReference=[{0}]を含む循環参照が見つかりました。
|
||||
lookupFactory.createFailed=JNDI lookup ファクトリークラスのインスタンスを作成できませんでした。
|
||||
lookupFactory.loadFailed=JNDIルックアップファクトリクラスをロードできませんでした。
|
||||
lookupFactory.typeMismatch=クラス [{1}] を期待する JNDI 参照 [{0}]に、lookup [{2}] はクラス [{3}] のオブジェクトを返却しました。
|
||||
|
||||
resourceFactory.factoryCreationError=リソースファクトリーのインスタンスを作成できません。
|
||||
|
||||
resourceLinkFactory.invalidGlobalContext=引数に不正な共通コンテキストが指定されました。
|
||||
resourceLinkFactory.nullType=グローバルリソース [{1}] を参照するローカルリソースリンク [{0}] に必要な属性がありません。
|
||||
resourceLinkFactory.unknownType=グローバルリソース [{1}] を参照するローカルリソースリンク [{0}] に未知のクラス [{2}] が指定されました。
|
||||
resourceLinkFactory.wrongType=グローバルリソース[{1}]を参照するローカルリソースリンク[{0}]は[{2}]のインスタンスを返すと予想されましたが、[{3}]のインスタンスを返しました。
|
||||
32
java/org/apache/naming/factory/LocalStrings_ko.properties
Normal file
32
java/org/apache/naming/factory/LocalStrings_ko.properties
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
dataSourceLinkFactory.badWrapper=타입 [{0}]을(를) 위한 wrapper가 아닙니다.
|
||||
|
||||
factoryBase.factoryClassError=리소스 팩토리 클래스를 로드하지 못했습니다.
|
||||
factoryBase.factoryCreationError=리소스 팩토리 인스턴스를 생성하지 못했습니다.
|
||||
factoryBase.instanceCreationError=리소스 인스턴스를 생성하지 못했습니다.
|
||||
|
||||
lookupFactory.circularReference=[{0}]을(를) 수반한 순환 참조를 발견했습니다.
|
||||
lookupFactory.createFailed=JNDI lookup 팩토리 클래스의 인스턴스를 생성할 수 없었습니다.
|
||||
lookupFactory.loadFailed=JNDI lookup 팩토리 클래스를 로드할 수 없었습니다.
|
||||
lookupFactory.typeMismatch=JNDI 참조 [{0}]은(는) 타입이 [{1}]이어야 하지만, lookup으로 찾아진 객체 [{2}]은(는) 타입이 [{3}]입니다.
|
||||
|
||||
resourceFactory.factoryCreationError=리소스 팩토리 인스턴스를 생성할 수 없었습니다.
|
||||
|
||||
resourceLinkFactory.invalidGlobalContext=호출자가, 유효하지 않은 글로벌 컨텍스트를 제공했습니다.
|
||||
resourceLinkFactory.nullType=글로벌 리소스 [{1}]을(를) 참조하는 해당 로컬 리소스 링크 [{0}]이(가) 필수적인 속성 타입을 지정하지 않았습니다.
|
||||
resourceLinkFactory.unknownType=글로벌 리소스 [{1}]을(를) 참조하는 해당 로컬 리소스 링크 [{0}]이(가), 알 수 없는 타입 [{2}]으로 지정되어 있습니다.
|
||||
resourceLinkFactory.wrongType=글로벌 리소스 [{1}]을(를) 참조하는 해당 로컬 리소스 링크 [{0}]은(는), 타입 [{2}]의 인스턴스틀 반환할 것으로 기대되었지만, 정작 타입 [{3}]의 인스턴스를 반환했습니다.
|
||||
25
java/org/apache/naming/factory/LocalStrings_zh_CN.properties
Normal file
25
java/org/apache/naming/factory/LocalStrings_zh_CN.properties
Normal file
@@ -0,0 +1,25 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
factoryBase.factoryClassError=无法加载资源工厂类
|
||||
factoryBase.factoryCreationError=无法创建资源工厂实例
|
||||
factoryBase.instanceCreationError=无法创建资源实例
|
||||
|
||||
lookupFactory.createFailed=无法创建JNDI查找工厂类实例
|
||||
lookupFactory.loadFailed=无法加载JNDI查找工厂类
|
||||
lookupFactory.typeMismatch=期望JNDI引用[{0}]的类型为[{1}],但查找[{2}]返回类型为[{3}]的对象
|
||||
|
||||
resourceLinkFactory.nullType=引用全局资源 [{1}] 的本地资源链接 [{0}] 未指定所需的属性类型
|
||||
resourceLinkFactory.unknownType=引用全局资源[{1}]的本地资源链接[{0}]指定了未知类型[{2}]
|
||||
155
java/org/apache/naming/factory/LookupFactory.java
Normal file
155
java/org/apache/naming/factory/LookupFactory.java
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.apache.naming.LookupRef;
|
||||
import org.apache.naming.StringManager;
|
||||
|
||||
/**
|
||||
* Object factory for lookups.
|
||||
*/
|
||||
public class LookupFactory implements ObjectFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(LookupFactory.class);
|
||||
private static final StringManager sm = StringManager.getManager(LookupFactory.class);
|
||||
|
||||
private static final ThreadLocal<Set<String>> names = new ThreadLocal<Set<String>>() {
|
||||
|
||||
@Override
|
||||
protected Set<String> initialValue() {
|
||||
return new HashSet<>();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new Resource env instance.
|
||||
*
|
||||
* @param obj The reference object describing the DataSource
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?, ?> environment) throws Exception {
|
||||
|
||||
String lookupName = null;
|
||||
Object result = null;
|
||||
|
||||
if (obj instanceof LookupRef) {
|
||||
Reference ref = (Reference) obj;
|
||||
ObjectFactory factory = null;
|
||||
RefAddr lookupNameRefAddr = ref.get(LookupRef.LOOKUP_NAME);
|
||||
if (lookupNameRefAddr != null) {
|
||||
lookupName = lookupNameRefAddr.getContent().toString();
|
||||
}
|
||||
|
||||
try {
|
||||
if (lookupName != null) {
|
||||
if (!names.get().add(lookupName)) {
|
||||
String msg = sm.getString("lookupFactory.circularReference", lookupName);
|
||||
NamingException ne = new NamingException(msg);
|
||||
log.warn(msg, ne);
|
||||
throw ne;
|
||||
}
|
||||
}
|
||||
RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
|
||||
if (factoryRefAddr != null) {
|
||||
// Using the specified factory
|
||||
String factoryClassName = factoryRefAddr.getContent().toString();
|
||||
// Loading factory
|
||||
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
|
||||
Class<?> factoryClass = null;
|
||||
if (tcl != null) {
|
||||
try {
|
||||
factoryClass = tcl.loadClass(factoryClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
NamingException ex = new NamingException(
|
||||
sm.getString("lookupFactory.loadFailed"));
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
factoryClass = Class.forName(factoryClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
NamingException ex = new NamingException(
|
||||
sm.getString("lookupFactory.loadFailed"));
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
if (factoryClass != null) {
|
||||
try {
|
||||
factory = (ObjectFactory) factoryClass.getConstructor().newInstance();
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof NamingException)
|
||||
throw (NamingException) t;
|
||||
NamingException ex = new NamingException(
|
||||
sm.getString("lookupFactory.createFailed"));
|
||||
ex.initCause(t);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Note: No defaults here
|
||||
if (factory != null) {
|
||||
result = factory.getObjectInstance(obj, name, nameCtx, environment);
|
||||
} else {
|
||||
if (lookupName == null) {
|
||||
throw new NamingException(sm.getString("lookupFactory.createFailed"));
|
||||
} else {
|
||||
result = new InitialContext().lookup(lookupName);
|
||||
}
|
||||
}
|
||||
|
||||
Class<?> clazz = Class.forName(ref.getClassName());
|
||||
if (result != null && !clazz.isAssignableFrom(result.getClass())) {
|
||||
String msg = sm.getString("lookupFactory.typeMismatch",
|
||||
name, ref.getClassName(), lookupName, result.getClass().getName());
|
||||
NamingException ne = new NamingException(msg);
|
||||
log.warn(msg, ne);
|
||||
// Close the resource we no longer need if we know how to do so
|
||||
if (result instanceof AutoCloseable) {
|
||||
try {
|
||||
((AutoCloseable) result).close();
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
throw ne;
|
||||
}
|
||||
} finally {
|
||||
names.get().remove(lookupName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
155
java/org/apache/naming/factory/MailSessionFactory.java
Normal file
155
java/org/apache/naming/factory/MailSessionFactory.java
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
/**
|
||||
* <p>Factory class that creates a JNDI named JavaMail Session factory,
|
||||
* which can be used for managing inbound and outbound electronic mail
|
||||
* messages via JavaMail APIs. All messaging environment properties
|
||||
* described in the JavaMail Specification may be passed to the Session
|
||||
* factory; however the following properties are the most commonly used:</p>
|
||||
* <ul>
|
||||
* <li>
|
||||
* <li><strong>mail.smtp.host</strong> - Hostname for outbound transport
|
||||
* connections. Defaults to <code>localhost</code> if not specified.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>This factory can be configured in a
|
||||
* <code><Context></code> element in your <code>conf/server.xml</code>
|
||||
* configuration file. An example of factory configuration is:</p>
|
||||
* <pre>
|
||||
* <Resource name="mail/smtp" auth="CONTAINER"
|
||||
* type="javax.mail.Session"/>
|
||||
* <ResourceParams name="mail/smtp">
|
||||
* <parameter>
|
||||
* <name>factory</name>
|
||||
* <value>org.apache.naming.factory.MailSessionFactory</value>
|
||||
* </parameter>
|
||||
* <parameter>
|
||||
* <name>mail.smtp.host</name>
|
||||
* <value>mail.mycompany.com</value>
|
||||
* </parameter>
|
||||
* </ResourceParams>
|
||||
* </pre>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
public class MailSessionFactory implements ObjectFactory {
|
||||
|
||||
|
||||
/**
|
||||
* The Java type for which this factory knows how to create objects.
|
||||
*/
|
||||
protected static final String factoryType = "javax.mail.Session";
|
||||
|
||||
|
||||
/**
|
||||
* Create and return an object instance based on the specified
|
||||
* characteristics.
|
||||
*
|
||||
* @param refObj Reference information containing our parameters, or null
|
||||
* if there are no parameters
|
||||
* @param name The name of this object, relative to context, or null
|
||||
* if there is no name
|
||||
* @param context The context to which name is relative, or null if name
|
||||
* is relative to the default initial context
|
||||
* @param env Environment variables, or null if there are none
|
||||
*
|
||||
* @exception Exception if an error occurs during object creation
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object refObj, Name name, Context context,
|
||||
Hashtable<?,?> env) throws Exception {
|
||||
|
||||
// Return null if we cannot create an object of the requested type
|
||||
final Reference ref = (Reference) refObj;
|
||||
if (!ref.getClassName().equals(factoryType))
|
||||
return null;
|
||||
|
||||
// Create a new Session inside a doPrivileged block, so that JavaMail
|
||||
// can read its default properties without throwing Security
|
||||
// exceptions.
|
||||
//
|
||||
// Bugzilla 31288, 33077: add support for authentication.
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Session>() {
|
||||
@Override
|
||||
public Session run() {
|
||||
|
||||
// Create the JavaMail properties we will use
|
||||
Properties props = new Properties();
|
||||
props.put("mail.transport.protocol", "smtp");
|
||||
props.put("mail.smtp.host", "localhost");
|
||||
|
||||
String password = null;
|
||||
|
||||
Enumeration<RefAddr> attrs = ref.getAll();
|
||||
while (attrs.hasMoreElements()) {
|
||||
RefAddr attr = attrs.nextElement();
|
||||
if ("factory".equals(attr.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("password".equals(attr.getType())) {
|
||||
password = (String) attr.getContent();
|
||||
continue;
|
||||
}
|
||||
|
||||
props.put(attr.getType(), attr.getContent());
|
||||
}
|
||||
|
||||
Authenticator auth = null;
|
||||
if (password != null) {
|
||||
String user = props.getProperty("mail.smtp.user");
|
||||
if(user == null) {
|
||||
user = props.getProperty("mail.user");
|
||||
}
|
||||
|
||||
if(user != null) {
|
||||
final PasswordAuthentication pa = new PasswordAuthentication(user, password);
|
||||
auth = new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return pa;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Create and return the new Session object
|
||||
Session session = Session.getInstance(props, auth);
|
||||
return session;
|
||||
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
91
java/org/apache/naming/factory/OpenEjbFactory.java
Normal file
91
java/org/apache/naming/factory/OpenEjbFactory.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.EjbRef;
|
||||
|
||||
/**
|
||||
* Object factory for EJBs.
|
||||
*
|
||||
* @author Jacek Laskowski
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class OpenEjbFactory implements ObjectFactory {
|
||||
|
||||
|
||||
// -------------------------------------------------------------- Constants
|
||||
|
||||
|
||||
protected static final String DEFAULT_OPENEJB_FACTORY =
|
||||
"org.openejb.client.LocalInitialContextFactory";
|
||||
|
||||
|
||||
// -------------------------------------------------- ObjectFactory Methods
|
||||
|
||||
|
||||
/**
|
||||
* Create a new EJB instance using OpenEJB.
|
||||
*
|
||||
* @param obj The reference object describing the DataSource
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?,?> environment)
|
||||
throws Exception {
|
||||
|
||||
Object beanObj = null;
|
||||
|
||||
if (obj instanceof EjbRef) {
|
||||
|
||||
Reference ref = (Reference) obj;
|
||||
|
||||
String factory = DEFAULT_OPENEJB_FACTORY;
|
||||
RefAddr factoryRefAddr = ref.get("openejb.factory");
|
||||
if (factoryRefAddr != null) {
|
||||
// Retrieving the OpenEJB factory
|
||||
factory = factoryRefAddr.getContent().toString();
|
||||
}
|
||||
|
||||
Properties env = new Properties();
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, factory);
|
||||
|
||||
RefAddr linkRefAddr = ref.get("openejb.link");
|
||||
if (linkRefAddr != null) {
|
||||
String ejbLink = linkRefAddr.getContent().toString();
|
||||
beanObj = (new InitialContext(env)).lookup(ejbLink);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return beanObj;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
47
java/org/apache/naming/factory/ResourceEnvFactory.java
Normal file
47
java/org/apache/naming/factory/ResourceEnvFactory.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.ResourceEnvRef;
|
||||
|
||||
/**
|
||||
* Object factory for Resources env.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ResourceEnvFactory extends FactoryBase {
|
||||
|
||||
@Override
|
||||
protected boolean isReferenceTypeSupported(Object obj) {
|
||||
return obj instanceof ResourceEnvRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectFactory getDefaultFactory(Reference ref) {
|
||||
// No default factory supported.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getLinked(Reference ref) {
|
||||
// Not supported
|
||||
return null;
|
||||
}
|
||||
}
|
||||
88
java/org/apache/naming/factory/ResourceFactory.java
Normal file
88
java/org/apache/naming/factory/ResourceFactory.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.ResourceRef;
|
||||
import org.apache.naming.StringManager;
|
||||
|
||||
/**
|
||||
* Object factory for Resources.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ResourceFactory extends FactoryBase {
|
||||
|
||||
private static final StringManager sm = StringManager.getManager(ResourceFactory.class);
|
||||
|
||||
@Override
|
||||
protected boolean isReferenceTypeSupported(Object obj) {
|
||||
return obj instanceof ResourceRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectFactory getDefaultFactory(Reference ref) throws NamingException {
|
||||
|
||||
ObjectFactory factory = null;
|
||||
|
||||
if (ref.getClassName().equals("javax.sql.DataSource")) {
|
||||
String javaxSqlDataSourceFactoryClassName =
|
||||
System.getProperty("javax.sql.DataSource.Factory",
|
||||
Constants.DBCP_DATASOURCE_FACTORY);
|
||||
try {
|
||||
factory = (ObjectFactory) Class.forName(
|
||||
javaxSqlDataSourceFactoryClassName).getConstructor().newInstance();
|
||||
} catch (Exception e) {
|
||||
NamingException ex = new NamingException(sm.getString("resourceFactory.factoryCreationError"));
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
} else if (ref.getClassName().equals("javax.mail.Session")) {
|
||||
String javaxMailSessionFactoryClassName =
|
||||
System.getProperty("javax.mail.Session.Factory",
|
||||
"org.apache.naming.factory.MailSessionFactory");
|
||||
try {
|
||||
factory = (ObjectFactory) Class.forName(
|
||||
javaxMailSessionFactoryClassName).getConstructor().newInstance();
|
||||
} catch(Throwable t) {
|
||||
if (t instanceof NamingException) {
|
||||
throw (NamingException) t;
|
||||
}
|
||||
if (t instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) t;
|
||||
}
|
||||
if (t instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) t;
|
||||
}
|
||||
NamingException ex = new NamingException(sm.getString("resourceFactory.factoryCreationError"));
|
||||
ex.initCause(t);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getLinked(Reference ref) {
|
||||
// Not supported
|
||||
return null;
|
||||
}
|
||||
}
|
||||
175
java/org/apache/naming/factory/ResourceLinkFactory.java
Normal file
175
java/org/apache/naming/factory/ResourceLinkFactory.java
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.ResourceLinkRef;
|
||||
import org.apache.naming.StringManager;
|
||||
|
||||
/**
|
||||
* <p>Object factory for resource links.</p>
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class ResourceLinkFactory implements ObjectFactory {
|
||||
|
||||
// ------------------------------------------------------- Static Variables
|
||||
|
||||
protected static final StringManager sm = StringManager.getManager(ResourceLinkFactory.class);
|
||||
|
||||
/**
|
||||
* Global naming context.
|
||||
*/
|
||||
private static Context globalContext = null;
|
||||
|
||||
private static Map<ClassLoader,Map<String,String>> globalResourceRegistrations =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
/**
|
||||
* Set the global context (note: can only be used once).
|
||||
*
|
||||
* @param newGlobalContext new global context value
|
||||
*/
|
||||
public static void setGlobalContext(Context newGlobalContext) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new RuntimePermission(
|
||||
ResourceLinkFactory.class.getName() + ".setGlobalContext"));
|
||||
}
|
||||
globalContext = newGlobalContext;
|
||||
}
|
||||
|
||||
|
||||
public static void registerGlobalResourceAccess(Context globalContext, String localName,
|
||||
String globalName) {
|
||||
validateGlobalContext(globalContext);
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Map<String,String> registrations = globalResourceRegistrations.get(cl);
|
||||
if (registrations == null) {
|
||||
// Web application initialization is single threaded so this is
|
||||
// safe.
|
||||
registrations = new HashMap<>();
|
||||
globalResourceRegistrations.put(cl, registrations);
|
||||
}
|
||||
registrations.put(localName, globalName);
|
||||
}
|
||||
|
||||
|
||||
public static void deregisterGlobalResourceAccess(Context globalContext, String localName) {
|
||||
validateGlobalContext(globalContext);
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
Map<String,String> registrations = globalResourceRegistrations.get(cl);
|
||||
if (registrations != null) {
|
||||
registrations.remove(localName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void deregisterGlobalResourceAccess(Context globalContext) {
|
||||
validateGlobalContext(globalContext);
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
globalResourceRegistrations.remove(cl);
|
||||
}
|
||||
|
||||
|
||||
private static void validateGlobalContext(Context globalContext) {
|
||||
if (ResourceLinkFactory.globalContext != null &&
|
||||
ResourceLinkFactory.globalContext != globalContext) {
|
||||
throw new SecurityException(sm.getString("resourceLinkFactory.invalidGlobalContext"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean validateGlobalResourceAccess(String globalName) {
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
while (cl != null) {
|
||||
Map<String,String> registrations = globalResourceRegistrations.get(cl);
|
||||
if (registrations != null && registrations.containsValue(globalName)) {
|
||||
return true;
|
||||
}
|
||||
cl = cl.getParent();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------- ObjectFactory Methods
|
||||
|
||||
/**
|
||||
* Create a new DataSource instance.
|
||||
*
|
||||
* @param obj The reference object describing the DataSource
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?,?> environment) throws NamingException {
|
||||
|
||||
if (!(obj instanceof ResourceLinkRef)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Can we process this request?
|
||||
Reference ref = (Reference) obj;
|
||||
|
||||
// Read the global ref addr
|
||||
String globalName = null;
|
||||
RefAddr refAddr = ref.get(ResourceLinkRef.GLOBALNAME);
|
||||
if (refAddr != null) {
|
||||
globalName = refAddr.getContent().toString();
|
||||
// Confirm that the current web application is currently configured
|
||||
// to access the specified global resource
|
||||
if (!validateGlobalResourceAccess(globalName)) {
|
||||
return null;
|
||||
}
|
||||
Object result = null;
|
||||
result = globalContext.lookup(globalName);
|
||||
// Check the expected type
|
||||
String expectedClassName = ref.getClassName();
|
||||
if (expectedClassName == null) {
|
||||
throw new IllegalArgumentException(
|
||||
sm.getString("resourceLinkFactory.nullType", name, globalName));
|
||||
}
|
||||
try {
|
||||
Class<?> expectedClazz = Class.forName(
|
||||
expectedClassName, true, Thread.currentThread().getContextClassLoader());
|
||||
if (!expectedClazz.isAssignableFrom(result.getClass())) {
|
||||
throw new IllegalArgumentException(sm.getString("resourceLinkFactory.wrongType",
|
||||
name, globalName, expectedClassName, result.getClass().getName()));
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(sm.getString("resourceLinkFactory.unknownType",
|
||||
name, globalName, expectedClassName), e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
132
java/org/apache/naming/factory/SendMailFactory.java
Normal file
132
java/org/apache/naming/factory/SendMailFactory.java
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimePartDataSource;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
/**
|
||||
* Factory class that creates a JNDI named javamail MimePartDataSource
|
||||
* object which can be used for sending email using SMTP.
|
||||
* <p>
|
||||
* Can be configured in the Context scope
|
||||
* of your server.xml configuration file.
|
||||
* <p>
|
||||
* Example:
|
||||
* <pre>
|
||||
* <Resource name="mail/send" auth="CONTAINER"
|
||||
* type="javax.mail.internet.MimePartDataSource"/>
|
||||
* <ResourceParams name="mail/send">
|
||||
* <parameter><name>factory</name>
|
||||
* <value>org.apache.naming.factory.SendMailFactory</value>
|
||||
* </parameter>
|
||||
* <parameter><name>mail.smtp.host</name>
|
||||
* <value>your.smtp.host</value>
|
||||
* </parameter>
|
||||
* <parameter><name>mail.smtp.user</name>
|
||||
* <value>someuser</value>
|
||||
* </parameter>
|
||||
* <parameter><name>mail.from</name>
|
||||
* <value>someuser@some.host</value>
|
||||
* </parameter>
|
||||
* <parameter><name>mail.smtp.sendpartial</name>
|
||||
* <value>true</value>
|
||||
* </parameter>
|
||||
* <parameter><name>mail.smtp.dsn.notify</name>
|
||||
* <value>FAILURE</value>
|
||||
* </parameter>
|
||||
* <parameter><name>mail.smtp.dsn.ret</name>
|
||||
* <value>FULL</value>
|
||||
* </parameter>
|
||||
* </ResourceParams>
|
||||
* </pre>
|
||||
*
|
||||
* @author Glenn Nielsen Rich Catlett
|
||||
*/
|
||||
|
||||
public class SendMailFactory implements ObjectFactory
|
||||
{
|
||||
// The class name for the javamail MimeMessageDataSource
|
||||
protected static final String DataSourceClassName =
|
||||
"javax.mail.internet.MimePartDataSource";
|
||||
|
||||
@Override
|
||||
public Object getObjectInstance(Object refObj, Name name, Context ctx,
|
||||
Hashtable<?,?> env) throws Exception {
|
||||
final Reference ref = (Reference)refObj;
|
||||
|
||||
// Creation of the DataSource is wrapped inside a doPrivileged
|
||||
// so that javamail can read its default properties without
|
||||
// throwing Security Exceptions
|
||||
if (ref.getClassName().equals(DataSourceClassName)) {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<MimePartDataSource>()
|
||||
{
|
||||
@Override
|
||||
public MimePartDataSource run() {
|
||||
// set up the smtp session that will send the message
|
||||
Properties props = new Properties();
|
||||
// enumeration of all refaddr
|
||||
Enumeration<RefAddr> list = ref.getAll();
|
||||
// current refaddr to be set
|
||||
RefAddr refaddr;
|
||||
// set transport to smtp
|
||||
props.put("mail.transport.protocol", "smtp");
|
||||
|
||||
while (list.hasMoreElements()) {
|
||||
refaddr = list.nextElement();
|
||||
|
||||
// set property
|
||||
props.put(refaddr.getType(), refaddr.getContent());
|
||||
}
|
||||
MimeMessage message = new MimeMessage(
|
||||
Session.getInstance(props));
|
||||
try {
|
||||
RefAddr fromAddr = ref.get("mail.from");
|
||||
String from = null;
|
||||
if (fromAddr != null) {
|
||||
from = (String)ref.get("mail.from").getContent();
|
||||
}
|
||||
if (from != null) {
|
||||
message.setFrom(new InternetAddress(from));
|
||||
}
|
||||
message.setSubject("");
|
||||
} catch (Exception e) {/*Ignore*/}
|
||||
MimePartDataSource mds = new MimePartDataSource(message);
|
||||
return mds;
|
||||
}
|
||||
} );
|
||||
}
|
||||
else { // We can't create an instance of the DataSource
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
47
java/org/apache/naming/factory/TransactionFactory.java
Normal file
47
java/org/apache/naming/factory/TransactionFactory.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory;
|
||||
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.TransactionRef;
|
||||
|
||||
/**
|
||||
* Object factory for User transactions.
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class TransactionFactory extends FactoryBase {
|
||||
|
||||
@Override
|
||||
protected boolean isReferenceTypeSupported(Object obj) {
|
||||
return obj instanceof TransactionRef;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectFactory getDefaultFactory(Reference ref) {
|
||||
// No default factory supported.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getLinked(Reference ref) {
|
||||
// Not supported
|
||||
return null;
|
||||
}
|
||||
}
|
||||
21
java/org/apache/naming/factory/package.html
Normal file
21
java/org/apache/naming/factory/package.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<body>
|
||||
|
||||
<p>This package contains object factories used by the naming service.</p>
|
||||
|
||||
</body>
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
serviceProxy.portNotFound=Port-component-ref [{0}] not found
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
serviceProxy.portNotFound=Kein Port mit dem Namen [{0}] gefunden
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
serviceProxy.portNotFound=Le port-component-ref [{0}] n''a pas été trouvé
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
serviceProxy.portNotFound=port-component-ref [{0}] [{0}]が見つかりません
|
||||
@@ -0,0 +1,16 @@
|
||||
# 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
serviceProxy.portNotFound=Port-component-ref [{0}]을(를) 찾을 수 없습니다.
|
||||
148
java/org/apache/naming/factory/webservices/ServiceProxy.java
Normal file
148
java/org/apache/naming/factory/webservices/ServiceProxy.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory.webservices;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.rmi.Remote;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.rpc.Service;
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.apache.naming.StringManager;
|
||||
|
||||
/**
|
||||
* Object proxy for Web Services.
|
||||
*
|
||||
* @author Fabien Carrion
|
||||
*/
|
||||
public class ServiceProxy implements InvocationHandler {
|
||||
|
||||
private static final StringManager sm = StringManager.getManager(ServiceProxy.class);
|
||||
|
||||
/**
|
||||
* Service object.
|
||||
* used for delegation
|
||||
*/
|
||||
private final Service service;
|
||||
|
||||
/**
|
||||
* changing behavior to method : Service.getPort(QName, Class)
|
||||
*/
|
||||
private static Method portQNameClass = null;
|
||||
|
||||
/**
|
||||
* changing behavior to method : Service.getPort(Class)
|
||||
*/
|
||||
private static Method portClass = null;
|
||||
|
||||
/**
|
||||
* PortComponentRef list
|
||||
*/
|
||||
private Hashtable<String,QName> portComponentRef = null;
|
||||
|
||||
/**
|
||||
* Constructs a new ServiceProxy wrapping given Service instance.
|
||||
* @param service the wrapped Service instance
|
||||
* @throws ServiceException should be never thrown
|
||||
*/
|
||||
public ServiceProxy(Service service) throws ServiceException {
|
||||
this.service = service;
|
||||
try {
|
||||
portQNameClass = Service.class.getDeclaredMethod("getPort", new Class[]{QName.class, Class.class});
|
||||
portClass = Service.class.getDeclaredMethod("getPort", new Class[]{Class.class});
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InvocationHandler#invoke(Object, Method, Object[])
|
||||
*/
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args)
|
||||
throws Throwable {
|
||||
|
||||
if (portQNameClass.equals(method)) {
|
||||
return getProxyPortQNameClass(args);
|
||||
}
|
||||
|
||||
if (portClass.equals(method)) {
|
||||
return getProxyPortClass(args);
|
||||
}
|
||||
|
||||
try {
|
||||
return method.invoke(service, args);
|
||||
} catch (InvocationTargetException ite) {
|
||||
throw ite.getTargetException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args Method call arguments
|
||||
* @return Returns the correct Port
|
||||
* @throws ServiceException if port's QName is an unknown Port (not defined in WSDL).
|
||||
*/
|
||||
private Object getProxyPortQNameClass(Object[] args) throws ServiceException {
|
||||
QName name = (QName) args[0];
|
||||
String nameString = name.getLocalPart();
|
||||
Class<?> serviceendpointClass = (Class<?>) args[1];
|
||||
|
||||
for (@SuppressWarnings("unchecked") Iterator<QName> ports = service.getPorts(); ports.hasNext();) {
|
||||
QName portName = ports.next();
|
||||
String portnameString = portName.getLocalPart();
|
||||
if (portnameString.equals(nameString)) {
|
||||
return service.getPort(name, serviceendpointClass);
|
||||
}
|
||||
}
|
||||
|
||||
// no ports have been found
|
||||
throw new ServiceException(sm.getString("serviceProxy.portNotFound", name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param portComponentRef List
|
||||
*/
|
||||
public void setPortComponentRef(Hashtable<String,QName> portComponentRef) {
|
||||
this.portComponentRef = portComponentRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args Method call arguments
|
||||
* @return Returns the correct Port
|
||||
* @throws ServiceException if port's QName is an unknown Port
|
||||
*/
|
||||
private Remote getProxyPortClass(Object[] args) throws ServiceException {
|
||||
Class<?> serviceendpointClass = (Class<?>) args[0];
|
||||
|
||||
if (this.portComponentRef == null) {
|
||||
return service.getPort(serviceendpointClass);
|
||||
}
|
||||
|
||||
QName portname = this.portComponentRef.get(serviceendpointClass.getName());
|
||||
if (portname != null) {
|
||||
return service.getPort(portname, serviceendpointClass);
|
||||
} else {
|
||||
return service.getPort(serviceendpointClass);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.naming.factory.webservices;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
import javax.wsdl.Definition;
|
||||
import javax.wsdl.Port;
|
||||
import javax.wsdl.extensions.ExtensibilityElement;
|
||||
import javax.wsdl.extensions.soap.SOAPAddress;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.wsdl.xml.WSDLReader;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.rpc.Service;
|
||||
import javax.xml.rpc.ServiceFactory;
|
||||
import javax.xml.rpc.handler.Handler;
|
||||
import javax.xml.rpc.handler.HandlerChain;
|
||||
import javax.xml.rpc.handler.HandlerInfo;
|
||||
import javax.xml.rpc.handler.HandlerRegistry;
|
||||
|
||||
import org.apache.naming.HandlerRef;
|
||||
import org.apache.naming.ServiceRef;
|
||||
|
||||
/**
|
||||
* Object factory for Web Services.
|
||||
*
|
||||
* @author Fabien Carrion
|
||||
*/
|
||||
public class ServiceRefFactory implements ObjectFactory {
|
||||
|
||||
/**
|
||||
* Create a new serviceref instance.
|
||||
*
|
||||
* @param obj The reference object describing the webservice
|
||||
*/
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?,?> environment) throws Exception {
|
||||
|
||||
if (obj instanceof ServiceRef) {
|
||||
ServiceRef ref = (ServiceRef) obj;
|
||||
|
||||
// ClassLoader
|
||||
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
|
||||
if (tcl == null) {
|
||||
tcl = this.getClass().getClassLoader();
|
||||
}
|
||||
ServiceFactory factory = ServiceFactory.newInstance();
|
||||
javax.xml.rpc.Service service = null;
|
||||
|
||||
// Service Interface
|
||||
RefAddr tmp = ref.get(ServiceRef.SERVICE_INTERFACE);
|
||||
String serviceInterface = null;
|
||||
if (tmp != null) {
|
||||
serviceInterface = (String) tmp.getContent();
|
||||
}
|
||||
|
||||
// WSDL
|
||||
tmp = ref.get(ServiceRef.WSDL);
|
||||
String wsdlRefAddr = null;
|
||||
if (tmp != null) {
|
||||
wsdlRefAddr = (String) tmp.getContent();
|
||||
}
|
||||
|
||||
// PortComponent
|
||||
Hashtable<String,QName> portComponentRef = new Hashtable<>();
|
||||
|
||||
// Create QName object
|
||||
QName serviceQname = null;
|
||||
tmp = ref.get(ServiceRef.SERVICE_LOCAL_PART);
|
||||
if (tmp != null) {
|
||||
String serviceLocalPart = (String) tmp.getContent();
|
||||
tmp = ref.get(ServiceRef.SERVICE_NAMESPACE);
|
||||
if (tmp == null) {
|
||||
serviceQname = new QName(serviceLocalPart);
|
||||
} else {
|
||||
String serviceNamespace = (String) tmp.getContent();
|
||||
serviceQname = new QName(serviceNamespace,
|
||||
serviceLocalPart);
|
||||
}
|
||||
}
|
||||
Class<?> serviceInterfaceClass = null;
|
||||
|
||||
// Create service object
|
||||
if (serviceInterface == null) {
|
||||
if (serviceQname == null) {
|
||||
throw new NamingException
|
||||
("Could not create service-ref instance");
|
||||
}
|
||||
try {
|
||||
if (wsdlRefAddr == null) {
|
||||
service = factory.createService( serviceQname );
|
||||
} else {
|
||||
service = factory.createService( new URL(wsdlRefAddr),
|
||||
serviceQname );
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NamingException ex = new NamingException("Could not create service");
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
} else {
|
||||
// Loading service Interface
|
||||
try {
|
||||
serviceInterfaceClass = tcl.loadClass(serviceInterface);
|
||||
} catch(ClassNotFoundException e) {
|
||||
NamingException ex = new NamingException("Could not load service Interface");
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
if (serviceInterfaceClass == null) {
|
||||
throw new NamingException
|
||||
("Could not load service Interface");
|
||||
}
|
||||
try {
|
||||
if (wsdlRefAddr == null) {
|
||||
if (!Service.class.isAssignableFrom(serviceInterfaceClass)) {
|
||||
throw new NamingException("service Interface should extend javax.xml.rpc.Service");
|
||||
}
|
||||
service = factory.loadService( serviceInterfaceClass );
|
||||
} else {
|
||||
service = factory.loadService( new URL(wsdlRefAddr),
|
||||
serviceInterfaceClass,
|
||||
new Properties() );
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NamingException ex = new NamingException("Could not create service");
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
if (service == null) {
|
||||
throw new NamingException
|
||||
("Cannot create service object");
|
||||
}
|
||||
serviceQname = service.getServiceName();
|
||||
serviceInterfaceClass = service.getClass();
|
||||
if (wsdlRefAddr != null) {
|
||||
try {
|
||||
WSDLFactory wsdlfactory = WSDLFactory.newInstance();
|
||||
WSDLReader reader = wsdlfactory.newWSDLReader();
|
||||
reader.setFeature("javax.wsdl.importDocuments", true);
|
||||
Definition def = reader.readWSDL((new URL(wsdlRefAddr)).toExternalForm());
|
||||
|
||||
javax.wsdl.Service wsdlservice = def.getService(serviceQname);
|
||||
@SuppressWarnings("unchecked") // Can't change the API
|
||||
Map<String,?> ports = wsdlservice.getPorts();
|
||||
Method m = serviceInterfaceClass.getMethod("setEndpointAddress",
|
||||
new Class[] { java.lang.String.class, java.lang.String.class });
|
||||
for (String portName : ports.keySet()) {
|
||||
Port port = wsdlservice.getPort(portName);
|
||||
String endpoint = getSOAPLocation(port);
|
||||
m.invoke(service, new Object[]{port.getName(), endpoint});
|
||||
portComponentRef.put(endpoint, new QName(port.getName()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e instanceof InvocationTargetException) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) cause;
|
||||
}
|
||||
if (cause instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) cause;
|
||||
}
|
||||
}
|
||||
NamingException ex = new NamingException("Error while reading Wsdl File");
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
ServiceProxy proxy = new ServiceProxy(service);
|
||||
|
||||
// Use port-component-ref
|
||||
for (int i = 0; i < ref.size(); i++) {
|
||||
if (ServiceRef.SERVICEENDPOINTINTERFACE.equals(ref.get(i).getType())) {
|
||||
String serviceendpoint = "";
|
||||
String portlink = "";
|
||||
serviceendpoint = (String) ref.get(i).getContent();
|
||||
if (ServiceRef.PORTCOMPONENTLINK.equals(ref.get(i + 1).getType())) {
|
||||
i++;
|
||||
portlink = (String) ref.get(i).getContent();
|
||||
}
|
||||
portComponentRef.put(serviceendpoint, new QName(portlink));
|
||||
|
||||
}
|
||||
}
|
||||
proxy.setPortComponentRef(portComponentRef);
|
||||
|
||||
// Instantiate service with proxy class
|
||||
Class<?>[] serviceInterfaces = serviceInterfaceClass.getInterfaces();
|
||||
|
||||
Class<?>[] interfaces = Arrays.copyOf(serviceInterfaces, serviceInterfaces.length + 1);
|
||||
interfaces[interfaces.length - 1] = javax.xml.rpc.Service.class;
|
||||
|
||||
Object proxyInstance = null;
|
||||
try {
|
||||
proxyInstance = Proxy.newProxyInstance(tcl, interfaces, proxy);
|
||||
} catch (IllegalArgumentException e) {
|
||||
proxyInstance = Proxy.newProxyInstance(tcl, serviceInterfaces, proxy);
|
||||
}
|
||||
|
||||
// Use handler
|
||||
if (ref.getHandlersSize() > 0) {
|
||||
|
||||
HandlerRegistry handlerRegistry = service.getHandlerRegistry();
|
||||
List<String> soaproles = new ArrayList<>();
|
||||
|
||||
while (ref.getHandlersSize() > 0) {
|
||||
HandlerRef handlerRef = ref.getHandler();
|
||||
HandlerInfo handlerInfo = new HandlerInfo();
|
||||
|
||||
// Loading handler Class
|
||||
tmp = handlerRef.get(HandlerRef.HANDLER_CLASS);
|
||||
if ((tmp == null) || (tmp.getContent() == null)) {
|
||||
break;
|
||||
}
|
||||
Class<?> handlerClass = null;
|
||||
try {
|
||||
handlerClass = tcl.loadClass((String) tmp.getContent());
|
||||
} catch(ClassNotFoundException e) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Load all datas relative to the handler : SOAPHeaders, config init element,
|
||||
// portNames to be set on
|
||||
List<QName> headers = new ArrayList<>();
|
||||
Hashtable<String,String> config = new Hashtable<>();
|
||||
List<String> portNames = new ArrayList<>();
|
||||
for (int i = 0; i < handlerRef.size(); i++) {
|
||||
if (HandlerRef.HANDLER_LOCALPART.equals(handlerRef.get(i).getType())) {
|
||||
String localpart = "";
|
||||
String namespace = "";
|
||||
localpart = (String) handlerRef.get(i).getContent();
|
||||
if (HandlerRef.HANDLER_NAMESPACE.equals(handlerRef.get(i + 1).getType())) {
|
||||
i++;
|
||||
namespace = (String) handlerRef.get(i).getContent();
|
||||
}
|
||||
QName header = new QName(namespace, localpart);
|
||||
headers.add(header);
|
||||
} else if (HandlerRef.HANDLER_PARAMNAME.equals(handlerRef.get(i).getType())) {
|
||||
String paramName = "";
|
||||
String paramValue = "";
|
||||
paramName = (String) handlerRef.get(i).getContent();
|
||||
if (HandlerRef.HANDLER_PARAMVALUE.equals(handlerRef.get(i + 1).getType())) {
|
||||
i++;
|
||||
paramValue = (String) handlerRef.get(i).getContent();
|
||||
}
|
||||
config.put(paramName, paramValue);
|
||||
} else if (HandlerRef.HANDLER_SOAPROLE.equals(handlerRef.get(i).getType())) {
|
||||
String soaprole = "";
|
||||
soaprole = (String) handlerRef.get(i).getContent();
|
||||
soaproles.add(soaprole);
|
||||
} else if (HandlerRef.HANDLER_PORTNAME.equals(handlerRef.get(i).getType())) {
|
||||
String portName = "";
|
||||
portName = (String) handlerRef.get(i).getContent();
|
||||
portNames.add(portName);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the handlers informations
|
||||
handlerInfo.setHandlerClass(handlerClass);
|
||||
handlerInfo.setHeaders(headers.toArray(new QName[headers.size()]));
|
||||
handlerInfo.setHandlerConfig(config);
|
||||
|
||||
if (!portNames.isEmpty()) {
|
||||
for (String portName : portNames) {
|
||||
initHandlerChain(new QName(portName), handlerRegistry,
|
||||
handlerInfo, soaproles);
|
||||
}
|
||||
} else {
|
||||
Enumeration<QName> e = portComponentRef.elements();
|
||||
while(e.hasMoreElements()) {
|
||||
initHandlerChain(e.nextElement(), handlerRegistry, handlerInfo, soaproles);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return proxyInstance;
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param port analyzed port
|
||||
* @return Returns the endpoint URL of the given Port
|
||||
*/
|
||||
private String getSOAPLocation(Port port) {
|
||||
String endpoint = null;
|
||||
@SuppressWarnings("unchecked") // Can't change the API
|
||||
List<ExtensibilityElement> extensions = port.getExtensibilityElements();
|
||||
for (ExtensibilityElement ext : extensions) {
|
||||
if (ext instanceof SOAPAddress) {
|
||||
SOAPAddress addr = (SOAPAddress) ext;
|
||||
endpoint = addr.getLocationURI();
|
||||
}
|
||||
}
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
|
||||
private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry,
|
||||
HandlerInfo handlerInfo, List<String> soaprolesToAdd) {
|
||||
HandlerChain handlerChain = (HandlerChain) handlerRegistry.getHandlerChain(portName);
|
||||
@SuppressWarnings("unchecked") // Can't change the API
|
||||
Iterator<Handler> iter = handlerChain.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Handler handler = iter.next();
|
||||
handler.init(handlerInfo);
|
||||
}
|
||||
String[] soaprolesRegistered = handlerChain.getRoles();
|
||||
String [] soaproles = new String[soaprolesRegistered.length + soaprolesToAdd.size()];
|
||||
int i;
|
||||
for (i = 0;i < soaprolesRegistered.length; i++) {
|
||||
soaproles[i] = soaprolesRegistered[i];
|
||||
}
|
||||
for (int j = 0; j < soaprolesToAdd.size(); j++) {
|
||||
soaproles[i+j] = soaprolesToAdd.get(j);
|
||||
}
|
||||
handlerChain.setRoles(soaproles);
|
||||
handlerRegistry.setHandlerChain(portName, handlerChain);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
122
java/org/apache/naming/java/javaURLContextFactory.java
Normal file
122
java/org/apache/naming/java/javaURLContextFactory.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.naming.java;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.spi.InitialContextFactory;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.apache.naming.ContextBindings;
|
||||
import org.apache.naming.NamingContext;
|
||||
import org.apache.naming.SelectorContext;
|
||||
|
||||
/**
|
||||
* Context factory for the "java:" namespace.
|
||||
* <p>
|
||||
* <b>Important note</b> : This factory MUST be associated with the "java" URL
|
||||
* prefix, which can be done by either :
|
||||
* <ul>
|
||||
* <li>Adding a
|
||||
* java.naming.factory.url.pkgs=org.apache.naming property
|
||||
* to the JNDI properties file</li>
|
||||
* <li>Setting an environment variable named Context.URL_PKG_PREFIXES with
|
||||
* its value including the org.apache.naming package name.
|
||||
* More detail about this can be found in the JNDI documentation :
|
||||
* {@link javax.naming.spi.NamingManager#getURLContext(java.lang.String, java.util.Hashtable)}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Remy Maucherat
|
||||
*/
|
||||
public class javaURLContextFactory
|
||||
implements ObjectFactory, InitialContextFactory {
|
||||
|
||||
|
||||
// ----------------------------------------------------------- Constructors
|
||||
|
||||
|
||||
// -------------------------------------------------------------- Constants
|
||||
|
||||
|
||||
public static final String MAIN = "initialContext";
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
|
||||
/**
|
||||
* Initial context.
|
||||
*/
|
||||
protected static volatile Context initialContext = null;
|
||||
|
||||
|
||||
// --------------------------------------------------------- Public Methods
|
||||
|
||||
|
||||
// -------------------------------------------------- ObjectFactory Methods
|
||||
|
||||
|
||||
/**
|
||||
* Crete a new Context's instance.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object getObjectInstance(Object obj, Name name, Context nameCtx,
|
||||
Hashtable<?,?> environment)
|
||||
throws NamingException {
|
||||
if ((ContextBindings.isThreadBound()) ||
|
||||
(ContextBindings.isClassLoaderBound())) {
|
||||
return new SelectorContext((Hashtable<String,Object>)environment);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a new (writable) initial context.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Context getInitialContext(Hashtable<?,?> environment)
|
||||
throws NamingException {
|
||||
if (ContextBindings.isThreadBound() ||
|
||||
(ContextBindings.isClassLoaderBound())) {
|
||||
// Redirect the request to the bound initial context
|
||||
return new SelectorContext(
|
||||
(Hashtable<String,Object>)environment, true);
|
||||
}
|
||||
|
||||
// If the thread is not bound, return a shared writable context
|
||||
if (initialContext == null) {
|
||||
synchronized(javaURLContextFactory.class) {
|
||||
if (initialContext == null) {
|
||||
initialContext = new NamingContext(
|
||||
(Hashtable<String,Object>)environment, MAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
return initialContext;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
21
java/org/apache/naming/java/package.html
Normal file
21
java/org/apache/naming/java/package.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<body>
|
||||
|
||||
<p>This package contains the URL context factory for the "java" namespace.</p>
|
||||
|
||||
</body>
|
||||
21
java/org/apache/naming/package.html
Normal file
21
java/org/apache/naming/package.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
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 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<body>
|
||||
|
||||
<p>This package contains a memory based naming service provider.</p>
|
||||
|
||||
</body>
|
||||
Reference in New Issue
Block a user