KickJava   Java API By Example, From Geeks To Geeks.

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


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.SecurityRoleMetaData;
26 import org.jboss.mx.loading.LoaderRepositoryFactory;
27 import org.jboss.xb.binding.ObjectModelFactory;
28 import org.jboss.xb.binding.UnmarshallingContext;
29 import org.xml.sax.Attributes JavaDoc;
30
31 /**
32  * An ObjectModelFactory implementation for parsing jboss-app.xml descriptors.
33  *
34  * @author Scott.Stark@jboss.org
35  * @version $Revision:$
36  */

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

72    public Object JavaDoc newChild(J2eeApplicationMetaData dd, UnmarshallingContext navigator,
73          String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc attrs)
74    {
75       Object JavaDoc child = null;
76       log.debug("newChild, " + localName);
77
78       // Check elements
79
if(localName.equals("module"))
80          child = new J2eeModuleMetaData();
81       else if( localName.equals("security-role"))
82          child = new SecurityRoleMetaData();
83       else if( localName.equals("loader-repository") )
84          child = new LoaderRepositoryFactory.LoaderRepositoryConfig();
85       else if (log.isTraceEnabled())
86       {
87          log.trace("Ignoring: " + localName);
88       }
89       return child;
90    }
91
92    /**
93     *
94     * @param module
95     * @param navigator
96     * @param namespaceURI
97     * @param localName
98     * @param value
99     */

100    public void setValue(J2eeModuleMetaData module,
101          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
102          String JavaDoc value)
103    {
104       if( localName.equals("service") )
105       {
106          module.setType(J2eeModuleMetaData.SERVICE);
107          module.setFileName(value);
108       }
109       else if( localName.equals("har") )
110       {
111          module.setType(J2eeModuleMetaData.HAR);
112          module.setFileName(value);
113       }
114    }
115
116    public void addChild(J2eeApplicationMetaData parent, J2eeModuleMetaData module,
117          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
118    {
119       parent.addModule(module);
120    }
121
122    public void addChild(J2eeApplicationMetaData parent, LoaderRepositoryFactory.LoaderRepositoryConfig cfg,
123          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName)
124    {
125       parent.setLoaderCfg(cfg);
126    }
127
128    /**
129     * Set text values of jboss-app/* children
130     * @param dd
131     * @param navigator
132     * @param namespaceURI
133     * @param localName
134     * @param value
135     */

136    public void setValue(J2eeApplicationMetaData dd,
137          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
138          String JavaDoc value)
139    {
140       if( localName.equals("security-domain") )
141          dd.setSecurityDomain(value);
142       else if( localName.equals("unauthenticated-principal") )
143          dd.setUnauthenticatedPrincipal(value);
144       else if( localName.equals("jmx-name") )
145          dd.setJMXName(value);
146       
147    }
148
149    public void setValue(SecurityRoleMetaData role,
150          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
151          String JavaDoc value)
152    {
153       if( localName.equals("role-name") )
154       {
155          role.setRoleName(value);
156       }
157       else if( localName.equals("principal-name") )
158       {
159          J2eeApplicationMetaData metaData = activeMetaData.get();
160          SecurityRoleMetaData srmd = metaData.getSecurityRole(role.getRoleName());
161          // Wolf: there could be no application.xml and thus no srmd
162
if(srmd == null)
163          {
164             srmd = new SecurityRoleMetaData();
165             srmd.setRoleName(role.getRoleName());
166             metaData.addSecurityRole(srmd);
167          }
168          srmd.addPrincipalName(value);
169       }
170    }
171
172    /*
173    <loader-repository loaderRepositoryClass='dot.com.LoaderRepository'>
174       dot.com:loader=unique-archive-name
175       <loader-repository-config configParserClass='dot.com.LoaderParser'>
176          java2ParentDelegaton=true
177       </loader-repository-config>
178    </loader-repository>
179     */

180    public void setValue(LoaderRepositoryFactory.LoaderRepositoryConfig cfg,
181          UnmarshallingContext navigator, String JavaDoc namespaceURI, String JavaDoc localName,
182          String JavaDoc value)
183    {
184       if( localName.equals("loader-repository-config") )
185       {
186          cfg.repositoryConfig = value;
187       }
188    }
189
190 }
191
Popular Tags