Author: agazzarini
Date: Sun Jan 18 22:56:14 2009
New Revision: 735621

URL: http://svn.apache.org/viewvc?rev=735621&view=rev
Log:
QPID-1578 : WS-Resources lifecycle improved adding "destroy" feature

Removed:
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/ICommand.java
Modified:
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java
    
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java
 Sun Jan 18 22:56:14 2009
@@ -62,6 +62,8 @@
        String QMAN_000027_WSDM_ADAPTER_STARTED = "<QMAN-000027> : WS-DM 
Adapter ready for incoming requests.";
        String QMAN_000028_TEST_MODULE_NOT_FOUND = "<QMAN-000028> : Qpid 
emulator not found. Test notifications are disabled.";
        String QMAN_000029_DEFAULT_URI = "<QMAN-000029> : Default URI will be 
set to %s";
+       String QMAN_000030_RESOURCE_HAS_BEEN_CREATED =  "<QMAN-000030> : New 
resource instance has been created and registered. Resource id is %s";
+       String QMAN_000031_RESOURCE_HAS_BEEN_REMOVED = "<QMAN-200031> : 
WS-Resource %s has been removed";
                
         // DEBUG
        String QMAN_200001_INCOMING_MESSAGE_HAS_BEEN_RECEIVED = "<QMAN-200001> 
: New incoming message has been received. Message content is %s";
@@ -105,14 +107,15 @@
        String QMAN_200039_DEBUG_JMX_NOTIFICATION = "<QMAN-200039> : %s";
        String QMAN_200040_WS_ARTIFACTS_CACHED = "<QMAN-200040> : WS Artifacts 
has been stored on cache with the following id : %s";
        String QMAN_200041_INCOMING_OBJECT_NAME_AND_DERIVED_KEY = 
"<QMAN-200041> : Incoming object name : %s, derived search key : %s";
-       
-       
+       String QMAN_200042_REMOVING_RESOURCE = "<QMAN-200042> : WS-Resource %s 
is going to be removed";
        
        // WARNING
     String QMAN_300001_MESSAGE_DISCARDED = "<QMAN-300001> : No handler has 
been configured for processing messages with \"%s\" as opcode. Message will be 
discarded.";
        String QMAN_300002_UNKNOWN_SEQUENCE_NUMBER = "<QMAN-300002> : Unable to 
deal with incoming message because it contains a unknown sequence number (%s).";
     String QMAN_300003_BROKER_ALREADY_CONNECTED = "<QMAN-300003> : Unable to 
enlist given broker connection data : QMan is already connected with broker %s";
     String QMAN_300004_INVALID_CONFIGURATION_FILE = "<QMAN-300004> : The given 
configuration file (%s) is not valid (it doesn't exist or cannot be read)";
+    
+    String QMAN_300005_QEMU_INITIALIZATION_FAILURE = "<QMAN-300005> : Unable 
to initialize QEmu module and therefore emulation won't be enabled...";
        
        // ERROR
        String QMAN_100001_BAD_MAGIC_NUMBER_FAILURE = "<QMAN-100001> : Message 
processing failure : incoming message contains a bad magic number (%s) and 
therefore will be discaded.";
@@ -138,5 +141,13 @@
        String QMAN_100023_BUILD_WS_ARTIFACTS_FAILURE = "<QMAN-100023> : Unable 
to build WS artifacts.";
        String QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE = "<QMAN-100024> : 
Unable to instantiate generated capability class for %s.";
        String QMAN_100025_WSRF_FAILURE = "<QMAN-100025> : Resource manager 
raised an exception while creating capability for %s.";     
-       String QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE = "<QMAN-100026> : 
Exception occurred while replacing the placeholder soap address with resource 
actual location.";         
+       String QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE = "<QMAN-100026> : 
Exception occurred while replacing the placeholder soap address with resource 
actual location.";
+       
+       //// NEW 
+       String QMAN_100027_RESOURCE_SHUTDOWN_FAILURE = "<QMAN-100027> : 
Shutdown failure while destroying resource %s.";
+       String QMAN_100029_MALFORMED_RESOURCE_URI_FAILURE = "<QMAN-100029> : 
Unable to define URI for QMan resources using \"%s\". It violates RFC 2396";
+       String QMAN_100030_JMX_CORE_STARTUP_FAILURE = "<QMAN-100030> : QMan JMX 
core Unexpected failure while starting up.";
+       String QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED = "<QMAN-100032> : 
Bad request has been received on this WS-Resource : Initialization is not 
possible because the resource has already been initialized.";
+       String QMAN_100032_WS_RESOURCE_NOT_YET_INITIALIZED = "<QMAN-100032> : 
Bad request has been received on this WS-Resource : Shutdown is not possible 
because the resource hasn't yet been initialized.";
+       String QMAN_100033_WS_RESOURCE_ALREADY_SHUTDOWN = "<QMAN-100033> : Bad 
request has been received on this WS-Resource : Shutdown is not possible 
because the resource has already been shutdown.";
 }
\ No newline at end of file

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/Names.java
 Sun Jan 18 22:56:14 2009
@@ -45,7 +45,7 @@
     public static String PACKAGE = "package";
     public static String CLASS = "class";
     public static String EVENT = "event";
-    public static String OBJECT_ID="objectID";    
+    public static String OBJECT_ID="objectId";    
     public static String BROKER_ID = "brokerID";
     public static String DOMAIN_NAME = "Q-MAN";
         
@@ -61,12 +61,34 @@
     
     public static String NOT_AVAILABLE = "N.A.";
     
