1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.handler;
17
18 import org.apache.juddi.datatype.RegistryObject;
19 import org.apache.juddi.datatype.publisher.Publisher;
20 import org.apache.juddi.util.Config;
21 import org.apache.juddi.util.xml.XMLUtils;
22 import org.w3c.dom.Element;
23
24 /***
25 * "Knows about the creation and populating of Publisher objects.
26 * Returns Publisher."
27 *
28 * @author Steve Viens (sviens@apache.org)
29 */
30 public class PublisherHandler extends AbstractHandler
31 {
32 public static final String TAG_NAME = "publisher";
33
34 protected PublisherHandler(HandlerMaker maker)
35 {
36 }
37
38 public RegistryObject unmarshal(Element element)
39 {
40 Publisher obj = new Publisher();
41
42
43 obj.setPublisherID(element.getAttribute("publisherID"));
44 obj.setName(element.getAttribute("publisherName"));
45
46 String admin = element.getAttribute("admin");
47 if ((admin != null) && (admin.length() > 0))
48 obj.setAdminValue(admin);
49 else
50 obj.setAdmin(false);
51
52 String enabled = element.getAttribute("enabled");
53 if ((enabled != null) && (enabled.length() > 0))
54 obj.setEnabledValue(enabled);
55 else
56 obj.setAdmin(false);
57
58 String emailAddress = element.getAttribute("emailAddress");
59 if ((emailAddress != null) && (emailAddress.length() > 0))
60 obj.setEmailAddress(emailAddress);
61
62
63 try {
64 String attrValue = element.getAttribute("maxBusinesses");
65 if ((attrValue != null) && (attrValue.length() > 0))
66 obj.setMaxBusinesses(Integer.parseInt(attrValue));
67 else
68 obj.setMaxBusinesses(Config.getMaxBusinessesPerPublisher());
69 }
70 catch (Exception ex) {
71 obj.setMaxBusinesses(
72 Config.getMaxBusinessesPerPublisher());
73 }
74
75
76 try {
77 String attrValue = element.getAttribute("maxServicesPerBusiness");
78 if ((attrValue != null) && (attrValue.length() > 0))
79 obj.setMaxServicesPerBusiness(Integer.parseInt(attrValue));
80 else
81 obj.setMaxServicesPerBusiness(Config.getMaxServicesPerBusiness());
82 }
83 catch (Exception ex) {
84 obj.setMaxServicesPerBusiness(
85 Config.getMaxServicesPerBusiness());
86 }
87
88
89 try {
90 String attrValue = element.getAttribute("maxBindingsPerService");
91 if ((attrValue != null) && (attrValue.length() > 0))
92 obj.setMaxBindingsPerService(Integer.parseInt(attrValue));
93 else
94 obj.setMaxBindingsPerService(Config.getMaxBindingsPerService());
95 }
96 catch (Exception ex) {
97 obj.setMaxBindingsPerService(
98 Config.getMaxBindingsPerService());
99 }
100
101
102 try {
103 String attrValue = element.getAttribute("maxTModels");
104 if ((attrValue != null) && (attrValue.length() > 0))
105 obj.setMaxTModels(Integer.parseInt(attrValue));
106 else
107 obj.setMaxTModels(Config.getMaxTModelsPerPublisher());
108 }
109 catch (Exception ex) {
110 obj.setMaxTModels(
111 Config.getMaxTModelsPerPublisher());
112 }
113
114
115
116
117
118
119
120 return obj;
121 }
122
123 public void marshal(RegistryObject object,Element parent)
124 {
125 Publisher publisher = (Publisher)object;
126 String generic = getGeneric(null);
127 String namespace = getUDDINamespace(generic);
128 Element element = parent.getOwnerDocument().createElementNS(namespace,TAG_NAME);
129
130
131 String publisherID = publisher.getPublisherID();
132 if ((publisherID != null) && (publisherID.length() > 0))
133 element.setAttribute("publisherID",publisherID);
134 else
135 element.setAttribute("publisherID","");
136
137 String publisherName = publisher.getName();
138 if ((publisherName != null) && (publisherName.length() > 0))
139 element.setAttribute("publisherName",publisherName);
140 else
141 element.setAttribute("publisherName","");
142
143 element.setAttribute("admin",String.valueOf(publisher.isAdmin()));
144 element.setAttribute("enabled",String.valueOf(publisher.isEnabled()));
145
146 String emailAddress = publisher.getEmailAddress();
147 if ((emailAddress != null) && (emailAddress.length() > 0))
148 element.setAttribute("emailAddress",emailAddress);
149
150 element.setAttribute("maxBusinessEntities",String.valueOf(publisher.getMaxBusinesses()));
151 element.setAttribute("maxServicesPerBusiness",String.valueOf(publisher.getMaxServicesPerBusiness()));
152 element.setAttribute("maxBindingsPerService",String.valueOf(publisher.getMaxBindingsPerService()));
153 element.setAttribute("maxTModels",String.valueOf(publisher.getMaxTModels()));
154
155
156
157
158
159
160
161 parent.appendChild(element);
162 }
163
164
165 /****************************************************************************/
166 /****************************** TEST DRIVER *********************************/
167 /****************************************************************************/
168
169
170 public static void main(String args[])
171 throws Exception
172 {
173 HandlerMaker maker = HandlerMaker.getInstance();
174 AbstractHandler handler = maker.lookup(PublisherHandler.TAG_NAME);
175 Element parent = XMLUtils.newRootElement();
176 Element child = null;
177
178 Publisher publisher = new Publisher();
179 publisher.setPublisherID("bcrosby");
180 publisher.setName("Bing Crosby");
181 publisher.setEmailAddress("bcrosby@juddi.org");
182 publisher.setAdmin(true);
183 publisher.setEnabled(true);
184 publisher.setMaxBusinesses(5);
185 publisher.setMaxServicesPerBusiness(10);
186 publisher.setMaxBindingsPerService(25);
187 publisher.setMaxTModels(10);
188
189 System.out.println();
190
191 RegistryObject regObject = publisher;
192 handler.marshal(regObject,parent);
193 child = (Element)parent.getFirstChild();
194 parent.removeChild(child);
195 XMLUtils.writeXML(child,System.out);
196
197 System.out.println();
198
199 regObject = handler.unmarshal(child);
200 handler.marshal(regObject,parent);
201 child = (Element)parent.getFirstChild();
202 parent.removeChild(child);
203 XMLUtils.writeXML(child,System.out);
204 }
205 }