1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/**
*
* 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.tuscany.binding.jms;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.osoa.sca.annotations.Scope;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
import org.apache.tuscany.spi.annotation.Autowire;
import org.apache.tuscany.spi.component.CompositeComponent;
import org.apache.tuscany.spi.deployer.DeploymentContext;
import org.apache.tuscany.spi.extension.LoaderExtension;
import org.apache.tuscany.spi.loader.LoaderException;
import org.apache.tuscany.spi.loader.LoaderRegistry;
import org.apache.tuscany.spi.loader.LoaderUtil;
/**
* Loader for handling <binding.jms> elements.
*
* @version $Rev$ $Date$
*/
@Scope("MODULE")
public class JMSBindingLoader extends LoaderExtension<JMSBinding> {
public static final QName BINDING_JMS = new QName(
"http://tuscany.apache.org/xmlns/binding/jms/1.0-SNAPSHOT", "binding.jms");
public JMSBindingLoader(@Autowire LoaderRegistry registry) {
super(registry);
}
public QName getXMLType() {
return BINDING_JMS;
}
public JMSBinding load(CompositeComponent parent,
XMLStreamReader reader,
DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), reader);
OMElement omElement = builder.getDocumentElement();
OMElement connectionOM = omElement.getFirstChildWithName(new QName("connection.jms"));
String activationSpecName = connectionOM.getAttributeValue(new QName("activationSpecName"));
String destinationName = connectionOM.getAttributeValue(new QName("destinationName"));
String connectionFactoryName = connectionOM.getAttributeValue(new QName("connectionFactoryName")) ;
String initialContextFactoryName = connectionOM.getAttributeValue(new QName("initialContextFactoryName")) ;
String jNDIProviderURL = connectionOM.getAttributeValue(new QName("providerURL")) ;
String deliveryMode = connectionOM.getAttributeValue(new QName(null, "deliveryMode")) ;
String timeToLive = connectionOM.getAttributeValue(new QName(null, "timeToLive")) ;
String priority = connectionOM.getAttributeValue(new QName(null, "priority")) ;
String replyTo = connectionOM.getAttributeValue(new QName(null, "replyTo")) ;
String jmsResourceFactoryName = connectionOM.getAttributeValue(new QName(null, "jmsResourceFactory")) ;
OMElement opSecOM = omElement.getFirstChildWithName(new QName("operationSelector"));
String operationSelector = opSecOM.getAttributeValue(new QName("name"));
OMElement opSecPropertyOM = opSecOM.getFirstChildWithName(new QName("property"));
String jmsOpSecPropertyName = opSecPropertyOM.getText();
LoaderUtil.skipToEndElement(reader);
JMSBinding binding = new JMSBinding();
binding.setActivationSpecName(activationSpecName);
binding.setConnectionFactoryName(connectionFactoryName);
binding.setDestinationName(destinationName);
binding.setInitialContextFactoryName(initialContextFactoryName);
binding.setJNDIProviderURL(jNDIProviderURL);
binding.setReplyTo(replyTo);
binding.setJmsResourceFactoryName(jmsResourceFactoryName);
binding.setOperationSelectorName(operationSelector);
binding.setOperationSelectorPropertyName(jmsOpSecPropertyName);
if (deliveryMode != null && deliveryMode.trim().equals("")){
try{
binding.setDeliveryMode(Integer.parseInt(deliveryMode));
}catch (Exception e){
}
}
if (priority != null && priority.trim().equals("")){
try{
binding.setPriority(Integer.parseInt(priority));
}catch (Exception e){
}
}
if (timeToLive != null && timeToLive.trim().equals("")){
try{
binding.setTimeToLive(Integer.parseInt(timeToLive));
}catch (Exception e){
}
}
return binding;
}
}
|