1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.jbi.component;
9
10 import it.imolinfo.jbi4corba.Logger;
11 import it.imolinfo.jbi4corba.LoggerFactory;
12 import it.imolinfo.jbi4corba.jbi.Messages;
13 import it.imolinfo.jbi4corba.jbi.component.runtime.ComponentRuntime;
14
15
16 import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaEndpoint;
17
18
19 import it.imolinfo.jbi4corba.jbi.endpoint.Jbi4CorbaSFServiceEndpoint;
20
21
22 import it.imolinfo.jbi4corba.utils.HelperEPRUtils;
23 import java.io.StringWriter;
24
25 import javax.jbi.component.ComponentLifeCycle;
26 import javax.jbi.component.ServiceUnitManager;
27 import javax.jbi.servicedesc.ServiceEndpoint;
28
29
30 import javax.xml.transform.OutputKeys;
31 import javax.xml.transform.Transformer;
32 import javax.xml.transform.TransformerException;
33 import javax.xml.transform.TransformerFactory;
34 import javax.xml.transform.dom.DOMSource;
35 import javax.xml.transform.stream.StreamResult;
36
37
38
39 import org.w3c.dom.Node;
40 import org.w3c.dom.NodeList;
41
42
43
44
45
46
47
48
49
50 public class Jbi4CorbaRuntime extends ComponentRuntime {
51
52
53 private static final Logger LOG = LoggerFactory
54 .getLogger(Jbi4CorbaRuntime.class);
55
56 private static final Messages MESSAGES =
57 Messages.getMessages(Jbi4CorbaRuntime .class);
58
59
60
61
62 public Jbi4CorbaRuntime() {
63 super();
64 }
65
66
67
68
69
70
71 protected ComponentLifeCycle createComponentLifeCycle() {
72 return new Jbi4CorbaLifeCycle(this);
73 }
74
75
76
77
78
79
80 protected ServiceUnitManager createServiceUnitManager() {
81 return new Jbi4CorbaSUManager(this);
82 }
83
84
85
86
87
88
89
90
91 @Override
92 public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(
93 org.w3c.dom.DocumentFragment epr) {
94
95 ServiceEndpoint sendpoint=null;
96 ServiceEndpoint resolvedEP=null;
97 String ior = null;
98 NodeList children = epr.getChildNodes();
99 try {
100
101 if (children != null && children.getLength() > 1) {
102
103 ior = HelperEPRUtils.getDynamicIORFromEPR(epr);
104 sendpoint = HelperEPRUtils.getEndpointInfo(epr);
105
106
107 } else if (children.getLength() == 1) {
108
109
110 Node child = children.item(0);
111
112 ior = HelperEPRUtils.getDynamicIORFromEPR(child);
113 sendpoint = HelperEPRUtils.getEndpointInfo(child);
114
115
116 } else {
117
118 throw new Exception(MESSAGES.getString("CRB000231_Invalid_EPR_Format"));
119 }
120
121
122
123 if (ior != null && sendpoint != null) {
124
125
126 Jbi4CorbaSUManager manager = (Jbi4CorbaSUManager) this.getServiceUnitManager();
127 if (manager != null) {
128 Jbi4CorbaEndpoint endpoint = manager.getDeployedEndpoint(sendpoint);
129
130 if (endpoint != null) {
131
132 LOG.debug("RESOLVED EPR ==>"+endpoint.getEndpointName());
133 resolvedEP=new Jbi4CorbaSFServiceEndpoint(endpoint,epr,ior);
134
135 }
136
137 }
138
139 } else {
140
141 String msg=MESSAGES.getString("CRB000232_Can't_find_Activate_Endpoint");
142 LOG.info(msg);
143
144 }
145
146 } catch (Exception e) {
147
148 LOG.error(MESSAGES.getString("CRB000232_Invalid_EPR_Format"));
149 }
150
151
152
153 return resolvedEP;
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167
168 @Override
169 public org.w3c.dom.Document getServiceDescription(ServiceEndpoint ref) {
170 LOG.debug("Called getServiceDescription for endpoint: " + ref);
171 Jbi4CorbaSUManager manager = (Jbi4CorbaSUManager) this.getServiceUnitManager();
172 if (manager != null) {
173 Jbi4CorbaEndpoint endpoint = manager.getDeployedEndpoint(ref);
174 if (endpoint != null) {
175 if (LOG.isDebugEnabled()) {
176 String documentString = null;
177 try {
178
179 TransformerFactory transfac = TransformerFactory.newInstance();
180 Transformer trans = transfac.newTransformer();
181 trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
182 trans.setOutputProperty(OutputKeys.INDENT, "yes");
183 StringWriter sw = new StringWriter();
184 StreamResult result = new StreamResult(sw);
185 DOMSource source = new DOMSource(endpoint.getServiceDescription());
186 trans.transform(source, result);
187 documentString = sw.toString();
188
189 } catch (TransformerException e) {
190
191 LOG.debug("Error in transforming service description to String for logging pourpose");
192 }
193 LOG.debug("Endpoint found, returning:" + documentString);
194 }
195 return endpoint.getServiceDescription();
196 } else {
197 LOG.debug("No endpoint found, returning null");
198 }
199 }
200
201 return null;
202 }
203
204 }