1
2
3
4
5
6
7
8 package it.imolinfo.jbi4ejb.jbi.wsdl;
9
10
11 import it.imolinfo.jbi4ejb.Logger;
12 import it.imolinfo.jbi4ejb.LoggerFactory;
13
14 import java.util.Enumeration;
15 import java.util.Properties;
16
17 import javax.wsdl.Definition;
18 import javax.wsdl.WSDLException;
19 import javax.wsdl.extensions.ExtensibilityElement;
20 import javax.wsdl.extensions.ExtensionRegistry;
21 import javax.wsdl.extensions.ExtensionSerializer;
22 import javax.xml.namespace.QName;
23
24 import com.ibm.wsdl.util.xml.DOMUtils;
25
26
27
28
29
30
31
32 public class Jbi4EjbBindingSerializer implements ExtensionSerializer {
33
34
35
36
37 private static final Logger LOG
38 = LoggerFactory.getLogger(Jbi4EjbBindingSerializer.class);
39
40
41
42
43
44 public Jbi4EjbBindingSerializer() {}
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 @SuppressWarnings("unchecked")
67 public void marshall(Class parentType, QName elementType,
68 ExtensibilityElement extension, java.io.PrintWriter pw, Definition def, ExtensionRegistry extReg)
69 throws WSDLException {
70
71
72 String prefix = DOMUtils.getPrefix(Jbi4EjbExtension.NS_URI_JBI4EJB, def);
73
74
75 if (prefix == null) {
76 prefix = Jbi4EjbExtension.DEFAULT_PREFIX;
77
78 def.addNamespace(Jbi4EjbExtension.DEFAULT_PREFIX, Jbi4EjbExtension.NS_URI_JBI4EJB);
79 }
80
81 prefix += ":";
82
83 LOG.debug("prefix found: " + prefix);
84
85 if (extension instanceof Jbi4EjbBinding) {
86 Jbi4EjbBinding jbi4EjbBinding = (Jbi4EjbBinding) extension;
87 pw.print("<" + prefix + Jbi4EjbExtension.BINDING_ELEMENT);
88 pw.print(">\n");
89
90
91 printJNDIElement(jbi4EjbBinding, pw, prefix);
92
93
94 printORBElement(jbi4EjbBinding, pw, prefix);
95
96 pw.print("</" + prefix + Jbi4EjbExtension.BINDING_ELEMENT+">\n");
97
98 } else {
99 LOG.warn("EJB000401_Error_in_extension_element", new Object[]{Jbi4EjbExtension.BINDING_ELEMENT});
100 }
101
102 }
103
104
105
106
107
108
109
110
111 @SuppressWarnings("unchecked")
112 private void printJNDIElement(Jbi4EjbBinding jbi4EjbBinding, java.io.PrintWriter pw, String prefix) {
113 if ((jbi4EjbBinding.getJndiProperties()!= null) &&
114 (!jbi4EjbBinding.getJndiProperties().isEmpty())) {
115 pw.print("<" + prefix + Jbi4EjbExtension.JNDI_ELEMENT+">\n");
116 Properties jndiProperties = jbi4EjbBinding.getJndiProperties();
117 Enumeration enKeys = jndiProperties.keys();
118 for (; enKeys.hasMoreElements() ;) {
119 String key = (String)enKeys.nextElement();
120 String prop = (String) jndiProperties.get(key);
121 pw.print("<" + prefix + Jbi4EjbExtension.PROPERTY_ELEMENT);
122 DOMUtils.printAttribute(Jbi4EjbExtension.NAME_ATTRIBUTE, key, pw);
123 DOMUtils.printAttribute(Jbi4EjbExtension.VALUE_ATTRIBUTE, prop, pw);
124 pw.print("/>\n");
125 }
126
127 pw.print("</" + prefix + Jbi4EjbExtension.JNDI_ELEMENT+">\n");
128 }
129 }
130
131
132
133
134
135
136
137
138 @SuppressWarnings("unchecked")
139 private void printORBElement(Jbi4EjbBinding jbi4EjbBinding, java.io.PrintWriter pw, String prefix) {
140 if (jbi4EjbBinding.getOrbProperties()!= null) {
141 pw.print("<" + prefix + Jbi4EjbExtension.ORB_ELEMENT+">\n");
142 Properties orbProperties = jbi4EjbBinding.getOrbProperties();
143 Enumeration enKeys = orbProperties.keys();
144 for (; enKeys.hasMoreElements() ;) {
145 String key = (String)enKeys.nextElement();
146 String prop = (String) orbProperties.get(key);
147 pw.print("<" + prefix + Jbi4EjbExtension.PROPERTY_ELEMENT);
148 DOMUtils.printAttribute(Jbi4EjbExtension.NAME_ATTRIBUTE, key, pw);
149 DOMUtils.printAttribute(Jbi4EjbExtension.VALUE_ATTRIBUTE, prop, pw);
150 pw.print("/>\n");
151 }
152
153 pw.print("</" + prefix + Jbi4EjbExtension.ORB_ELEMENT+">\n");
154 }
155 }
156 }