KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > J2eeApplicationObjectFactory


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
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.deployment;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.metadata.IconMetaData;
26 import org.jboss.metadata.SecurityRoleMetaData;
27 import org.jboss.metadata.SecurityRoleRefMetaData;
28 import org.jboss.xb.binding.ObjectModelFactory;
29 import org.jboss.xb.binding.UnmarshallingContext;
30 import org.xml.sax.Attributes JavaDoc;
31
32 /**
33  * An ObjectModelFactory implementation for parsing web.xml descriptors.
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision:$
37  */

38 public class J2eeApplicationObjectFactory implements ObjectModelFactory
39 {
40    private static Logger log = Logger.getLogger(J2eeApplicationObjectFactory.class);
41
42    public J2eeApplicationMetaData newRoot(Object JavaDoc root, UnmarshallingContext navigator,
43          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
44    {
45       J2eeApplicationMetaData metaData = null;
46       if (root != null)
47          metaData = (J2eeApplicationMetaData) root;
48       else
49          metaData = new J2eeApplicationMetaData();
50       return metaData;
51    }
52
53    public Object JavaDoc completeRoot(Object JavaDoc root, UnmarshallingContext ctx,
54          String JavaDoc uri, String JavaDoc name)
55    {
56       return root;
57    }
58
59    /**
60     * Create the application child elements
61     *
62     * @param dd
63     * @param navigator
64     * @param namespaceURI
65     * @param localName
66     * @param attrs
67     * @return
68     */

69    public Object JavaDoc newChild(J2eeApplicationMetaData dd, UnmarshallingContext navigator,
70          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
71    {
72       Object JavaDoc child = null;
73       log.debug("newChild, " + localName);
74
75       // Check attributes
76
String JavaDoc version = attrs.getValue(namespaceURI, "version");
77       if( version != null )
78          dd.setVersion(version);
79
80       // Check elements
81
if (localName.equals("icon"))
82          child = new IconMetaData();
83       else if(localName.equals("module"))
84          child = new J2eeModuleMetaData();
85       else if( localName.equals("security-role"))
86          child = new SecurityRoleMetaData();
87       else if (log.isTraceEnabled())
88       {
89          log.trace("Ignoring: " + localName);
90       }
91       return child;
92    }
93
94    /**
95     * application/module children
96     *
97     * @param module
98     * @param navigator
99     * @param namespaceURI
100     * @param localName
101     * @param attrs
102     * @return
103     */

104    public Object JavaDoc newChild(J2eeModuleMetaData module, UnmarshallingContext navigator,
105          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
106    {
107       Object JavaDoc child = null;
108       if (localName.equals("web"))
109       {
110          child = new WebModuleMetaData(module);
111       }
112       else if (localName.equals("security-role-ref"))
113       {
114          child = new SecurityRoleRefMetaData();
115       }
116       return child;
117    }
118
119    public void addChild(J2eeApplicationMetaData parent, J2eeModuleMetaData module,
120          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
121    {
122       parent.addModule(module);
123    }
124    public void addChild(J2eeApplicationMetaData parent, SecurityRoleMetaData role,
125          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
126    {
127       parent.addSecurityRole(role);
128    }
129
130    /**
131     * Set text values of application/* children
132     * @param dd
133     * @param navigator
134     * @param namespaceURI
135     * @param localName
136     * @param value
137     */

138    public void setValue(J2eeApplicationMetaData dd,
139          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
140          String JavaDoc value)
141    {
142       if( localName.equals("display-name") )
143          dd.setDisplayName(value);
144       else if( localName.equals("description") )
145          dd.setDescription(value);
146       else if( localName.equals("library-directory") )
147          dd.setLibraryDirectory(value);
148    }
149
150    public void setValue(IconMetaData icon,
151          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
152          String JavaDoc value)
153    {
154       if( localName.equals("small-icon") )
155          icon.setSmallIcon(value);
156       if( localName.equals("large-icon") )
157          icon.setLargeIcon(value);
158    }
159    public void setValue(J2eeModuleMetaData module,
160          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
161          String JavaDoc value)
162    {
163       if( localName.equals("ejb") )
164       {
165          module.setType(J2eeModuleMetaData.EJB);
166          module.setFileName(value);
167       }
168       else if( localName.equals("java") )
169       {
170          module.setType(J2eeModuleMetaData.CLIENT);
171          module.setFileName(value);
172       }
173       else if( localName.equals("connector") )
174       {
175          module.setType(J2eeModuleMetaData.CONNECTOR);
176          module.setFileName(value);
177       }
178       else if( localName.equals("service") )
179       {
180          module.setType(J2eeModuleMetaData.SERVICE);
181          module.setFileName(value);
182       }
183       else if( localName.equals("har") )
184       {
185          module.setType(J2eeModuleMetaData.HAR);
186          module.setFileName(value);
187       }
188       else if( localName.equals("alt-dd") )
189          module.setAlternativeDD(value);
190    }
191    public void setValue(WebModuleMetaData module,
192          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
193          String JavaDoc value)
194    {
195       if( localName.equals("web-uri") )
196       {
197          module.setFileName(value);
198       }
199       else if( localName.equals("context-root") )
200       {
201          module.setWebContext(value);
202       }
203       else if( localName.equals("alt-dd") )
204          module.setAlternativeDD(value);
205    }
206
207    public void setValue(SecurityRoleMetaData role,
208          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
209          String JavaDoc value)
210    {
211       if( localName.equals("description") )
212       {
213          role.setDescription(value);
214       }
215       else if( localName.equals("role-name") )
216       {
217          role.setRoleName(value);
218       }
219    }
220
221 }
222
Popular Tags