KickJava   Java API By Example, From Geeks To Geeks.

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


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.deployment;
23
24 // $Id: J2eeModuleMetaData.java 57837 2006-10-25 23:43:41Z scott.stark@jboss.org $
25

26 import org.jboss.metadata.MetaData;
27
28 import org.w3c.dom.Element JavaDoc;
29
30 /**
31  * The metadata for an application/module element
32  *
33  * @author <a HREF="mailto:daniel.schulze@telkel.com">Daniel Schulze</a>
34  * @author Thomas.Diesler@jboss.org
35  * @version $Revision: 57837 $
36  */

37 public class J2eeModuleMetaData
38         extends MetaData
39 {
40    // Constants -----------------------------------------------------
41
public static final int EJB = 0;
42    public static final int WEB = 1;
43    public static final int CLIENT = 2;
44    public static final int CONNECTOR = 3;
45    public static final int SERVICE = 4;
46    public static final int HAR = 5;
47    private static final String JavaDoc[] tags = {"ejb", "web", "java", "connector", "service", "har"};
48
49    // Attributes ----------------------------------------------------
50
int type;
51
52    String JavaDoc fileName;
53    String JavaDoc alternativeDD;
54    String JavaDoc webContext;
55
56    // Static --------------------------------------------------------
57

58    // Public --------------------------------------------------------
59

60    /**
61     * Default ctor used when populating the metadata via xml descriptors
62     */

63    public J2eeModuleMetaData()
64    {
65       
66    }
67
68    /**
69     * Ctor used when populating the metadata without a descriptor
70     * @param type - one of EJB, WEB, CLIENT, CONNECTOR, SERVICE, HAR
71     * @param fileName - the module name
72     */

73    public J2eeModuleMetaData(int type, String JavaDoc fileName)
74    {
75       this.type = type;
76       this.fileName = fileName;
77       if( type == WEB )
78       {
79          int dot = fileName.lastIndexOf('.');
80          if( dot >= 0 )
81             webContext = fileName.substring(0, dot);
82       }
83    }
84
85    public int getType()
86    {
87       return type;
88    }
89    public void setType(int type)
90    {
91       this.type = type;
92    }
93
94    public boolean isEjb()
95    {
96       return (type == EJB);
97    }
98
99    public boolean isWeb()
100    {
101       return (type == WEB);
102    }
103
104    public boolean isJava()
105    {
106       return (type == CLIENT);
107    }
108
109    public boolean isConnector()
110    {
111       return (type == CONNECTOR);
112    }
113
114
115    public String JavaDoc getFileName()
116    {
117       return fileName;
118    }
119    public void setFileName(String JavaDoc name)
120    {
121       this.fileName = name;
122       if( type == WEB )
123       {
124          int dot = fileName.lastIndexOf('.');
125          if( dot >= 0 )
126             webContext = fileName.substring(0, dot);
127       }
128    }
129
130    public String JavaDoc getAlternativeDD()
131    {
132       return alternativeDD;
133    }
134    public void setAlternativeDD(String JavaDoc dd)
135    {
136       this.alternativeDD = dd;
137    }
138
139    public String JavaDoc getWebContext()
140    {
141       if (type == WEB)
142       {
143          return webContext;
144       }
145       else
146       {
147          return null;
148       }
149    }
150    public void setWebContext(String JavaDoc context)
151    {
152       this.webContext = context;
153    }
154
155    public void importXml(Element JavaDoc rootElement) throws DeploymentException
156    {
157       String JavaDoc rootTag = rootElement.getOwnerDocument().getDocumentElement().getTagName();
158       if (rootTag.equals("application"))
159          importXml(rootElement, false);
160       else if (rootTag.equals("jboss-app"))
161          importXml(rootElement, true);
162       else
163          throw new DeploymentException("Unrecognized root tag: " + rootTag);
164    }
165
166    protected void importXml(Element JavaDoc element, boolean jbossSpecific) throws DeploymentException
167    {
168       String JavaDoc name = element.getTagName();
169       if (name.equals("module"))
170       {
171          boolean done = false; // only one of the tags can hit!
172
for (int i = 0; done == false && i < tags.length; ++i)
173          {
174             Element JavaDoc child = getOptionalChild(element, tags[i]);
175             if (child == null)
176             {
177                continue;
178             }
179
180             type = i;
181             switch (type)
182             {
183                case SERVICE:
184                   if (jbossSpecific == false)
185                   {
186                      throw new DeploymentException("Service archives must be in jboss-app.xml");
187                   } // end of if ()
188
//fall through.
189
case HAR:
190                   if (jbossSpecific == false)
191                   {
192                      throw new DeploymentException("Hibernate archives must be in jboss-app.xml");
193                   }
194                case EJB:
195                case CLIENT:
196                case CONNECTOR:
197                   fileName = getElementContent(child);
198                   alternativeDD = getElementContent(getOptionalChild(element, "alt-dd"));
199                   break;
200                case WEB:
201                   fileName = getElementContent(getUniqueChild(child, "web-uri"));
202                   webContext = getElementContent(getOptionalChild(child, "context-root"));
203                   alternativeDD = getElementContent(getOptionalChild(element, "alt-dd"));
204                   break;
205             }
206             done = true;
207          }
208
209          // If the module content is not recognized throw an exception
210
if (done == false)
211          {
212             StringBuffer JavaDoc msg = new StringBuffer JavaDoc("Invalid module content, must be one of: ");
213             for (int i = 0; i < tags.length; i ++)
214             {
215                msg.append(tags[i]);
216                msg.append(", ");
217             }
218             throw new DeploymentException(msg.toString());
219          }
220       }
221       else
222       {
223          throw new DeploymentException("non-module tag in application dd: " + name);
224       }
225    }
226 }
227
Popular Tags