Author: kentam Date: Thu Dec 2 17:14:20 2004 New Revision: 109614 URL: http://svn.apache.org/viewcvs?view=rev&rev=109614 Log: Additional thread-safety work on control operations; simplified the timing for binding of the control implementation class.
Fixed WSM-related tests in controls DRT. Adding some infrastructure for supporting JavaBean services that use JNDI -- contributed by Brett Bennett. Added: incubator/beehive/trunk/controls/src/spi/ incubator/beehive/trunk/controls/src/spi/org/ incubator/beehive/trunk/controls/src/spi/org/apache/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/JndiService.java (contents, props changed) incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/ServiceException.java (contents, props changed) incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/BaseJndiService.java (contents, props changed) incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/DefaultJndiService.java (contents, props changed) incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/JndiBasedService.java (contents, props changed) Modified: incubator/beehive/trunk/controls/build.xml incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd Modified: incubator/beehive/trunk/controls/build.xml Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/build.xml?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/build.xml&r1=109613&p2=incubator/beehive/trunk/controls/build.xml&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/build.xml (original) +++ incubator/beehive/trunk/controls/build.xml Thu Dec 2 17:14:20 2004 @@ -28,11 +28,15 @@ <property name="docs.dir" value="${build.dir}/docs"/> <property name="api.dir" value="src/api"/> <property name="api.classes" value="${classes.dir}/api"/> + <property name="spi.dir" value="src/spi"/> + <property name="spi.classes" value="${classes.dir}/spi"/> <property name="runtime.dir" value="src/runtime"/> <property name="runtime.classes" value="${classes.dir}/runtime"/> <property name="controls.jar" value="${jars.dir}/controls.jar"/> <path id="api.classpath"> - </path> + </path> + <path id="spi.classpath"> + </path> <path id="runtime.classpath"> <pathelement location="${ant.jar}"/> <pathelement location="${servlet24.jar}"/> @@ -40,6 +44,7 @@ <pathelement location="${velocity14.jar}"/> <pathelement location="${velocitydep14.jar}"/> <pathelement location="${api.classes}"/> + <pathelement location="${spi.classes}"/> <path id="${api.classpath}"/> </path> <condition property="controls.os" value="windows"> @@ -85,6 +90,7 @@ <!-- ==================================================================== --> <target name="dirs"> <mkdir dir="${api.classes}"/> + <mkdir dir="${spi.classes}"/> <mkdir dir="${runtime.classes}"/> <mkdir dir="${jars.dir}"/> <mkdir dir="${docs.dir}"/> @@ -97,6 +103,10 @@ <javac destdir="${api.classes}" classpathref="api.classpath" debug="on"> <src path="${api.dir}"/> </javac> + <!-- Build the SPI classes --> + <javac destdir="${spi.classes}" classpathref="spi.classpath" debug="on"> + <src path="${spi.dir}"/> + </javac> <!-- Build the runtime classes --> <javac destdir="${runtime.classes}" classpathref="runtime.classpath" debug="on"> <src path="${runtime.dir}"/> @@ -119,6 +129,7 @@ <echo message="--------------------------------------------------"/> <jar jarfile="${controls.jar}"> <fileset dir="${api.classes}"/> + <fileset dir="${spi.classes}"/> <fileset dir="${runtime.classes}"/> </jar> <echo message="--------------------------------------------------"/> Modified: incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java&r1=109613&p2=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java (original) +++ incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java Thu Dec 2 17:14:20 2004 @@ -61,6 +61,12 @@ public Class getControlInterface(); /** + * Returns the binding from a control interface to a control implementation for the + * current container context. + */ + public Class getControlBinding(Class controlIntf); + + /** * Returns the current value of PropertySet for the associated control, or * null if the property set has not been bound. Actual bindings for property * values may be the result of annotations on the control field or class, Modified: incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java&r1=109613&p2=incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java (original) +++ incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlContainerContext.java Thu Dec 2 17:14:20 2004 @@ -44,7 +44,7 @@ * Returns the binding from a control interface to a control implementation for the * current container context. */ - public Class getControlBinding(Class controlClass); + public Class getControlBinding(Class controlIntf); /** * Returns a ControlHandle to the component containing the control. This handle can be Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java&r1=109613&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java Thu Dec 2 17:14:20 2004 @@ -62,17 +62,17 @@ * associate with an active context at runtime (via thread-locals). * @param id * @param initProperties - * @param controlClass + * @param controlIntf */ protected ControlBean(org.apache.beehive.controls.api.context.ControlBeanContext context, - String id, PropertyMap initProperties, Class controlClass) + String id, PropertyMap initProperties, Class controlIntf) { super(); _localID = id; _id = _localID; - _controlClass = controlClass; - + _controlIntf = controlIntf; + // // If no containing context was specified during construction, see if there is a current // active container context and implicitly associated the control with it. @@ -81,7 +81,24 @@ context = ControlThreadContext.getContext(); // - // Associate the constructed bean w/ a context (if any). Beans may run without a context! + // If we've got a context, use it to bind to an implementation of the control, else use default binding. + // + if (context != null) + _implClass = context.getControlBinding(_controlIntf); + else + _implClass = ControlBeanContext.getDefaultControlBinding(_controlIntf); + + // + // Cache the threading policy associated with the impl + // + Threading thr = (Threading)_implClass.getAnnotation(Threading.class); + if ( thr != null ) + _threadingPolicy = thr.value(); + + // + // Associate this bean with the context. Beans may run without a context! + // Note that the add() call has the side-effect of calling ControlBean.setBeanContext(), which does + // additional setup work! // if (context != null) context.add(this); @@ -90,7 +107,7 @@ // Get the default map for the control class. This contains the default property // values for all beans of the class. // - PropertyMap classMap = getAnnotationMap(controlClass); + PropertyMap classMap = getAnnotationMap(controlIntf); if (initProperties != null) { // @@ -110,7 +127,7 @@ // map, and then create a wrapper map around it for storing per instance // properties. // - if (annotElem != controlClass) + if (annotElem != controlIntf) initProperties.setDelegateMap(classMap); _properties = new BeanPropertyMap(initProperties); } @@ -150,9 +167,14 @@ } /** - * Called by the BeanContextProxy whenever the context associated with this control bean is + * Called by the BeanContextProxy (_cbc) whenever the _parent_ context containing this control bean is * changed. This is the place to do any initialization (or reinitialization) that is dependent - * upon attributes of the container for the ControlBean + * upon attributes of the container for the ControlBean. + * + * Note: this is called in the ControlBean ctor, when a parent context calls add() on the nascent + * bean. + * + * @param bc the new parent context containing this control bean (not _cbc) */ final public synchronized void setBeanContext(BeanContext bc) { @@ -180,16 +202,15 @@ */ final public Class getControlInterface() { - return _controlClass; + return _controlIntf; } /** * This method will return true if the external container for this control * guarantees single-threaded behavior. For example, the EJB container does - * provide this guarantee, the servlet container does not. This implementation is - * thread-safe even though it is not synchronized. + * provide this guarantee, the servlet container does not. */ - /* package */ boolean hasSingleThreadedContainer() + /* package */ synchronized boolean hasSingleThreadedContainer() { BeanContext bc = getBeanContext(); if (bc instanceof ControlBeanContext) @@ -203,7 +224,7 @@ * Returns true if the implementation class for this ControlBean can be assumed to * be thread-safe. */ - private synchronized boolean hasSingleThreadedImpl() + private boolean hasSingleThreadedImpl() { return _threadingPolicy == ThreadingPolicy.SINGLE_THREADED; } @@ -211,10 +232,8 @@ /** * Returns true if the ControlBean instance is running in an environment that * guarantees single-threaded behaviour, false otherwise. - * - * Thread-safe even thought not synchronized. */ - public boolean isSingleThreadedBean() + public synchronized boolean isSingleThreadedBean() { // // If the thread safe marker interface isn't found on the implementation, then @@ -238,10 +257,8 @@ { try { - ControlBeanContext context = getBeanContextProxy(); - Class implClass = context.getControlBinding(_controlClass); - Class initClass = implClass.getClassLoader().loadClass( - implClass.getName() + "Initializer"); + Class initClass = _implClass.getClassLoader().loadClass( + _implClass.getName() + "Initializer"); _implInitializer = (ImplInitializer)initClass.newInstance(); } catch (Exception e) @@ -261,30 +278,14 @@ */ protected synchronized Object ensureControl() { - Class implClass = null; - if (_control == null) { try { // - // Query the current context for the binding between public interface and - // an associated implementation. - // - ControlBeanContext context = getBeanContextProxy(); - implClass = context.getControlBinding(_controlClass); - - // - // Read the threading policy associated with the impl - // - Threading thr = (Threading)implClass.getAnnotation(Threading.class); - if ( thr != null ) - _threadingPolicy = thr.value(); - - // // Create and initialize the new instance // - _control = implClass.newInstance(); + _control = _implClass.newInstance(); try { @@ -320,14 +321,6 @@ _hasServices = true; } - // - // If the implementation class requires a guarantee of single-threaded behavior and the - // outer container does not guarantee it, then enable invocation locking on this - // bean instance. - // - if (hasSingleThreadedImpl() && !hasSingleThreadedContainer()) - _invokeLock = new Semaphore(1, true); - return _control; } @@ -682,12 +675,17 @@ /* * The following fields must be: - * 1) only written in synchronized methods + * 1) only written in synchronized methods or (unsynchronized) constructors * 2) only read in synchronized methods or methods that are safe wrt the values changing during * execution. */ /** + * The control implementation class bound to this ControlBean + */ + private Class _implClass; + + /** * The control implementation instance wrapped by this ControlBean */ private Object _control; @@ -737,7 +735,7 @@ /** * The public control interface associated with this ControlBean */ - private Class _controlClass; + private Class _controlIntf; /** * Contains the per-instance properties set for this ControlBean. Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java&r1=109613&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java Thu Dec 2 17:14:20 2004 @@ -68,11 +68,6 @@ protected ControlBeanContext(ControlBean bean) { _bean = bean; - - // If _bean is non-null, this ControlBeanContext is defined by a ControlBean. - // If that ControlBean is single-threaded, it implies this context acts as a single-threaded container. - if ( _bean != null ) - _isSingleThreadedContainer = _bean.isSingleThreadedBean(); } /** @@ -155,7 +150,7 @@ * additional processing that needs to occur when the control is associated with a new * nesting context. */ - public void setBeanContext(BeanContext beanContext) throws PropertyVetoException + public synchronized void setBeanContext(BeanContext beanContext) throws PropertyVetoException { ControlBeanContext cbcs = null; @@ -179,16 +174,25 @@ super.setBeanContext(beanContext); + if (_bean != null) { String id = _bean.getLocalID(); // - // Notify the bean that its context (container) has been set + // Notify the bean that its context (container) has been set. // _bean.setBeanContext(beanContext); // + // The parent context relationship has been established (by the super.setBeanContext() call above). + // The bean can now answer the question of whether it's single threaded (it needs to be able to query + // the parent context to determine that), which means this context can now determine whether _it's_ + // single threaded. + // + _isSingleThreadedContainer = _bean.isSingleThreadedBean(); + + // // Establish a new value for the absolute control ID based upon the nesting context // and parent bean (if any). // @@ -353,10 +357,10 @@ * Returns true if this container associated with this context service enforces * single-threaded invocation, false otherwise. * - * This should be overridden by container-specific subclasses that guarantee - * single-threaded behavior (such as the EJB container) to return true. + * This MUST be overridden by container-specific subclasses. If they guarantee + * single-threaded behavior (such as the EJB container), they should return true. */ - public boolean isSingleThreadedContainer() + public synchronized boolean isSingleThreadedContainer() { return _isSingleThreadedContainer; } @@ -445,51 +449,52 @@ * Returns the control implementation class that is bound to (implements) the * public or extension interface in the current context. */ - public Class getControlBinding(Class controlClass) + public Class getControlBinding(Class controlIntf) { // - // Delegate up until a ControlContainerContext is found to manage the binding. + // Delegate up until a container-specific subclass of ControlBeanContext + // (ControlContainerContext?) is found to manage the binding. // ControlBeanContext cbc = (ControlBeanContext)getBeanContext(); if (cbc != null) - return cbc.getControlBinding(controlClass); + return cbc.getControlBinding(controlIntf); // No parent context exists, just return default binding - return getDefaultControlBinding(controlClass); + return getDefaultControlBinding(controlIntf); } /** * Returns the default binding based entirely upon annotations or naming conventions. */ - static protected Class getDefaultControlBinding(Class controlClass) + static public Class getDefaultControlBinding(Class controlIntf) { - while (controlClass.isAnnotationPresent(ControlExtension.class)) + while (controlIntf.isAnnotationPresent(ControlExtension.class)) { - Class [] intfs = controlClass.getInterfaces(); + Class [] intfs = controlIntf.getInterfaces(); boolean found = false; for (int i = 0; i < intfs.length; i++) { if (intfs[i].isAnnotationPresent(ControlExtension.class) || intfs[i].isAnnotationPresent(ControlInterface.class)) { - controlClass = intfs[i]; + controlIntf = intfs[i]; found = true; break; } } if (!found) { - throw new ControlException("Can't find base control interface for " + controlClass); + throw new ControlException("Can't find base control interface for " + controlIntf); } } ControlInterface intfAnnot = - (ControlInterface)controlClass.getAnnotation(ControlInterface.class); + (ControlInterface)controlIntf.getAnnotation(ControlInterface.class); String implBinding = intfAnnot.defaultBinding(); - implBinding = resolveDefaultBinding( implBinding, controlClass.getName() ); + implBinding = resolveDefaultBinding( implBinding, controlIntf.getName() ); try { - return controlClass.getClassLoader().loadClass(implBinding); + return controlIntf.getClassLoader().loadClass(implBinding); } catch (ClassNotFoundException cnfe) { @@ -724,8 +729,8 @@ /** * Indicates whether this context acts as a single-threaded container (for ControlBeans nested - * by the ControlBean that scopes this context, i.e. _bean). This is fixed at construction time - * of the context, and defaults to false for safety. + * by the ControlBean that scopes this context, i.e. _bean). This is dependent on the parent context, + * so may be changed during setBeanContext(). It defaults to false for safety. */ private boolean _isSingleThreadedContainer = false; Modified: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java&r1=109613&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java (original) +++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java Thu Dec 2 17:14:20 2004 @@ -179,6 +179,16 @@ return getDefaultControlBinding(controlClass); } + /** + * Returns true if this container guarantees single-threaded behaviour. By default, top-level + * containers are assumed to NOT guarantee this; specific container implementations (for example, + * for EJB containers) should override this appropriately. + */ + public boolean isSingleThreadedContainer() + { + return false; + } + boolean _releasingAll; Stack<ResourceContext> _resourceContexts = new Stack<ResourceContext>(); } Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/JndiService.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/JndiService.java?view=auto&rev=109614 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/JndiService.java Thu Dec 2 17:14:20 2004 @@ -0,0 +1,34 @@ +package org.apache.beehive.controls.spi.svc; + +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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. + * + * $Header:$ + */ + +/** + * The Jndi Service protocol + */ +public interface JndiService +{ + /** + * Get a jndi-based resource. + * @param resource the resource name. + * @param resourceClass the resource class. + * @return the resource object. + * @throws ServiceException + */ + public Object getResource(String resource,Class resourceClass) throws ServiceException; +} Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/ServiceException.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/ServiceException.java?view=auto&rev=109614 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/ServiceException.java Thu Dec 2 17:14:20 2004 @@ -0,0 +1,52 @@ +package org.apache.beehive.controls.spi.svc; + +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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. + * + * $Header:$ + */ + +/** + * The ServiceException class declares an checked exception that is thrown by the Service API + * runtime under certain failure conditions. + */ +public class ServiceException extends Exception +{ + /** + * Constructs a ServiceException object with the specified String as a message. + * + * @param message The message to use. + */ + public ServiceException(String message) + { + super(message); + } + + /** + * Constructs a ServiceException object using the specified String as a message, and the + * specified Throwable as a nested exception. + * + * @param message The message to use. + * @param t The exception to nest within this + * exception. + */ + public ServiceException(String message, Throwable t) + { + super(message + "[" + t.getMessage() + "]", t); + } + + /* Private Constant(s) */ + private static final long serialVersionUID = 8818197331269164527L; +} Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/BaseJndiService.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/BaseJndiService.java?view=auto&rev=109614 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/BaseJndiService.java Thu Dec 2 17:14:20 2004 @@ -0,0 +1,87 @@ +package org.apache.beehive.controls.spi.svc.impl; + +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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. + * + * $Header:$ + */ + +import java.util.Hashtable; + +import javax.naming.InitialContext; +import javax.naming.NamingException; + +import org.apache.beehive.controls.spi.svc.JndiService; +import org.apache.beehive.controls.spi.svc.ServiceException; + +/** + * The base Jndi Service. Implements the getResource method using + * a polymorphic getInitialContext() method. + */ +public class BaseJndiService implements JndiService +{ + /* Public Method(s) */ + + /** + * @see com.apache.beehive.controls.api.svc.getResource() + */ + public Object getResource(String resource,Class resourceClass) throws ServiceException + { + InitialContext cntxt = getInitialContext(); + try + { + Object obj = cntxt.lookup(resource); + if(resourceClass != null && !(resourceClass.isInstance(obj))) + { + throw new ServiceException("JNDI resource '"+resource+"' is not an instance of '"+resourceClass.getName()+"'"); + } + return obj; + } + catch(NamingException e) + { + throw new ServiceException("Cannot load JNDI resource '"+resource+"'"); + } + } + /* Protected Method(s) */ + /** + * Get the initial context. + * @return the initial context. + */ + protected InitialContext getInitialContext() + throws ServiceException + { + return getInitialContext(null); + + } + /** + * Get the initial context using the given environment. + * @param env an JNDI environment. + * @return an initial context. + * @throws ServiceException + */ + protected InitialContext getInitialContext(Hashtable<String,String> env) + throws ServiceException + { + try + { + return new InitialContext(env); + } + catch(NamingException e) + { + throw new ServiceException("Cannot get initial context",e); + } + } + +} Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/DefaultJndiService.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/DefaultJndiService.java?view=auto&rev=109614 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/DefaultJndiService.java Thu Dec 2 17:14:20 2004 @@ -0,0 +1,101 @@ +package org.apache.beehive.controls.spi.svc.impl; + +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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. + * + * $Header:$ + */ + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import org.apache.beehive.controls.spi.svc.ServiceException; + +/** + * The default Jndi Service. Returns a default initial context + * unless the provider-url and the jndi-factory properties are set. + */ +public class DefaultJndiService extends BaseJndiService +{ + /* Public Method(s) */ + + /** + * Set the provider-url. + * @param url the url. + */ + public void setUrl(String url) + { + _url = url; + } + + /** + * get the provider-url. + * @return the url. + */ + public String getUrl() + { + return _url; + } + + /** + * Set the jndi-factory. + * @param factory the factory class. + */ + public void setFactory(String factory) + { + _factory = factory; + } + + /** + * Get the jndi-factory. + * @return the factory class. + */ + public String getFactory() + { + return _factory; + } + + /** + * Get the initial context. + * @return the initial context. + */ + protected InitialContext getInitialContext() + throws ServiceException + { + if(_url == null && _factory == null) + { + return super.getInitialContext(); + + } + if(_url == null || _factory == null) + { + throw new ServiceException("Both the provider-url and jndi factory need to be provided"); + + } + Hashtable<String,String> env = new Hashtable<String,String>(); + env.put(Context.INITIAL_CONTEXT_FACTORY, _factory); + env.put(Context.PROVIDER_URL,_url); + return getInitialContext(env); + } + + /* Private Field(s) */ + + /** The provider-url */ + private String _url; + /** The jndi-factory */ + private String _factory; +} Added: incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/JndiBasedService.java Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/JndiBasedService.java?view=auto&rev=109614 ============================================================================== --- (empty file) +++ incubator/beehive/trunk/controls/src/spi/org/apache/beehive/controls/spi/svc/impl/JndiBasedService.java Thu Dec 2 17:14:20 2004 @@ -0,0 +1,128 @@ +package org.apache.beehive.controls.spi.svc.impl; + +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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. + * + * $Header:$ + */ + +import java.beans.beancontext.BeanContextChildSupport; +import java.beans.beancontext.BeanContextServices; +import java.util.TooManyListenersException; + +import javax.naming.NamingException; + +import org.apache.beehive.controls.spi.svc.JndiService; +import org.apache.beehive.controls.spi.svc.ServiceException; + + +/** + * Common base class for services that utilize jndi to obtain a resource. + * Allows for run-time checking of the resource class and resource + * name definition with defaulting. + */ +abstract public class JndiBasedService extends BeanContextChildSupport +{ + /* Protected Constructor(s) */ + + /** + * Support serialization. + */ + protected JndiBasedService() + { + + } + + /** + * Construct a jndi-based-service with the given default and class. + * @param resource The default resource name. + * @param resourceClass The default resource class. + */ + protected JndiBasedService(String resource, Class resourceClass) + { + setResource(resource); + _resourceClass = resourceClass; + } + + /* Public Method(s) */ + + /** + * Set the resource name. + * @param resource a jndi name. + */ + public void setResource(String resource) + { + _resource = resource; + } + + /** + * Get the resource name. + * @return a jndi name. + */ + public String getResource() + { + return _resource; + } + + /* Protected Method(s) */ + + /** + * Get the jndi-service. + * @return an instance of the service object. + */ + protected JndiService getJndiService() throws ServiceException + { + if(_jndiService == null) + { + try + { + BeanContextServices cntxt = (BeanContextServices)getBeanContext(); + _jndiService = (JndiService)cntxt.getService(this,this,JndiService.class,this,this); + } + catch(TooManyListenersException e) + { + throw new ServiceException(e.getMessage()); + } + if(_jndiService == null) + { + throw new ServiceException("Cannot obtain JNDI service"); + } + } + return _jndiService; + } + + /** + * Get the jndi-based resource. + * @return the resource object. + * @throws ControlException + * @throws NamingException + */ + protected Object getJndiResource() throws ServiceException + { + return getJndiService().getResource(_resource,_resourceClass); + + } + + /* Private Constant(s) */ + private static final long serialVersionUID = -2058335290089535943L; + + /* Private Field(s) */ + /** The JNDI service used by this service. */ + private transient JndiService _jndiService; + /** The resource name. */ + private String _resource; + /** The resource class. */ + private Class _resourceClass; +} Modified: incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd?view=diff&rev=109614&p1=incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd&r1=109613&p2=incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd&r2=109614 ============================================================================== --- incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd (original) +++ incubator/beehive/trunk/controls/test/webapps/controlsWeb/WEB-INF/server-config.wsdd Thu Dec 2 17:14:20 2004 @@ -11,9 +11,6 @@ <handler type="java:org.apache.beehive.wsm.axis.AnnotatedWebServiceDeploymentHandler"> <parameter name="scope" value="session"/> </handler> - <handler type="java:org.apache.beehive.wsm.axis.DropInDeploymentHandler"> - <parameter name="scope" value="session"/> - </handler> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="session"/> </handler>
