KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > repository > impl > cache > J2eeApplication


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt.repository.impl.cache;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29
30 /**
31  * Represents a J2EE Application with ejb and web modules that have
32  * web services.
33  *
34  * @author Nazrul Islam
35  * @since J2SE 5.0
36  */

37 public class J2eeApplication {
38
39     /**
40      * Constructor.
41      *
42      * @param name name of the application
43      * @param ejb name of ejb bundles with web services
44      * @param web name of web bundles with web services
45      */

46     J2eeApplication(String JavaDoc name, List JavaDoc ejb, List JavaDoc web) {
47         _name = name;
48         _ejbBundles = ejb;
49         _webBundles = web;
50     }
51
52     /**
53      * Constructor.
54      *
55      * @param key name of the application
56      * @param val string representation of the ejb and web bundles
57      */

58     J2eeApplication(String JavaDoc key, String JavaDoc val) {
59         _name = key;
60         _ejbBundles = new ArrayList JavaDoc();
61         _webBundles = new ArrayList JavaDoc();
62
63         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(val, DELIM);
64         while (st.hasMoreTokens()) {
65             String JavaDoc m = st.nextToken();
66             if (m.startsWith(EJB_KEY)) {
67                 int ejbKeyLength = EJB_KEY.length();
68                 String JavaDoc ejbModule = m.substring(ejbKeyLength);
69                 addEjbBundle(ejbModule);
70
71             } else if (m.startsWith(WEB_KEY)) {
72                 int webKeyLength = WEB_KEY.length();
73                 String JavaDoc webModule = m.substring(webKeyLength);
74                 addWebBundle(webModule);
75             }
76         }
77     }
78
79     /**
80      * Returns the name of the application.
81      *
82      * @return name of the application
83      */

84     public String JavaDoc getName() {
85         return _name;
86     }
87
88     /**
89      * Returns a string representation of the ejb and web bundles.
90      *
91      * @return a string representation of the ejb and web bundles
92      */

93     String JavaDoc getPersistentValue() {
94         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
95
96         for (Iterator JavaDoc iter=_ejbBundles.iterator(); iter.hasNext();) {
97             String JavaDoc ejb = (String JavaDoc) iter.next();
98             sb.append(EJB_KEY);
99             sb.append(ejb);
100             sb.append(DELIM);
101         }
102
103         for (Iterator JavaDoc iter=_webBundles.iterator(); iter.hasNext();) {
104             String JavaDoc web = (String JavaDoc) iter.next();
105             sb.append(WEB_KEY);
106             sb.append(web);
107             sb.append(DELIM);
108         }
109
110         String JavaDoc persistentValue = null;
111         int length = sb.length();
112         if (length > 0) {
113             String JavaDoc val = sb.toString();
114             persistentValue = val.substring(0, length-1);
115         }
116         return persistentValue;
117     }
118
119     /**
120      * Returns the name of the ejb bundles that have web services.
121      *
122      * @return list of ejb bundles with web services
123      */

124     public List JavaDoc getEjbBundles() {
125         return _ejbBundles;
126     }
127
128     /**
129      * Adds an ejb bundle to the list.
130      *
131      * @param name name of the ejb bundle
132      */

133     void addEjbBundle(String JavaDoc name) {
134         _ejbBundles.add(name);
135     }
136
137     /**
138      * Removes an ejb bundle from the list.
139      *
140      * @param name name of the ejb bundle
141      * @return true if the bundle was removed
142      */

143     boolean removeEjbBundle(String JavaDoc name) {
144         return _ejbBundles.remove(name);
145     }
146
147     /**
148      * Returns the name of the web bundles that have web services.
149      *
150      * @return list of web bundles with web services
151      */

152     public List JavaDoc getWebBundles() {
153         return _webBundles;
154     }
155
156     /**
157      * Adds a web bundle to the list.
158      *
159      * @param name name of the web bundle
160      */

161     void addWebBundle(String JavaDoc name) {
162         _webBundles.add(name);
163     }
164
165     /**
166      * Removes a web bundle from the list.
167      *
168      * @param name name of the web bundle
169      * @return true if bundle was removed
170      */

171     boolean removeWebBundle(String JavaDoc name) {
172         return _webBundles.remove(name);
173     }
174
175     // ---- VARIABLES - PRIVATE --------------------------------------
176
String JavaDoc _name = null;
177     List JavaDoc _ejbBundles = null;
178     List JavaDoc _webBundles = null;
179     static final String JavaDoc DELIM = ",";
180     static final String JavaDoc EJB_KEY = "EJB_";
181     static final String JavaDoc WEB_KEY = "WEB_";
182 }
183
Popular Tags