You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pubscribe-commits@ws.apache.org by sc...@apache.org on 2005/08/02 18:41:44 UTC
svn commit: r227035 [8/12] - in /webservices/pubscribe/trunk: ./
src/java/org/apache/ws/eventing/ src/java/org/apache/ws/eventing/porttype/
src/java/org/apache/ws/eventing/porttype/impl/
src/java/org/apache/ws/eventing/pubsub/ src/java/org/apache/ws/ev...
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourcePropertyValueChangeTopicImpl.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourcePropertyValueChangeTopicImpl.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourcePropertyValueChangeTopicImpl.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourcePropertyValueChangeTopicImpl.java Tue Aug 2 09:41:00 2005
@@ -1,69 +1,87 @@
-/*=============================================================================*
- * 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.notification.topics.impl;
-
-import org.apache.ws.notification.topics.ResourcePropertyValueChangeTopic;
-import org.apache.ws.resource.properties.ResourceProperty;
-import org.apache.ws.resource.properties.ResourcePropertyValueChangeEvent;
-import org.apache.ws.XmlObjectWrapper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * A Topic implementation used for handling ResourcePropertyValueChange Events.
- *
- * This topic should be registered for each resource property which will be exposed to emit
- * the ResourcePropertyValueChange Event.
- */
-public class ResourcePropertyValueChangeTopicImpl extends TopicImpl implements ResourcePropertyValueChangeTopic
-{
- private static final Log LOG = LogFactory.getLog(ResourcePropertyValueChangeTopicImpl.class);
- private ResourceProperty m_prop;
-
- public ResourcePropertyValueChangeTopicImpl( ResourceProperty prop )
- {
- super( prop.getMetaData().getName().getLocalPart() );
- m_prop = prop;
- }
-
- public ResourceProperty getResourceProperty()
- {
- return m_prop;
- }
-
- public void propertyChanged( ResourcePropertyValueChangeEvent event )
- {
- Object msg;
- if ( event instanceof XmlObjectWrapper )
- {
- msg = ((XmlObjectWrapper)event).getXmlObject();
- }
- else
- {
- msg = event;
- }
- try
- {
- publish( msg );
- }
- catch ( Exception e )
- {
- LOG.debug("A exception occurred while publishing a ResourcePropertyValueChangeEvent: ",e);
- // TODO: *SJC* This is tricky, we may need to devise a List of Exceptions to collect any exceptions. The other thing to consider is where does the exception go?
- }
- }
-
-}
+/*=============================================================================*
+ * 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.notification.topics.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.XmlObjectWrapper;
+import org.apache.ws.notification.topics.ResourcePropertyValueChangeTopic;
+import org.apache.ws.resource.properties.ResourceProperty;
+import org.apache.ws.resource.properties.ResourcePropertyValueChangeEvent;
+
+/**
+ * A Topic implementation used for handling ResourcePropertyValueChange Events.
+ *
+ * This topic should be registered for each resource property which will be exposed to emit
+ * the ResourcePropertyValueChange Event.
+ */
+public class ResourcePropertyValueChangeTopicImpl
+ extends TopicImpl
+ implements ResourcePropertyValueChangeTopic
+{
+ private static final Log LOG = LogFactory.getLog( ResourcePropertyValueChangeTopicImpl.class );
+ private ResourceProperty m_prop;
+
+ /**
+ * Creates a new {@link ResourcePropertyValueChangeTopicImpl} object.
+ *
+ * @param prop DOCUMENT_ME
+ */
+ public ResourcePropertyValueChangeTopicImpl( ResourceProperty prop )
+ {
+ super( prop.getMetaData( ).getName( ).getLocalPart( ) );
+ m_prop = prop;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public ResourceProperty getResourceProperty( )
+ {
+ return m_prop;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param event DOCUMENT_ME
+ */
+ public void propertyChanged( ResourcePropertyValueChangeEvent event )
+ {
+ Object msg;
+ if ( event instanceof XmlObjectWrapper )
+ {
+ msg = ( (XmlObjectWrapper) event ).getXmlObject( );
+ }
+ else
+ {
+ msg = event;
+ }
+
+ try
+ {
+ publish( msg );
+ }
+ catch ( Exception e )
+ {
+ LOG.debug( "A exception occurred while publishing a ResourcePropertyValueChangeEvent: ", e );
+
+ // TODO: *SJC* This is tricky, we may need to devise a List of Exceptions to collect any exceptions. The other thing to consider is where does the exception go?
+ }
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourceTerminationTopicImpl.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourceTerminationTopicImpl.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourceTerminationTopicImpl.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/ResourceTerminationTopicImpl.java Tue Aug 2 09:41:00 2005
@@ -1,45 +1,70 @@
-package org.apache.ws.notification.topics.impl;
-
-import org.apache.ws.resource.lifetime.ResourceTerminationEvent;
-import org.apache.ws.resource.lifetime.ResourceTerminationListener;
-import org.apache.ws.resource.lifetime.impl.ResourceTerminationEventImpl;
-import org.apache.ws.resource.properties.NamespaceVersionHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author Sal Campana
- */
-public class ResourceTerminationTopicImpl extends TopicImpl implements ResourceTerminationListener
-{
- private static final Log LOG = LogFactory.getLog(ResourceTerminationTopicImpl.class);
- public static final String TOPIC_NAME = "ResourceTermination";
-
- /**
- * This provides the version of the topic we are dealing with for use when creating the notification.
- */
- private NamespaceVersionHolder m_namespaceSet;
-
- /**
- * Create a resource termination topic for the given WSRF namespace set.
- */
- public ResourceTerminationTopicImpl( NamespaceVersionHolder namespaceSet )
- {
- super( TOPIC_NAME );
- m_namespaceSet = namespaceSet;
- }
-
- public void terminationOccurred( ResourceTerminationEvent event )
- {
- Object msg = ( (ResourceTerminationEventImpl) event ).getTerminationNotifDocXmlBean( m_namespaceSet );
- try
- {
- publish( msg );
- }
- catch ( Exception e )
- {
- LOG.debug("A exception occurred while publishing a ResourceTerminationEvent: ",e);
- // TODO: *SJC* This is tricky, we may need to devise a List of Exceptions to collect any exceptions. The other thing to consider is where does the exception go?
- }
- }
-}
+/*=============================================================================*
+ * 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.notification.topics.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.resource.lifetime.ResourceTerminationEvent;
+import org.apache.ws.resource.lifetime.ResourceTerminationListener;
+import org.apache.ws.resource.lifetime.impl.ResourceTerminationEventImpl;
+import org.apache.ws.resource.properties.NamespaceVersionHolder;
+
+/**
+ * @author Sal Campana
+ */
+public class ResourceTerminationTopicImpl
+ extends TopicImpl
+ implements ResourceTerminationListener
+{
+ private static final Log LOG = LogFactory.getLog( ResourceTerminationTopicImpl.class );
+
+ /** DOCUMENT_ME */
+ public static final String TOPIC_NAME = "ResourceTermination";
+
+ /**
+ * This provides the version of the topic we are dealing with for use when creating the notification.
+ */
+ private NamespaceVersionHolder m_namespaceSet;
+
+ /**
+ * Create a resource termination topic for the given WSRF namespace set.
+ */
+ public ResourceTerminationTopicImpl( NamespaceVersionHolder namespaceSet )
+ {
+ super( TOPIC_NAME );
+ m_namespaceSet = namespaceSet;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param event DOCUMENT_ME
+ */
+ public void terminationOccurred( ResourceTerminationEvent event )
+ {
+ Object msg = ( (ResourceTerminationEventImpl) event ).getTerminationNotifDocXmlBean( m_namespaceSet );
+ try
+ {
+ publish( msg );
+ }
+ catch ( Exception e )
+ {
+ LOG.debug( "A exception occurred while publishing a ResourceTerminationEvent: ", e );
+
+ // TODO: *SJC* This is tricky, we may need to devise a List of Exceptions to collect any exceptions. The other thing to consider is where does the exception go?
+ }
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/SubscriptionTopicListener.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/SubscriptionTopicListener.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/SubscriptionTopicListener.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/SubscriptionTopicListener.java Tue Aug 2 09:41:00 2005
@@ -1,312 +1,319 @@
-/*=============================================================================*
- * 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.notification.topics.impl;
-
-import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
-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.addressing.XmlBeansEndpointReference;
-import org.apache.ws.addressing.v2003_03.AddressingConstants;
-import org.apache.ws.notification.base.Subscription;
-import org.apache.ws.notification.base.v2004_06.BaseNotificationConstants;
-import org.apache.ws.notification.topics.Topic;
-import org.apache.ws.notification.topics.TopicListener;
-import org.apache.ws.pubsub.emitter.EmitterTask;
-import org.apache.ws.resource.properties.ResourcePropertySet;
-import org.apache.ws.resource.properties.query.InvalidQueryExpressionException;
-import org.apache.ws.resource.properties.query.QueryEngine;
-import org.apache.ws.resource.properties.query.QueryEvaluationErrorException;
-import org.apache.ws.resource.properties.query.QueryExpression;
-import org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
-import org.apache.ws.resource.properties.query.impl.QueryEngineImpl;
-import org.apache.ws.util.JaxpUtils;
-import org.apache.ws.util.XmlBeanUtils;
-import org.apache.ws.util.thread.NamedThread;
-import org.apache.xmlbeans.XmlCursor;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationMessageHolderType;
-import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument;
-import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
-import org.xmlsoap.schemas.ws.x2003.x03.addressing.ReferencePropertiesType;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPElement;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPFactory;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPHeaderElement;
-import javax.xml.soap.SOAPMessage;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.URL;
-
-/**
- * Topic listener implementation that is associated with a particular {@link Subscription}. Upon a message being
- * published to the topic being listened to, a notification will be emitted to the consumer associated with the
- * subscription.
- */
-public class SubscriptionTopicListener
- implements TopicListener,
- Serializable
-{
- private static Log LOG = LogFactory.getLog( SubscriptionTopicListener.class.getName() );
-
- // the thread pool used to emit notifications
- private static final PooledExecutor EMITTER_POOL;
-
- static
- {
- EMITTER_POOL = new PooledExecutor( 100 );
- // make sure the threads are non-daemon threads so they have time to complete even if the JVM wants to shut down
- EMITTER_POOL.setThreadFactory( new NamedThread.ConcurrentThreadFactory( "notifmgr-emitter", false ) );
- }
-
- private static final QueryEngine QUERY_ENGINE = new QueryEngineImpl();
-
- private Subscription m_subscription;
-
- /**
- * Construct a listener instance.
- *
- * @param subscription the subscription which is being wrapped in a listener
- */
- public SubscriptionTopicListener( Subscription subscription )
- {
- m_subscription = subscription;
- }
-
- /**
- * @return Subscription
- */
- public Subscription getSubscription()
- {
- return m_subscription;
- }
-
- private void notify( Object rawMsg )
- throws Exception
- {
- synchronized ( m_subscription )
- {
- if ( !m_subscription.isPaused() )
- {
- LOG.debug( "Notification being sent for subscription with id " + m_subscription.getID()
- + "; message value: " + rawMsg );
- XmlObject msg = XmlBeanUtils.toXmlObject( rawMsg );
- if ( evaluateSelector( m_subscription.getSelector(), msg ) &&
- evaluatePrecondition( m_subscription.getPrecondition(),
- m_subscription.getProducerResource().getResourcePropertySet() ) )
- {
- if ( m_subscription.getUseNotify() )
- {
- msg = wrapMessageWithNotify( msg );
- }
- Document dom = toDomDocument( msg );
- EndpointReference consumerEPR = m_subscription.getConsumerReference();
- SOAPMessage soapMsg =
- buildSOAPMessage( dom,
- (EndpointReferenceType) ( (XmlObjectWrapper) consumerEPR ).getXmlObject() );
- EMITTER_POOL.execute( EmitterTask.createEmitterTask( soapMsg,
- new URL( consumerEPR.getAddress().toString() ) ) );
- }
- }
- }
- }
-
- private XmlObject wrapMessageWithNotify( XmlObject msg )
- {
- NotifyDocument notifyDoc = NotifyDocument.Factory.newInstance();
- NotifyDocument.Notify notify = notifyDoc.addNewNotify();
- NotificationMessageHolderType notifMsgHolder = notify.addNewNotificationMessage();
- notifMsgHolder.setMessage( msg );
- EndpointReference producerEPR = m_subscription.getProducerResource().getEndpointReference();
- XmlBeansEndpointReference xBeansProducerEPR = ((XmlBeansEndpointReference)producerEPR);
- notifMsgHolder.setProducerReference( (EndpointReferenceType) xBeansProducerEPR.getXmlObject(org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA) );
- TopicExpressionType topicExpr = (TopicExpressionType) ( (XmlObjectWrapper) m_subscription.getTopicExpression() ).getXmlObject();
- notifMsgHolder.setTopic( topicExpr );
- return notifyDoc;
- }
-
- private boolean evaluateSelector( QueryExpression selector, XmlObject msg )
- throws UnknownQueryExpressionDialectException, QueryEvaluationErrorException,
- InvalidQueryExpressionException
- {
- boolean result;
- if ( selector == null )
- {
- result = true;
- }
- else
- {
- Object queryResult = QUERY_ENGINE.executeQuery( selector, msg );
- try
- {
- result = ( (Boolean) queryResult ).booleanValue();
- }
- catch ( RuntimeException re )
- {
- result = false;
- LOG.error(
- "Notification selector '" + selector + "' did not evaluate to a Boolean at notification time." );
- }
- LOG.debug(
- "Notification selector '" + selector + "' evaluated to " + result + " for subscription with id " +
- m_subscription.getID() +
- "." );
- }
- return result;
- }
-
- private boolean evaluatePrecondition( QueryExpression precondition, ResourcePropertySet propSet )
- throws Exception
- {
- boolean result;
- if ( precondition == null )
- {
- result = true;
- }
- else
- {
- Object queryResult = QUERY_ENGINE.executeQuery( precondition, propSet );
- try
- {
- result = ( (Boolean) queryResult ).booleanValue();
- LOG.debug(
- "Notification precondition '" + precondition + "' evaluated to " + result +
- " for subscription with id " +
- m_subscription.getID() +
- "." );
- }
- catch ( RuntimeException re )
- {
- result = false;
- LOG.error(
- "Notification precondition '" + precondition +
- "' did not evaluate to a Boolean at notification time." );
- }
- }
- return result;
- }
-
- private Document toDomDocument( XmlObject notifyDoc )
- throws ParserConfigurationException, SAXException, IOException
- {
- Document dom;
- if ( XmlBeanUtils.isDocument( notifyDoc ) )
- {
- dom = (Document) notifyDoc.newDomNode();
- }
- else
- {
- String notifyDocAsString = notifyDoc.xmlText( new XmlOptions().setSaveOuter() );
- dom = JaxpUtils.toDocument( notifyDocAsString );
- }
- return dom;
- }
-
- /**
- * DOCUMENT_ME
- *
- * @param topic DOCUMENT_ME
- */
- public void topicChanged( Topic topic )
- {
- if ( m_subscription != null )
- {
- try
- {
- notify( topic.getCurrentMessage() );
- }
- catch ( Exception e )
- {
- LOG.debug( "Notification for topic " + topic + " failed for subscription: " + m_subscription, e );
- }
- }
- }
-
-
- /*
- * Add WS-Addressing headers to a notification.
- *
- * @param header - The header to which to add the WS-Addressing headers.
- * @param consumerEPR - An endpointReferece to the consumer of this notification.
- * @throws Exception
- */
- private void addWSAHeaders( SOAPHeader header,
- EndpointReferenceType consumerEPR )
- throws Exception
- {
- SOAPFactory factory = SOAPFactory.newInstance();
- // TODO: *SJC* this should not be hard-coded to use WSA 2003/03. Once a new version of WSN is implemented we will need to support multiple versions
- SOAPHeaderElement headerElem =
- header.addHeaderElement( factory.createName( org.apache.ws.addressing.v2003_03.AddressingConstants.TO,
- org.apache.ws.addressing.v2003_03.AddressingConstants.NSPREFIX_ADDRESSING_SCHEMA,
- org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA ) );
-
- headerElem.addTextNode( consumerEPR.getAddress().getStringValue() );
- headerElem = header.addHeaderElement( factory.createName( AddressingConstants.ACTION,
- AddressingConstants.NSPREFIX_ADDRESSING_SCHEMA,
- AddressingConstants.NSURI_ADDRESSING_SCHEMA ) );
-
- headerElem.addTextNode( BaseNotificationConstants.NOTIFY_ACTION_URL );
- addReferencePropertyHeaders( header, consumerEPR );
- }
-
- private void addReferencePropertyHeaders( SOAPHeader header, EndpointReferenceType consumerEPR )
- throws Exception
- {
- SOAPHeaderElement headerElem;
- ReferencePropertiesType props = consumerEPR.getReferenceProperties();
- if ( props != null )
- {
- XmlCursor cursor = props.newCursor();
- boolean hasAnotherChild = cursor.toFirstChild();
- while ( hasAnotherChild )
- {
- // TODO: *SJC* the below logic should handle refProps that are complexTypes..
- // Best way to do may be to build SOAPMessage as XmlBean and use MessageFactory.createMessage(..) to construct using the InputStream
- SOAPElement soapElem = XmlBeanUtils.toSOAPElement( cursor.getObject() );
- headerElem = header.addHeaderElement( soapElem.getElementName() );
- headerElem.addTextNode( soapElem.getValue() );
- hasAnotherChild = cursor.toNextSibling();
-
- }
- cursor.dispose();
- }
- }
-
- private SOAPMessage buildSOAPMessage( Document fullMsgBodyElem,
- EndpointReferenceType consumerEPR )
- throws Exception
- {
- SOAPMessage msg = MessageFactory.newInstance().createMessage();
- SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
- SOAPBody body = envelope.getBody();
- body.addDocument( fullMsgBodyElem );
- SOAPHeader header = msg.getSOAPHeader();
- addWSAHeaders( header, consumerEPR );
- return msg;
- }
-
-}
+/*=============================================================================*
+ * 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.notification.topics.impl;
+
+import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
+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.addressing.XmlBeansEndpointReference;
+import org.apache.ws.addressing.v2003_03.AddressingConstants;
+import org.apache.ws.notification.base.Subscription;
+import org.apache.ws.notification.base.v2004_06.BaseNotificationConstants;
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicListener;
+import org.apache.ws.pubsub.emitter.EmitterTask;
+import org.apache.ws.resource.properties.ResourcePropertySet;
+import org.apache.ws.resource.properties.query.InvalidQueryExpressionException;
+import org.apache.ws.resource.properties.query.QueryEngine;
+import org.apache.ws.resource.properties.query.QueryEvaluationErrorException;
+import org.apache.ws.resource.properties.query.QueryExpression;
+import org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
+import org.apache.ws.resource.properties.query.impl.QueryEngineImpl;
+import org.apache.ws.util.JaxpUtils;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.ws.util.thread.NamedThread;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationMessageHolderType;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.TopicExpressionType;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.ReferencePropertiesType;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import javax.xml.soap.SOAPMessage;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URL;
+
+/**
+ * Topic listener implementation that is associated with a particular {@link Subscription}. Upon a message being
+ * published to the topic being listened to, a notification will be emitted to the consumer associated with the
+ * subscription.
+ */
+public class SubscriptionTopicListener
+ implements TopicListener,
+ Serializable
+{
+ private static Log LOG = LogFactory.getLog( SubscriptionTopicListener.class.getName( ) );
+
+ // the thread pool used to emit notifications
+ private static final PooledExecutor EMITTER_POOL;
+
+ static
+ {
+ EMITTER_POOL = new PooledExecutor( 100 );
+
+ // make sure the threads are non-daemon threads so they have time to complete even if the JVM wants to shut down
+ EMITTER_POOL.setThreadFactory( new NamedThread.ConcurrentThreadFactory( "notifmgr-emitter", false ) );
+ }
+
+ private static final QueryEngine QUERY_ENGINE = new QueryEngineImpl( );
+ private Subscription m_subscription;
+
+ /**
+ * Construct a listener instance.
+ *
+ * @param subscription the subscription which is being wrapped in a listener
+ */
+ public SubscriptionTopicListener( Subscription subscription )
+ {
+ m_subscription = subscription;
+ }
+
+ /**
+ * @return Subscription
+ */
+ public Subscription getSubscription( )
+ {
+ return m_subscription;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic DOCUMENT_ME
+ */
+ public void topicChanged( Topic topic )
+ {
+ if ( m_subscription != null )
+ {
+ try
+ {
+ notify( topic.getCurrentMessage( ) );
+ }
+ catch ( Exception e )
+ {
+ LOG.debug( "Notification for topic " + topic + " failed for subscription: " + m_subscription, e );
+ }
+ }
+ }
+
+ private void addReferencePropertyHeaders( SOAPHeader header,
+ EndpointReferenceType consumerEPR )
+ throws Exception
+ {
+ SOAPHeaderElement headerElem;
+ ReferencePropertiesType props = consumerEPR.getReferenceProperties( );
+ if ( props != null )
+ {
+ XmlCursor cursor = props.newCursor( );
+ boolean hasAnotherChild = cursor.toFirstChild( );
+ while ( hasAnotherChild )
+ {
+ // TODO: *SJC* the below logic should handle refProps that are complexTypes..
+ // Best way to do may be to build SOAPMessage as XmlBean and use MessageFactory.createMessage(..) to construct using the InputStream
+ SOAPElement soapElem = XmlBeanUtils.toSOAPElement( cursor.getObject( ) );
+ headerElem = header.addHeaderElement( soapElem.getElementName( ) );
+ headerElem.addTextNode( soapElem.getValue( ) );
+ hasAnotherChild = cursor.toNextSibling( );
+ }
+
+ cursor.dispose( );
+ }
+ }
+
+ /*
+ * Add WS-Addressing headers to a notification.
+ *
+ * @param header - The header to which to add the WS-Addressing headers.
+ * @param consumerEPR - An endpointReferece to the consumer of this notification.
+ * @throws Exception
+ */
+ private void addWSAHeaders( SOAPHeader header,
+ EndpointReferenceType consumerEPR )
+ throws Exception
+ {
+ SOAPFactory factory = SOAPFactory.newInstance( );
+
+ // TODO: *SJC* this should not be hard-coded to use WSA 2003/03. Once a new version of WSN is implemented we will need to support multiple versions
+ SOAPHeaderElement headerElem =
+ header.addHeaderElement( factory.createName( org.apache.ws.addressing.v2003_03.AddressingConstants.TO,
+ org.apache.ws.addressing.v2003_03.AddressingConstants.NSPREFIX_ADDRESSING_SCHEMA,
+ org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA ) );
+
+ headerElem.addTextNode( consumerEPR.getAddress( ).getStringValue( ) );
+ headerElem =
+ header.addHeaderElement( factory.createName( AddressingConstants.ACTION,
+ AddressingConstants.NSPREFIX_ADDRESSING_SCHEMA,
+ AddressingConstants.NSURI_ADDRESSING_SCHEMA ) );
+
+ headerElem.addTextNode( BaseNotificationConstants.NOTIFY_ACTION_URL );
+ addReferencePropertyHeaders( header, consumerEPR );
+ }
+
+ private SOAPMessage buildSOAPMessage( Document fullMsgBodyElem,
+ EndpointReferenceType consumerEPR )
+ throws Exception
+ {
+ SOAPMessage msg = MessageFactory.newInstance( ).createMessage( );
+ SOAPEnvelope envelope = msg.getSOAPPart( ).getEnvelope( );
+ SOAPBody body = envelope.getBody( );
+ body.addDocument( fullMsgBodyElem );
+ SOAPHeader header = msg.getSOAPHeader( );
+ addWSAHeaders( header, consumerEPR );
+ return msg;
+ }
+
+ private boolean evaluatePrecondition( QueryExpression precondition,
+ ResourcePropertySet propSet )
+ throws Exception
+ {
+ boolean result;
+ if ( precondition == null )
+ {
+ result = true;
+ }
+ else
+ {
+ Object queryResult = QUERY_ENGINE.executeQuery( precondition, propSet );
+ try
+ {
+ result = ( (Boolean) queryResult ).booleanValue( );
+ LOG.debug( "Notification precondition '" + precondition + "' evaluated to " + result
+ + " for subscription with id " + m_subscription.getID( ) + "." );
+ }
+ catch ( RuntimeException re )
+ {
+ result = false;
+ LOG.error( "Notification precondition '" + precondition
+ + "' did not evaluate to a Boolean at notification time." );
+ }
+ }
+
+ return result;
+ }
+
+ private boolean evaluateSelector( QueryExpression selector,
+ XmlObject msg )
+ throws UnknownQueryExpressionDialectException,
+ QueryEvaluationErrorException,
+ InvalidQueryExpressionException
+ {
+ boolean result;
+ if ( selector == null )
+ {
+ result = true;
+ }
+ else
+ {
+ Object queryResult = QUERY_ENGINE.executeQuery( selector, msg );
+ try
+ {
+ result = ( (Boolean) queryResult ).booleanValue( );
+ }
+ catch ( RuntimeException re )
+ {
+ result = false;
+ LOG.error( "Notification selector '" + selector
+ + "' did not evaluate to a Boolean at notification time." );
+ }
+
+ LOG.debug( "Notification selector '" + selector + "' evaluated to " + result
+ + " for subscription with id " + m_subscription.getID( ) + "." );
+ }
+
+ return result;
+ }
+
+ private void notify( Object rawMsg )
+ throws Exception
+ {
+ synchronized ( m_subscription )
+ {
+ if ( !m_subscription.isPaused( ) )
+ {
+ LOG.debug( "Notification being sent for subscription with id " + m_subscription.getID( )
+ + "; message value: " + rawMsg );
+ XmlObject msg = XmlBeanUtils.toXmlObject( rawMsg );
+ if ( evaluateSelector( m_subscription.getSelector( ),
+ msg )
+ && evaluatePrecondition( m_subscription.getPrecondition( ),
+ m_subscription.getProducerResource( ).getResourcePropertySet( ) ) )
+ {
+ if ( m_subscription.getUseNotify( ) )
+ {
+ msg = wrapMessageWithNotify( msg );
+ }
+
+ Document dom = toDomDocument( msg );
+ EndpointReference consumerEPR = m_subscription.getConsumerReference( );
+ SOAPMessage soapMsg =
+ buildSOAPMessage( dom,
+ (EndpointReferenceType) ( (XmlObjectWrapper) consumerEPR ).getXmlObject( ) );
+ EMITTER_POOL.execute( EmitterTask.createEmitterTask( soapMsg,
+ new URL( consumerEPR.getAddress( ).toString( ) ) ) );
+ }
+ }
+ }
+ }
+
+ private Document toDomDocument( XmlObject notifyDoc )
+ throws ParserConfigurationException,
+ SAXException,
+ IOException
+ {
+ Document dom;
+ if ( XmlBeanUtils.isDocument( notifyDoc ) )
+ {
+ dom = (Document) notifyDoc.newDomNode( );
+ }
+ else
+ {
+ String notifyDocAsString = notifyDoc.xmlText( new XmlOptions( ).setSaveOuter( ) );
+ dom = JaxpUtils.toDocument( notifyDocAsString );
+ }
+
+ return dom;
+ }
+
+ private XmlObject wrapMessageWithNotify( XmlObject msg )
+ {
+ NotifyDocument notifyDoc = NotifyDocument.Factory.newInstance( );
+ NotifyDocument.Notify notify = notifyDoc.addNewNotify( );
+ NotificationMessageHolderType notifMsgHolder = notify.addNewNotificationMessage( );
+ notifMsgHolder.setMessage( msg );
+ EndpointReference producerEPR =
+ m_subscription.getProducerResource( ).getEndpointReference( );
+ XmlBeansEndpointReference xBeansProducerEPR = ( (XmlBeansEndpointReference) producerEPR );
+ notifMsgHolder.setProducerReference( (EndpointReferenceType) xBeansProducerEPR.getXmlObject( org.apache.ws.addressing.v2003_03.AddressingConstants.NSURI_ADDRESSING_SCHEMA ) );
+ TopicExpressionType topicExpr =
+ (TopicExpressionType) ( (XmlObjectWrapper) m_subscription.getTopicExpression( ) ).getXmlObject( );
+ notifMsgHolder.setTopic( topicExpr );
+ return notifyDoc;
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicImpl.java Tue Aug 2 09:41:00 2005
@@ -1,4 +1,4 @@
-/*
+/*=============================================================================*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,7 +12,7 @@
* 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.notification.topics.impl;
import org.apache.commons.logging.Log;
@@ -21,7 +21,6 @@
import org.apache.ws.notification.topics.TopicListener;
import org.apache.ws.notification.topics.TopicSpace;
import org.apache.ws.notification.topics.expression.TopicExpression;
-
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -33,220 +32,377 @@
/**
* Simple in-memory implementation of the Topic interface
*/
-public class TopicImpl implements Topic, TopicListener
+public class TopicImpl
+ implements Topic,
+ TopicListener
{
+ private static final Log LOG = LogFactory.getLog( TopicImpl.class.getName( ) );
+
+ /** DOCUMENT_ME */
+ protected Map m_subTopics;
+
+ /** DOCUMENT_ME */
+ protected TopicExpression m_reference;
- protected Map m_subTopics;
- protected TopicExpression m_reference;
- protected Collection m_listeners;
- protected String m_name;
- protected Object m_currentMsg;
- protected List m_topicPath; // ordered set of QNames
- protected TopicSpace m_topicSpace;
- private Topic m_parent;
-
- private static final Log LOG = LogFactory.getLog( TopicImpl.class.getName() );
- protected boolean m_isVisible = true;
-
- public Topic addTopic( Topic topic )
- {
- if ( m_reference != null )
- {
- throw new IllegalStateException( "Cannot modify the TopicExpression reference by adding an additional Topic." );
- }
-
- m_subTopics.put( topic.getName(), topic );
-
- List topicPath = new LinkedList();
-
- topicPath.addAll( m_topicPath );
- topicPath.add( topic.getName() );
-
- topic.setTopicPath( topicPath );
- topic.addTopicListener( this );
-
- topic.setTopicSpace(m_topicSpace);
- ((TopicImpl)topic).setParent( this );
-
- return topic;
- }
-
- public Topic addTopic( String name )
- {
- return addTopic( new TopicImpl( name ) );
- }
-
- public void removeTopic( String name )
- {
- m_subTopics.remove( name );
- }
-
- public synchronized void addTopicListener( TopicListener listener )
- {
- m_listeners.add( listener );
- }
-
- public String getName()
- {
- return m_name;
- }
-
- public Topic getTopic( String topicName )
- {
- return (Topic) m_subTopics.get( topicName );
- }
-
- public boolean containsTopic( String name )
- {
- return m_subTopics.containsKey( name );
- }
-
- /**
- * Get the topic expression for the topic(s) that this topic references.
- *
- * @return The topic expression that this topic reference or null if this topic is not a reference.
- */
- public TopicExpression getTopicReference()
- {
- return m_reference;
- }
-
- public boolean isReference()
- {
- return m_reference != null;
- }
-
- public Iterator topicIterator()
- {
- return m_subTopics.values().iterator();
- }
-
- public void publish( Object msg ) throws Exception
- {
- m_currentMsg = msg;
- if ( LOG.isDebugEnabled() )
- {
- LOG.debug( "Publish called on topic " +
- m_name + " with message " + msg );
- }
- this.topicChanged( this );
- }
-
- public Object getCurrentMessage()
- {
- return m_currentMsg;
- }
-
- public void removeTopic( Topic topic )
- {
- m_subTopics.remove( topic.getName() );
- topic.removeTopicListener( this );
- }
-
- public synchronized void removeTopicListener( TopicListener listener )
- {
- this.m_listeners.remove( listener );
- }
-
- public synchronized Iterator topicListenerIterator()
- {
- return this.m_listeners.iterator();
- }
-
- public void setTopicReference( TopicExpression topicPath )
- {
- this.m_reference = topicPath;
- }
-
- public void setTopicPath( List topicPath )
- {
- m_topicPath = topicPath;
- }
-
- public List getTopicPath()
- {
- return m_topicPath;
- }
-
- /**
- * Create a topic with the given name
- *
- * @param name The name of the created topic
- */
- public TopicImpl( String name )
- {
- this( new HashMap(), null, new Vector(), name, null, null );
- }
-
- /**
- * Create a topic with the given parameters
- *
- * @param subTopics A map of child topics
- * @param reference A topic expression (only used if this is a topic alias)
- * @param listeners A collection of topic listeners
- * @param name The name of this topic
- * @param current The current value of this topic
- * @param topicPath The concrete topic path of this topic
- */
- public TopicImpl( Map subTopics, TopicExpression reference,
- Collection listeners, String name,
- Object current, List topicPath )
- {
- this.m_subTopics = subTopics;
- this.m_reference = reference;
- this.m_listeners = listeners;
- this.m_name = name;
- this.m_currentMsg = current;
- if(topicPath==null){
- this.m_topicPath = new java.util.LinkedList();
- m_topicPath.add(name);
- }
- }
-
-
-
- public synchronized void topicChanged( Topic topic )
- {
- Iterator listenerIterator = this.m_listeners.iterator();
- TopicListener listener;
- while ( listenerIterator.hasNext() )
- {
- listener = (TopicListener) listenerIterator.next();
- listener.topicChanged( topic );
- }
- }
-
-
- void setParent( Topic parent )
- {
- m_parent = parent;
- }
-
- public Topic getParent()
- {
- return m_parent;
- }
-
- public String toString(){
- // TODO: *SJC* make this print the full concrete path of this Topic instead of just its name
- return getName();
- }
-
- public void setTopicSpace(TopicSpace topicSpace) {
- m_topicSpace = topicSpace;
- }
-
- public TopicSpace getTopicSpace() {
- return m_topicSpace;
- }
-
- public boolean isVisible()
- {
- return m_isVisible;
- }
-
- public void setIsVisible(boolean visible)
- {
- m_isVisible = visible;
- }
-}
+ /** DOCUMENT_ME */
+ protected Collection m_listeners;
+
+ /** DOCUMENT_ME */
+ protected String m_name;
+
+ /** DOCUMENT_ME */
+ protected Object m_currentMsg;
+
+ /** DOCUMENT_ME */
+ protected List m_topicPath; // ordered set of QNames
+
+ /** DOCUMENT_ME */
+ protected TopicSpace m_topicSpace;
+ private Topic m_parent;
+
+ /** DOCUMENT_ME */
+ protected boolean m_isVisible = true;
+
+ /**
+ * Create a topic with the given name
+ *
+ * @param name The name of the created topic
+ */
+ public TopicImpl( String name )
+ {
+ this( new HashMap( ), null, new Vector( ), name, null, null );
+ }
+
+ /**
+ * Create a topic with the given parameters
+ *
+ * @param subTopics A map of child topics
+ * @param reference A topic expression (only used if this is a topic alias)
+ * @param listeners A collection of topic listeners
+ * @param name The name of this topic
+ * @param current The current value of this topic
+ * @param topicPath The concrete topic path of this topic
+ */
+ public TopicImpl( Map subTopics,
+ TopicExpression reference,
+ Collection listeners,
+ String name,
+ Object current,
+ List topicPath )
+ {
+ this.m_subTopics = subTopics;
+ this.m_reference = reference;
+ this.m_listeners = listeners;
+ this.m_name = name;
+ this.m_currentMsg = current;
+ if ( topicPath == null )
+ {
+ this.m_topicPath = new java.util.LinkedList( );
+ m_topicPath.add( name );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Object getCurrentMessage( )
+ {
+ return m_currentMsg;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param visible DOCUMENT_ME
+ */
+ public void setIsVisible( boolean visible )
+ {
+ m_isVisible = visible;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getName( )
+ {
+ return m_name;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic getParent( )
+ {
+ return m_parent;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean isReference( )
+ {
+ return m_reference != null;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicName DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic getTopic( String topicName )
+ {
+ return (Topic) m_subTopics.get( topicName );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicPath DOCUMENT_ME
+ */
+ public void setTopicPath( List topicPath )
+ {
+ m_topicPath = topicPath;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public List getTopicPath( )
+ {
+ return m_topicPath;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicPath DOCUMENT_ME
+ */
+ public void setTopicReference( TopicExpression topicPath )
+ {
+ this.m_reference = topicPath;
+ }
+
+ /**
+ * Get the topic expression for the topic(s) that this topic references.
+ *
+ * @return The topic expression that this topic reference or null if this topic is not a reference.
+ */
+ public TopicExpression getTopicReference( )
+ {
+ return m_reference;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicSpace DOCUMENT_ME
+ */
+ public void setTopicSpace( TopicSpace topicSpace )
+ {
+ m_topicSpace = topicSpace;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public TopicSpace getTopicSpace( )
+ {
+ return m_topicSpace;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean isVisible( )
+ {
+ return m_isVisible;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic addTopic( Topic topic )
+ {
+ if ( m_reference != null )
+ {
+ throw new IllegalStateException( "Cannot modify the TopicExpression reference by adding an additional Topic." );
+ }
+
+ m_subTopics.put( topic.getName( ),
+ topic );
+
+ List topicPath = new LinkedList( );
+
+ topicPath.addAll( m_topicPath );
+ topicPath.add( topic.getName( ) );
+
+ topic.setTopicPath( topicPath );
+ topic.addTopicListener( this );
+
+ topic.setTopicSpace( m_topicSpace );
+ ( (TopicImpl) topic ).setParent( this );
+
+ return topic;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic addTopic( String name )
+ {
+ return addTopic( new TopicImpl( name ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param listener DOCUMENT_ME
+ */
+ public synchronized void addTopicListener( TopicListener listener )
+ {
+ m_listeners.add( listener );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean containsTopic( String name )
+ {
+ return m_subTopics.containsKey( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param msg DOCUMENT_ME
+ *
+ * @throws Exception DOCUMENT_ME
+ */
+ public void publish( Object msg )
+ throws Exception
+ {
+ m_currentMsg = msg;
+ if ( LOG.isDebugEnabled( ) )
+ {
+ LOG.debug( "Publish called on topic " + m_name + " with message " + msg );
+ }
+
+ this.topicChanged( this );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void removeTopic( String name )
+ {
+ m_subTopics.remove( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic DOCUMENT_ME
+ */
+ public void removeTopic( Topic topic )
+ {
+ m_subTopics.remove( topic.getName( ) );
+ topic.removeTopicListener( this );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param listener DOCUMENT_ME
+ */
+ public synchronized void removeTopicListener( TopicListener listener )
+ {
+ this.m_listeners.remove( listener );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String toString( )
+ {
+ // TODO: *SJC* make this print the full concrete path of this Topic instead of just its name
+ return getName( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic DOCUMENT_ME
+ */
+ public synchronized void topicChanged( Topic topic )
+ {
+ Iterator listenerIterator = this.m_listeners.iterator( );
+ TopicListener listener;
+ while ( listenerIterator.hasNext( ) )
+ {
+ listener = (TopicListener) listenerIterator.next( );
+ listener.topicChanged( topic );
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Iterator topicIterator( )
+ {
+ return m_subTopics.values( ).iterator( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public synchronized Iterator topicListenerIterator( )
+ {
+ return this.m_listeners.iterator( );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param parent DOCUMENT_ME
+ */
+ void setParent( Topic parent )
+ {
+ m_parent = parent;
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceImpl.java Tue Aug 2 09:41:00 2005
@@ -1,87 +1,144 @@
-/*=============================================================================*
- * 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.notification.topics.impl;
-
-import org.apache.ws.notification.topics.Topic;
-import org.apache.ws.notification.topics.TopicSpace;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * An implementation of a TopicSpace.
- */
-public class TopicSpaceImpl implements TopicSpace
-{
-
- private String m_targetNs;
- private String m_name = "TopicSpace";
- private Map m_rootTopicMap = new HashMap();
-
- public TopicSpaceImpl( String targetNs )
- {
- m_targetNs = targetNs != null ? targetNs : "";
- }
-
- public String getTargetNamespace()
- {
- return m_targetNs;
- }
-
- public String getName()
- {
- return m_name;
- }
-
- public void setName( String name )
- {
- m_name = name;
- }
-
- public Topic addTopic( Topic topic )
- {
- m_rootTopicMap.put( topic.getName(), topic );
- topic.setTopicSpace(this);
- return topic;
- }
-
- public Topic addTopic( String name )
- {
- return addTopic( new TopicImpl( name ) );
- }
-
- public void removeTopic( String name )
- {
- m_rootTopicMap.remove( name );
- }
-
- public Topic getTopic( String name )
- {
- return (Topic) m_rootTopicMap.get( name );
- }
-
- public boolean containsTopic( String name )
- {
- return m_rootTopicMap.containsKey( name );
- }
-
- public Iterator topicIterator()
- {
- return m_rootTopicMap.values().iterator();
- }
-
-}
+/*=============================================================================*
+ * 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.notification.topics.impl;
+
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicSpace;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * An implementation of a TopicSpace.
+ */
+public class TopicSpaceImpl
+ implements TopicSpace
+{
+ private String m_targetNs;
+ private String m_name = "TopicSpace";
+ private Map m_rootTopicMap = new HashMap( );
+
+ /**
+ * Creates a new {@link TopicSpaceImpl} object.
+ *
+ * @param targetNs DOCUMENT_ME
+ */
+ public TopicSpaceImpl( String targetNs )
+ {
+ m_targetNs = ( targetNs != null ) ? targetNs : "";
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void setName( String name )
+ {
+ m_name = name;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getName( )
+ {
+ return m_name;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public String getTargetNamespace( )
+ {
+ return m_targetNs;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic getTopic( String name )
+ {
+ return (Topic) m_rootTopicMap.get( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topic DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic addTopic( Topic topic )
+ {
+ m_rootTopicMap.put( topic.getName( ),
+ topic );
+ topic.setTopicSpace( this );
+ return topic;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Topic addTopic( String name )
+ {
+ return addTopic( new TopicImpl( name ) );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean containsTopic( String name )
+ {
+ return m_rootTopicMap.containsKey( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param name DOCUMENT_ME
+ */
+ public void removeTopic( String name )
+ {
+ m_rootTopicMap.remove( name );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public Iterator topicIterator( )
+ {
+ return m_rootTopicMap.values( ).iterator( );
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/impl/TopicSpaceSetImpl.java Tue Aug 2 09:41:00 2005
@@ -1,89 +1,144 @@
-package org.apache.ws.notification.topics.impl;
-
-import org.apache.ws.notification.topics.Topic;
-import org.apache.ws.notification.topics.TopicSpace;
-import org.apache.ws.notification.topics.TopicSpaceSet;
-import org.apache.ws.notification.topics.expression.TopicExpression;
-import org.apache.ws.notification.topics.expression.TopicExpressionEngine;
-import org.apache.ws.notification.topics.expression.TopicExpressionException;
-import org.apache.ws.notification.topics.expression.impl.TopicExpressionEngineImpl;
-
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * @author Sal Campana
- */
-public class TopicSpaceSetImpl implements TopicSpaceSet
-{
-
- private static final TopicExpressionEngine TOPIC_EXPR_ENGINE =
- TopicExpressionEngineImpl.getInstance();
-
- private Map m_topicSpaces = new Hashtable();
- private boolean m_fixed;
-
- public TopicSpaceSetImpl( boolean fixed )
- {
- m_fixed = fixed;
- }
-
- /**
- * Adds the TopicSpace to the TopicSpaceSet.
- *
- * Note. If the TopiSpace already exists, this method will add all the known Topics
- * to the passed-in TopicSpace and set it as the current TopicSpace in the TopicSpaceSet.
- * This will ensure there is only 1 TopicSpace in the set and it is complete...
- *
- * @param topicSpace
- */
- public TopicSpace addTopicSpace(TopicSpace topicSpace)
- {
- String namespaceURI = topicSpace.getTargetNamespace();
- //if topicSpace exists, simply add all topics to topicspace
- if(m_topicSpaces.containsKey(namespaceURI))
- {
- TopicSpace topicSpc = (TopicSpace) m_topicSpaces.get(namespaceURI);
- Iterator iterator = topicSpc.topicIterator();
- while (iterator.hasNext())
- {
- Topic topic = (Topic) iterator.next();
- topicSpace.addTopic(topic);
- }
- }
- m_topicSpaces.put(namespaceURI, topicSpace);
- return topicSpace;
- }
-
- public void removeTopicSpace(String namespaceURI)
- {
- m_topicSpaces.remove(namespaceURI);
- }
-
- public TopicSpace getTopicSpace(String namespaceURI)
- {
- return (TopicSpace) m_topicSpaces.get(namespaceURI);
- }
-
- public TopicSpace[] getTopicSpaces()
- {
- return (TopicSpace[]) m_topicSpaces.values().toArray(new TopicSpace[0]);
- }
-
- public Topic[] evaluateTopicExpression(TopicExpression topicExpr)
- throws TopicExpressionException
- {
- return TOPIC_EXPR_ENGINE.evaluateTopicExpression( this, topicExpr );
- }
-
- public boolean isFixed()
- {
- return m_fixed;
- }
-
- public void setFixed( boolean fixed )
- {
- m_fixed = fixed;
- }
-}
+/*=============================================================================*
+ * 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.notification.topics.impl;
+
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.expression.TopicExpression;
+import org.apache.ws.notification.topics.expression.TopicExpressionEngine;
+import org.apache.ws.notification.topics.expression.TopicExpressionException;
+import org.apache.ws.notification.topics.expression.impl.TopicExpressionEngineImpl;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author Sal Campana
+ */
+public class TopicSpaceSetImpl
+ implements TopicSpaceSet
+{
+ private static final TopicExpressionEngine TOPIC_EXPR_ENGINE = TopicExpressionEngineImpl.getInstance( );
+ private Map m_topicSpaces = new Hashtable( );
+ private boolean m_fixed;
+
+ /**
+ * Creates a new {@link TopicSpaceSetImpl} object.
+ *
+ * @param fixed DOCUMENT_ME
+ */
+ public TopicSpaceSetImpl( boolean fixed )
+ {
+ m_fixed = fixed;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param fixed DOCUMENT_ME
+ */
+ public void setFixed( boolean fixed )
+ {
+ m_fixed = fixed;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public boolean isFixed( )
+ {
+ return m_fixed;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param namespaceURI DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public TopicSpace getTopicSpace( String namespaceURI )
+ {
+ return (TopicSpace) m_topicSpaces.get( namespaceURI );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public TopicSpace[] getTopicSpaces( )
+ {
+ return (TopicSpace[]) m_topicSpaces.values( ).toArray( new TopicSpace[0] );
+ }
+
+ /**
+ * Adds the TopicSpace to the TopicSpaceSet.
+ *
+ * Note. If the TopiSpace already exists, this method will add all the known Topics
+ * to the passed-in TopicSpace and set it as the current TopicSpace in the TopicSpaceSet.
+ * This will ensure there is only 1 TopicSpace in the set and it is complete...
+ *
+ * @param topicSpace
+ */
+ public TopicSpace addTopicSpace( TopicSpace topicSpace )
+ {
+ String namespaceURI = topicSpace.getTargetNamespace( );
+
+ //if topicSpace exists, simply add all topics to topicspace
+ if ( m_topicSpaces.containsKey( namespaceURI ) )
+ {
+ TopicSpace topicSpc = (TopicSpace) m_topicSpaces.get( namespaceURI );
+ Iterator iterator = topicSpc.topicIterator( );
+ while ( iterator.hasNext( ) )
+ {
+ Topic topic = (Topic) iterator.next( );
+ topicSpace.addTopic( topic );
+ }
+ }
+
+ m_topicSpaces.put( namespaceURI, topicSpace );
+ return topicSpace;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param topicExpr DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ *
+ * @throws TopicExpressionException DOCUMENT_ME
+ */
+ public Topic[] evaluateTopicExpression( TopicExpression topicExpr )
+ throws TopicExpressionException
+ {
+ return TOPIC_EXPR_ENGINE.evaluateTopicExpression( this, topicExpr );
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param namespaceURI DOCUMENT_ME
+ */
+ public void removeTopicSpace( String namespaceURI )
+ {
+ m_topicSpaces.remove( namespaceURI );
+ }
+}
\ No newline at end of file
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicSpaceParser.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicSpaceParser.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicSpaceParser.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicSpaceParser.java Tue Aug 2 09:41:00 2005
@@ -1,83 +1,144 @@
-/*
- * TopicSpaceParser.java
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
*
- * Created on 1. März 2005, 12:54
- */
-
+ * 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.notification.topics.util;
+
import org.apache.ws.notification.topics.*;
-import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
import org.apache.ws.notification.topics.impl.TopicImpl;
-import java.io.InputStream;
-import javax.xml.parsers.*;
+import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
+import javax.xml.parsers.*;
+import java.io.InputStream;
+
/**
*
* @author Stefan Lischke
*/
-public class TopicSpaceParser extends DefaultHandler{
- private static TopicSpace m_topicSpace;
- private static java.util.Stack stack;
- private int depth=0;
- private String tns;
-
- public static TopicSpace parse(InputStream is){
- // Use an instance of ourselves as the SAX event handler
- DefaultHandler handler = new TopicSpaceParser();
- // Parse the input with the default (non-validating) parser
- stack= new java.util.Stack();
- try{
- SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
- //System.out.println("start parsing");
- saxParser.parse( is, handler );
- //System.out.println("end parsing");
-
- }catch(Exception e){
- e.printStackTrace();
- }
- return m_topicSpace;
- }
-
- public void startElement( String namespaceURI,
- String localName, // local name
- String qName, // qualified name
- Attributes attrs ) throws SAXException {
- try{
- //System.out.println("start element "+qName);
- if(qName.endsWith("topicSpace")){
- tns=attrs.getValue("targetNamespace");
- m_topicSpace=new TopicSpaceImpl(tns);
- //System.out.println("topicspace "+tns);
- }
- if(qName.endsWith("topic")){
- Topic t=new TopicImpl(attrs.getValue("name"));
- if(depth==0){
- m_topicSpace.addTopic(t);
- stack.push(t);
- }else{
- Topic in = (Topic)stack.peek();
- in.addTopic(t);
- stack.push(t);
- }
- //System.out.println(depth+" : "+attrs.getValue("name"));
- depth++;
+public class TopicSpaceParser
+ extends DefaultHandler
+{
+ private static TopicSpace m_topicSpace;
+ private static java.util.Stack stack;
+ private int depth = 0;
+ private String tns;
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param is DOCUMENT_ME
+ *
+ * @return DOCUMENT_ME
+ */
+ public static TopicSpace parse( InputStream is )
+ {
+ // Use an instance of ourselves as the SAX event handler
+ DefaultHandler handler = new TopicSpaceParser( );
+
+ // Parse the input with the default (non-validating) parser
+ stack = new java.util.Stack( );
+ try
+ {
+ SAXParser saxParser = SAXParserFactory.newInstance( ).newSAXParser( );
+
+ //System.out.println("start parsing");
+ saxParser.parse( is, handler );
+
+ //System.out.println("end parsing");
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace( );
+ }
+
+ return m_topicSpace;
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param namespaceURI DOCUMENT_ME
+ * @param localName DOCUMENT_ME
+ * @param qName DOCUMENT_ME
+ *
+ * @throws SAXException DOCUMENT_ME
+ */
+ public void endElement( String namespaceURI,
+ String localName, // local name
+ String qName ) // qualified name
+ throws SAXException
+ {
+ if ( qName.endsWith( "topic" ) )
+ {
+ if ( depth > 0 )
+ {
+ depth--;
+ stack.pop( );
+ }
+ }
+ }
+
+ /**
+ * DOCUMENT_ME
+ *
+ * @param namespaceURI DOCUMENT_ME
+ * @param localName DOCUMENT_ME
+ * @param qName DOCUMENT_ME
+ * @param attrs DOCUMENT_ME
+ *
+ * @throws SAXException DOCUMENT_ME
+ */
+ public void startElement( String namespaceURI,
+ String localName, // local name
+ String qName, // qualified name
+ Attributes attrs )
+ throws SAXException
+ {
+ try
+ {
+ //System.out.println("start element "+qName);
+ if ( qName.endsWith( "topicSpace" ) )
+ {
+ tns = attrs.getValue( "targetNamespace" );
+ m_topicSpace = new TopicSpaceImpl( tns );
+
+ //System.out.println("topicspace "+tns);
+ }
+
+ if ( qName.endsWith( "topic" ) )
+ {
+ Topic t = new TopicImpl( attrs.getValue( "name" ) );
+ if ( depth == 0 )
+ {
+ m_topicSpace.addTopic( t );
+ stack.push( t );
}
- }catch(Exception e){
- e.printStackTrace();
- }
- }
-
- public void endElement( String namespaceURI,
- String localName, // local name
- String qName ) // qualified name
- throws SAXException {
- if(qName.endsWith("topic")){
- if(depth>0){
- depth--;
- stack.pop();
+ else
+ {
+ Topic in = (Topic) stack.peek( );
+ in.addTopic( t );
+ stack.push( t );
}
-
- }
- }
+
+ //System.out.println(depth+" : "+attrs.getValue("name"));
+ depth++;
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace( );
+ }
+ }
}
Modified: webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java
URL: http://svn.apache.org/viewcvs/webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java?rev=227035&r1=227034&r2=227035&view=diff
==============================================================================
--- webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java (original)
+++ webservices/pubscribe/trunk/src/java/org/apache/ws/notification/topics/util/TopicUtils.java Tue Aug 2 09:41:00 2005
@@ -1,131 +1,137 @@
-/*=============================================================================*
- * 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.notification.topics.util;
-
-import org.apache.ws.notification.topics.ResourcePropertyValueChangeTopic;
-import org.apache.ws.notification.topics.Topic;
-import org.apache.ws.notification.topics.TopicSpace;
-import org.apache.ws.notification.topics.TopicSpaceSet;
-import org.apache.ws.notification.topics.impl.ResourcePropertyValueChangeTopicImpl;
-import org.apache.ws.notification.topics.impl.ResourceTerminationTopicImpl;
-import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
-import org.apache.ws.resource.Resource;
-import org.apache.ws.resource.lifetime.ResourceTerminationListener;
-import org.apache.ws.resource.properties.NamespaceVersionHolder;
-import org.apache.ws.resource.properties.ResourceProperty;
-import org.apache.ws.resource.properties.ResourcePropertySet;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A utility class containing static methods used as helpers for working with WSN Topics.
- *
- * @author Sal Campana
- */
-public class TopicUtils
-{
-
- /**
- * Adds the topic for ResourceTermination....there should be only one of these!
- *
- * @param topicSpaceSet
- * @return
- */
- public static Topic addResourceTerminationTopic(TopicSpaceSet topicSpaceSet, Resource resource, NamespaceVersionHolder namespaces)
- throws Exception
- {
- //there can be only 1 !
- String namespace = namespaces.getLifetimeXsdNamespace();
- TopicSpace topicSpace = topicSpaceSet.getTopicSpace(namespace);
- if (topicSpace == null)
- {
- topicSpace = new TopicSpaceImpl(namespace);
- topicSpaceSet.addTopicSpace(topicSpace);
- }
- Topic resourceTerminationTopic = null;
- while (topicSpace.topicIterator().hasNext())
- {
- Topic topic = (Topic) topicSpace.topicIterator().next();
- if(topic.getName().equals(ResourceTerminationTopicImpl.TOPIC_NAME))
- {
- resourceTerminationTopic = topic;
- break;
- }
- }
-
- if(resourceTerminationTopic == null)
- {
- resourceTerminationTopic = new ResourceTerminationTopicImpl(namespaces);
- resource.addTerminationListener((ResourceTerminationListener) resourceTerminationTopic);
- topicSpace.addTopic(resourceTerminationTopic);
- }
- return resourceTerminationTopic;
- }
-
- /**
- * Adds a topic for the specified property to the specified topic set.
- *
- * @param prop
- * @param topicSpaceSet
- * @return
- */
- public static Topic addResourcePropertyValueChangeTopic( ResourceProperty prop, TopicSpaceSet topicSpaceSet )
- throws Exception
- {
- if ( prop.getMetaData().isReadOnly() )
- {
- throw new IllegalArgumentException( "Property " + prop.getMetaData().getName() + " is readonly!" );
- }
- ResourcePropertyValueChangeTopic valueChangeTopic = new ResourcePropertyValueChangeTopicImpl( prop );
- prop.addChangeListener( valueChangeTopic );
- String topicNsURI = prop.getMetaData().getName().getNamespaceURI();
- TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicNsURI );
- if ( topicSpace == null )
- {
- topicSpace = new TopicSpaceImpl( topicNsURI );
- topicSpaceSet.addTopicSpace( topicSpace );
- }
- topicSpace.addTopic( valueChangeTopic );
- return valueChangeTopic;
- }
-
- /**
- * Adds topics for all non-readonly properties from the specified property set to the specified topic set.
- *
- * @param propSet
- * @param topicSpaceSet
- * @return
- */
- public static Topic[] addResourcePropertyValueChangeTopics( ResourcePropertySet propSet, TopicSpaceSet topicSpaceSet )
- throws Exception
- {
- List topicList = new ArrayList();
- Iterator propIter = propSet.iterator();
- while ( propIter.hasNext() )
- {
- ResourceProperty prop = (ResourceProperty) propIter.next();
- if ( ! prop.getMetaData().isReadOnly() )
- {
- Topic topic = addResourcePropertyValueChangeTopic( prop, topicSpaceSet );
- topicList.add( topic );
- }
- }
- return (Topic[]) topicList.toArray( new Topic[0] );
- }
-
-}
+/*=============================================================================*
+ * 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.notification.topics.util;
+
+import org.apache.ws.notification.topics.ResourcePropertyValueChangeTopic;
+import org.apache.ws.notification.topics.Topic;
+import org.apache.ws.notification.topics.TopicSpace;
+import org.apache.ws.notification.topics.TopicSpaceSet;
+import org.apache.ws.notification.topics.impl.ResourcePropertyValueChangeTopicImpl;
+import org.apache.ws.notification.topics.impl.ResourceTerminationTopicImpl;
+import org.apache.ws.notification.topics.impl.TopicSpaceImpl;
+import org.apache.ws.resource.Resource;
+import org.apache.ws.resource.lifetime.ResourceTerminationListener;
+import org.apache.ws.resource.properties.NamespaceVersionHolder;
+import org.apache.ws.resource.properties.ResourceProperty;
+import org.apache.ws.resource.properties.ResourcePropertySet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A utility class containing static methods used as helpers for working with WSN Topics.
+ *
+ * @author Sal Campana
+ */
+public class TopicUtils
+{
+ /**
+ * Adds a topic for the specified property to the specified topic set.
+ *
+ * @param prop
+ * @param topicSpaceSet
+ * @return
+ */
+ public static Topic addResourcePropertyValueChangeTopic( ResourceProperty prop,
+ TopicSpaceSet topicSpaceSet )
+ throws Exception
+ {
+ if ( prop.getMetaData( ).isReadOnly( ) )
+ {
+ throw new IllegalArgumentException( "Property " + prop.getMetaData( ).getName( ) + " is readonly!" );
+ }
+
+ ResourcePropertyValueChangeTopic valueChangeTopic = new ResourcePropertyValueChangeTopicImpl( prop );
+ prop.addChangeListener( valueChangeTopic );
+ String topicNsURI = prop.getMetaData( ).getName( ).getNamespaceURI( );
+ TopicSpace topicSpace = topicSpaceSet.getTopicSpace( topicNsURI );
+ if ( topicSpace == null )
+ {
+ topicSpace = new TopicSpaceImpl( topicNsURI );
+ topicSpaceSet.addTopicSpace( topicSpace );
+ }
+
+ topicSpace.addTopic( valueChangeTopic );
+ return valueChangeTopic;
+ }
+
+ /**
+ * Adds topics for all non-readonly properties from the specified property set to the specified topic set.
+ *
+ * @param propSet
+ * @param topicSpaceSet
+ * @return
+ */
+ public static Topic[] addResourcePropertyValueChangeTopics( ResourcePropertySet propSet,
+ TopicSpaceSet topicSpaceSet )
+ throws Exception
+ {
+ List topicList = new ArrayList( );
+ Iterator propIter = propSet.iterator( );
+ while ( propIter.hasNext( ) )
+ {
+ ResourceProperty prop = (ResourceProperty) propIter.next( );
+ if ( !prop.getMetaData( ).isReadOnly( ) )
+ {
+ Topic topic = addResourcePropertyValueChangeTopic( prop, topicSpaceSet );
+ topicList.add( topic );
+ }
+ }
+
+ return (Topic[]) topicList.toArray( new Topic[0] );
+ }
+
+ /**
+ * Adds the topic for ResourceTermination....there should be only one of these!
+ *
+ * @param topicSpaceSet
+ * @return
+ */
+ public static Topic addResourceTerminationTopic( TopicSpaceSet topicSpaceSet,
+ Resource resource,
+ NamespaceVersionHolder namespaces )
+ throws Exception
+ {
+ //there can be only 1 !
+ String namespace = namespaces.getLifetimeXsdNamespace( );
+ TopicSpace topicSpace = topicSpaceSet.getTopicSpace( namespace );
+ if ( topicSpace == null )
+ {
+ topicSpace = new TopicSpaceImpl( namespace );
+ topicSpaceSet.addTopicSpace( topicSpace );
+ }
+
+ Topic resourceTerminationTopic = null;
+ while ( topicSpace.topicIterator( ).hasNext( ) )
+ {
+ Topic topic = (Topic) topicSpace.topicIterator( ).next( );
+ if ( topic.getName( ).equals( ResourceTerminationTopicImpl.TOPIC_NAME ) )
+ {
+ resourceTerminationTopic = topic;
+ break;
+ }
+ }
+
+ if ( resourceTerminationTopic == null )
+ {
+ resourceTerminationTopic = new ResourceTerminationTopicImpl( namespaces );
+ resource.addTerminationListener( (ResourceTerminationListener) resourceTerminationTopic );
+ topicSpace.addTopic( resourceTerminationTopic );
+ }
+
+ return resourceTerminationTopic;
+ }
+}
\ No newline at end of file