KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > metamodel > descriptor > WebDDObjectFactory


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.web.metamodel.descriptor;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.metamodel.descriptor.DDObjectFactory;
26 import org.jboss.metamodel.descriptor.EjbLocalRef;
27 import org.jboss.metamodel.descriptor.EjbRef;
28 import org.jboss.metamodel.descriptor.EnvEntry;
29 import org.jboss.metamodel.descriptor.Listener;
30 import org.jboss.metamodel.descriptor.MessageDestination;
31 import org.jboss.metamodel.descriptor.MessageDestinationRef;
32 import org.jboss.metamodel.descriptor.NameValuePair;
33 import org.jboss.metamodel.descriptor.ResourceEnvRef;
34 import org.jboss.metamodel.descriptor.ResourceRef;
35 import org.jboss.metamodel.descriptor.RunAs;
36 import org.jboss.metamodel.descriptor.SecurityRoleRef;
37 import org.jboss.util.xml.JBossEntityResolver;
38 import org.jboss.xb.binding.JBossXBException;
39 import org.jboss.xb.binding.ObjectModelFactory;
40 import org.jboss.xb.binding.Unmarshaller;
41 import org.jboss.xb.binding.UnmarshallerFactory;
42 import org.jboss.xb.binding.UnmarshallingContext;
43 import org.xml.sax.Attributes JavaDoc;
44
45 import java.io.IOException JavaDoc;
46 import java.io.InputStream JavaDoc;
47 import java.net.URL JavaDoc;
48
49 /**
50  * org.jboss.xb.binding.ObjectModelFactory implementation that accepts data
51  * chuncks from unmarshaller and assembles them into an WebDD instance.
52  *
53  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
54  * @version <tt>$Revision: 55497 $</tt>
55  */