+    public static ObjectName QPID_EMULATOR_OBJECT_NAME;
+    static 
+    {
+           try 
+           {
+               QPID_EMULATOR_OBJECT_NAME = new ObjectName(
+                               new StringBuilder()
+                                       .append(DOMAIN_NAME)
+                                       .append(':')
+                                       .append("Name=Qpid,Type=Emulator")
+                                       .toString());
+           } catch(Exception exception)
+           {
+               throw new ExceptionInInitializerError(exception);
+           }
+    }    
+    
     public static ObjectName QMAN_OBJECT_NAME;
     static 
     {
            try 
            {
-               QMAN_OBJECT_NAME = new ObjectName(new 
StringBuilder().append(DOMAIN_NAME).append(':').append("Type=Service").toString());
+               QMAN_OBJECT_NAME = new ObjectName(
+                               new StringBuilder()
+                                       .append(DOMAIN_NAME)
+                                       .append(':')
+                                       .append("Type=Service")
+                                       .toString());
            } catch(Exception exception)
            {
                throw new ExceptionInInitializerError(exception);
@@ -75,8 +97,13 @@
     
     // WSDM Stuff
     public static String NAMESPACE_URI = 
"http://amqp.apache.org/qpid/management/qman";;
+    public static String ADDRESSING_URI = 
"http://amqp.apache.org/qpid/management/qman/addressing";;
+    public static String ADDRESSING_PREFIX = "qman-wsa";
+    
+    public static final QName RESOURCE_ID_QNAME = new QName(ADDRESSING_URI, 
"ResourceId", ADDRESSING_PREFIX);   
        public final static String PREFIX = "qman";
        public final static String QMAN_RESOURCE_NAME = "QManWsResource";
+       
     public final static String VALIDATE_WSRP_PARAM = "validate-wsrp-schema";
 
     public static final String WEB_APP_CLASSES_FOLDER = "/WEB-INF/classes";

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/jmx/EntityLifecycleNotification.java
 Sun Jan 18 22:56:14 2009
@@ -46,8 +46,8 @@
        public static final String SCHEMA_REQUESTED = 
"org.apache.qpid.management.lifecycle.entity.schema.requested";
        public static final String MALFORMED_SCHEMA = 
"org.apache.qpid.management.lifecycle.error.schema";
        
-       public static final String INSTANCE_ADDED = 
"org.apache.qpid.management.lifecycle.entity.instance.created";
-       public static final String INSTANCE_REMOVED = 
"org.apache.qpid.management.lifecycle.entity.instance.removed";
+       public static final String INSTANCE_ADDED = 
"qman.lifecycle.entity.instance.created";
+       public static final String INSTANCE_REMOVED = 
"qman.lifecycle.entity.instance.removed";
        
        private String _packageName = Names.NOT_AVAILABLE;
        private String _className = Names.NOT_AVAILABLE;

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/ConnectQManToBroker.java
 Sun Jan 18 22:56:14 2009
@@ -69,6 +69,14 @@
                }
        }
        
+       /**
+        * This is a startup module only so an override of the default servlet 
+        * behaviour must be done in order to prevent incoming http requests 
processing.
+        * 
+        * @param request the http request.
+        * @param response the http response.
+        * @throws ServletException each time this method is called.
+        */
        @Override
        public void service(HttpServletRequest request, HttpServletResponse 
response) throws ServletException
        {

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/QManLifeCycleManager.java
 Sun Jan 18 22:56:14 2009
@@ -24,34 +24,24 @@
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
+import org.apache.qpid.management.Messages;
 import org.apache.qpid.management.Names;
 import org.apache.qpid.management.domain.services.QMan;
 import org.apache.qpid.management.domain.services.StartupFailureException;
+import org.apache.qpid.transport.util.Logger;
 
 /**
- * QMan lifecycle management.
+ * QMan JMX lifecycle manager.
+ * Provides lifecycle management of QMan JMX core including startup and 
shutdown. 
  * 
  * @author Andrea Gazzarini
  */
 public class QManLifeCycleManager implements ServletContextListener 
 {
+       private final static Logger LOGGER = 
Logger.get(QManLifeCycleManager.class);
+       
        /**
-        * Stops QMan.
-        * 
-        * @param event the application context event.
-        */
-       public void contextDestroyed(ServletContextEvent event) 
-       {
-               ServletContext context = event.getServletContext();
-               
-               QMan qman = (QMan) 
context.getAttribute(Names.APPLICATION_NAME);                
-               qman.stop();
-               
-               context.setAttribute(Names.APPLICATION_NAME, qman);
-       }
-
-       /**
-        * Starts QMan.
+        * Starts QMan JMX Core.
         * 
         * @param event the application context event.
         */
@@ -61,12 +51,29 @@
                {
                        QMan qman = new QMan();
                        qman.start();
-
-                       
event.getServletContext().setAttribute(Names.APPLICATION_NAME, qman);
+                       event.getServletContext().setAttribute(
+                                       Names.APPLICATION_NAME, 
+                                       qman);
                } catch (StartupFailureException exception) 
                {
-                       // TODO : LOG ERROR.
-                       exception.printStackTrace();
+                       LOGGER.error(
+                                       exception, 
+                                       
Messages.QMAN_100030_JMX_CORE_STARTUP_FAILURE);
                }
        }
+       
+       /**
+        * Sutdown QMan JMX Core.
+        * 
+        * @param event the application context event.
+        */
+       public void contextDestroyed(ServletContextEvent event) 
+       {
+               ServletContext context = event.getServletContext();
+               
+               QMan qman = (QMan) 
context.getAttribute(Names.APPLICATION_NAME);                
+               qman.stop();
+               
+               context.removeAttribute(Names.APPLICATION_NAME);
+       }       
 }
\ No newline at end of file

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/servlet/WSDMAdapter.java
 Sun Jan 18 22:56:14 2009
@@ -51,9 +51,15 @@
        
        @Override
        public void init() throws ServletException {
-               _isolationLayer = new 
WSDMAdapterIsolationLayer(getServletContext());
+        LOGGER.debug(Messages.QMAN_000026_WSDM_ADAPTER_STARTS);
+        
+        
+        _isolationLayer = new WSDMAdapterIsolationLayer(getServletContext());
         _isolationLayer.initialize();
-       }
+        
+        LOGGER.debug(Messages.QMAN_000027_WSDM_ADAPTER_STARTED);
+        
+       }
        
        /**
         * Accepts http requests containing a soap envelope (request) and 
therefore
@@ -92,23 +98,11 @@
                        writer.flush(); 
                        
                        XmlDebugger.debug(soapEnvelopeRequest);
-                       XmlDebugger.debug(soapEnvelopeResposeAsString);
-               }
-       }
-
-       /**
-        * Stops QMan Adapter.
-        */
-       public void destroy() 
-       {
-               try 
-               {
-                       _isolationLayer.shutdown();
-               } catch (Exception exception) 
-               {
-                       LOGGER.error(
-                                       exception, 
-                                       
Messages.QMAN_100022_ISOLATION_LAYER_SHUTDOWN_FAILURE);
+                       try {
+                               XmlDebugger.debug(soapEnvelopeResposeAsString);
+                       } catch(Exception exception) {
+                               System.out.println("Unable to parse response.");
+                       }
                }
        }
 }
\ No newline at end of file

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapability.java
 Sun Jan 18 22:56:14 2009
@@ -160,13 +160,12 @@
         * 
         * @param name
         * @param value
-        * TODO TODO TODO!!! Vedi che poi fà co 'sto metodo che è un pò una 
monnezza!!!
+        * TODO : Vedi che poi fà co 'sto metodo che è un pò una monnezza!!!
         * @return The XML representation of the resource property value(s).
         * 
         */
        @SuppressWarnings("unchecked")
