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.spring;
018
019 import javax.xml.bind.JAXBElement;
020
021 import org.apache.servicemix.wsn.AbstractSubscription;
022 import org.apache.servicemix.wsn.client.AbstractWSAClient;
023 import org.oasis_open.docs.wsn.b_2.FilterType;
024 import org.oasis_open.docs.wsn.b_2.QueryExpressionType;
025 import org.oasis_open.docs.wsn.b_2.Subscribe;
026 import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
027 import org.oasis_open.docs.wsn.b_2.UseRaw;
028 import org.springframework.beans.factory.FactoryBean;
029
030 /**
031 *
032 * @author gnodet
033 * @version $Revision: 376451 $
034 * @org.apache.xbean.XBean element="subscribe"
035 */
036 public class SubscribeFactoryBean implements FactoryBean {
037
038 private String consumer;
039
040 private String topic;
041
042 private String xpath;
043
044 private boolean raw;
045
046 /**
047 * @return Returns the consumer.
048 */
049 public String getConsumer() {
050 return consumer;
051 }
052
053 /**
054 * @param consumer
055 * The consumer to set.
056 */
057 public void setConsumer(String consumer) {
058 this.consumer = consumer;
059 }
060
061 /**
062 * @return Returns the topic.
063 */
064 public String getTopic() {
065 return topic;
066 }
067
068 /**
069 * @param topic
070 * The topic to set.
071 */
072 public void setTopic(String topic) {
073 this.topic = topic;
074 }
075
076 /**
077 * @return Returns the xpath.
078 */
079 public String getXpath() {
080 return xpath;
081 }
082
083 /**
084 * @param xpath
085 * The xpath to set.
086 */
087 public void setXpath(String xpath) {
088 this.xpath = xpath;
089 }
090
091 /**
092 * @return Returns the raw.
093 */
094 public boolean isRaw() {
095 return raw;
096 }
097
098 /**
099 * @param raw
100 * The raw to set.
101 */
102 public void setRaw(boolean raw) {
103 this.raw = raw;
104 }
105
106 /*
107 * (non-Javadoc)
108 *
109 * @see org.springframework.beans.factory.FactoryBean#getObject()
110 */
111 public Object getObject() throws Exception {
112 Subscribe subscribe = new Subscribe();
113 subscribe.setConsumerReference(AbstractWSAClient.createWSA(consumer));
114 subscribe.setFilter(new FilterType());
115 if (topic != null) {
116 TopicExpressionType topicExp = new TopicExpressionType();
117 topicExp.getContent().add(topic);
118 subscribe.getFilter().getAny().add(
119 new JAXBElement<TopicExpressionType>(AbstractSubscription.QNAME_TOPIC_EXPRESSION,
120 TopicExpressionType.class, topicExp));
121 }
122 if (xpath != null) {
123 QueryExpressionType xpathExp = new QueryExpressionType();
124 xpathExp.setDialect(AbstractSubscription.XPATH1_URI);
125 xpathExp.getContent().add(xpath);
126 subscribe.getFilter().getAny().add(
127 new JAXBElement<QueryExpressionType>(AbstractSubscription.QNAME_MESSAGE_CONTENT,
128 QueryExpressionType.class, xpathExp));
129 }
130 if (raw) {
131 subscribe.setSubscriptionPolicy(new Subscribe.SubscriptionPolicy());
132 subscribe.getSubscriptionPolicy().getAny().add(new UseRaw());
133 }
134 return subscribe;
135 }
136
137 /*
138 * (non-Javadoc)
139 *
140 * @see org.springframework.beans.factory.FactoryBean#getObjectType()
141 */
142 public Class getObjectType() {
143 return Subscribe.class;
144 }
145
146 /*
147 * (non-Javadoc)
148 *
149 * @see org.springframework.beans.factory.FactoryBean#isSingleton()
150 */
151 public boolean isSingleton() {
152 return false;
153 }
154
155 }