56 public class WebDDObjectFactory extends DDObjectFactory
57 {
58    private static final Logger log = Logger
59            .getLogger(WebDDObjectFactory.class);
60
61    public static WebDD parse(URL JavaDoc ddResource)
62            throws JBossXBException, IOException JavaDoc
63    {
64       if (ddResource == null) return null;
65       log.debug("found web.xml " + ddResource);
66       InputStream JavaDoc is = ddResource.openStream();
67
68       return parse(is);
69    }
70
71    public static WebDD parse(InputStream JavaDoc is)
72            throws JBossXBException
73    {
74       ObjectModelFactory factory = null;
75       Unmarshaller unmarshaller = null;
76       WebDD dd = null;
77
78       factory = new WebDDObjectFactory();
79       UnmarshallerFactory unmarshallerFactory = UnmarshallerFactory
80               .newInstance();
81       // unmarshallerFactory.setFeature(Unmarshaller.SCHEMA_VALIDATION, Boolean.TRUE);
82
unmarshaller = unmarshallerFactory.newUnmarshaller();
83       JBossEntityResolver entityResolver = new JBossEntityResolver();
84       unmarshaller.setEntityResolver(entityResolver);
85
86       dd = (WebDD) unmarshaller.unmarshal(is,
87               factory, null);
88       return dd;
89    }
90
91    /**
92     * Return the root.
93     */

94    public Object JavaDoc newRoot(Object JavaDoc root, UnmarshallingContext navigator,
95                          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
96    {
97
98       final WebDD dd;
99       if (root == null)
100          root = dd = new WebDD();
101       else
102          dd = (WebDD) root;
103
104       return root;
105    }
106
107    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx,
108                               String JavaDoc uri, String JavaDoc name)
109    {
110       return root;
111    }
112
113    public Object JavaDoc newChild(WebDD dd, UnmarshallingContext navigator,
114                           String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
115    {
116       Object JavaDoc child = null;
117
118       if ((child = newEnvRefGroupChild(localName)) != null)
119          return child;
120
121       if (localName.equals("filter"))
122       {
123          child = new Filter();
124       }
125       else if (localName.equals("filter-mapping"))
126       {
127          child = new FilterMapping();
128       }
129       else if (localName.equals("listener"))
130       {
131          child = new Listener();
132       }
133       else if (localName.equals("servlet"))
134       {
135          child = new Servlet();
136       }
137       else if (localName.equals("servlet-mapping"))
138       {
139          child = new ServletMapping();
140       }
141       else if (localName.equals("session-config"))
142       {
143          child = new SessionConfig();
144       }
145       else if (localName.equals("error-page"))
146       {
147          child = new ErrorPage();
148       }
149       else if (localName.equals("security-role"))
150       {
151          child = new SecurityRole();
152       }
153       else if (localName.equals("security-constraint"))
154       {
155          child = new SecurityConstraint();
156       }
157       else if (localName.equals("login-config"))
158       {
159          child = new LoginConfig();
160       }
161       else if (localName.equals("message-destination"))
162       {
163          child = new MessageDestination();
164       }
165
166       return child;
167    }
168
169    public Object JavaDoc newChild(Filter filter, UnmarshallingContext navigator,
170                           String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
171    {
172       Object JavaDoc child = null;
173
174       if (localName.equals("init-param"))
175       {
176          child = new NameValuePair();
177       }
178
179       return child;
180    }
181
182    public Object JavaDoc newChild(Servlet servlet, UnmarshallingContext navigator,
183                           String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
184    {
185       Object JavaDoc child = null;
186
187       if (localName.equals("init-param"))
188       {
189          child = new NameValuePair();
190       }
191       else if (localName.equals("run-as"))
192       {
193          child = new RunAs();
194       }
195       else if (localName.equals("security-role-ref"))
196       {
197          child = new SecurityRoleRef();
198       }
199
200       return child;
201    }
202
203    public Object JavaDoc newChild(SecurityConstraint constraint, UnmarshallingContext navigator,
204                           String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
205    {
206       Object JavaDoc child = null;
207
208       if (localName.equals("web-resource-collection"))
209       {
210          child = new WebResourceCollection();
211       }
212       else if (localName.equals("auth-constraint"))
213       {
214          child = new AuthConstraint();
215       }
216       else if (localName.equals("user-data-constraint"))
217       {
218          child = new UserDataConstraint();
219       }
220
221       return child;
222    }
223
224    public Object JavaDoc newChild(LoginConfig config, UnmarshallingContext navigator,
225                           String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
226    {
227       Object JavaDoc child = null;
228
229       if (localName.equals("form-login-config"))
230       {
231          child = new FormLoginConfig();
232       }
233
234       return child;
235    }
236
237    public void addChild(WebDD parent, Filter filter,
238                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
239    {
240       parent.addFilter(filter);
241    }
242
243    public void addChild(WebDD parent, FilterMapping mapping,
244                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
245    {
246       parent.addFilterMapping(mapping);
247    }
248
249    public void addChild(WebDD parent, Listener listener,
250                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
251    {
252       parent.addListener(listener);
253    }
254
255    public void addChild(WebDD parent, Servlet servlet,
256                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
257    {
258       parent.addServlet(servlet);
259    }
260
261    public void addChild(WebDD parent, ServletMapping mapping,
262                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
263    {
264       parent.addServletMapping(mapping);
265    }
266
267    public void addChild(WebDD parent, SessionConfig config,
268                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
269    {
270       parent.addSessionConfig(config);
271    }
272
273    public void addChild(WebDD parent, SecurityConstraint constraint,
274                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
275    {
276       parent.addSecurityConstraint(constraint);
277    }
278
279    public void addChild(WebDD parent, ErrorPage page,
280                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
281    {
282       parent.addErrorPage(page);
283    }
284
285    public void addChild(WebDD parent, SecurityRole role,
286                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
287    {
288       parent.addSecurityRole(role);
289    }
290
291    public void addChild(WebDD parent, EjbLocalRef ref,
292                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
293    {
294       parent.addEjbLocalRef(ref);
295    }
296
297    public void addChild(WebDD parent, EjbRef ref,
298                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
299    {
300       parent.addEjbRef(ref);
301    }
302
303    public void addChild(WebDD parent, EnvEntry ref,
304                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
305    {
306       parent.addEnvEntry(ref);
307    }
308
309    public void addChild(WebDD parent, MessageDestinationRef ref,
310                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
311    {
312       parent.addMessageDestinationRef(ref);
313    }
314
315    public void addChild(WebDD parent, ResourceEnvRef ref,
316                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
317    {
318       parent.addResourceEnvRef(ref);
319    }
320
321    public void addChild(WebDD parent, ResourceRef ref,
322                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
323    {
324       parent.addResourceRef(ref);
325    }
326
327    public void addChild(WebDD parent, LoginConfig config,
328                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
329    {
330       parent.setLoginConfig(config);
331    }
332
333    public void addChild(WebDD parent, MessageDestination destination,
334                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
335    {
336       parent.addMessageDestination(destination);
337    }
338
339    public void addChild(Filter parent, NameValuePair param,
340                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
341    {
342       parent.addInitParam(param);
343    }
344
345    public void addChild(Servlet parent, NameValuePair param,
346                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
347    {
348       parent.addInitParam(param);
349    }
350
351    public void addChild(Servlet parent, RunAs runAs,
352                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
353    {
354       parent.setRunAs(runAs);
355    }
356
357    public void addChild(Servlet parent, SecurityRoleRef ref,
358                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
359    {
360       parent.addSecurityRoleRef(ref);
361    }
362
363    public void addChild(SecurityConstraint parent, WebResourceCollection collection,
364                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
365    {
366       parent.setWebResourceCollection(collection);
367    }
368
369    public void addChild(SecurityConstraint parent, AuthConstraint constraint,
370                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
371    {
372       parent.setAuthConstraint(constraint);
373    }
374
375    public void addChild(SecurityConstraint parent, UserDataConstraint constraint,
376                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
377    {
378       parent.setUserDataConstraint(constraint);
379    }
380
381    public void addChild(LoginConfig parent, FormLoginConfig config,
382                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
383    {
384       parent.setFormLoginConfig(config);
385    }
386
387    public void setValue(Filter filter,
388                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
389                         String JavaDoc value)
390    {
391       if (localName.equals("filter-name"))
392       {
393          filter.setName(value);
394       }
395       else if (localName.equals("filter-class"))
396       {
397          filter.setFilterClass(value);
398       }
399    }
400
401    public void setValue(FilterMapping mapping,
402                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
403                         String JavaDoc value)
404    {
405       if (localName.equals("filter-name"))
406       {
407          mapping.setFilterName(value);
408       }
409       else if (localName.equals("url-pattern"))
410       {
411          mapping.setUrlPattern(value);
412       }
413       else if (localName.equals("servlet-name"))
414       {
415          mapping.setServletName(value);
416       }
417    }
418
419    public void setValue(Servlet servlet,
420                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
421                         String JavaDoc value)
422    {
423       if (localName.equals("servlet-name"))
424       {
425          servlet.setName(value);
426       }
427       else if (localName.equals("servlet-class"))
428       {
429          servlet.setServletClass(value);
430       }
431       else if (localName.equals("jsp-file"))
432       {
433          servlet.setJspFile(value);
434       }
435       else if (localName.equals("load-on-startup"))
436       {
437          servlet.setLoadOnStartup(value);
438       }
439    }
440
441    public void setValue(ServletMapping mapping,
442                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
443                         String JavaDoc value)
444    {
445       if (localName.equals("servlet-name"))
446       {
447          mapping.setName(value);
448       }
449       else if (localName.equals("url-pattern"))
450       {
451          mapping.setUrlPattern(value);
452       }
453    }
454
455    public void setValue(ErrorPage page,
456                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
457                         String JavaDoc value)
458    {
459       if (localName.equals("error-code"))
460       {
461          page.setErrorCode(value);
462       }
463       else if (localName.equals("location"))
464       {
465          page.setLocation(value);
466       }
467    }
468
469    public void setValue(SessionConfig config,
470                         UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
471                         String JavaDoc value)
472    {
473       if (localName.equals("session-timeout"))
474       {
475          config.setSessionTimeout(value);
476       }
477    }
478
479    public void setValue(NameValuePair param, UnmarshallingContext navigator,
480                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
481    {
482       if (localName.equals("param-name"))
483       {
484          param.setName(value);
485       }
486       else if (localName.equals("param-value"))
487       {
488          param.setValue(value);
489       }
490    }
491
492    public void setValue(WebResourceCollection collection, UnmarshallingContext navigator,
493                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
494    {
495       if (localName.equals("web-resource-name"))
496       {
497          collection.setWebResourceName(value);
498       }
499       else if (localName.equals("url-pattern"))
500       {
501          collection.setUrlPattern(value);
502       }
503    }
504
505    public void setValue(AuthConstraint contraint, UnmarshallingContext navigator,
506                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
507    {
508       if (localName.equals("role-name"))
509       {
510          contraint.setRoleName(value);
511       }
512    }
513
514    public void setValue(UserDataConstraint contraint, UnmarshallingContext navigator,
515                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
516    {
517       if (localName.equals("transport-guarantee"))
518       {
519          contraint.setTransportGuarantee(value);
520       }
521    }
522
523    public void setValue(LoginConfig config, UnmarshallingContext navigator,
524                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
525    {
526       if (localName.equals("auth-method"))
527       {
528          config.setAuthMethod(value);
529       }
530       else if (localName.equals("realm-name"))
531       {
532          config.setRealmName(value);
533       }
534    }
535
536    public void setValue(FormLoginConfig config, UnmarshallingContext navigator,
537                         String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc value)
538    {
539       if (localName.equals("form-login-page"))
540       {
541          config.setLoginPage(value);
542       }
543       else if (localName.equals("form-error-page"))
544       {
545          config.setErrorPage(value);
546       }
547    }
548 }
549
Popular Tags