001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Florent BENOIT & Ludovic BERT
022: * --------------------------------------------------------------------------
023: * $Id: Ear.java 6618 2005-04-22 11:15:08Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas.ear;
026:
027: import java.net.URL;
028: import java.util.ArrayList;
029:
030: import javax.management.MalformedObjectNameException;
031: import javax.management.ObjectName;
032:
033: import org.objectweb.jonas.jmx.J2eeObjectName;
034: import org.objectweb.jonas.management.j2eemanagement.J2EEDeployedObject;
035:
036: /**
037: * Class representing an Ear structure which is composed of :
038: * <ul>
039: * <li>array of URL of ejb-jar files</li>
040: * <li>array of URL of war files</li>
041: * <li>array of URL of rar files</li>
042: * </ul>
043: * @author Florent Benoit
044: * @author Michel-Ange Anton (JSR77: J2EEApplication)
045: * @author Adriana Danes
046: */
047: public class Ear extends J2EEDeployedObject implements EarMBean {
048:
049: /**
050: * URLs of ejb-jars files
051: */
052: private URL[] ejbJars = null;
053:
054: /**
055: * Urls of wars files
056: */
057: private URL[] wars = null;
058:
059: /**
060: * Urls of rars files
061: */
062: private URL[] rars = null;
063:
064: /**
065: * Url of this EAR
066: */
067: private URL earUrl = null;
068:
069: /**
070: * The name of this EAR (J2EEApplication name).
071: */
072: private String name = null;
073:
074: /**
075: * The unpack work copy of this EAR.
076: */
077: private String unpackName = null;
078:
079: /**
080: * The modules OBJECT_NAMEs
081: */
082: private String[] modules = null;
083:
084: /**
085: * The web modules OBJECT_NAMEs
086: */
087: private String[] webModules = null;
088:
089: /**
090: * Construct an Ear structure with the specified files
091: * @param objectName The object name of the deployed object
092: * @param pName name of the application
093: * @param pUnpackName name of the working copy of the ear
094: * @param earUrl the url of this ear
095: * @param deploymentDescriptor the deployment descriptor of the file
096: * @param ejbJars the URLs of ejb-jar files
097: * @param wars the URLs of the war files
098: * @param rars the URLs of the rar files
099: */
100: public Ear(String objectName, String pName, String pUnpackName,
101: URL earUrl, String deploymentDescriptor, URL[] ejbJars,
102: URL[] wars, URL[] rars) {
103: super (objectName);
104: this .earUrl = earUrl;
105: //this.deploymentDescriptor = deploymentDescriptor;
106: setDeploymentDescriptor(deploymentDescriptor);
107: this .ejbJars = ejbJars;
108: this .wars = wars;
109: this .rars = rars;
110: name = pName;
111: unpackName = pUnpackName;
112: setModules();
113: setWebModules();
114: }
115:
116: /**
117: * Return the url of this Ear
118: * @return the url of this Ear
119: */
120: public URL getEarUrl() {
121: return earUrl;
122: }
123:
124: /**
125: * Return the ejb-jar files
126: * @return the ejb-jar files
127: */
128: public URL[] getEjbJars() {
129: return ejbJars;
130: }
131:
132: /**
133: * Return the war files
134: * @return the war files
135: */
136: public URL[] getWars() {
137: return wars;
138: }
139:
140: /**
141: * Return the rar files
142: * @return the rar files
143: */
144: public URL[] getRars() {
145: return rars;
146: }
147:
148: /**
149: * The application name.
150: * @return application name
151: */
152: public String getName() {
153: return name;
154: }
155:
156: /**
157: * The name of the working copy of the ear
158: * @return work name
159: */
160: public String getUnpackName() {
161: return unpackName;
162: }
163:
164: /**
165: * Determine the J2EEModules used by this J2EEApplication (jar, war, rar).
166: */
167: private void setModules() {
168: ArrayList al = new ArrayList();
169: try {
170: // ear ObjectName
171: ObjectName on = ObjectName.getInstance(getObjectName());
172: String domain = on.getDomain();
173: String serverName = on.getKeyProperty(J2EE_TYPE_SERVER);
174: String appName = on.getKeyProperty(NAME);
175: // Add EJBModules
176: ObjectName modulesOn = J2eeObjectName.getEJBModules(domain,
177: serverName, appName);
178: al.addAll(J2eeObjectName.queryStrings(modulesOn));
179: // Add WebModules
180: modulesOn = J2eeObjectName.getWebModules(domain,
181: serverName, appName);
182: al.addAll(J2eeObjectName.queryStrings(modulesOn));
183: // Add ResourceAdapterModules
184: modulesOn = J2eeObjectName.getResourceAdapterModules(
185: domain, serverName, appName);
186: al.addAll(J2eeObjectName.queryStrings(modulesOn));
187: // Add AppClientModules
188: modulesOn = J2eeObjectName.getAppClientModules(domain,
189: serverName, appName);
190: al.addAll(J2eeObjectName.queryStrings(modulesOn));
191: } catch (MalformedObjectNameException e) {
192: // none action
193: throw new RuntimeException(
194: "Error while using an objectname", e);
195: }
196: modules = ((String[]) al.toArray(new String[al.size()]));
197: }
198:
199: /**
200: * Return the J2EEModules used by this J2EEApplication (jar, war, rar).
201: * @return A array of OBJECT_NAMEs corresponding to these modules.
202: */
203: public String[] getModules() {
204: return modules;
205: }
206:
207: /**
208: * @return Returns the webModules.
209: */
210: public String[] getWebModules() {
211: return webModules;
212: }
213:
214: /**
215: * Determine the web modules contained in this J2EEApplication
216: */
217: public void setWebModules() {
218: ArrayList al = new ArrayList();
219: try {
220: // ear ObjectName
221: ObjectName on = ObjectName.getInstance(getObjectName());
222: String domain = on.getDomain();
223: String serverName = on.getKeyProperty(J2EE_TYPE_SERVER);
224: String appName = on.getKeyProperty(NAME);
225: // Add WebModules
226: ObjectName modulesOn = J2eeObjectName.getWebModules(domain,
227: serverName, appName);
228: al.addAll(J2eeObjectName.queryStrings(modulesOn));
229: } catch (MalformedObjectNameException e) {
230: // none action
231: throw new RuntimeException(
232: "Error while using an objectname", e);
233: }
234: webModules = ((String[]) al.toArray(new String[al.size()]));
235: }
236: }
|