You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/07/16 20:50:34 UTC
svn commit: r422494 - in
/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src: ./ org/
org/apache/ org/apache/muse/ org/apache/muse/ws/ org/apache/muse/ws/dm/
org/apache/muse/ws/dm/muws/ org/apache/muse/ws/dm/muws/adv/
org/apache/muse/ws/dm/muws...
Author: danj
Date: Sun Jul 16 11:50:33 2006
New Revision: 422494
URL: http://svn.apache.org/viewvc?rev=422494&view=rev
Log:
Step 2 in the WS-* top level directory additions - moving impl source and POM to top-level impl directory.
Added:
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java
Added: webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java?rev=422494&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java (added)
+++ webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java Sun Jul 16 11:50:33 2006
@@ -0,0 +1,171 @@
+/*=============================================================================*
+ * Copyright 2006 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.muse.ws.dm.muws.adv.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.AbstractCapability;
+import org.apache.muse.core.Environment;
+import org.apache.muse.core.Resource;
+import org.apache.muse.core.ResourceManager;
+import org.apache.muse.core.ResourceManagerListener;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.dm.muws.MuwsConstants;
+import org.apache.muse.ws.dm.muws.adv.Advertisement;
+import org.apache.muse.ws.dm.muws.events.Component;
+import org.apache.muse.ws.dm.muws.events.ComponentAddress;
+import org.apache.muse.ws.dm.muws.events.ManagementEvent;
+import org.apache.muse.ws.dm.muws.events.Situation;
+import org.apache.muse.ws.dm.muws.events.WefFactory;
+import org.apache.muse.ws.dm.muws.events.WefConstants;
+import org.apache.muse.ws.dm.muws.events.impl.SimpleWefFactory;
+import org.apache.muse.ws.notification.NotificationProducer;
+import org.apache.muse.ws.notification.WsnConstants;
+import org.apache.muse.ws.notification.impl.TopicFilter;
+
+/**
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public class SimpleAdvertisement
+ extends AbstractCapability implements Advertisement, ResourceManagerListener
+{
+ private static final String _CONSUMER_EPR_PARAM = "initial-consumer-reference";
+
+ protected WefFactory createWefFactory()
+ {
+ return new SimpleWefFactory();
+ }
+
+ public void initializeCompleted()
+ throws SoapFault
+ {
+ super.initializeCompleted();
+
+ Resource resource = getResource();
+
+ //
+ // this allows the advertisement capability to hear about
+ // all resource lifecycle events that happen in the touchpoint
+ //
+ ResourceManager manager = resource.getResourceManager();
+ manager.addListener(this);
+
+ //
+ // initialize the advertisement topics
+ //
+ NotificationProducer wsn =
+ (NotificationProducer)resource.getCapability(WsnConstants.PRODUCER_URI);
+
+ wsn.addTopic(MuwsConstants.ADV_ME_CREATION_TOPIC);
+ wsn.addTopic(MuwsConstants.ADV_ME_DESTRUCTION_TOPIC);
+
+ //
+ // create subscriptions for all event consumer that are going to
+ // receive notifications from the above topics
+ //
+ subscribeInitialConsumer();
+ }
+
+ public void resourceAdded(EndpointReference epr, Resource resource)
+ throws SoapFault
+ {
+ Element payload = XmlUtils.createElement(MuwsConstants.MANAGEABILITY_EPR_QNAME, epr.toXML());
+ sendMessage(epr, MuwsConstants.ADV_ME_CREATION_TOPIC, MuwsConstants.CREATE_NOTIFICATION_QNAME, payload);
+ }
+
+ public void resourceRemoved(EndpointReference epr)
+ throws SoapFault
+ {
+ Element payload = XmlUtils.createElement(MuwsConstants.DESTROY_NOTIFICATION_QNAME);
+ sendMessage(epr, MuwsConstants.ADV_ME_DESTRUCTION_TOPIC, WefConstants.DESTROY_SITUATION_QNAME, payload);
+
+ Resource advertiser = getResource();
+
+ if (advertiser.hasBeenShutdown())
+ advertiser.getResourceManager().removeListener(this);
+ }
+
+ protected void sendMessage(EndpointReference sourceEPR,
+ QName topicName,
+ QName situationCategory,
+ Element payload)
+ throws SoapFault
+ {
+ Resource advertiser = getResource();
+
+ WefFactory factory = createWefFactory();
+ ManagementEvent event = factory.createEvent();
+
+ event.addExtendedElement(payload);
+
+ Component source = factory.createComponent();
+ source.setName(WefConstants.SOURCE_COMP_QNAME);
+
+ ComponentAddress address = factory.createComponentAddress(sourceEPR);
+ source.setAddress(address);
+
+ event.setSource(source);
+
+ Component reporter = factory.createComponent();
+ reporter.setName(WefConstants.REPORTER_COMP_QNAME);
+
+ address = factory.createComponentAddress(advertiser.getEndpointReference());
+ reporter.setAddress(address);
+
+ event.setReporter(reporter);
+
+ Situation situation = factory.createSituation();
+ situation.setCategoryType(situationCategory);
+ event.setSituation(situation);
+
+ NotificationProducer wsn = (NotificationProducer)advertiser.getCapability(WsnConstants.PRODUCER_URI);
+ wsn.publish(topicName, event.toXML());
+ }
+
+ protected void subscribeInitialConsumer()
+ throws SoapFault
+ {
+ String fileName = getInitializationParameter(_CONSUMER_EPR_PARAM);
+
+ //
+ // pre-existing consumer is optional - other consumers can
+ // still subscribe using WS-N
+ //
+ if (fileName != null)
+ {
+ Environment env = getResource().getEnvironment();
+ Document eprDoc = env.getDocument(fileName);
+ Element eprXML = XmlUtils.getFirstElement(eprDoc);
+
+ EndpointReference epr = new EndpointReference(eprXML);
+
+ NotificationProducer wsn =
+ (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
+
+ wsn.subscribe(epr, new TopicFilter(MuwsConstants.ADV_ME_CREATION_TOPIC), null, null);
+ wsn.subscribe(epr, new TopicFilter(MuwsConstants.ADV_ME_DESTRUCTION_TOPIC), null, null);
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org