KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ear > Ear


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Florent BENOIT & Ludovic BERT
22  * --------------------------------------------------------------------------
23  * $Id: Ear.java,v 1.11 2005/04/22 11:15:07 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.ear;
28
29 import java.net.URL JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 import javax.management.MalformedObjectNameException JavaDoc;
33 import javax.management.ObjectName JavaDoc;
34
35 import org.objectweb.jonas.jmx.J2eeObjectName;
36 import org.objectweb.jonas.management.j2eemanagement.J2EEDeployedObject;
37
38 /**
39  * Class representing an Ear structure which is composed of :
40  * <ul>
41  * <li>array of URL of ejb-jar files</li>
42  * <li>array of URL of war files</li>
43  * <li>array of URL of rar files</li>
44  * </ul>
45  * @author Florent Benoit
46  * @author Michel-Ange Anton (JSR77: J2EEApplication)
47  * @author Adriana Danes
48  */

49 public class Ear extends J2EEDeployedObject implements EarMBean {
50
51     /**
52      * URLs of ejb-jars files
53      */

54     private URL JavaDoc[] ejbJars = null;
55
56
57     /**
58      * Urls of wars files
59      */

60     private URL JavaDoc[] wars = null;
61
62     /**
63      * Urls of rars files
64      */

65     private URL JavaDoc[] rars = null;
66
67     /**
68      * Url of this EAR
69      */

70     private URL JavaDoc earUrl = null;
71
72     /**
73      * The name of this EAR (J2EEApplication name).
74      */

75     private String JavaDoc name = null;
76
77     /**
78      * The unpack work copy of this EAR.
79      */

80     private String JavaDoc unpackName = null;
81
82     /**
83      * The modules OBJECT_NAMEs
84      */

85     private String JavaDoc[] modules = null;
86
87     /**
88      * The web modules OBJECT_NAMEs
89      */

90     private String JavaDoc[] webModules = null;
91
92     /**
93      * Construct an Ear structure with the specified files
94      * @param objectName The object name of the deployed object
95      * @param pName name of the application
96      * @param pUnpackName name of the working copy of the ear
97      * @param earUrl the url of this ear
98      * @param deploymentDescriptor the deployment descriptor of the file
99      * @param ejbJars the URLs of ejb-jar files
100      * @param wars the URLs of the war files
101      * @param rars the URLs of the rar files
102      */

103     public Ear(String JavaDoc objectName, String JavaDoc pName, String JavaDoc pUnpackName, URL JavaDoc earUrl, String JavaDoc deploymentDescriptor, URL JavaDoc[] ejbJars, URL JavaDoc[] wars,
104             URL JavaDoc[] rars) {
105         super(objectName);
106         this.earUrl = earUrl;
107         //this.deploymentDescriptor = deploymentDescriptor;
108
setDeploymentDescriptor(deploymentDescriptor);
109         this.ejbJars = ejbJars;
110         this.wars = wars;
111         this.rars = rars;
112         name = pName;
113         unpackName = pUnpackName;
114         setModules();
115         setWebModules();
116     }
117
118     /**
119      * Return the url of this Ear
120      * @return the url of this Ear
121      */

122     public URL JavaDoc getEarUrl() {
123         return earUrl;
124     }
125
126     /**
127      * Return the ejb-jar files
128      * @return the ejb-jar files
129      */

130     public URL JavaDoc[] getEjbJars() {
131         return ejbJars;
132     }
133
134     /**
135      * Return the war files
136      * @return the war files
137      */

138     public URL JavaDoc[] getWars() {
139         return wars;
140     }
141
142     /**
143      * Return the rar files
144      * @return the rar files
145      */

146     public URL JavaDoc[] getRars() {
147         return rars;
148     }
149
150     /**
151      * The application name.
152      * @return application name
153      */

154     public String JavaDoc getName() {
155         return name;
156     }
157
158     /**
159      * The name of the working copy of the ear
160      * @return work name
161      */

162     public String JavaDoc getUnpackName() {
163         return unpackName;
164     }
165
166     /**
167      * Determine the J2EEModules used by this J2EEApplication (jar, war, rar).
168      */

169     private void setModules() {
170         ArrayList JavaDoc al = new ArrayList JavaDoc();
171         try {
172             // ear ObjectName
173
ObjectName JavaDoc on = ObjectName.getInstance(getObjectName());
174             String JavaDoc domain = on.getDomain();
175             String JavaDoc serverName = on.getKeyProperty(J2EE_TYPE_SERVER);
176             String JavaDoc appName = on.getKeyProperty(NAME);
177             // Add EJBModules
178
ObjectName JavaDoc modulesOn = J2eeObjectName.getEJBModules(domain, serverName, appName);
179             al.addAll(J2eeObjectName.queryStrings(modulesOn));
180             // Add WebModules
181
modulesOn = J2eeObjectName.getWebModules(domain, serverName, appName);
182             al.addAll(J2eeObjectName.queryStrings(modulesOn));
183             // Add ResourceAdapterModules
184
modulesOn = J2eeObjectName.getResourceAdapterModules(domain, serverName, appName);
185             al.addAll(J2eeObjectName.queryStrings(modulesOn));
186             // Add AppClientModules
187
modulesOn = J2eeObjectName.getAppClientModules(domain, serverName, appName);
188             al.addAll(J2eeObjectName.queryStrings(modulesOn));
189         } catch (MalformedObjectNameException JavaDoc e) {
190             // none action
191
throw new RuntimeException JavaDoc("Error while using an objectname", e);
192         }
193         modules = ((String JavaDoc[]) al.toArray(new String JavaDoc[al.size()]));
194     }
195     /**
196      * Return the J2EEModules used by this J2EEApplication (jar, war, rar).
197      * @return A array of OBJECT_NAMEs corresponding to these modules.
198      */

199     public String JavaDoc[] getModules() {
200         return modules;
201     }
202     /**
203      * @return Returns the webModules.
204      */

205     public String JavaDoc[] getWebModules() {
206         return webModules;
207     }
208     /**
209      * Determine the web modules contained in this J2EEApplication
210      */

211     public void setWebModules() {
212         ArrayList JavaDoc al = new ArrayList JavaDoc();
213         try {
214             // ear ObjectName
215
ObjectName JavaDoc on = ObjectName.getInstance(getObjectName());
216             String JavaDoc domain = on.getDomain();
217             String JavaDoc serverName = on.getKeyProperty(J2EE_TYPE_SERVER);
218             String JavaDoc appName = on.getKeyProperty(NAME);
219             // Add WebModules
220
ObjectName JavaDoc modulesOn = J2eeObjectName.getWebModules(domain, serverName, appName);
221             al.addAll(J2eeObjectName.queryStrings(modulesOn));
222         } catch (MalformedObjectNameException JavaDoc e) {
223             // none action
224
throw new RuntimeException JavaDoc("Error while using an objectname", e);
225         }
226         webModules = ((String JavaDoc[]) al.toArray(new String JavaDoc[al.size()]));
227     }
228 }
Popular Tags