001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.wsn.jms;
018
019 import java.net.URI;
020
021 import javax.jms.Connection;
022 import javax.jms.ConnectionFactory;
023 import javax.xml.namespace.QName;
024 import javax.xml.bind.JAXBElement;
025 import javax.xml.datatype.DatatypeFactory;
026
027 import org.apache.servicemix.wsn.AbstractNotificationBroker;
028 import org.apache.servicemix.wsn.AbstractPublisher;
029 import org.apache.servicemix.wsn.AbstractSubscription;
030 import org.oasis_open.docs.wsrf.rp_2.GetResourcePropertyResponse;
031 import org.oasis_open.docs.wsrf.rp_2.InvalidResourcePropertyQNameFaultType;
032 import org.oasis_open.docs.wsrf.rw_2.ResourceUnavailableFault;
033 import org.oasis_open.docs.wsrf.rw_2.ResourceUnknownFault;
034 import org.oasis_open.docs.wsrf.rpw_2.InvalidResourcePropertyQNameFault;
035
036 public abstract class JmsNotificationBroker extends AbstractNotificationBroker {
037
038 private ConnectionFactory connectionFactory;
039
040 private Connection connection;
041
042 public JmsNotificationBroker(String name) {
043 super(name);
044 }
045
046 public void init() throws Exception {
047 if (connection == null) {
048 connection = connectionFactory.createConnection();
049 connection.start();
050 }
051 super.init();
052 }
053
054 public void destroy() throws Exception {
055 if (connection != null) {
056 connection.close();
057 }
058 super.destroy();
059 }
060
061 @Override
062 protected AbstractPublisher createPublisher(String name) {
063 JmsPublisher publisher = createJmsPublisher(name);
064 publisher.setManager(getManager());
065 publisher.setConnection(connection);
066 return publisher;
067 }
068
069 @Override
070 protected AbstractSubscription createSubcription(String name) {
071 JmsSubscription subscription = createJmsSubscription(name);
072 subscription.setManager(getManager());
073 subscription.setConnection(connection);
074 return subscription;
075 }
076
077 protected abstract JmsSubscription createJmsSubscription(String name);
078
079 protected abstract JmsPublisher createJmsPublisher(String name);
080
081 public ConnectionFactory getConnectionFactory() {
082 return connectionFactory;
083 }
084
085 public void setConnectionFactory(ConnectionFactory connectionFactory) {
086 this.connectionFactory = connectionFactory;
087 }
088
089 protected GetResourcePropertyResponse handleGetResourceProperty(QName property)
090 throws ResourceUnavailableFault, ResourceUnknownFault, InvalidResourcePropertyQNameFault {
091 if (TOPIC_EXPRESSION_QNAME.equals(property)) {
092 // TODO
093 } else if (FIXED_TOPIC_SET_QNAME.equals(property)) {
094 // TODO
095 } else if (TOPIC_EXPRESSION_DIALECT_QNAME.equals(property)) {
096 GetResourcePropertyResponse r = new GetResourcePropertyResponse();
097 r.getAny().add(new JAXBElement(TOPIC_EXPRESSION_DIALECT_QNAME, URI.class, JmsTopicExpressionConverter.SIMPLE_DIALECT));
098 return r;
099 } else if (TOPIC_SET_QNAME.equals(property)) {
100 // TODO
101 }
102 return super.handleGetResourceProperty(property);
103 }
104
105 }