KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > ClientMetaData


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.metadata;
23
24 // $Id: ClientMetaData.java 58121 2006-11-04 19:57:58Z thomas.diesler@jboss.com $
25

26 import org.jboss.logging.Logger;
27 import org.jboss.deployment.DeploymentException;
28 import org.jboss.webservice.metadata.serviceref.ServiceRefMetaData;
29 import org.w3c.dom.Element JavaDoc;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.net.URLClassLoader JavaDoc;
35
36 /** The metdata data from a j2ee application-client.xml descriptor
37  *
38  * @author Scott.Stark@jboss.org
39  * @author Thomas.Diesler@jboss.org
40  * @version $Revision: 58121 $
41  */

42 public class ClientMetaData
43 {
44    // provide logging
45
private static Logger log = Logger.getLogger(ClientMetaData.class);
46
47    /** The application-client/display-name */
48    private String JavaDoc displayName;
49    /** The location for the server side client context ENC bindings */
50    private String JavaDoc jndiName;
51    /** An ArrayList<EnvEntryMetaData> for the env-entry element(s) */
52    private ArrayList JavaDoc environmentEntries = new ArrayList JavaDoc();
53    /** A HashMap<String, EjbRefMetaData> for the ejb-ref element(s) */
54    private HashMap JavaDoc ejbReferences = new HashMap JavaDoc();
55    /** The HashMap<String, ServiceRefMetaData> service-ref element(s) info */
56    private HashMap JavaDoc serviceReferences = new HashMap JavaDoc();
57    /** A HashMap<String, ResourceRefMetaData> resource-ref element(s) info */
58    private HashMap JavaDoc resourceReferences = new HashMap JavaDoc();
59    /** A HashMap<String, ResourceEnvRefMetaData> resource-env-ref element(s) info */
60    private HashMap JavaDoc resourceEnvReferences = new HashMap JavaDoc();
61    /** A HashMap<String, ArrayList<ResourceEnvRefMetaData>> of
62     * message-destination-ref that resolve to a jndi-name via a message-destination
63     * via a message-destination-link
64     */

65    private HashMap JavaDoc resourceEnvReferenceLinks = new HashMap JavaDoc();
66    /** The JAAS callback handler */
67    private String JavaDoc callbackHandler;
68
69    /** The ClassLoader to load additional resources */
70    private URLClassLoader JavaDoc resourceCl;
71
72    /** Set the ClassLoader to load additional resources */
73    public void setResourceClassLoader(URLClassLoader JavaDoc resourceCl)
74    {
75       this.resourceCl = resourceCl;
76    }
77
78    /** The application-client/display-name
79     * @return application-client/display-name value
80     */

81    public String JavaDoc getDisplayName()
82    {
83       return displayName;
84    }
85
86    /** The location for the server side client context ENC bindings
87     * @return the JNDI name for the server side client context ENC bindings. This
88     * is either the jboss-client/jndi-name or the application-client/display-name
89     * value.
90     */

91    public String JavaDoc getJndiName()
92    {
93       String JavaDoc name = jndiName;
94       if( name == null )
95          name = displayName;
96       return name;
97    }
98
99    /**
100     * @return ArrayList<EnvEntryMetaData>
101     */

102    public ArrayList JavaDoc getEnvironmentEntries()
103    {
104       return environmentEntries;
105    }
106    /**
107     * @return HashMap<EjbRefMetaData>
108     */

109    public HashMap JavaDoc getEjbReferences()
110    {
111       return ejbReferences;
112    }
113    /**
114     * @return HashMap<ResourceRefMetaData>
115     */

116    public HashMap JavaDoc getResourceReferences()
117    {
118       return resourceReferences;
119    }
120    /**
121     * @return HashMap<ResourceEnvRefMetaData>
122     */

123    public HashMap JavaDoc getResourceEnvReferences()
124    {
125       return resourceEnvReferences;
126    }
127    /**
128     * @return The CallbackHandler if defined, null otherwise
129     */

130    public String JavaDoc getCallbackHandler()
131    {
132       return callbackHandler;
133    }
134    /**
135     * @return HashMap<ServiceRefMetaData>
136     */

137    public HashMap JavaDoc getServiceReferences()
138    {
139       return serviceReferences;
140    }
141
142    public void importClientXml(Element JavaDoc element)
143       throws DeploymentException
144    {
145       displayName = MetaData.getOptionalChildContent(element, "display-name");
146
147       // set the environment entries
148
Iterator JavaDoc iterator = MetaData.getChildrenByTagName(element, "env-entry");
149
150       while (iterator.hasNext())
151       {
152          Element JavaDoc envEntry = (Element JavaDoc) iterator.next();
153
154          EnvEntryMetaData envEntryMetaData = new EnvEntryMetaData();
155          envEntryMetaData.importEjbJarXml(envEntry);
156
157          environmentEntries.add(envEntryMetaData);
158       }
159
160       // set the ejb references
161
iterator = MetaData.getChildrenByTagName(element, "ejb-ref");
162
163       while (iterator.hasNext())
164       {
165          Element JavaDoc ejbRef = (Element JavaDoc) iterator.next();
166
167          EjbRefMetaData ejbRefMetaData = new EjbRefMetaData();
168          ejbRefMetaData.importEjbJarXml(ejbRef);
169
170          ejbReferences.put(ejbRefMetaData.getName(), ejbRefMetaData);
171       }
172
173       // Parse the service-ref elements
174
iterator = MetaData.getChildrenByTagName(element, "service-ref");
175       while (iterator.hasNext())
176       {
177          Element JavaDoc serviceRef = (Element JavaDoc) iterator.next();
178          if (ServiceRefMetaData.isValidDoctype(serviceRef))
179          {
180             ServiceRefMetaData refMetaData = new ServiceRefMetaData(resourceCl);
181             refMetaData.importStandardXml(serviceRef);
182             serviceReferences.put(refMetaData.getServiceRefName(), refMetaData);
183          }
184       }
185
186       // The callback-handler element
187
Element JavaDoc callbackElement = MetaData.getOptionalChild(element,
188          "callback-handler");
189       if (callbackElement != null)
190       {
191          callbackHandler = MetaData.getElementContent(callbackElement);
192       }
193
194       // set the resource references
195
iterator = MetaData.getChildrenByTagName(element, "resource-ref");
196       while (iterator.hasNext())
197       {
198          Element JavaDoc resourceRef = (Element JavaDoc) iterator.next();
199
200          ResourceRefMetaData resourceRefMetaData = new ResourceRefMetaData();
201          resourceRefMetaData.importEjbJarXml(resourceRef);
202
203          resourceReferences.put(resourceRefMetaData.getRefName(),
204             resourceRefMetaData);
205       }
206
207       // Parse the resource-env-ref elements
208
iterator = MetaData.getChildrenByTagName(element, "resource-env-ref");
209       while (iterator.hasNext())
210       {
211          Element JavaDoc resourceRef = (Element JavaDoc) iterator.next();
212          ResourceEnvRefMetaData refMetaData = new ResourceEnvRefMetaData();
213          refMetaData.importEjbJarXml(resourceRef);
214          resourceEnvReferences.put(refMetaData.getRefName(), refMetaData);
215       }
216
217       // Parse the message-destination-ref elements
218
iterator = MetaData.getChildrenByTagName(element, "message-destination-ref");
219       while (iterator.hasNext())
220       {
221          Element JavaDoc resourceRef = (Element JavaDoc) iterator.next();
222          ResourceEnvRefMetaData refMetaData = new ResourceEnvRefMetaData();
223          refMetaData.importEjbJarXml(resourceRef);
224          /* A message-destination-ref is linked to a jndi-name either via
225          the message-destination-ref/message-destination-ref-name mapping to
226          a jboss resource-env-ref/resource-env-ref-name if there is no
227          message-destination-link, or by the message-destination-link ->
228          message-destination/message-destination-name mapping to a jboss
229          resource-env-ref/resource-env-ref-name.
230          */

231          String JavaDoc refName = refMetaData.getRefName();
232          String JavaDoc link = refMetaData.getLink();
233          if( link != null )
234          {
235             ArrayList JavaDoc linkedRefs = (ArrayList JavaDoc) resourceEnvReferenceLinks.get(link);
236             if( linkedRefs == null )
237             {
238                linkedRefs = new ArrayList JavaDoc();
239                resourceEnvReferenceLinks.put(link, linkedRefs);
240             }
241             linkedRefs.add(refMetaData);
242          }
243          resourceEnvReferences.put(refName, refMetaData);
244       }
245    }
246
247    public void importJbossClientXml(Element JavaDoc element) throws DeploymentException
248    {
249       jndiName = MetaData.getOptionalChildContent(element, "jndi-name");
250
251       // Get the JNDI names of ejb-refs
252
Iterator JavaDoc iterator = MetaData.getChildrenByTagName(element, "ejb-ref");
253       while (iterator.hasNext())
254       {
255          Element JavaDoc ejbRef = (Element JavaDoc) iterator.next();
256          String JavaDoc ejbRefName = MetaData.getElementContent(
257             MetaData.getUniqueChild(ejbRef, "ejb-ref-name"));
258          EjbRefMetaData ejbRefMetaData = (EjbRefMetaData) ejbReferences.get(ejbRefName);
259          if (ejbRefMetaData == null)
260          {
261             throw new DeploymentException("ejb-ref " + ejbRefName
262                + " found in jboss-client.xml but not in application-client.xml");
263          }
264          ejbRefMetaData.importJbossXml(ejbRef);
265       }
266
267       // Parse the service-ref elements
268
iterator = MetaData.getChildrenByTagName(element, "service-ref");
269       while (iterator.hasNext())
270       {
271          Element JavaDoc serviceRef = (Element JavaDoc) iterator.next();
272          String JavaDoc serviceRefName = MetaData.getUniqueChildContent(serviceRef, "service-ref-name");
273          ServiceRefMetaData refMetaData = (ServiceRefMetaData)serviceReferences.get(serviceRefName);
274          if (refMetaData == null && ServiceRefMetaData.isValidDoctype(serviceRef))
275          {
276             throw new DeploymentException("service-ref " + serviceRefName + " found in jboss-client.xml but not in application-client.xml");
277          }
278          if (refMetaData != null)
279             refMetaData.importJBossXml(serviceRef);
280       }
281
282       // Get the JNDI name binding for resource-refs
283
iterator = MetaData.getChildrenByTagName(element, "resource-ref");
284       while (iterator.hasNext())
285       {
286          Element JavaDoc resourceRef = (Element JavaDoc) iterator.next();
287          String JavaDoc resRefName = MetaData.getElementContent(
288             MetaData.getUniqueChild(resourceRef, "res-ref-name"));
289          ResourceRefMetaData resourceRefMetaData =
290             (ResourceRefMetaData) resourceReferences.get(resRefName);
291          if (resourceRefMetaData == null)
292          {
293             throw new DeploymentException("resource-ref " + resRefName
294                + " found in jboss-client.xml but not in application-client.xml");
295          }
296          resourceRefMetaData.importJbossXml(resourceRef);
297       }
298
299       // Get the JNDI name binding resource-env-refs
300
iterator = MetaData.getChildrenByTagName(element, "resource-env-ref");
301       while (iterator.hasNext())
302       {
303          Element JavaDoc resourceRef = (Element JavaDoc) iterator.next();
304          String JavaDoc resRefName = MetaData.getElementContent(
305             MetaData.getUniqueChild(resourceRef, "resource-env-ref-name"));
306          ResourceEnvRefMetaData refMetaData =
307             (ResourceEnvRefMetaData) resourceEnvReferences.get(resRefName);
308          if (refMetaData == null)
309          {
310             // Try the resourceEnvReferenceLinks
311
ArrayList JavaDoc linkedRefs = (ArrayList JavaDoc) resourceEnvReferenceLinks.get(resRefName);
312             if( linkedRefs != null )
313             {
314                for(int n = 0; n < linkedRefs.size(); n ++)
315                {
316                   refMetaData = (ResourceEnvRefMetaData) linkedRefs.get(n);
317                   refMetaData.importJbossXml(resourceRef);
318                }
319             }
320             else
321             {
322                throw new DeploymentException("resource-env-ref " + resRefName
323                   + " found in jboss-client.xml but not in application-client.xml");
324             }
325          }
326          else
327          {
328             refMetaData.importJbossXml(resourceRef);
329          }
330       }
331    }
332 }
333
Popular Tags