You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by sc...@apache.org on 2005/05/10 23:29:11 UTC

svn commit: r169528 - in /incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0: impl/advertiser/ topics/impl/XmlBeansAdvertisementTopicImpl.java

Author: scamp
Date: Tue May 10 14:29:11 2005
New Revision: 169528

URL: http://svn.apache.org/viewcvs?rev=169528&view=rev
Log: (empty)

Added:
    incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0/impl/advertiser/
    incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0/topics/impl/XmlBeansAdvertisementTopicImpl.java

Added: incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0/topics/impl/XmlBeansAdvertisementTopicImpl.java
URL: http://svn.apache.org/viewcvs/incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0/topics/impl/XmlBeansAdvertisementTopicImpl.java?rev=169528&view=auto
==============================================================================
--- incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0/topics/impl/XmlBeansAdvertisementTopicImpl.java (added)
+++ incubator/muse/trunk/src/java/org/apache/ws/muws/v1_0/topics/impl/XmlBeansAdvertisementTopicImpl.java Tue May 10 14:29:11 2005
@@ -0,0 +1,147 @@
+package org.apache.ws.muws.v1_0.topics.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.XmlObjectWrapper;
+import org.apache.ws.addressing.EndpointReference;
+import org.apache.ws.muws.impl.CategoryImpl;
+import org.apache.ws.muws.v1_0.MuwsConstants;
+import org.apache.ws.muws.v1_0.events.Situation;
+import org.apache.ws.muws.v1_0.events.impl.SituationImpl;
+import org.apache.ws.muws.v1_0.events.impl.XmlBeansManagementEvent;
+import org.apache.ws.notification.topics.impl.TopicImpl;
+import org.apache.ws.resource.ResourceCreationEvent;
+import org.apache.ws.resource.ResourceCreationListener;
+import org.apache.ws.resource.ResourceDestructionEvent;
+import org.apache.ws.resource.ResourceDestructionListener;
+import org.apache.ws.resource.i18n.MessagesImpl;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.ws.util.i18n.Messages;
+import org.apache.xmlbeans.XmlObject;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManagementEventDocument;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.CreationNotificationDocument;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.DestructionNotificationDocument;
+import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
+
+
+/**
+ * An Advertisement Topic impl for Resource Creation and Deletion.
+ *
+ * @author Sal Campana
+ */
+public class XmlBeansAdvertisementTopicImpl extends TopicImpl implements ResourceCreationListener, ResourceDestructionListener
+{
+
+    private static final Log LOG = LogFactory.getLog( XmlBeansAdvertisementTopicImpl.class );
+    private static final Messages MSG = MessagesImpl.getInstance();
+
+    public XmlBeansAdvertisementTopicImpl(String s)
+    {
+        super(s);
+    }
+
+    /**
+     * Publishes an event to subscribers.
+     *
+     * @param o
+     * @throws Exception
+     */
+    public void publish(Object o) throws Exception
+    {
+        super.publish(o);
+    }
+
+    /**
+     * Handles the event when a creation occurs.  Builds a CreationNotification
+     * and sends notif to subscribers
+     *
+     * @param event
+     */
+    public void creationOccurred(ResourceCreationEvent event)
+    {
+        CreationNotificationDocument creationNotificationDocument = CreationNotificationDocument.Factory.newInstance();
+        org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.CreationNotificationDocument.CreationNotification creationNotification = creationNotificationDocument.addNewCreationNotification();
+        EndpointReference endpointReference = event.getEndpointReference();
+        if(endpointReference != null && endpointReference instanceof XmlObjectWrapper)
+        {
+            XmlObject xmlObject = ((XmlObjectWrapper)endpointReference).getXmlObject();
+            if(xmlObject instanceof EndpointReferenceType)
+            {
+                creationNotification.setManageabilityEndpointReferenceArray(new EndpointReferenceType[]{(EndpointReferenceType)xmlObject});
+                try
+                {
+                    publish(buildManagementEvent(creationNotificationDocument));
+                }
+                catch (Exception e)
+                {
+                    if (LOG.isDebugEnabled())
+                        {
+                            LOG.debug("Publishing of the notification: " + creationNotificationDocument.toString() + " failed.", e);
+                        }
+                }
+            }
+            else
+            {
+                LOG.debug("EPR did not contain an instance of: " + EndpointReferenceType.class.getName() + " but rather it was: " + xmlObject.getClass().getName());
+            }
+        }
+        else
+        {
+            LOG.debug("The EndpointReference was either null or it was not an instance of XmlObjectWrapper.  EPR: " + endpointReference );
+        }
+    }
+
+    /**
+     * Handles the event when a destruction occurs.  Builds a DestructionNotificationDocument
+     * and sends notif to subscribers
+     *
+     * @param event
+     */
+    public void destructionOccurred(ResourceDestructionEvent event)
+    {
+        Object resourceID = event.getResourceID();
+        if (resourceID != null)
+        {
+            DestructionNotificationDocument destructionNotificationDocument = DestructionNotificationDocument.Factory.newInstance();
+            org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.DestructionNotificationDocument.DestructionNotification destructionNotification = destructionNotificationDocument.addNewDestructionNotification();
+            EndpointReference endpointReference = event.getEndpointReference();
+            if (endpointReference != null && endpointReference instanceof XmlObjectWrapper)
+            {
+                    destructionNotification.setResourceId((String)resourceID);
+                    try
+                    {
+                        publish(buildManagementEvent(destructionNotificationDocument));
+                    }
+                    catch (Exception e)
+                    {
+                        if (LOG.isDebugEnabled())
+                        {
+                            LOG.debug("Publishing of the notification: " + destructionNotificationDocument.toString() + " failed.", e);
+                        }
+                    }
+            }
+            else
+            {
+                LOG.debug("The EndpointReference was either null or it was not an instance of XmlObjectWrapper.  EPR: " + endpointReference );
+            }
+        }
+    }
+
+    /**
+     * Builds a ManagementEvent to hold the Creation/Destruction event.
+     *
+     * @param event
+     * @return  ManagementEvent
+     */
+    private XmlObject buildManagementEvent(XmlObject event)
+    {
+        ManagementEventDocument me;
+        Situation situation = new SituationImpl(new CategoryImpl(MuwsConstants.SITUATION_OTHER));
+        XmlBeansManagementEvent xme = new XmlBeansManagementEvent(situation);
+        me = (ManagementEventDocument) ((XmlObjectWrapper) xme).getXmlObject();
+        org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManagementEventType managementEvent = me.getManagementEvent();
+        XmlBeanUtils.addChildElement(managementEvent, ((XmlObjectWrapper) event).getXmlObject());
+        return me;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org