You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrf-commits@ws.apache.org by sc...@apache.org on 2005/10/20 19:51:37 UTC
svn commit: r326958 [3/9] - in /webservices/wsrf/trunk/src:
examples/filesystem/
examples/filesystem/src/java/org/apache/ws/resource/example/filesystem/
java/org/apache/ws/addressing/ java/org/apache/ws/addressing/handler/
java/org/apache/ws/addressing...
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/i18n/Keys.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/i18n/Keys.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/i18n/Keys.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/i18n/Keys.java Thu Oct 20 10:50:00 2005
@@ -172,10 +172,10 @@
*/
String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR";
- /**
- * @msg An unexpected error occured during processing of a request.
- */
- String UNEXPECTED_ERROR = "UNEXPECTED_ERROR";
+ /**
+ * @msg An unexpected error occured during processing of a request.
+ */
+ String UNEXPECTED_ERROR = "UNEXPECTED_ERROR";
/**
* @msg Handling response...
@@ -677,20 +677,20 @@
*/
String NO_WSA_ACTION = "NO_WSA_ACTION";
- /**
- * @msg Received request with WS-Addressing Action ({0}) that is not a valid URI.
- */
- String INVALID_WSA_ACTION = "INVALID_WSA_ACTION";
+ /**
+ * @msg Received request with WS-Addressing Action ({0}) that is not a valid URI.
+ */
+ String INVALID_WSA_ACTION = "INVALID_WSA_ACTION";
/**
* @msg Received request with no WS-Addressing To header.
*/
String NO_WSA_TO = "NO_WSA_TO";
- /**
- * @msg Received request with WS-Addressing To ({0}) that is not a valid URI.
- */
- String INVALID_WSA_TO = "INVALID_WSA_TO";
+ /**
+ * @msg Received request with WS-Addressing To ({0}) that is not a valid URI.
+ */
+ String INVALID_WSA_TO = "INVALID_WSA_TO";
/**
* @msg Received request with no WS-Addressing headers.
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java Thu Oct 20 10:50:00 2005
@@ -15,29 +15,15 @@
*=============================================================================*/
package org.apache.ws.resource.impl;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.xml.namespace.QName;
-import javax.xml.rpc.JAXRPCException;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPHeaderElement;
-
+import commonj.timers.Timer;
+import commonj.timers.TimerManager;
import org.apache.commons.collections.map.ReferenceMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.Soap1_1Constants;
import org.apache.ws.addressing.EndpointReference;
import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.metadata.MetadataConfiguration;
import org.apache.ws.resource.IllegalResourceTypeException;
import org.apache.ws.resource.JndiConstants;
import org.apache.ws.resource.PersistentResource;
@@ -62,7 +48,6 @@
import org.apache.ws.util.i18n.Messages;
import org.apache.ws.util.jndi.Initializable;
import org.apache.ws.util.jndi.XmlBeanJndiUtils;
-import org.apache.ws.util.jndi.tools.MetadataConfigImpl;
import org.apache.ws.util.lock.Lock;
import org.apache.ws.util.lock.LockManager;
import org.apache.ws.util.platform.JaxRpcPlatform;
@@ -70,9 +55,21 @@
import org.apache.xmlbeans.XmlObject;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ListableBeanFactory;
-
-import commonj.timers.Timer;
-import commonj.timers.TimerManager;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.xml.namespace.QName;
+import javax.xml.rpc.JAXRPCException;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
/**
* TODO: Update these Javadocs
@@ -119,937 +116,981 @@
* @author Globus, Ian Springer
*/
public abstract class AbstractResourceHome
- implements ResourceHome,
- Initializable, Serializable
+ implements ResourceHome,
+ Initializable,
+ Serializable
{
+ private static final Log LOG = LogFactory.getLog( AbstractResourceHome.class );
+ private static final Messages MSG = MessagesImpl.getInstance( );
+ private static final int DEFAULT_SWEEPER_DELAY = 60000;
- private static final Log LOG = LogFactory.getLog( AbstractResourceHome.class );
- private static final Messages MSG = MessagesImpl.getInstance();
-
- private static final int DEFAULT_SWEEPER_DELAY = 60000;
- /*
+ /*
* A static key used only for registering Singleton Resources
*/
- private static final Object SINGLETON_KEY = new Object();
+ private static final Object SINGLETON_KEY = new Object( );
+ private static final String CONTEXT_NAME_J2EE_TIMER_MANAGER = "java:comp/env/tm/TimerManager";
- /**
- * DOCUMENT_ME
- */
- protected Map m_resources;
-
- /**
- * DOCUMENT_ME
- */
- protected boolean m_resourceIsPersistent;
- private QName m_resourceIdRefParamName;
- private String m_wsdlTargetNamespace;
-
-
- /**
- * DOCUMENT_ME
- */
- protected LockManager m_lockManager;
- private String m_cacheLocation;
- private Cache m_cache;
- private long m_sweeperDelay = DEFAULT_SWEEPER_DELAY;
- private Sweeper m_sweeper;
- private boolean m_initialized;
- private List m_creationListeners = new ArrayList();
- private List m_destructionListeners = new ArrayList();
- private Class m_resourceClass;
- private Class m_serviceClass;
- private String m_portComponentName;
- private MetadataConfigImpl m_metadataConfig;
- private static final String CONTEXT_NAME_J2EE_TIMER_MANAGER = "java:comp/env/tm/TimerManager";
-
- /**
- * DOCUMENT_ME
- *
- * @param jndiLocation DOCUMENT_ME
- */
- public void setCacheLocation( String jndiLocation )
- {
- m_cacheLocation = jndiLocation;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String getCacheLocation()
- {
- return m_cacheLocation;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public abstract org.apache.ws.resource.NamespaceVersionHolder getNamespaceSet();
-
- /**
- * Returns the EndpointReference associated with this Resource. Only the required fields will be filled in (i.e.
- * Address) AND the ReferenceProperty for the ResourceKey (if not a singleton)
- * <p/>
- * If the resourceKey is not equal to null ( not a singleton ), the reference properties will contain the key.
- *
- * @param resourceId the resource identifier, or null if the resource is a singleton
- *
- * @return an EndpointReference (EPR) for the resource
- */
- public EndpointReference getEndpointReference( Object resourceId )
- {
- String endpointAddress =
- JaxRpcPlatform.getJaxRpcPlatform().getEndpointUrl( WsrfRuntime.getRuntime().getBaseWebappUrl().toString(),
- getServiceName().getLocalPart() );
- String wsAddressingURI = getNamespaceSet().getAddressingNamespace();
-
- XmlBeansEndpointReference xBeansEPR =
- new XmlBeansEndpointReference( endpointAddress, wsAddressingURI );
- if ( resourceId != null )
- {
- XmlObject resourceIdRefParam = XmlBeanUtils.createElement( m_resourceIdRefParamName );
- XmlBeanUtils.setValue( resourceIdRefParam, resourceId.toString() );
- xBeansEPR.addReferenceParameter( resourceIdRefParam );
- }
- xBeansEPR.setPortTypeQName( getPortType() );
- xBeansEPR.setServicePortName( getServicePortName() );
- xBeansEPR.setServiceQName( getServiceName() );
- return xBeansEPR;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public abstract QName getPortType();
-
- /**
- * DOCUMENT_ME
- *
- * @param resourceClassName DOCUMENT_ME
- *
- * @deprecated use {@link #setResourceClass(Class)} instead
- */
- public void setResourceClassName( String resourceClassName )
- {
- try
- {
- m_resourceClass = Class.forName( resourceClassName );
- }
- catch ( ClassNotFoundException cnfe )
- {
- throw new RuntimeException( cnfe );
- }
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param serviceClassName DOCUMENT_ME
- *
- * @deprecated use {@link #setServiceClass(Class)} instead
- */
- public void setServiceClassName( String serviceClassName )
- {
- try
- {
- m_serviceClass = Class.forName( serviceClassName );
- }
- catch ( ClassNotFoundException cnfe )
- {
- throw new RuntimeException( cnfe );
- }
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param resourceClass DOCUMENT_ME
- */
- public void setResourceClass( Class resourceClass )
- {
- if ( resourceClass != null && !Resource.class.isAssignableFrom( resourceClass ) )
- {
- throw new IllegalArgumentException( "Specified resource class '" + resourceClass.getName()
- + "' does not implement the " + Resource.class.getName()
- + " interface." );
- }
- m_resourceClass = resourceClass;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param serviceClass
- */
- public void setServiceClass( Class serviceClass )
- {
- m_serviceClass = serviceClass;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String getResourceClassName()
- {
- return m_resourceClass != null ? m_resourceClass.getName() : null;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String getServiceClassName()
- {
- return m_serviceClass != null ? m_serviceClass.getName() : null;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public abstract QName getServiceName();
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public abstract String getServicePortName();
-
-
-
- /**
- * Returns true if the home has been initialized, else false
- *
- * @return true if the home has been initialized, else false
- */
- public boolean isInitialized()
- {
- return m_initialized;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param name DOCUMENT_ME
- */
- public void setResourceIdentifierReferenceParameterName( String name )
- {
- m_resourceIdRefParamName = QName.valueOf( name );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String getResourceIdentifierReferenceParameterName()
- {
- //case of singleton...
- if ( m_resourceIdRefParamName == null )
- {
- return null;
- }
-
- return m_resourceIdRefParamName.toString();
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public QName getResourceIdentifierReferenceParameterQName()
- {
- return m_resourceIdRefParamName;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param delay DOCUMENT_ME
- */
- public void setSweeperDelay( long delay )
- {
- m_sweeperDelay = delay;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public long getSweeperDelay()
- {
- return m_sweeperDelay;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param targetNamespace DOCUMENT_ME
- */
- public void setWsdlTargetNamespace( String targetNamespace )
- {
- m_wsdlTargetNamespace = targetNamespace;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String getWsdlTargetNamespace()
- {
- return m_wsdlTargetNamespace;
- }
-
- /**
- * @see ResourceHome#add(org.apache.ws.resource.Resource)
- */
- public boolean add( Resource resource )
- throws IllegalResourceTypeException
- {
- boolean resourceWasAdded = true;
- if ( !m_resourceClass.isAssignableFrom( resource.getClass() ) )
- {
- throw new IllegalResourceTypeException( "This home only supports resources of type "
- + m_resourceClass.getName() );
- }
- if ( m_resources == null )
- {
- m_resources = getResourceMap(); // in case this.init() was never called for some reason
- }
-
- try
- {
- initEndpointReference( resource );
- resource.init();
- }
- catch ( RuntimeException re )
- { re.printStackTrace();
- throw new RuntimeException( MSG.getMessage( Keys.FAILED_TO_INIT_RESOURCE, resource, re ), re );
- }
- LOG.debug( MSG.getMessage( Keys.ADDING_RESOURCE_WITH_ID,
- resource.getID(),
- getClass().getName() ) );
- m_resources.put( getNonNullKey( resource.getID() ), resource );
- scheduleSweeperTask();
- notifyResourceCreatedListeners( resource );
- updateCache( resource );
- return resourceWasAdded;
- }
-
- private void initEndpointReference( Resource resource )
- {
- if ( resource.getEndpointReference() == null )
- {
- resource.setEndpointReference( getEndpointReference( resource.getID() ) );
- }
- }
-
- /**
- * Adds a listener for ResourceCreationEvents
- *
- * @param listener
- */
- public void addResourceCreationListener( ResourceCreationListener listener )
- {
- m_creationListeners.add( listener );
- }
-
- /**
- * Adds a listener for ResourceDestructionEvents
- *
- * @param listener
- */
- public void addResourceDestructionListener( ResourceDestructionListener listener )
- {
- m_destructionListeners.add( listener );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param context DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public Object extractResourceIdentifier( ResourceContext context )
- {
- if ( getResourceIdentifierReferenceParameterName() == null )
- {
- return null;
- }
- try
- {
- SOAPHeader soapHeader = context.getSOAPMessage().getSOAPHeader();
- Iterator resourceIdElemsIter =
- soapHeader.getChildElements( NameUtils.toName( getResourceIdentifierReferenceParameterQName() ) );
- if ( !resourceIdElemsIter.hasNext() )
- {
- throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
- "The expected resource identifier reference parameter named "
- + getResourceIdentifierReferenceParameterName()
- + " was not found in the SOAP header." );
- }
+ /**
+ * DOCUMENT_ME
+ */
+ protected Map m_resources;
- SOAPHeaderElement resourceIdElem = (SOAPHeaderElement) resourceIdElemsIter.next();
- if ( resourceIdElemsIter.hasNext() )
- {
- throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
- "More than one resource identifier reference parameter named "
- + getResourceIdentifierReferenceParameterName()
- + " was found in the SOAP header. Exactly one is expected." );
- }
+ /**
+ * DOCUMENT_ME
+ */
+ protected boolean m_resourceIsPersistent;
+ private QName m_resourceIdRefParamName;
+ private String m_wsdlTargetNamespace;
- return resourceIdElem.getValue();
- }
- catch ( SOAPException soape )
- {
- throw new JAXRPCException( soape );
- }
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param epr the endpoint reference of a WS-Resource
- *
- * @return DOCUMENT_ME
- */
- public Object extractResourceIdentifier( EndpointReference epr )
- {
- QName resourceIdElemName = getResourceIdentifierReferenceParameterQName();
- if ( resourceIdElemName == null ) // singletons have a null id
- {
- return null;
- }
- String resourceId = null;
- if ( resourceIdElemName != null )
- {
- Object[] refProps = epr.getReferenceProperties();
- for ( int i = 0; i < refProps.length; i++ )
- {
- XmlObject refPropXBean = (XmlObject) refProps[i];
- if ( XmlBeanUtils.getName( refPropXBean ).equals( resourceIdElemName ) )
- {
- resourceId = XmlBeanUtils.getValue( refPropXBean );
- }
- }
- if ( resourceId == null )
- {
- Object[] refParams = epr.getReferenceParameters();
- for ( int i = 0; i < refParams.length; i++ )
- {
- XmlObject refParamXBean = (XmlObject) refParams[i];
- if ( XmlBeanUtils.getName( refParamXBean ).equals( resourceIdElemName ) )
- {
- resourceId = XmlBeanUtils.getValue( refParamXBean );
- }
- }
- }
- if ( resourceId == null )
- {
- throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
- "The expected resource identifier reference parameter named "
- + getResourceIdentifierReferenceParameterName()
- + " was not found in the SOAP header." );
- }
- }
- return resourceId;
- }
-
- /**
- * @see ResourceHome#find(Object)
- */
- public Resource find( Object resourceId )
- throws ResourceUnknownException,
- ResourceException
- {
- LOG.debug( MSG.getMessage( Keys.FINDING_RESOURCE_WITH_KEY,
- String.valueOf( resourceId ) ) );
- Resource resource = null;
- synchronized ( m_resources )
- {
- //Lock lock = acquireLock( resourceId );
- //try
- //{
- resource = get( resourceId );
- updateCache( resource );
-
- //}
- //finally
- //{
- // lock.release();
- //}
- }
-
- return resource;
- }
-
- /**
- * Initializes this home. Should be called <em>after</em> setters have been called on all bean properties.
- *
- * @throws Exception on error
- */
- public void init()
- throws Exception
- {
- synchronized ( this )
- {
- if ( m_initialized )
- {
- return;
- }
+ /**
+ * DOCUMENT_ME
+ */
+ protected LockManager m_lockManager;
+ private String m_cacheLocation;
+ private Cache m_cache;
+ private long m_sweeperDelay = DEFAULT_SWEEPER_DELAY;
+ private Sweeper m_sweeper;
+ private boolean m_initialized;
+ private List m_creationListeners = new ArrayList( );
+ private List m_destructionListeners = new ArrayList( );
+ private Class m_resourceClass;
+ private Class m_serviceClass;
+ private String m_portComponentName;
+ private MetadataConfiguration m_metadataConfig;
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param jndiLocation DOCUMENT_ME
+ */
+ public void setCacheLocation( String jndiLocation )
+ {
+ m_cacheLocation = jndiLocation;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getCacheLocation( )
+ {
+ return m_cacheLocation;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract org.apache.ws.resource.NamespaceVersionHolder getNamespaceSet( );
- LOG.debug( MSG.getMessage( Keys.INIT_HOME ) );
- if ( m_resourceClass == null )
- {
- throw new ResourceException( "The resourceClass property of this home is not defined." );
- }
- if ( PersistentResource.class.isAssignableFrom( m_resourceClass ) )
- {
- m_resourceIsPersistent = true;
- }
+ /**
+ * Returns the EndpointReference associated with this Resource. Only the required fields will be filled in (i.e.
+ * Address) AND the ReferenceProperty for the ResourceKey (if not a singleton)
+ * <p/>
+ * If the resourceKey is not equal to null ( not a singleton ), the reference properties will contain the key.
+ *
+ * @param resourceId the resource identifier, or null if the resource is a singleton
+ *
+ * @return an EndpointReference (EPR) for the resource
+ */
+ public EndpointReference getEndpointReference( Object resourceId )
+ {
+ String endpointAddress =
+ JaxRpcPlatform.getJaxRpcPlatform( ).getEndpointUrl( WsrfRuntime.getRuntime( ).getBaseWebappUrl( )
+ .toString( ),
+ getServiceName( ).getLocalPart( ) );
+ String wsAddressingURI = getNamespaceSet( ).getAddressingNamespace( );
+
+ XmlBeansEndpointReference xBeansEPR = new XmlBeansEndpointReference( endpointAddress, wsAddressingURI );
+ if ( resourceId != null )
+ {
+ XmlObject resourceIdRefParam = XmlBeanUtils.createElement( m_resourceIdRefParamName );
+ XmlBeanUtils.setValue( resourceIdRefParam,
+ resourceId.toString( ) );
+ xBeansEPR.addReferenceParameter( resourceIdRefParam );
+ }
+
+ xBeansEPR.setPortTypeQName( getPortType( ) );
+ xBeansEPR.setServicePortName( getServicePortName( ) );
+ xBeansEPR.setServiceQName( getServiceName( ) );
+ return xBeansEPR;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract QName getPortType( );
- Context initialContext = new InitialContext();
- m_resources = getResourceMap();
- m_lockManager = new LockManager();
- if ( ScheduledResourceTerminationResource.class.isAssignableFrom( m_resourceClass ) )
- {
- initSweeper( initialContext );
- }
+ /**
+ * DOCUMENT_ME
+ *
+ * @param config DOCUMENT_ME
+ */
+ public void setMetadataConfig( MetadataConfiguration config )
+ {
+ m_metadataConfig = config;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public MetadataConfiguration getMetadataConfig( )
+ {
+ return m_metadataConfig;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param portComponentName DOCUMENT_ME
+ */
+ public void setPortComponentName( String portComponentName )
+ {
+ m_portComponentName = portComponentName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getPortComponentName( )
+ {
+ return m_portComponentName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param resourceClass DOCUMENT_ME
+ */
+ public void setResourceClass( Class resourceClass )
+ {
+ if ( ( resourceClass != null ) && !Resource.class.isAssignableFrom( resourceClass ) )
+ {
+ throw new IllegalArgumentException( "Specified resource class '" + resourceClass.getName( )
+ + "' does not implement the " + Resource.class.getName( )
+ + " interface." );
+ }
+
+ m_resourceClass = resourceClass;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param resourceClassName DOCUMENT_ME
+ *
+ * @deprecated use {@link #setResourceClass(Class)} instead
+ */
+ public void setResourceClassName( String resourceClassName )
+ {
+ try
+ {
+ m_resourceClass = Class.forName( resourceClassName );
+ }
+ catch ( ClassNotFoundException cnfe )
+ {
+ throw new RuntimeException( cnfe );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getResourceClassName( )
+ {
+ return ( m_resourceClass != null ) ? m_resourceClass.getName( ) : null;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param serviceClass
+ */
+ public void setServiceClass( Class serviceClass )
+ {
+ m_serviceClass = serviceClass;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param serviceClassName DOCUMENT_ME
+ *
+ * @deprecated use {@link #setServiceClass(Class)} instead
+ */
+ public void setServiceClassName( String serviceClassName )
+ {
+ try
+ {
+ m_serviceClass = Class.forName( serviceClassName );
+ }
+ catch ( ClassNotFoundException cnfe )
+ {
+ throw new RuntimeException( cnfe );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getServiceClassName( )
+ {
+ return ( m_serviceClass != null ) ? m_serviceClass.getName( ) : null;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract QName getServiceName( );
- initCachePolicy( new InitialContext() );
- m_initialized = true;
- }
- }
-
- /**
- * @see ResourceHome#remove(Object)
- */
- public void remove( Object resourceId )
- throws ResourceUnknownException,
- ResourceException
- {
- Resource resource = null;
- Lock lock = acquireLock( resourceId );
- try
- {
- resource = get( resourceId );
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public abstract String getServicePortName( );
- try
- {
- resource.destroy();
- }
- catch ( RuntimeException re )
- {
- throw new ResourceException( MSG.getMessage( Keys.FAILED_TO_DESTROY_RESOURCE, resource, re ) );
- }
+ /**
+ * Returns true if the home has been initialized, else false
+ *
+ * @return true if the home has been initialized, else false
+ */
+ public boolean isInitialized( )
+ {
+ return m_initialized;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void setResourceIdentifierReferenceParameterName( String name )
+ {
+ m_resourceIdRefParamName = QName.valueOf( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getResourceIdentifierReferenceParameterName( )
+ {
+ //case of singleton...
+ if ( m_resourceIdRefParamName == null )
+ {
+ return null;
+ }
+
+ return m_resourceIdRefParamName.toString( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public QName getResourceIdentifierReferenceParameterQName( )
+ {
+ return m_resourceIdRefParamName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param delay DOCUMENT_ME
+ */
+ public void setSweeperDelay( long delay )
+ {
+ m_sweeperDelay = delay;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public long getSweeperDelay( )
+ {
+ return m_sweeperDelay;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param targetNamespace DOCUMENT_ME
+ */
+ public void setWsdlTargetNamespace( String targetNamespace )
+ {
+ m_wsdlTargetNamespace = targetNamespace;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getWsdlTargetNamespace( )
+ {
+ return m_wsdlTargetNamespace;
+ }
- Resource removedResource = (Resource) m_resources.remove( getNonNullKey( resourceId ) );
- if ( removedResource instanceof PropertiesResource )
+ /**
+ * @see ResourceHome#add(org.apache.ws.resource.Resource)
+ */
+ public boolean add( Resource resource )
+ throws IllegalResourceTypeException
+ {
+ boolean resourceWasAdded = true;
+ if ( !m_resourceClass.isAssignableFrom( resource.getClass( ) ) )
+ {
+ throw new IllegalResourceTypeException( "This home only supports resources of type "
+ + m_resourceClass.getName( ) );
+ }
+
+ if ( m_resources == null )
+ {
+ m_resources = getResourceMap( ); // in case this.init() was never called for some reason
+ }
+
+ try
+ {
+ initEndpointReference( resource );
+ resource.init( );
+ }
+ catch ( RuntimeException re )
+ {
+ re.printStackTrace( );
+ throw new RuntimeException( MSG.getMessage( Keys.FAILED_TO_INIT_RESOURCE, resource, re ), re );
+ }
+
+ LOG.debug( MSG.getMessage( Keys.ADDING_RESOURCE_WITH_ID,
+ resource.getID( ),
+ getClass( ).getName( ) ) );
+ m_resources.put( getNonNullKey( resource.getID( ) ),
+ resource );
+ scheduleSweeperTask( );
+ notifyResourceCreatedListeners( resource );
+ updateCache( resource );
+ return resourceWasAdded;
+ }
+
+ /**
+ * Adds a listener for ResourceCreationEvents
+ *
+ * @param listener
+ */
+ public void addResourceCreationListener( ResourceCreationListener listener )
+ {
+ m_creationListeners.add( listener );
+ }
+
+ /**
+ * Adds a listener for ResourceDestructionEvents
+ *
+ * @param listener
+ */
+ public void addResourceDestructionListener( ResourceDestructionListener listener )
+ {
+ m_destructionListeners.add( listener );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param context DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Object extractResourceIdentifier( ResourceContext context )
+ {
+ if ( getResourceIdentifierReferenceParameterName( ) == null )
+ {
+ return null;
+ }
+
+ try
+ {
+ SOAPHeader soapHeader = context.getSOAPMessage( ).getSOAPHeader( );
+ Iterator resourceIdElemsIter =
+ soapHeader.getChildElements( NameUtils.toName( getResourceIdentifierReferenceParameterQName( ) ) );
+ if ( !resourceIdElemsIter.hasNext( ) )
+ {
+ throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
+ "The expected resource identifier reference parameter named "
+ + getResourceIdentifierReferenceParameterName( )
+ + " was not found in the SOAP header." );
+ }
+
+ SOAPHeaderElement resourceIdElem = (SOAPHeaderElement) resourceIdElemsIter.next( );
+ if ( resourceIdElemsIter.hasNext( ) )
+ {
+ throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
+ "More than one resource identifier reference parameter named "
+ + getResourceIdentifierReferenceParameterName( )
+ + " was found in the SOAP header. Exactly one is expected." );
+ }
+
+ return resourceIdElem.getValue( );
+ }
+ catch ( SOAPException soape )
+ {
+ throw new JAXRPCException( soape );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param epr the endpoint reference of a WS-Resource
+ *
+ * @return DOCUMENT_ME
+ */
+ public Object extractResourceIdentifier( EndpointReference epr )
+ {
+ QName resourceIdElemName = getResourceIdentifierReferenceParameterQName( );
+ if ( resourceIdElemName == null ) // singletons have a null id
+ {
+ return null;
+ }
+
+ String resourceId = null;
+ if ( resourceIdElemName != null )
+ {
+ Object[] refProps = epr.getReferenceProperties( );
+ for ( int i = 0; i < refProps.length; i++ )
+ {
+ XmlObject refPropXBean = (XmlObject) refProps[i];
+ if ( XmlBeanUtils.getName( refPropXBean ).equals( resourceIdElemName ) )
{
- notifyResourceDeletedListeners( removedResource );
+ resourceId = XmlBeanUtils.getValue( refPropXBean );
}
+ }
- LOG.debug( MSG.getMessage( Keys.REMOVED_RESOURCE_WITH_KEY,
- resource.getClass().getName(),
- String.valueOf( resourceId ) ) );
- if ( m_cache != null )
+ if ( resourceId == null )
+ {
+ Object[] refParams = epr.getReferenceParameters( );
+ for ( int i = 0; i < refParams.length; i++ )
{
- m_cache.remove( resource );
+ XmlObject refParamXBean = (XmlObject) refParams[i];
+ if ( XmlBeanUtils.getName( refParamXBean ).equals( resourceIdElemName ) )
+ {
+ resourceId = XmlBeanUtils.getValue( refParamXBean );
+ }
}
- }
- finally
- {
- lock.release();
- }
- }
-
- /**
- * Removes a listener for ResourceCreationEvents
- *
- * @param listener
- *
- * @return true if the listener was removed, else false
- */
- public boolean removeResourceCreationListener( ResourceCreationListener listener )
- {
- return m_creationListeners.remove( listener );
- }
-
- /**
- * Removes a listener for ResourceDestructionEvents
- *
- * @param listener
- *
- * @return true if the listener was removed, else false
- */
- public boolean removeResourceDestructionListener( ResourceDestructionListener listener )
- {
- return m_destructionListeners.remove( listener );
- }
-
- public String getPortComponentName()
- {
- return m_portComponentName;
- }
-
- public void setPortComponentName( String portComponentName )
- {
- m_portComponentName = portComponentName;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- protected abstract Map getResourceMap();
-
-
- /**
- * This method uses reflection to create an instance of a Resource which contains an empty constructor. It will not
- * work with Resources which do not have an empty constructor.
- * <p/>
- * Note: the returned Resource will an EndpointReference associated with it.
- *
- * @param id the resource identifier
- *
- * @return a resource of the type associated with this home
- *
- * @throws ResourceException
- */
- protected Resource createInstance( Object id )
- throws ResourceException
- {
- LOG.debug( MSG.getMessage( Keys.CREATING_RESOURCE_WITH_ID, id ) );
- Resource resource = createInstanceViaSpringBeanFactory();
- if ( resource == null )
- {
- resource = createInstanceViaReflection();
- }
- if ( resource.getID() == null )
- {
- resource.setID( id );
- }
- return resource;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param id DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- *
- * @throws ResourceException DOCUMENT_ME
- */
- protected Resource createNewInstanceAndLoad( Object id )
- throws ResourceException
- {
- Resource resource = createInstance( id );
- LOG.debug( MSG.getMessage( Keys.LOADING_RESOURCE_FROM_PERSISTENCE,
- String.valueOf( id ) ) );
- ( (PersistentResource) resource ).load();
- if ( ResourceSweeper.isExpired( resource ) )
- {
- throw new ResourceUnknownException( getNonNullKey( id ),
- getServicePortName() );
- }
-
- return resource;
- }
-
- /**
- * Creates a synschronized map for storing {@link Resource}s. If the resource is persistent, a {@link ReferenceMap}
- * is used, otherwise a {@link HashMap} is used. Provided for the convenience of subclasses, which are responsible
- * for creating a map of resources and maintaining a static reference to that map.
- *
- * @param isPersistent if the resource is persistent
- *
- * @return a synschronized map for storing {@link Resource}s
- */
- protected static Map createResourceMap( boolean isPersistent )
- {
- Map resourceMap;
- if ( isPersistent )
- {
- resourceMap = new ReferenceMap( ReferenceMap.HARD, ReferenceMap.SOFT, true );
- }
- else
- {
- resourceMap = new HashMap();
- }
-
- return Collections.synchronizedMap( resourceMap );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param initialContext DOCUMENT_ME
- *
- * @throws NamingException DOCUMENT_ME
- */
- protected void initCachePolicy( Context initialContext )
- throws NamingException
- {
- if ( m_cacheLocation != null )
- {
- m_cache = (Cache) XmlBeanJndiUtils.lookup( initialContext, m_cacheLocation, Cache.class );
- }
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param obj DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- Object getNonNullKey( Object obj )
- {
- return ( obj != null ) ? obj : SINGLETON_KEY;
- }
-
- private Lock acquireLock( Object resourceId )
- throws ResourceException
- {
- Lock lock = m_lockManager.getLock( getNonNullKey( resourceId ) );
- try
- {
- lock.acquire();
- }
- catch ( InterruptedException ie )
- {
- throw new ResourceException( ie );
- }
-
- return lock;
- }
-
- private Resource get( Object resourceId )
- throws ResourceException
- {
- LOG.debug( MSG.getMessage( Keys.GETTING_RESOURCE_WITH_ID,
- resourceId,
- getClass().getName() ) );
- Resource resource = (Resource) m_resources.get( getNonNullKey( resourceId ) );
- if ( resource == null )
- {
- if ( !m_resourceIsPersistent )
+ }
+
+ if ( resourceId == null )
+ {
+ throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
+ "The expected resource identifier reference parameter named "
+ + getResourceIdentifierReferenceParameterName( )
+ + " was not found in the SOAP header." );
+ }
+ }
+
+ return resourceId;
+ }
+
+ /**
+ * @see ResourceHome#find(Object)
+ */
+ public Resource find( Object resourceId )
+ throws ResourceUnknownException,
+ ResourceException
+ {
+ LOG.debug( MSG.getMessage( Keys.FINDING_RESOURCE_WITH_KEY,
+ String.valueOf( resourceId ) ) );
+ Resource resource = null;
+ synchronized ( m_resources )
+ {
+ //Lock lock = acquireLock( resourceId );
+ //try
+ //{
+ resource = get( resourceId );
+ updateCache( resource );
+
+ //}
+ //finally
+ //{
+ // lock.release();
+ //}
+ }
+
+ return resource;
+ }
+
+ /**
+ * Initializes this home. Should be called <em>after</em> setters have been called on all bean properties.
+ *
+ * @throws Exception on error
+ */
+ public void init( )
+ throws Exception
+ {
+ synchronized ( this )
+ {
+ if ( m_initialized )
+ {
+ return;
+ }
+
+ LOG.debug( MSG.getMessage( Keys.INIT_HOME ) );
+ if ( m_resourceClass == null )
+ {
+ throw new ResourceException( "The resourceClass property of this home is not defined." );
+ }
+
+ if ( PersistentResource.class.isAssignableFrom( m_resourceClass ) )
+ {
+ m_resourceIsPersistent = true;
+ }
+
+ Context initialContext = new InitialContext( );
+ m_resources = getResourceMap( );
+ m_lockManager = new LockManager( );
+ if ( ScheduledResourceTerminationResource.class.isAssignableFrom( m_resourceClass ) )
+ {
+ initSweeper( initialContext );
+ }
+
+ initCachePolicy( new InitialContext( ) );
+ m_initialized = true;
+ }
+ }
+
+ /**
+ * @see ResourceHome#remove(Object)
+ */
+ public void remove( Object resourceId )
+ throws ResourceUnknownException,
+ ResourceException
+ {
+ Resource resource = null;
+ Lock lock = acquireLock( resourceId );
+ try
+ {
+ resource = get( resourceId );
+
+ try
+ {
+ resource.destroy( );
+ }
+ catch ( RuntimeException re )
+ {
+ throw new ResourceException( MSG.getMessage( Keys.FAILED_TO_DESTROY_RESOURCE, resource, re ) );
+ }
+
+ Resource removedResource = (Resource) m_resources.remove( getNonNullKey( resourceId ) );
+ if ( removedResource instanceof PropertiesResource )
+ {
+ notifyResourceDeletedListeners( removedResource );
+ }
+
+ LOG.debug( MSG.getMessage( Keys.REMOVED_RESOURCE_WITH_KEY,
+ resource.getClass( ).getName( ),
+ String.valueOf( resourceId ) ) );
+ if ( m_cache != null )
+ {
+ m_cache.remove( resource );
+ }
+ }
+ finally
+ {
+ lock.release( );
+ }
+ }
+
+ /**
+ * Removes a listener for ResourceCreationEvents
+ *
+ * @param listener
+ *
+ * @return true if the listener was removed, else false
+ */
+ public boolean removeResourceCreationListener( ResourceCreationListener listener )
+ {
+ return m_creationListeners.remove( listener );
+ }
+
+ /**
+ * Removes a listener for ResourceDestructionEvents
+ *
+ * @param listener
+ *
+ * @return true if the listener was removed, else false
+ */
+ public boolean removeResourceDestructionListener( ResourceDestructionListener listener )
+ {
+ return m_destructionListeners.remove( listener );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ protected abstract Map getResourceMap( );
+
+ /**
+ * This method uses reflection to create an instance of a Resource which contains an empty constructor. It will not
+ * work with Resources which do not have an empty constructor.
+ * <p/>
+ * Note: the returned Resource will an EndpointReference associated with it.
+ *
+ * @param id the resource identifier
+ *
+ * @return a resource of the type associated with this home
+ *
+ * @throws ResourceException
+ */
+ protected Resource createInstance( Object id )
+ throws ResourceException
+ {
+ LOG.debug( MSG.getMessage( Keys.CREATING_RESOURCE_WITH_ID, id ) );
+ Resource resource = createInstanceViaSpringBeanFactory( );
+ if ( resource == null )
+ {
+ resource = createInstanceViaReflection( );
+ }
+
+ if ( resource.getID( ) == null )
+ {
+ resource.setID( id );
+ }
+
+ return resource;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param id DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws ResourceException DOCUMENT_ME
+ */
+ protected Resource createNewInstanceAndLoad( Object id )
+ throws ResourceException
+ {
+ Resource resource = createInstance( id );
+ LOG.debug( MSG.getMessage( Keys.LOADING_RESOURCE_FROM_PERSISTENCE,
+ String.valueOf( id ) ) );
+ ( (PersistentResource) resource ).load( );
+ if ( ResourceSweeper.isExpired( resource ) )
+ {
+ throw new ResourceUnknownException( getNonNullKey( id ),
+ getServicePortName( ) );
+ }
+
+ return resource;
+ }
+
+ /**
+ * Creates a synschronized map for storing {@link Resource}s. If the resource is persistent, a {@link ReferenceMap}
+ * is used, otherwise a {@link HashMap} is used. Provided for the convenience of subclasses, which are responsible
+ * for creating a map of resources and maintaining a static reference to that map.
+ *
+ * @param isPersistent if the resource is persistent
+ *
+ * @return a synschronized map for storing {@link Resource}s
+ */
+ protected static Map createResourceMap( boolean isPersistent )
+ {
+ Map resourceMap;
+ if ( isPersistent )
+ {
+ resourceMap = new ReferenceMap( ReferenceMap.HARD, ReferenceMap.SOFT, true );
+ }
+ else
+ {
+ resourceMap = new HashMap( );
+ }
+
+ return Collections.synchronizedMap( resourceMap );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param initialContext DOCUMENT_ME
+ *
+ * @throws NamingException DOCUMENT_ME
+ */
+ protected void initCachePolicy( Context initialContext )
+ throws NamingException
+ {
+ if ( m_cacheLocation != null )
+ {
+ m_cache = (Cache) XmlBeanJndiUtils.lookup( initialContext, m_cacheLocation, Cache.class );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param obj DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ Object getNonNullKey( Object obj )
+ {
+ return ( obj != null ) ? obj : SINGLETON_KEY;
+ }
+
+ private TimerManager getTimerManager( Context initialContext )
+ {
+ TimerManager timerManager;
+ try
+ {
+ timerManager = (TimerManager) initialContext.lookup( CONTEXT_NAME_J2EE_TIMER_MANAGER );
+ }
+ catch ( NamingException ne )
+ {
+ try
+ {
+ timerManager = (TimerManager) initialContext.lookup( JndiConstants.CONTEXT_NAME_DEFAULT_TIMER );
+ }
+ catch ( NamingException ne2 )
+ {
+ timerManager = new TimerManagerImpl( );
+ }
+ }
+
+ LOG.debug( MSG.getMessage( Keys.TIMER_MANAGER_IMPL,
+ timerManager.getClass( ).getName( ) ) );
+ return timerManager;
+ }
+
+ private Lock acquireLock( Object resourceId )
+ throws ResourceException
+ {
+ Lock lock = m_lockManager.getLock( getNonNullKey( resourceId ) );
+ try
+ {
+ lock.acquire( );
+ }
+ catch ( InterruptedException ie )
+ {
+ throw new ResourceException( ie );
+ }
+
+ return lock;
+ }
+
+ private Resource createInstanceViaReflection( )
+ throws ResourceException
+ {
+ Resource resource;
+ try
+ {
+ resource = (Resource) m_resourceClass.newInstance( );
+ }
+ catch ( Exception e )
+ {
+ throw new ResourceException( e );
+ }
+
+ return resource;
+ }
+
+ private Resource createInstanceViaSpringBeanFactory( )
+ throws ResourceException
+ {
+ Resource resource = null;
+ ListableBeanFactory beanFactory = WsrfRuntime.getRuntime( ).getBeanFactory( );
+ if ( beanFactory != null )
+ {
+ String[] beanDefNames = beanFactory.getBeanNamesForType( m_resourceClass );
+ if ( beanDefNames.length != 0 )
+ {
+ if ( beanDefNames.length > 1 )
{
- throw new ResourceUnknownException( resourceId, getServicePortName() );
+ LOG.warn( "More than one bean definition found for resource of type " + m_resourceClass.getName( ) );
}
- add( createNewInstanceAndLoad( resourceId ) );
- }
- return resource;
- }
-
- private void initSweeper( Context initialContext )
- {
- m_sweeper = new Sweeper( this, m_resources, getTimerManager( initialContext ), m_sweeperDelay );
- }
-
- private TimerManager getTimerManager( Context initialContext )
- {
- TimerManager timerManager;
- try
- {
- timerManager = (TimerManager) initialContext.lookup( CONTEXT_NAME_J2EE_TIMER_MANAGER );
- }
- catch ( NamingException ne )
- {
+
try
{
- timerManager = (TimerManager) initialContext.lookup( JndiConstants.CONTEXT_NAME_DEFAULT_TIMER );
- }
- catch ( NamingException ne2 )
- {
- timerManager = new TimerManagerImpl();
- }
- }
- LOG.debug( MSG.getMessage( Keys.TIMER_MANAGER_IMPL, timerManager.getClass().getName() ) );
- return timerManager;
- }
-
- /**
- * This method is used to notify listeners a resource has been created.
- *
- * @param resource The Resource which was created
- */
- private void notifyResourceCreatedListeners( Resource resource )
- {
- for ( int i = 0; i < m_creationListeners.size(); i++ )
- {
- ResourceCreationListener resourceCreationListener =
- (ResourceCreationListener) m_creationListeners.get( i );
- resourceCreationListener.creationOccurred( new ResourceCreationEvent( resource ) );
- }
- }
-
- /**
- * This method is used to notify listeners a resource has been deleted.
- *
- * @param resource The EndpointReference for the Resource which was created
- */
- private void notifyResourceDeletedListeners( Resource resource )
- {
- for ( int i = 0; i < m_destructionListeners.size(); i++ )
- {
- ResourceDestructionListener resourceDestructionListener =
- (ResourceDestructionListener) m_destructionListeners.get( i );
- ResourceDestructionEvent event = new ResourceDestructionEvent( resource );
- resourceDestructionListener.destructionOccurred( event );
- }
- }
-
- private void scheduleSweeperTask()
- {
- if ( m_sweeper != null )
- {
- m_sweeper.schedule();
- }
- }
-
- private void updateCache( Resource resource )
- {
- if ( m_cache != null )
- {
- m_cache.update( resource );
- }
- }
-
- private Resource createInstanceViaSpringBeanFactory()
- throws ResourceException
- {
- Resource resource = null;
- ListableBeanFactory beanFactory = WsrfRuntime.getRuntime().getBeanFactory();
- if ( beanFactory != null )
- {
- String[] beanDefNames = beanFactory.getBeanNamesForType( m_resourceClass );
- if ( beanDefNames.length != 0 )
- {
- if ( beanDefNames.length > 1 )
- {
- LOG.warn( "More than one bean definition found for resource of type " + m_resourceClass.getName() );
- }
- try
- {
- resource = (Resource) beanFactory.getBean( beanDefNames[0], m_resourceClass );
- }
- catch ( BeansException be )
- {
- throw new ResourceException(
- "Failed to instantiate " + getResourceClassName() + " resource via Spring bean factory.",
- be );
- }
+ resource = (Resource) beanFactory.getBean( beanDefNames[0], m_resourceClass );
}
- }
- return resource;
- }
-
- private Resource createInstanceViaReflection()
- throws ResourceException
- {
- Resource resource;
- try
- {
- resource = (Resource) m_resourceClass.newInstance();
- }
- catch ( Exception e )
- {
- throw new ResourceException( e );
- }
- return resource;
- }
-
- /**
- * This ResourceSweeper implementation just returns the resources currently stored in the map. The reason is that
- * the sweeper doesn't have to reactivate/reload a persistent resource if the resource object was reclaimed. So
- * lifetime checks are not done on reclained resources. Lifetime checks have to be done on resource load.
- */
- private static class Sweeper
- extends ResourceSweeper
- {
- private TimerManager m_timerManager;
- private Timer m_timer;
- private long m_delay;
-
- /**
- * Creates a new {@link Sweeper} object.
- *
- * @param home DOCUMENT_ME
- * @param resources DOCUMENT_ME
- * @param timerManager DOCUMENT_ME
- * @param delay DOCUMENT_ME
- */
- public Sweeper( ResourceHome home,
- Map resources,
- TimerManager timerManager,
- long delay )
- {
- super( home, resources );
- m_timerManager = timerManager;
- m_delay = delay;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param timer DOCUMENT_ME
- */
- public void timerExpired( Timer timer )
- {
- super.timerExpired( timer );
- cancel();
- if ( !m_resources.isEmpty() )
+ catch ( BeansException be )
{
- schedule();
+ throw new ResourceException( "Failed to instantiate " + getResourceClassName( )
+ + " resource via Spring bean factory.", be );
}
- }
+ }
+ }
- /**
- * Schedules this resource sweeper.
- */
- synchronized void schedule()
- {
- if ( m_timer == null )
- {
- LOG.debug( MSG.getMessage( Keys.SCHEDULE_RESOURCE_SWEEPER ) );
- m_timer = m_timerManager.schedule( this, m_delay );
- }
- }
+ return resource;
+ }
- /**
- * Cancels this resource sweeper.
- */
- private synchronized void cancel()
- {
- if ( m_timer != null )
- {
- LOG.debug( MSG.getMessage( Keys.CANCEL_RESOURCE_SWEEPER ) );
- m_timer = null;
- }
- }
- }
- public MetadataConfigImpl getMetadataConfig()
- {
- return m_metadataConfig;
- }
- public void setMetadataConfig(MetadataConfigImpl config) {
- m_metadataConfig = config;
- }
-}
+ private Resource get( Object resourceId )
+ throws ResourceException
+ {
+ LOG.debug( MSG.getMessage( Keys.GETTING_RESOURCE_WITH_ID,
+ resourceId,
+ getClass( ).getName( ) ) );
+ Resource resource = (Resource) m_resources.get( getNonNullKey( resourceId ) );
+ if ( resource == null )
+ {
+ if ( !m_resourceIsPersistent )
+ {
+ throw new ResourceUnknownException( resourceId,
+ getServicePortName( ) );
+ }
+
+ add( createNewInstanceAndLoad( resourceId ) );
+ }
+
+ return resource;
+ }
+
+ private void initEndpointReference( Resource resource )
+ {
+ if ( resource.getEndpointReference( ) == null )
+ {
+ resource.setEndpointReference( getEndpointReference( resource.getID( ) ) );
+ }
+ }
+
+ private void initSweeper( Context initialContext )
+ {
+ m_sweeper = new Sweeper( this,
+ m_resources,
+ getTimerManager( initialContext ),
+ m_sweeperDelay );
+ }
+
+ /**
+ * This method is used to notify listeners a resource has been created.
+ *
+ * @param resource The Resource which was created
+ */
+ private void notifyResourceCreatedListeners( Resource resource )
+ {
+ for ( int i = 0; i < m_creationListeners.size( ); i++ )
+ {
+ ResourceCreationListener resourceCreationListener =
+ (ResourceCreationListener) m_creationListeners.get( i );
+ resourceCreationListener.creationOccurred( new ResourceCreationEvent( resource ) );
+ }
+ }
+
+ /**
+ * This method is used to notify listeners a resource has been deleted.
+ *
+ * @param resource The EndpointReference for the Resource which was created
+ */
+ private void notifyResourceDeletedListeners( Resource resource )
+ {
+ for ( int i = 0; i < m_destructionListeners.size( ); i++ )
+ {
+ ResourceDestructionListener resourceDestructionListener =
+ (ResourceDestructionListener) m_destructionListeners.get( i );
+ ResourceDestructionEvent event = new ResourceDestructionEvent( resource );
+ resourceDestructionListener.destructionOccurred( event );
+ }
+ }
+
+ private void scheduleSweeperTask( )
+ {
+ if ( m_sweeper != null )
+ {
+ m_sweeper.schedule( );
+ }
+ }
+
+ private void updateCache( Resource resource )
+ {
+ if ( m_cache != null )
+ {
+ m_cache.update( resource );
+ }
+ }
+
+ /**
+ * This ResourceSweeper implementation just returns the resources currently stored in the map. The reason is that
+ * the sweeper doesn't have to reactivate/reload a persistent resource if the resource object was reclaimed. So
+ * lifetime checks are not done on reclained resources. Lifetime checks have to be done on resource load.
+ */
+ private static class Sweeper
+ extends ResourceSweeper
+ {
+ private TimerManager m_timerManager;
+ private Timer m_timer;
+ private long m_delay;
+
+ /**
+ * Creates a new {@link Sweeper} object.
+ *
+ * @param home DOCUMENT_ME
+ * @param resources DOCUMENT_ME
+ * @param timerManager DOCUMENT_ME
+ * @param delay DOCUMENT_ME
+ */
+ public Sweeper( ResourceHome home,
+ Map resources,
+ TimerManager timerManager,
+ long delay )
+ {
+ super( home, resources );
+ m_timerManager = timerManager;
+ m_delay = delay;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param timer DOCUMENT_ME
+ */
+ public void timerExpired( Timer timer )
+ {
+ super.timerExpired( timer );
+ cancel( );
+ if ( !m_resources.isEmpty( ) )
+ {
+ schedule( );
+ }
+ }
+
+ /**
+ * Schedules this resource sweeper.
+ */
+ synchronized void schedule( )
+ {
+ if ( m_timer == null )
+ {
+ LOG.debug( MSG.getMessage( Keys.SCHEDULE_RESOURCE_SWEEPER ) );
+ m_timer = m_timerManager.schedule( this, m_delay );
+ }
+ }
+
+ /**
+ * Cancels this resource sweeper.
+ */
+ private synchronized void cancel( )
+ {
+ if ( m_timer != null )
+ {
+ LOG.debug( MSG.getMessage( Keys.CANCEL_RESOURCE_SWEEPER ) );
+ m_timer = null;
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceCapabilityImpl.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceCapabilityImpl.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceCapabilityImpl.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceCapabilityImpl.java Thu Oct 20 10:50:00 2005
@@ -15,6 +15,19 @@
*=============================================================================*/
package org.apache.ws.resource.impl;
+import org.apache.ws.resource.InvalidWsrfWsdlException;
+import org.apache.ws.resource.ResourceCapability;
+import org.apache.ws.util.OperationInfo;
+import org.apache.ws.util.WsdlUtils;
+import org.apache.ws.util.WsrfWsdlUtils;
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Operation;
+import javax.wsdl.PortType;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -26,21 +39,6 @@
import java.util.Map;
import java.util.Set;
-import javax.wsdl.Binding;
-import javax.wsdl.Definition;
-import javax.wsdl.Import;
-import javax.wsdl.Operation;
-import javax.wsdl.PortType;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
-import javax.xml.namespace.QName;
-
-import org.apache.ws.resource.InvalidWsrfWsdlException;
-import org.apache.ws.resource.ResourceCapability;
-import org.apache.ws.util.OperationInfo;
-import org.apache.ws.util.WsdlUtils;
-import org.apache.ws.util.WsrfWsdlUtils;
-
/**
* A {@link ResourceCapability} implementation.
*
@@ -61,66 +59,83 @@
private URL m_baseUrl;
private QName m_bindingName;
- /**
- * Creates a new {@link ResourceCapabilityImpl} based on the specified JWSDL definition and portType.
- *
- * @param def a JWSDL definition
- * @param baseURL
- */
- public ResourceCapabilityImpl( Definition def,
- PortType portType,
- URL baseURL )
- throws InvalidWsrfWsdlException
- {
- m_def = def;
- m_portType = portType;
- if(m_portType.isUndefined())
- {
- throw new InvalidWsrfWsdlException("The portType: " + m_portType.getQName() + " is undefined in your WSDL. Please check the name of your wsdl:portType and its reference in the wsdl:binding." );
- }
- m_baseUrl = baseURL;
- m_bindingName = getBindingName(def, m_portType.getQName());
- initImplementedPortTypes( );
- initCustomOperations( );
- initPropertyNames( );
- m_metadataDescName = WsrfWsdlUtils.getMetadataDescriptorName( m_portType );
- m_metadataDescLocation = WsrfWsdlUtils.getMetadataDescriptorLocation( m_portType );
- if ( !m_def.getTargetNamespace( ).startsWith( "http://docs.oasis-open.org/" ) )
- {
- validateOperations( );
- validateProperties( );
- }
- }
-
- private QName getBindingName(Definition def, QName portTypeQName)
- {
- Map bindings = def.getBindings();
- Iterator iterator = bindings.values().iterator();
- while (iterator.hasNext())
- {
- Binding binding = (Binding) iterator.next();
- if(binding.getPortType().getQName().equals(portTypeQName))
- {
- return binding.getQName();
- }
- }
- return null;
- }
-
- public QName getBindingName()
- {
- return m_bindingName;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String[] getCustomOperationNames( )
- {
- return m_customOpNames;
- }
+ /**
+ * Creates a new {@link ResourceCapabilityImpl} based on the specified JWSDL definition and portType.
+ *
+ * @param def a JWSDL definition
+ * @param baseURL
+ */
+ public ResourceCapabilityImpl( Definition def,
+ PortType portType,
+ URL baseURL )
+ throws InvalidWsrfWsdlException
+ {
+ m_def = def;
+ m_portType = portType;
+ if ( m_portType.isUndefined( ) )
+ {
+ throw new InvalidWsrfWsdlException( "The portType: " + m_portType.getQName( )
+ + " is undefined in your WSDL. Please check the name of your wsdl:portType and its reference in the wsdl:binding." );
+ }
+
+ m_baseUrl = baseURL;
+ m_bindingName = getBindingName( def,
+ m_portType.getQName( ) );
+ initImplementedPortTypes( );
+ initCustomOperations( );
+ initPropertyNames( );
+ m_metadataDescName = WsrfWsdlUtils.getMetadataDescriptorName( m_portType );
+ m_metadataDescLocation = WsrfWsdlUtils.getMetadataDescriptorLocation( m_portType );
+ if ( !m_def.getTargetNamespace( ).startsWith( "http://docs.oasis-open.org/" ) )
+ {
+ validateOperations( );
+ validateProperties( );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Map getAllOperations( )
+ {
+ Map opMap = new HashMap( );
+ List operations = m_portType.getOperations( );
+
+ for ( int i = 0; i < operations.size( ); i++ )
+ {
+ Operation o = (Operation) operations.get( i );
+
+ //does this work??
+ OperationInfo opInfo = new OperationInfo( o,
+ m_portType.getQName( ).getNamespaceURI( ) );
+ opMap.put( o.getName( ),
+ opInfo );
+ }
+
+ return opMap;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public QName getBindingName( )
+ {
+ return m_bindingName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String[] getCustomOperationNames( )
+ {
+ return m_customOpNames;
+ }
/**
* @return
@@ -399,6 +414,23 @@
}
}
+ private QName getBindingName( Definition def,
+ QName portTypeQName )
+ {
+ Map bindings = def.getBindings( );
+ Iterator iterator = bindings.values( ).iterator( );
+ while ( iterator.hasNext( ) )
+ {
+ Binding binding = (Binding) iterator.next( );
+ if ( binding.getPortType( ).getQName( ).equals( portTypeQName ) )
+ {
+ return binding.getQName( );
+ }
+ }
+
+ return null;
+ }
+
private ResourceCapability[] getImportedResourceDefinitions( )
throws InvalidWsrfWsdlException
{
@@ -549,21 +581,6 @@
}
return importIsRedundant;
- }
-
- public Map getAllOperations()
- {
- Map opMap = new HashMap();
- List operations = m_portType.getOperations();
-
- for (int i = 0; i < operations.size(); i++)
- {
- Operation o = (Operation)operations.get(i);
- //does this work??
- OperationInfo opInfo = new OperationInfo(o, m_portType.getQName().getNamespaceURI());
- opMap.put(o.getName(), opInfo);
- }
- return opMap;
}
private void initCustomOperations( )
Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java?rev=326958&r1=326957&r2=326958&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java Thu Oct 20 10:50:00 2005
@@ -1,329 +1,361 @@
-/*=============================================================================*
- * 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.
- *=============================================================================*/
-package org.apache.ws.resource.impl;
-
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.rpc.handler.MessageContext;
-import javax.xml.rpc.handler.soap.SOAPMessageContext;
-import javax.xml.soap.SOAPMessage;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.ws.Soap1_1Constants;
-import org.apache.ws.addressing.handler.WSAddressingHandler;
-import org.apache.ws.resource.Resource;
-import org.apache.ws.resource.ResourceContext;
-import org.apache.ws.resource.ResourceException;
-import org.apache.ws.resource.ResourceHome;
-import org.apache.ws.resource.WsrfRuntime;
-import org.apache.ws.resource.faults.FaultException;
-import org.apache.ws.resource.i18n.Keys;
-import org.apache.ws.resource.i18n.MessagesImpl;
-import org.apache.ws.util.i18n.Messages;
-
-/**
- * An implementation of a resource context.
- */
-public class ResourceContextImpl
- implements ResourceContext
-{
- private static final Log LOG = LogFactory.getLog( ResourceContextImpl.class.getName() );
- private static final Messages MSG = MessagesImpl.getInstance();
- private SOAPMessage m_msg;
- private ResourceHome m_home;
- private String m_serviceName;
- private URL m_serviceURL;
- private Map m_propsMap = Collections.synchronizedMap( new HashMap() );
- private String m_action;
- private SOAPMessageContext m_msgContext;
-
- protected ResourceContextImpl() throws Exception
- {
- }
-
- /**
- * Creates a new {@link ResourceContextImpl} object.
- *
- * @param soapMsgContext SOAP message context corresponding to a particular request
- */
- public ResourceContextImpl( SOAPMessageContext soapMsgContext ) throws Exception
- {
- if ( soapMsgContext == null )
- {
- throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_SOAPMSGCTX ) );
- }
- m_msgContext = soapMsgContext;
- m_msg = soapMsgContext.getMessage();
- extractFields( soapMsgContext );
- lookupHome();
- }
-
- protected void lookupHome() throws Exception
- {
- m_home = WsrfRuntime.getRuntime().getResourceHome( getServiceName() );
- initializeResourceHome();
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param name DOCUMENT_ME
- * @param value DOCUMENT_ME
- */
- public void setProperty( String name,
- Object value )
- {
- m_propsMap.put( name, value );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param name DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public Object getProperty( String name )
- {
- return this.m_propsMap.get( name );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public Iterator getPropertyNames()
- {
- return this.m_propsMap.keySet().iterator();
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public String getRequestAction()
- {
- return m_action;
- }
-
- /**
- * @see org.apache.ws.resource.ResourceContext#getResource()
- */
- public Resource getResource()
- throws ResourceException
- {
- ResourceHome home = getResourceHome();
- Object id = home.extractResourceIdentifier( this );
- return home.find( id );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public ResourceHome getResourceHome()
- {
- return m_home;
- }
-
- /**
- * @see ResourceContext#setResponseAction(java.net.URI)
- */
- public void setResponseAction( URI action )
- {
- if ( action != null )
- {
- m_msgContext.setProperty( WSAddressingHandler.CONTEXT_PROP_WSA_RESPONSE_ACTION, action.toString() );
- }
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public SOAPMessage getSOAPMessage()
- {
- return m_msg;
- }
-
- /**
- * Returns target service name associated with this context.
- *
- * @return the target m_serviceName that was set with {@link #setServiceName(String) setService()}. If set to
- * <code>null</code> or not set at all, by default it returns the target service name associated with the
- * underlying SOAP message context.
- */
- public String getServiceName()
- {
- return m_serviceName;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public URL getServiceURL()
- {
- return m_serviceURL;
- }
-
- protected void setServiceURL(URL serviceURL)
- {
- m_serviceURL = serviceURL;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param name DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- public boolean containsProperty( String name )
- {
- return this.m_propsMap.containsKey( name );
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param name DOCUMENT_ME
- */
- public void removeProperty( String name )
- {
- this.m_propsMap.remove( name );
- }
-
- /**
- * Returns the value of the WS-Addressing Action header element.
- *
- * @param msgContext the context for the current SOAP request; must not be null
- *
- * @return
- */
- protected String getAddressingAction( SOAPMessageContext msgContext )
- {
- return WSAddressingHandler.getAddressingAction( msgContext );
- }
-
- /**
- * Sets the target m_serviceName of this context.
- *
- * @param serviceName m_serviceName name.
- */
- protected void setServiceName( String serviceName )
- {
- m_serviceName = serviceName;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param msgContext DOCUMENT_ME
- *
- * @return DOCUMENT_ME
- */
- protected String getServiceName( MessageContext msgContext )
- {
- URL serviceURL = ( m_serviceURL != null ) ? m_serviceURL : getServiceURL( (SOAPMessageContext) msgContext );
- String serviceName = serviceURL.toString();
- serviceName = serviceName.substring( serviceName.lastIndexOf( "/" ) + 1 );
- return serviceName;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param msgContext the context for the current SOAP request; must not be null
- *
- * @return DOCUMENT_ME
- */
- protected URL getServiceURL( SOAPMessageContext msgContext )
- {
- String addressingTo = WSAddressingHandler.getAddressingTo( msgContext );
- if ( addressingTo != null )
- {
- try
- {
- LOG.debug( MSG.getMessage( Keys.GET_SERVICE_URL_FROM_ADDR_HDR, addressingTo ) );
- return new URL( addressingTo );
- }
- catch ( MalformedURLException murle )
- {
- LOG.debug( MSG.getMessage( Keys.INVALID_WSA_TO, addressingTo ) );
- throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
- "The WS-Addressing destination specified in the SOAP header (i.e. wsa:To header element) is not a valid URI." );
- }
- }
- return null; // should an exception be thrown here instead of returning null?
- }
-
- protected String getBaseURL( URL serviceURL )
- {
- String s = serviceURL.toString();
- s = s.substring( 0,
- s.lastIndexOf( "/" ) );
- return s;
- }
-
- private void extractFields( SOAPMessageContext msgContext )
- {
- //extract the properties first so subclasses can look for platform specific props
- extractProperties( msgContext );
- m_action = getAddressingAction( msgContext );
- m_serviceURL = getServiceURL( msgContext );
- m_serviceName = getServiceName( msgContext );
- }
-
- private void initializeResourceHome()
- throws Exception
- {
- if ( m_home instanceof AbstractResourceHome )
- {
- AbstractResourceHome abstractResourceHome = ( (AbstractResourceHome) m_home );
- synchronized ( abstractResourceHome )
- {
- if ( !abstractResourceHome.isInitialized() )
- {
- abstractResourceHome.init();
- }
- }
- }
- }
-
- protected void extractProperties( MessageContext msgContext )
- {
- Iterator propertyNames = msgContext.getPropertyNames();
- while ( propertyNames.hasNext() )
- {
- String keyName = (String) propertyNames.next();
- m_propsMap.put( keyName,
- msgContext.getProperty( keyName ) );
- }
- }
-}
+/*=============================================================================*
+ * 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.
+ *=============================================================================*/
+package org.apache.ws.resource.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.Soap1_1Constants;
+import org.apache.ws.addressing.handler.WSAddressingHandler;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.ResourceContext;
+import org.apache.ws.resource.ResourceException;
+import org.apache.ws.resource.ResourceHome;
+import org.apache.ws.resource.WsrfRuntime;
+import org.apache.ws.resource.faults.FaultException;
+import org.apache.ws.resource.i18n.Keys;
+import org.apache.ws.resource.i18n.MessagesImpl;
+import org.apache.ws.util.i18n.Messages;
+import javax.xml.rpc.handler.MessageContext;
+import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.soap.SOAPMessage;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * An implementation of a resource context.
+ */
+public class ResourceContextImpl
+ implements ResourceContext
+{
+ private static final Log LOG = LogFactory.getLog( ResourceContextImpl.class.getName( ) );
+ private static final Messages MSG = MessagesImpl.getInstance( );
+ private SOAPMessage m_msg;
+ private ResourceHome m_home;
+ private String m_serviceName;
+ private URL m_serviceURL;
+ private Map m_propsMap = Collections.synchronizedMap( new HashMap( ) );
+ private String m_action;
+ private SOAPMessageContext m_msgContext;
+
+ /**
+ * Creates a new {@link ResourceContextImpl} object.
+ *
+ * @param soapMsgContext SOAP message context corresponding to a particular request
+ */
+ public ResourceContextImpl( SOAPMessageContext soapMsgContext )
+ throws Exception
+ {
+ if ( soapMsgContext == null )
+ {
+ throw new IllegalArgumentException( MSG.getMessage( Keys.NULL_SOAPMSGCTX ) );
+ }
+
+ m_msgContext = soapMsgContext;
+ m_msg = soapMsgContext.getMessage( );
+ extractFields( soapMsgContext );
+ lookupHome( );
+ }
+
+ /**
+ * Creates a new {@link ResourceContextImpl} object.
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ protected ResourceContextImpl( )
+ throws Exception
+ {
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ * @param value DOCUMENT_ME
+ */
+ public void setProperty( String name,
+ Object value )
+ {
+ m_propsMap.put( name, value );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Object getProperty( String name )
+ {
+ return this.m_propsMap.get( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Iterator getPropertyNames( )
+ {
+ return this.m_propsMap.keySet( ).iterator( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getRequestAction( )
+ {
+ return m_action;
+ }
+
+ /**
+ * @see org.apache.ws.resource.ResourceContext#getResource()
+ */
+ public Resource getResource( )
+ throws ResourceException
+ {
+ ResourceHome home = getResourceHome( );
+ Object id = home.extractResourceIdentifier( this );
+ return home.find( id );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public ResourceHome getResourceHome( )
+ {
+ return m_home;
+ }
+
+ /**
+ * @see ResourceContext#setResponseAction(java.net.URI)
+ */
+ public void setResponseAction( URI action )
+ {
+ if ( action != null )
+ {
+ m_msgContext.setProperty( WSAddressingHandler.CONTEXT_PROP_WSA_RESPONSE_ACTION,
+ action.toString( ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public SOAPMessage getSOAPMessage( )
+ {
+ return m_msg;
+ }
+
+ /**
+ * Returns target service name associated with this context.
+ *
+ * @return the target m_serviceName that was set with {@link #setServiceName(String) setService()}. If set to
+ * <code>null</code> or not set at all, by default it returns the target service name associated with the
+ * underlying SOAP message context.
+ */
+ public String getServiceName( )
+ {
+ return m_serviceName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public URL getServiceURL( )
+ {
+ return m_serviceURL;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean containsProperty( String name )
+ {
+ return this.m_propsMap.containsKey( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void removeProperty( String name )
+ {
+ this.m_propsMap.remove( name );
+ }
+
+ /**
+ * Returns the value of the WS-Addressing Action header element.
+ *
+ * @param msgContext the context for the current SOAP request; must not be null
+ *
+ * @return
+ */
+ protected String getAddressingAction( SOAPMessageContext msgContext )
+ {
+ return WSAddressingHandler.getAddressingAction( msgContext );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param serviceURL DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ protected String getBaseURL( URL serviceURL )
+ {
+ String s = serviceURL.toString( );
+ s = s.substring( 0,
+ s.lastIndexOf( "/" ) );
+ return s;
+ }
+
+ /**
+ * Sets the target m_serviceName of this context.
+ *
+ * @param serviceName m_serviceName name.
+ */
+ protected void setServiceName( String serviceName )
+ {
+ m_serviceName = serviceName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param msgContext DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ protected String getServiceName( MessageContext msgContext )
+ {
+ URL serviceURL =
+ ( m_serviceURL != null ) ? m_serviceURL : getServiceURL( (SOAPMessageContext) msgContext );
+ String serviceName = serviceURL.toString( );
+ serviceName = serviceName.substring( serviceName.lastIndexOf( "/" ) + 1 );
+ return serviceName;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param serviceURL DOCUMENT_ME
+ */
+ protected void setServiceURL( URL serviceURL )
+ {
+ m_serviceURL = serviceURL;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param msgContext the context for the current SOAP request; must not be null
+ *
+ * @return DOCUMENT_ME
+ */
+ protected URL getServiceURL( SOAPMessageContext msgContext )
+ {
+ String addressingTo = WSAddressingHandler.getAddressingTo( msgContext );
+ if ( addressingTo != null )
+ {
+ try
+ {
+ LOG.debug( MSG.getMessage( Keys.GET_SERVICE_URL_FROM_ADDR_HDR, addressingTo ) );
+ return new URL( addressingTo );
+ }
+ catch ( MalformedURLException murle )
+ {
+ LOG.debug( MSG.getMessage( Keys.INVALID_WSA_TO, addressingTo ) );
+ throw new FaultException( Soap1_1Constants.FAULT_CLIENT,
+ "The WS-Addressing destination specified in the SOAP header (i.e. wsa:To header element) is not a valid URI." );
+ }
+ }
+
+ return null; // should an exception be thrown here instead of returning null?
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param msgContext DOCUMENT_ME
+ */
+ protected void extractProperties( MessageContext msgContext )
+ {
+ Iterator propertyNames = msgContext.getPropertyNames( );
+ while ( propertyNames.hasNext( ) )
+ {
+ String keyName = (String) propertyNames.next( );
+ m_propsMap.put( keyName,
+ msgContext.getProperty( keyName ) );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ protected void lookupHome( )
+ throws Exception
+ {
+ m_home = WsrfRuntime.getRuntime( ).getResourceHome( getServiceName( ) );
+ initializeResourceHome( );
+ }
+
+ private void extractFields( SOAPMessageContext msgContext )
+ {
+ //extract the properties first so subclasses can look for platform specific props
+ extractProperties( msgContext );
+ m_action = getAddressingAction( msgContext );
+ m_serviceURL = getServiceURL( msgContext );
+ m_serviceName = getServiceName( msgContext );
+ }
+
+ private void initializeResourceHome( )
+ throws Exception
+ {
+ if ( m_home instanceof AbstractResourceHome )
+ {
+ AbstractResourceHome abstractResourceHome = ( (AbstractResourceHome) m_home );
+ synchronized ( abstractResourceHome )
+ {
+ if ( !abstractResourceHome.isInitialized( ) )
+ {
+ abstractResourceHome.init( );
+ }
+ }
+ }
+ }
+}
\ No newline at end of file