KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > wsn > spring > SubscribeFactoryBean


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.wsn.spring;
18
19 import javax.xml.bind.JAXBElement;
20
21 import org.apache.servicemix.wsn.AbstractSubscription;
22 import org.apache.servicemix.wsn.client.AbstractWSAClient;
23 import org.oasis_open.docs.wsn.b_2.FilterType;
24 import org.oasis_open.docs.wsn.b_2.QueryExpressionType;
25 import org.oasis_open.docs.wsn.b_2.Subscribe;
26 import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
27 import org.oasis_open.docs.wsn.b_2.UseRaw;
28 import org.springframework.beans.factory.FactoryBean;
29
30 /**
31  *
32  * @author gnodet
33  * @version $Revision: 376451 $
34  * @org.apache.xbean.XBean element="subscribe"
35  */

36 public class SubscribeFactoryBean implements FactoryBean {
37
38     private String JavaDoc consumer;
39     private String JavaDoc topic;
40     private String JavaDoc xpath;
41     private boolean raw;
42     
43     /**
44      * @return Returns the consumer.
45      */

46     public String JavaDoc getConsumer() {
47         return consumer;
48     }
49
50     /**
51      * @param consumer The consumer to set.
52      */

53     public void setConsumer(String JavaDoc consumer) {
54         this.consumer = consumer;
55     }
56
57     /**
58      * @return Returns the topic.
59      */

60     public String JavaDoc getTopic() {
61         return topic;
62     }
63
64     /**
65      * @param topic The topic to set.
66      */

67     public void setTopic(String JavaDoc topic) {
68         this.topic = topic;
69     }
70
71     /**
72      * @return Returns the xpath.
73      */

74     public String JavaDoc getXpath() {
75         return xpath;
76     }
77
78     /**
79      * @param xpath The xpath to set.
80      */

81     public void setXpath(String JavaDoc xpath) {
82         this.xpath = xpath;
83     }
84
85     /**
86      * @return Returns the raw.
87      */

88     public boolean isRaw() {
89         return raw;
90     }
91
92     /**
93      * @param raw The raw to set.
94      */

95     public void setRaw(boolean raw) {
96         this.raw = raw;
97     }
98
99     /* (non-Javadoc)
100      * @see org.springframework.beans.factory.FactoryBean#getObject()
101      */

102     public Object JavaDoc getObject() throws Exception JavaDoc {
103         Subscribe subscribe = new Subscribe();
104         subscribe.setConsumerReference(AbstractWSAClient.createWSA(consumer));
105         subscribe.setFilter(new FilterType());
106         if (topic != null) {
107             TopicExpressionType topicExp = new TopicExpressionType();
108             topicExp.getContent().add(topic);
109             subscribe.getFilter().getAny().add(new JAXBElement<TopicExpressionType>(AbstractSubscription.QNAME_TOPIC_EXPRESSION, TopicExpressionType.class, topicExp));
110         }
111         if (xpath != null) {
112             QueryExpressionType xpathExp = new QueryExpressionType();
113             xpathExp.setDialect(AbstractSubscription.XPATH1_URI);
114             xpathExp.getContent().add(xpath);
115             subscribe.getFilter().getAny().add(new JAXBElement<QueryExpressionType>(AbstractSubscription.QNAME_MESSAGE_CONTENT, QueryExpressionType.class, xpathExp));
116         }
117         if (raw) {
118             subscribe.setSubscriptionPolicy(new Subscribe.SubscriptionPolicy());
119             subscribe.getSubscriptionPolicy().getAny().add(new UseRaw());
120         }
121         return subscribe;
122     }
123
124     /* (non-Javadoc)
125      * @see org.springframework.beans.factory.FactoryBean#getObjectType()
126      */

127     public Class JavaDoc getObjectType() {
128         return Subscribe.class;
129     }
130
131     /* (non-Javadoc)
132      * @see org.springframework.beans.factory.FactoryBean#isSingleton()
133      */

134     public boolean isSingleton() {
135         return false;
136     }
137
138 }
139
Popular Tags