-       protected Element[] getPropertyElements(QName name, Object value)
-                       throws BaseFault {
+       protected Element[] getPropertyElements(QName name, Object value) 
throws BaseFault {
                //
                // in this case, we have to determine if there IS a property
                // and it's null, or there is no property
@@ -226,19 +225,20 @@
                Serializer ser = registry.getSerializer(type);
 
                for (int n = 0; n < length; ++n)
+               {
                        properties[n] = serializeValue(ser, 
Array.get(valuesArray, n), name);
-
+               }
                return properties;
        }
 
        private Element serializeValue(Serializer ser, Object value, QName 
name) throws BaseFault 
        {
-               try {
+               try 
+               {
                        return ser.toXML(value, name);
-               }
-
-               catch (SoapFault error) {
-                       throw WsbfUtils.convertToFault(error);
+               } catch (SoapFault exception) 
+               {
+                       throw WsbfUtils.convertToFault(exception);
                }
        }
 }
\ No newline at end of file

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/MBeanCapabilityBuilder.java
 Sun Jan 18 22:56:14 2009
@@ -101,7 +101,6 @@
                        }               
                } catch(Exception exception)
                {
-                       System.err.println(buffer);
                        throw new BuilderException(exception);
                }
        }
@@ -133,7 +132,7 @@
        
        public void onOperation(MBeanOperationInfo operation) 
        {
-               // TODO
+               // TODO : operation on mbean capability
        }
 
        public Class<MBeanCapability> getCapabilityClass() 
@@ -157,7 +156,6 @@
                        _capabilityClassDefinition.addMethod(getPropertyNames);
                } catch(Exception exception) 
                { 
-                       System.err.println(_properties);
                        throw new BuilderException(exception);
                }
        }
@@ -167,7 +165,10 @@
        {
                try 
                {
-                       _capabilityClass = _capabilityClassDefinition.toClass();
+                       // Class loader and protection domain are needed for 
Qpid emulation.
+                       _capabilityClass = _capabilityClassDefinition.toClass(
+                                       
QManAdapterCapability.class.getClassLoader(),
+                                       
QManAdapterCapability.class.getProtectionDomain());
                } catch (Exception exception) 
                {
                        throw new BuilderException(exception);

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java
 Sun Jan 18 22:56:14 2009
@@ -21,11 +21,12 @@
 package org.apache.qpid.management.wsdm.capabilities;
 
 import java.lang.management.ManagementFactory;
+import java.net.URI;
 
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.Notification;
-import javax.management.NotificationFilterSupport;
+import javax.management.NotificationFilter;
 import javax.management.NotificationListener;
 import javax.management.ObjectName;
 
@@ -33,35 +34,51 @@
 import org.apache.muse.core.Resource;
 import org.apache.muse.core.ResourceManager;
 import org.apache.muse.core.serializer.SerializerRegistry;
+import org.apache.muse.ws.addressing.EndpointReference;
 import org.apache.muse.ws.addressing.soap.SoapFault;
 import org.apache.qpid.management.Messages;
 import org.apache.qpid.management.Names;
 import org.apache.qpid.management.jmx.EntityLifecycleNotification;
 import org.apache.qpid.management.wsdm.common.ThreadSessionManager;
+import org.apache.qpid.management.wsdm.muse.engine.WSDMAdapterEnvironment;
 import org.apache.qpid.management.wsdm.muse.serializer.ByteArraySerializer;
 import org.apache.qpid.transport.util.Logger;
 
 /**
- * MBean Server capabilty interface implementor.
- * Providers all the operations of the MBeanServer interface using the 
platform MBeanServer.
+ * QMan Adapter capability.
+ * Basically it acts as a lifecycle manager of all ws resource that correspond 
to entities on JMX side.
+ * 
+ * @author Andrea Gazzarini
 */
 public class QManAdapterCapability extends AbstractCapability
 {      
-       private MBeanServer _mxServer;
        private final static Logger LOGGER = 
Logger.get(QManAdapterCapability.class);
-       
+
+       private MBeanServer _mxServer;
        private WsArtifactsFactory _artifactsFactory; 
+       private URI _resourceURI;
        
+       /**
+        * This listener handles "create" mbean events and therefore provides 
procedure to create and initialize
+        * corresponding ws resources.
+        */
        private final NotificationListener listenerForNewInstances = new 
NotificationListener() 
        {
+               /**
+                * Handles JMX "create" notification type.
+                * 
+                * @param notification the entity lifecycle notification.
+                * @param data user data associated with the incoming 
notifiication : it is not used at the moment.
+                */
                public void handleNotification(Notification notification, 
Object data) 
                {
-                       EntityLifecycleNotification lifecycleNotification = 
(EntityLifecycleNotification) notification;
-                       ObjectName eventSourceName = 
lifecycleNotification.getObjectName();
-                       
ThreadSessionManager.getInstance().getSession().setObjectName(eventSourceName);
-                       
+                       ObjectName eventSourceName = null;
                        try 
-                       {
+                       {                               
+                               EntityLifecycleNotification 
lifecycleNotification = (EntityLifecycleNotification) notification;
+                               eventSourceName = 
lifecycleNotification.getObjectName();
+                               
ThreadSessionManager.getInstance().getSession().setObjectName(eventSourceName);
+                       
                                
LOGGER.debug(Messages.QMAN_200039_DEBUG_JMX_NOTIFICATION, notification);
 
                                ResourceManager resourceManager = 
getResource().getResourceManager();
@@ -72,42 +89,91 @@
                                                artifacts.getCapabilityClass(), 
                                                eventSourceName);
                                
-                               
                                
ThreadSessionManager.getInstance().getSession().setWsdlDocument(artifacts.getWsdl());
                                
ThreadSessionManager.getInstance().getSession().setResourceMetadataDescriptor(artifacts.getResourceMetadataDescriptor());
                                
-//                             ResourceManager resourceManager = 
getResource().getResourceManager();
-//                             
-//                             Resource resource = 
resourceManager.createResource(Names.QMAN_RESOURCE_NAME);
-//                             
resource.setWsdlPortType(Names.QMAN_RESOURCE_PORT_TYPE_NAME);
+                               
resource.setWsdlPortType(Names.QMAN_RESOURCE_PORT_TYPE_NAME);
+                               
capability.setCapabilityURI(Names.NAMESPACE_URI+"/"+capability.getClass().getSimpleName());
                                resource.addCapability(capability);
                                resource.initialize();
                                
resourceManager.addResource(resource.getEndpointReference(), resource);
+                               
+                               LOGGER.info(
+                                               
Messages.QMAN_000030_RESOURCE_HAS_BEEN_CREATED,
+                                               eventSourceName);
                        } catch (ArtifactsNotAvailableException exception) 
                        {
-                               
LOGGER.error(exception,Messages.QMAN_100023_BUILD_WS_ARTIFACTS_FAILURE);
+                               LOGGER.error(
+                                               exception,
+                                               
Messages.QMAN_100023_BUILD_WS_ARTIFACTS_FAILURE);
                        } catch (IllegalAccessException exception) 
                        {
-                               
LOGGER.error(exception,Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE,eventSourceName);
+                               LOGGER.error(
+                                               exception,
+                                               
Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE,
+                                               eventSourceName);
                        } catch (InstantiationException exception) 
                        {
-                               
LOGGER.error(exception,Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE,eventSourceName);
+                               LOGGER.error(
+                                               exception,
+                                               
Messages.QMAN_100024_CAPABILITY_INSTANTIATION_FAILURE,
+                                               eventSourceName);
                        } catch (SoapFault exception) 
                        {
-                               
LOGGER.error(exception,Messages.QMAN_100025_WSRF_FAILURE,eventSourceName);      
+                               LOGGER.error(
+                                               
exception,Messages.QMAN_100025_WSRF_FAILURE,
+                                               eventSourceName);       
                        } catch (Exception exception) 
                        {
-                               
LOGGER.error(exception,Messages.QMAN_100025_WSRF_FAILURE,eventSourceName);      
+                               LOGGER.error(
+                                               exception,
+                                               
Messages.QMAN_100025_WSRF_FAILURE,
+                                               eventSourceName);       
                        } 
-
                }
        };
        
+       /**
+        * This listener handles "remove" mbean events and therefore provides 
procedure to shutdown and remove
+        * corresponding ws resources.
+        */
        private final NotificationListener listenerForRemovedInstances = new 
NotificationListener() 
        {
+               /**
+                * Handles JMX "remove" notification type.
+                * 
+                * @param notification the entity lifecycle notification.
+                * @param data user data associated with the incoming 
notifiication : it is not used at the moment.
+                */
                public void handleNotification(Notification notification, 
Object data) 
                {
-                       LOGGER.warn("TBD : Notification Listener for removed 
instances has not yet implemeted!");
+                       EntityLifecycleNotification lifecycleNotification = 
(EntityLifecycleNotification) notification;
+                       ObjectName eventSourceName = 
lifecycleNotification.getObjectName();
+
+                       LOGGER.debug(Messages.QMAN_200042_REMOVING_RESOURCE, 
eventSourceName);
+
+                       EndpointReference endpointPointReference = new 
EndpointReference(_resourceURI);                 
+                       endpointPointReference.addParameter(
+                                       Names.RESOURCE_ID_QNAME, 
+                                       eventSourceName.getCanonicalName());
+                       
+                       ResourceManager resourceManager = 
getResource().getResourceManager();
+                       try 
+                       {
+                               Resource resource = 
resourceManager.getResource(endpointPointReference);
+                               resource.shutdown();
+                               
+                               LOGGER.info(
+                                               
Messages.QMAN_000031_RESOURCE_HAS_BEEN_REMOVED, 
+                                               eventSourceName);
+                       }
+                       catch(Exception exception) 
+                       {
+                               LOGGER.error(
+                                               exception, 
+                                               
Messages.QMAN_100027_RESOURCE_SHUTDOWN_FAILURE, 
+                                               eventSourceName);
+                       }
                }
        };      
                        
@@ -120,24 +186,71 @@
                // What is the stringified name of the class? 
byte[].getClass().getName() is [B but is not working (ClassNotFound).
                // So, at the end, this is hard-coded here!
                
SerializerRegistry.getInstance().registerSerializer(byte[].class, new 
ByteArraySerializer());
-               
+               WSDMAdapterEnvironment environment = (WSDMAdapterEnvironment) 
getEnvironment();
+               String resourceURI = 
environment.getDefaultURIPrefix()+Names.QMAN_RESOURCE_NAME;
                try 
                {
+                       _resourceURI = URI.create(resourceURI);
+                       
                        _mxServer = ManagementFactory.getPlatformMBeanServer();
                        _artifactsFactory = new 
WsArtifactsFactory(getEnvironment(),_mxServer);
                        
-                       NotificationFilterSupport filterForNewInstances = new 
NotificationFilterSupport();
-                       
filterForNewInstances.enableType(EntityLifecycleNotification.INSTANCE_ADDED);
-                       
-                       NotificationFilterSupport filterForRemovedInstances = 
new NotificationFilterSupport();
-                       
filterForNewInstances.enableType(EntityLifecycleNotification.INSTANCE_REMOVED);
+                       /**
+                        * NotificationFilter for "create" only events.
+                        */
+                       NotificationFilter filterForNewInstances = new 
NotificationFilter(){
+
+                               private static final long serialVersionUID = 
1733325390964454595L;
+
+                               public boolean 
isNotificationEnabled(Notification notification)
+                               {
+                                       return 
EntityLifecycleNotification.INSTANCE_ADDED.equals(notification.getType());
+                               }
+                               
+                       };
+
+                       /**
+                        * NotificationFilter for "remove" only events.
+                        */
+                       NotificationFilter filterForRemovedInstances = new 
NotificationFilter(){
+
+                               private static final long serialVersionUID = 
1733325390964454595L;
+
+                               public boolean 
isNotificationEnabled(Notification notification)
+                               {
+                                       return 
EntityLifecycleNotification.INSTANCE_REMOVED.equals(notification.getType());
+                               }
+                               
+                       };
                        
-                       
_mxServer.addNotificationListener(Names.QMAN_OBJECT_NAME, 
listenerForNewInstances, filterForNewInstances, null);
-                       
_mxServer.addNotificationListener(Names.QMAN_OBJECT_NAME, 
listenerForRemovedInstances, filterForRemovedInstances, null);
+                       _mxServer.addNotificationListener(
+                                       Names.QMAN_OBJECT_NAME, 
+                                       listenerForNewInstances, 
+                                       filterForNewInstances, 
+                                       null);
+                       
+                       _mxServer.addNotificationListener(
+                                       Names.QMAN_OBJECT_NAME, 
+                                       listenerForRemovedInstances, 
+                                       filterForRemovedInstances, 
+                                       null);
 
                        try {
-                               _mxServer.addNotificationListener(new 
ObjectName("A:A=1"), listenerForNewInstances, filterForNewInstances, null);
-                       } catch (Exception exception) {
+                               _mxServer.addNotificationListener(
+                                               
Names.QPID_EMULATOR_OBJECT_NAME, 
+                                               listenerForNewInstances, 
+                                               filterForNewInstances, null);
+
+                               _mxServer.addNotificationListener(
+                                               
Names.QPID_EMULATOR_OBJECT_NAME, 
+                                               listenerForRemovedInstances, 
+                                               filterForRemovedInstances, 
null);
+
+                       } catch(IllegalArgumentException exception)
+                       {
+                               
LOGGER.info(exception,Messages.QMAN_000029_DEFAULT_URI,resourceURI);            
                
+                       }
+                       catch (Exception exception) {
                                
LOGGER.info(Messages.QMAN_000028_TEST_MODULE_NOT_FOUND);
                        } 
                        

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/WsdlBuilder.java
 Sun Jan 18 22:56:14 2009
@@ -155,17 +155,17 @@
        
        public void onOperation(MBeanOperationInfo operation) 
        {
-               // TODO
+               // TODO : Operations on wsdl
        }
 
        public void endAttributes() 
        {
-               // TODO
+               // N.A.
        }
 
        public void endOperations() 
        {
-               // TODO
+               // N.A.
        }
 
        public Document getWsdl() 
@@ -184,9 +184,10 @@
                _document = WsdlUtils.createWSDL(_environment, wsdlPath, true);
                try 
                {
-                       Attr location = (Attr) 
XPathAPI.selectSingleNode(_document, 
"/wsdl:definitions/wsdl:service/wsdl:port/wsdl-soap:address/@location");
+                       Attr location = (Attr) XPathAPI.selectSingleNode(
+                                       _document, 
+                                       
"/wsdl:definitions/wsdl:service/wsdl:port/wsdl-soap:address/@location");
                                        
-                       // TODO : come faccio a recuperare l'URL sul quale gira 
l'applicazione?
                        StringBuilder builder = new StringBuilder("http://";)
                                
.append(InetAddress.getLocalHost().getHostName())
                                .append(':')
@@ -198,7 +199,9 @@
                        location.setValue(builder.toString());
                } catch(Exception exception)
                {
-                       
LOGGER.error(exception,Messages.QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE);
+                       LOGGER.error(
+                                       exception,
+                                       
Messages.QMAN_100026_SOAP_ADDRESS_REPLACEMENT_FAILURE);
                }
        }
 }

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java
 Sun Jan 18 22:56:14 2009
@@ -23,19 +23,26 @@
 import javax.xml.namespace.QName;
 
 import org.apache.muse.core.routing.ResourceIdFactory;
-import org.apache.muse.ws.addressing.WsaConstants;
+import org.apache.qpid.management.Names;
 
 /**
  * ResourceIdFactory implementation that is using an objectName as 
  * resource identifier.
+ * This is done in order to make a relationship between an MBean (which is 
part of the
+ * JMX core domain model) and a WS-Resource (the same entity as is represented 
on WS-DM adapter side).
  * 
  * @author Andrea Gazzarini
  */
 public class ObjectNameIdFactory implements ResourceIdFactory 
 {
+       /**
+        * Returns the name of the identifier element.
+        * 
+        *  @return the name of the identifier element.
+        */
        public QName getIdentifierName() 
        {
-               return WsaConstants.DEFAULT_RESOURCE_ID_QNAME;
+               return Names.RESOURCE_ID_QNAME;
     }
 
        /**

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/engine/WSDMAdapterEnvironment.java
 Sun Jan 18 22:56:14 2009
@@ -23,7 +23,8 @@
 {
        private final static Logger LOGGER = 
Logger.get(WSDMAdapterEnvironment.class);
        private final File _realDirectory;
-    
+    private final ServletContext _servletContext;
+       
     /**
      * Builds a new qman environment with the given application context.
      *  
@@ -31,32 +32,17 @@
      */
     public WSDMAdapterEnvironment(ServletContext servletContext)
     {
-        String realDirectoryPath = 
servletContext.getRealPath(Names.WEB_APP_CLASSES_FOLDER);
+       this._servletContext = servletContext;
+       String realDirectoryPath = 
servletContext.getRealPath(Names.WEB_APP_CLASSES_FOLDER);
         
         _realDirectory = (realDirectoryPath != null) 
                ? new File(realDirectoryPath) 
                : FileUtils.CURRENT_DIR;
-
-        String host = null;
-   
-        try {
-                       host = InetAddress.getLocalHost().getHostName();
-               } catch (UnknownHostException e) {
-                       host = "localhost";
-               }
                
-        String defaultURI = new StringBuilder()
-               .append("http://";)
-               .append(host)
-               .append(":")
-               .append(System.getProperty(Names.ADAPTER_PORT))
-               .append(servletContext.getContextPath())
-               .append("/services/adapter")
-               .toString();
+        String defaultURI = getDefaultURIPrefix()+"adapter";
+        setDefaultURI(defaultURI);
         
         LOGGER.info(Messages.QMAN_000029_DEFAULT_URI, defaultURI);
-        
-        setDefaultURI(defaultURI);
     }
     
     /**
@@ -78,4 +64,23 @@
     {
         return _realDirectory;
     }
+    
+    public String getDefaultURIPrefix()
+    {
+       String host = null;
+         try {
+                       host = InetAddress.getLocalHost().getHostName();
+               } catch (UnknownHostException e) {
+                       host = "localhost";
+               }
+               
+        return new StringBuilder()
+               .append("http://";)
+               .append(host)
+               .append(":")
+               .append(System.getProperty(Names.ADAPTER_PORT))
+               .append(_servletContext.getContextPath())
+               .append("/services/")
+               .toString();            
+    }
 }
\ No newline at end of file

Modified: 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java?rev=735621&r1=735620&r2=735621&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java
 (original)
+++ 
qpid/trunk/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/muse/resources/QManWsResource.java
 Sun Jan 18 22:56:14 2009
@@ -52,7 +52,6 @@
 import 
org.apache.muse.ws.resource.properties.schema.impl.SimpleResourcePropertiesSchema;
 import org.apache.muse.ws.wsdl.WsdlUtils;
 import org.apache.qpid.management.Messages;
-import org.apache.qpid.management.Names;
 import org.apache.qpid.management.wsdm.common.ThreadSessionManager;
 import org.apache.qpid.transport.util.Logger;
 import org.w3c.dom.Document;
@@ -60,26 +59,215 @@
 
 /**
  * QMan WS resource.
- * This is the WS Resource wrapper of a QMan managed entity.
+ * We could say that this is a QMan manageable entity under the 
+ * WS-DM perspective.
  * 
  * @author Andrea Gazzarini
- * TODO :Refactoring :: use STATE Pattern!
  */
 @SuppressWarnings("unchecked")
 public class QManWsResource implements WsResource
 {    
        private final static Logger LOGGER = Logger.get(QManWsResource.class);
+               
+       /**
+        * Internal state of this resource.
+        * 
+        * @author Andrea Gazzarini
+        */
+       interface State 
+       {
+               /**
+                * Provides initialization of this resource.
+                * 
+                * @throws SoapFault when the initialization fails.
+                */
+               void initialize() throws SoapFault;
+               
+               /**
+                * Returns true if this resource has been initialized.
+                * 
+                * @return true if this resource has been initialized.
+                */
+               boolean hasBeenInitialized();
+               
+               /**
+                * Returns true if this resource has been shutdown.
+                * 
+                * @return true if this resource has been shutdown.
+                */
+               boolean hasBeenShutdown();
+               
+               /**
+                * Shuts down this resource.
+                * 
+                * @throws SoapFault when the shutdown procedure fails.
+                */
+               void shutdown() throws SoapFault;               
+       }
        
-       // Utility class for logging.
-       private final static class Log {
-               static void debugElement(String message,Element element) 
+       private final State _hasBeenShutdown = new State()
+       {
+               /**
+                * Return false because this resource has been shutdown so 
therefore 
+                * initialization occurred.
+                * 
+                * @return true;
+                */
+               public boolean hasBeenInitialized()
                {
-                       if (LOGGER.isDebugEnabled())
-                       {
-                               LOGGER.debug(message, 
XmlUtils.toString(element));
-                       }
+                       return true;
                }
-       }
+
+               /**
+                * Returns true because this state indicates that resource has 
been shutdown.
+                * 
+                * @return true.
+                */
+               public boolean hasBeenShutdown()
+               {
+                       return true;
+               }
+
+               /**
+                * Since this resource has been shutdown the initialization
+                * cannot be performed again.
+                * As conseguence of that this method throws an exception.
+                * 
+                * @throws SoapFault each time this method is called.
+                */
+               public void initialize() throws SoapFault
+               {
+                       
LOGGER.error(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED);
+                       throw new 
SoapFault(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED);
+               }
+
+               public void shutdown() throws SoapFault
+               {
+                       
LOGGER.error(Messages.QMAN_100033_WS_RESOURCE_ALREADY_SHUTDOWN);
+                       throw new 
SoapFault(Messages.QMAN_100033_WS_RESOURCE_ALREADY_SHUTDOWN);                 
+               }
+       };
+       
+       private final State _hasBeenInitialized = new State()
+       {
+               /**
+                * Returns true because this is the state where a resource is 
when it 
+                * has been initialized.
+                * 
+                * @return true.
+                */
+               public boolean hasBeenInitialized()
+               {
+                       return true;
+               }
+
+               /**
+                * Returns false because this resource has been initialized but 
no shutdown request
+                * has been received.
+                * 
+                * @return false.
+                */
+               public boolean hasBeenShutdown()
+               {
+                       return false;
+               }
+
+               /**
+                * A resource in this state cannot be initialized again so if 
this method is called an
+                * exception is thrown.
+                * 
+                * @throws SoapFault each time this method is called.
+                */
+               public void initialize() throws SoapFault
+               {
+                       
LOGGER.error(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED);
+                       throw new 
SoapFault(Messages.QMAN_100031_WS_RESOURCE_ALREADY_INITIALIZED);
+               }
+               
+               /**
+                * Shuts down this resource.
+                * 
+                * @throws SoapFault when the shutdown procedure fails.
+                */
+               public void shutdown() throws SoapFault 
+               {
+               shutdownCapabilities();
+            
+               ResourceManager manager = getResourceManager();
+               
+               if (manager.getResource(_enpointReference) != null)
+               {
+                   manager.removeResource(_enpointReference);
+               }
+               
+               _currentState = _hasBeenShutdown;
+               }               
+       };
+       
+       /**
+        * The initial state of this resource.
+        * As the name suggests, it is not yet initialized.
+        */
+       private final State _notYetInitialized = new State() 
+       {
+               /**
+                * Provides initialization of this resource.
+                * 
+                * @throws SoapFault when the initialization fails.
+                */
+               public void initialize() throws SoapFault
+               {
+               _properties = new SimpleResourcePropertyCollection();
+               _wsdl = 
ThreadSessionManager.getInstance().getSession().getWsdlDocument();
+               
+               ResourcePropertiesSchema schema = createPropertiesSchema(_wsdl);
+               _properties.setSchema(schema);
+             
+               MetadataDescriptor metadata = createMetadataDescriptor(_wsdl);
+               _properties.setMetadata(metadata);
+                       
+               initializeCapabilities();
+                               
+               _properties.applyMetadata();
+               _properties.validateMetadata();
+               
+               // Resource intialization completed : Let's make a state change.
+               _currentState = _hasBeenInitialized;
+               }
+
+               /**
+                * Shuts down this resource.
+                * 
+                * @throws SoapFault when the shutdown procedure fails.         
 */
+               public void shutdown() throws SoapFault
+               {
+                       
LOGGER.error(Messages.QMAN_100032_WS_RESOURCE_NOT_YET_INITIALIZED);
+                       throw new 
SoapFault(Messages.QMAN_100032_WS_RESOURCE_NOT_YET_INITIALIZED);                
      
+               }
+               
+               /**
+                * Returns false because this state indicates that 
+                * the resource has not yet been initialized.
+                * 
+                * @return false;
+                */
+               public boolean hasBeenInitialized()
+               {
+                       return false;
+               }
+
+               /**
+                * Returns false because the resource, when is in this state 
+                * hasn't been initialized and as conseguence of that hasn't 
+                * been shutdonm.
+                * 
+                * @return false;
+                */
+               public boolean hasBeenShutdown()
+               {
+                       return false;
+               }
+       };
        
     private Map<String,Capability>  _capabilitiesByAction = new 
HashMap<String, Capability>();
     private Map<String, Capability> _capabilitiesByURI = new 
LinkedHashMap<String, Capability>();
@@ -88,14 +276,15 @@
     private Environment _environment;    
     private EndpointReference _enpointReference;
     
-    private boolean _hasBeenInitialized;
-    private boolean _hasBeenShutdown;
+    private State _currentState = _notYetInitialized;
     
     private ResourceManager _resourceManager;
     private ResourcePropertyCollection _properties;
 
     private Map<String,String> _initParameters = Collections.EMPTY_MAP;
     
+    // Workaround : muse is using and hardcoded java.util.logging.Logger but 
we should use 
+    // SLF4j so this is the original implementatation that won't never be used 
(on QMan classes)
     private java.util.logging.Logger _logger;
     
     private Document _wsdl;    
@@ -116,7 +305,10 @@
         String uri = capability.getCapabilityURI();
         _capabilitiesByURI.put(uri, capability);
         
-        LOGGER.debug(Messages.QMAN_200033_CAPABILITY_CLASS_HAS_BEEN_ADDED, 
capability.getClass(),uri);
+        LOGGER.debug(
+                       Messages.QMAN_200033_CAPABILITY_CLASS_HAS_BEEN_ADDED, 
+                       capability.getClass(),
+                       uri);
     }
     
     /**
@@ -124,31 +316,20 @@
      * 
      * @return the capability associated with the given URI.
      */
-    public final Capability getCapability(String capabilityURI)
+    public Capability getCapability(String capabilityURI)
     {
         return _capabilitiesByURI.get(capabilityURI);
     }
     
-    /**
-     * Returns all the WS-Action URIs supported by this resource.
-     * 
-     * @return all of the WS-A Action URIs supported by this resource.
-     */
-    protected Collection getCapabilityActions()
-    {
-        return Collections.unmodifiableSet(_capabilitiesByAction.keySet());
-    }
-    
-    /**
-     * Returns the capability associated with the given action.
-     * 
-     * @param action the wsa:action of the requested capability.
-     * @return the capability associated with the given action.
-     */
-    protected Capability getCapabilityForAction(String action)
-    {
-        return (Capability)_capabilitiesByAction.get(action);
-    }
+//    /**
+//     * Returns all the WS-Action URIs supported by this resource.
+//     * 
+//     * @return all of the WS-A Action URIs supported by this resource.
+//     */
+//    protected Collection getCapabilityActions()
+//    {
+//        return Collections.unmodifiableSet(_capabilitiesByAction.keySet());
+//    }
     
     /**
      * Returns a collection with all registered capability URIs.
@@ -258,7 +439,7 @@
      */
     public final boolean hasBeenInitialized()
     {
-        return _hasBeenInitialized;
+        return _currentState.hasBeenInitialized();
     }
     
     /**
@@ -268,7 +449,7 @@
      */
     public final boolean hasBeenShutdown()
     {
-        return _hasBeenShutdown;
+        return _currentState.hasBeenShutdown();
     }
     
     /**
@@ -282,62 +463,6 @@
     }
     
     /**
-     * Creates a metadata descriptor for this resource.
-     * 
-     * @param wsdl the WSDL document. 
-     * @return a metadata descriptor for this resource.
-     * @throws SoapFault when it's not possible build the descriptor.
-     */
-    protected MetadataDescriptor createMetadataDescriptor(Document wsdl) 
throws SoapFault
-    {
-        try 
-        {      
-               Element portTypeXML = WsdlUtils.getPortType(wsdl, 
getWsdlPortType());
-               
-               String rmdName = XmlUtils.getAttribute(portTypeXML, 
WsrmdConstants.DESCRIPTOR_ATTR_QNAME);
-               String rmdPath = XmlUtils.getAttribute(portTypeXML, 
WsrmdConstants.DESCRIPTOR_LOCATION_ATTR_QNAME);
-               
-               LOGGER.debug(Messages.QMAN_200034_RMD_NAME, rmdName);
-               LOGGER.debug(Messages.QMAN_200035_RMD_PATH, rmdPath);
-               
-               Environment env = getEnvironment();
-               String path = env.createRelativePath(getWsdlPath(), rmdPath);   
     
-               Document rmdDoc = env.getDocument(path);
-               
-               Element[] additionalProperties = 
ThreadSessionManager.getInstance().getSession().getResourceMetadataDescriptor();
-               Element metadataDescriptor = 
WsrmdUtils.getMetadataDescriptor(rmdDoc, rmdName);
-        
-               for (Element element : additionalProperties) 
-               {
-                               rmdDoc.adoptNode(element);
-                               metadataDescriptor.appendChild(element);
-                               
-                               
Log.debugElement(Messages.QMAN_200036_ADDITIONAL_RMD_PROPERTY,element);
-                       }
-                       
-                       return new SimpleMetadataDescriptor(metadataDescriptor);
-        } 
-        catch(Exception exception)
-        {
-               
LOGGER.error(exception,Messages.QMAN_100021_RMD_BUID_FAILURE,getContextPath());
-               throw new SoapFault(exception);
-        }
-    }
-
-    /**
-     * Creates a WSRP document representing schema properties for this 
resource.
-     * 
-     * @param wsdl the DOM document holding the resource's WSDL.       
-     * @return the WSRP document schema.
-     */
-    protected ResourcePropertiesSchema createPropertiesSchema(Document wsdl)
-    {
-        QName wsrpName = WsrpUtils.getPropertiesName(wsdl, getWsdlPortType());
-        Element wsrpDoc = WsdlUtils.getElementDeclaration(wsdl, wsrpName);     
   
-        return new SimpleResourcePropertiesSchema(wsrpName, wsrpDoc);
-    }    
-    
-    /**
      * Returns the collection containing all properties of this resource.
      * 
      * @return the collection containing all properties of this resource.
@@ -359,55 +484,16 @@
     
     /**
      * Initializes this resources.
+     * Note that the what needs to be done depends on the current state of this
+     * resource.
      * 
      * @throws SoapFault when the initialization fails.
      */
     public void initialize() throws SoapFault
     {          
-        _properties = new SimpleResourcePropertyCollection();
-        _wsdl = 
ThreadSessionManager.getInstance().getSession().getWsdlDocument();
-        
-        ResourcePropertiesSchema schema = createPropertiesSchema(_wsdl);
-        _properties.setSchema(schema);
-      
-        MetadataDescriptor metadata = createMetadataDescriptor(_wsdl);
-        _properties.setMetadata(metadata);
-                
-        initializeCapabilities();
-        
-        _hasBeenInitialized = true;
-        
-        _properties.applyMetadata();
-        
-        if 
(Boolean.parseBoolean(getInitializationParameter(Names.VALIDATE_WSRP_PARAM)))
-           {
-               _properties.validateSchema();                   
-           }
-
-        _properties.validateMetadata();
-    }
-    
-    /**
-     * Initializes capabilities of this resource.
-     * 
-     * @throws SoapFault when at least one capability fails to initialize.
-     */
-    public void initializeCapabilities() throws SoapFault
-    {
-        for (Entry<String, Capability> entry : _capabilitiesByURI.entrySet()) 
-        {
-               Capability capability = entry.getValue();
-                       capability.initialize();
-                       
-                       for (Object action : capability.getActions()) 
-                       {
-                _capabilitiesByAction.put((String)action, capability);
-                       }
-                       
-                       capability.initializeCompleted();
-               }
+       _currentState.initialize();
     }
-    
+        
     /**
      * Invokes the action specified in the given soap request on this resource.
      * 
@@ -422,7 +508,10 @@
         // Sanity check : is there a capability for the given action?
         if (capability == null)
         {
-            SoapFault wsaFault = new 
SoapFault(String.format(Messages.ACTION_NOT_SUPPORTED, 
action,getContextPath()));
+            SoapFault wsaFault = new SoapFault(
+                       String.format(
+                                       Messages.ACTION_NOT_SUPPORTED, 
+                                       action,getContextPath()));
 
             wsaFault.setCode(SoapConstants.SENDER_QNAME);
             wsaFault.setSubCode(WsaConstants.ACTION_NOT_SUPPORTED_FAULT_QNAME);
@@ -431,7 +520,10 @@
             XmlUtils.setElement(detail, WsaConstants.ACTION_QNAME, action);
             wsaFault.setDetail(detail);
             
-            LOGGER.error(Messages.QMAN_100020_ACTION_NOT_SUPPORTED, 
action,getContextPath());
+            LOGGER.error(
+                       Messages.QMAN_100020_ACTION_NOT_SUPPORTED, 
+                       action,
+                       getContextPath());
 
             return wsaFault.toXML();
         }
@@ -545,23 +637,39 @@
      */
     public synchronized void shutdown() throws SoapFault
     {
-        if (hasBeenShutdown())
-            throw new SoapFault(("ResourceAlreadyDestroyed"));
-        
-        if (!hasBeenInitialized())
-            throw new SoapFault(("ResourceNotInitialized"));
-
-        _hasBeenShutdown = true;
+       _currentState.shutdown();
+    }
         
-        shutdownCapabilities();
-                
-        ResourceManager manager = getResourceManager();
-
-        //
-        // remove resource visibility
-        // 
-        if (manager.getResource(_enpointReference) != null)
-            manager.removeResource(_enpointReference);
+    /**
+     * Returns a string representation of this resource.
+     * Basically the resource endpoint reference (as a string) is returned.
+     * 
+     * @return the resource endpoint reference (as a string) is returned.
+     */
+    public String toString()
+    {
+        return getEndpointReference().toString();
+    }     
+    
+    /**
+     * Initializes capabilities of this resource.
+     * 
+     * @throws SoapFault when at least one capability fails to initialize.
+     */
+    private void initializeCapabilities() throws SoapFault
+    {
+        for (Entry<String, Capability> entry : _capabilitiesByURI.entrySet()) 
+        {
+               Capability capability = entry.getValue();
+                       capability.initialize();
+                       
+                       for (Object action : capability.getActions()) 
+                       {
+                _capabilitiesByAction.put((String)action, capability);
+                       }
+                       
+                       capability.initializeCompleted();
+               }
     }
     
     /**
@@ -569,7 +677,7 @@
      * 
      * @throws SoapFault when at least one capability shutdown fails.
      */
-    protected void shutdownCapabilities() throws SoapFault
+    private void shutdownCapabilities() throws SoapFault
     {
         for (Entry<String,Capability> entry : _capabilitiesByURI.entrySet()) 
         {
@@ -577,16 +685,80 @@
                capabilty.prepareShutdown();
                capabilty.shutdown();
                }        
-    }
+    }    
     
     /**
-     * Returns a string representation of this resource.
-     * Basically the resource endpoint reference (as a string) is returned.
+     * Creates a metadata descriptor for this resource.
      * 
-     * @return the resource endpoint reference (as a string) is returned.
+     * @param wsdl the WSDL document. 
+     * @return a metadata descriptor for this resource.
+     * @throws SoapFault when it's not possible build the descriptor.
      */
-    public String toString()
+    private MetadataDescriptor createMetadataDescriptor(Document wsdl) throws 
SoapFault
     {
-        return getEndpointReference().toString();
-    }     
+        try 
+        {      
+               Element portTypeXML = WsdlUtils.getPortType(wsdl, 
getWsdlPortType());
+               
+               String rmdName = XmlUtils.getAttribute(
+                               portTypeXML, 
+                               WsrmdConstants.DESCRIPTOR_ATTR_QNAME);
+               
+               String rmdPath = XmlUtils.getAttribute(
+                               portTypeXML, 
+                               WsrmdConstants.DESCRIPTOR_LOCATION_ATTR_QNAME);
+               
+               LOGGER.debug(Messages.QMAN_200034_RMD_NAME, rmdName);
+               LOGGER.debug(Messages.QMAN_200035_RMD_PATH, rmdPath);
+               
+               Environment env = getEnvironment();
+               String path = env.createRelativePath(getWsdlPath(), rmdPath);   
     
+               Document rmdDoc = env.getDocument(path);
+               
+               Element[] additionalProperties = 
+                       ThreadSessionManager
+                               .getInstance()
+                               .getSession()
+                               .getResourceMetadataDescriptor();
+               
+               Element metadataDescriptor = 
WsrmdUtils.getMetadataDescriptor(rmdDoc, rmdName);
+        
+               for (Element element : additionalProperties) 
+               {
+                               rmdDoc.adoptNode(element);
+                               metadataDescriptor.appendChild(element);
+                       }
+                       
+                       return new SimpleMetadataDescriptor(metadataDescriptor);
+        } 
+        catch(Exception exception)
+        {
+               
LOGGER.error(exception,Messages.QMAN_100021_RMD_BUID_FAILURE,getContextPath());
+               throw new SoapFault(exception);
+        }
+    }    
+    
+    /**
+     * Returns the capability associated with the given action.
+     * 
+     * @param action the wsa:action of the requested capability.
+     * @return the capability associated with the given action.
+     */
+    private Capability getCapabilityForAction(String action)
+    {
+        return (Capability)_capabilitiesByAction.get(action);
+    }    
+    
+    /**
+     * Creates a WSRP document representing schema properties for this 
resource.
+     * 
+     * @param wsdl the DOM document holding the resource's WSDL.       
+     * @return the WSRP document schema.
+     */
+    private ResourcePropertiesSchema createPropertiesSchema(Document wsdl)
+    {
+        QName wsrpName = WsrpUtils.getPropertiesName(wsdl, getWsdlPortType());
+        Element wsrpDoc = WsdlUtils.getElementDeclaration(wsdl, wsrpName);     
   
+        return new SimpleResourcePropertiesSchema(wsrpName, wsrpDoc);
+    }        
 }
\ No newline at end of file


Reply via email to