001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.web.deployment;
017:
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.Set;
021:
022: import javax.enterprise.deploy.model.DDBean;
023: import javax.enterprise.deploy.spi.DConfigBean;
024: import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
025: import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
026:
027: import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
028: import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
029: import org.apache.geronimo.naming.deployment.ENCHelper;
030: import org.apache.geronimo.naming.deployment.jsr88.EjbLocalRef;
031: import org.apache.geronimo.naming.deployment.jsr88.EjbRef;
032: import org.apache.geronimo.naming.deployment.jsr88.MessageDestination;
033: import org.apache.geronimo.naming.deployment.jsr88.ResourceEnvRef;
034: import org.apache.geronimo.naming.deployment.jsr88.ResourceRef;
035: import org.apache.geronimo.xbeans.geronimo.j2ee.GerAbstractSecurityType;
036: import org.apache.geronimo.xbeans.geronimo.naming.GerEjbLocalRefType;
037: import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefType;
038: import org.apache.geronimo.xbeans.geronimo.naming.GerMessageDestinationType;
039: import org.apache.geronimo.xbeans.geronimo.naming.GerResourceEnvRefType;
040: import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
041: import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
042: import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
043: import org.apache.xmlbeans.SchemaTypeLoader;
044:
045: /**
046: * @version $Rev: 594759 $ $Date: 2007-11-13 20:32:35 -0800 (Tue, 13 Nov 2007) $
047: */
048: public class WebAppDConfigBean extends DConfigBeanSupport {
049: private final ENCHelper encHelper;
050: private EnvironmentData environment;
051: private EjbRef[] ejbRefs = new EjbRef[0];
052: private EjbLocalRef[] ejbLocalRefs = new EjbLocalRef[0];
053: private ResourceRef[] resourceRefs = new ResourceRef[0];
054: private ResourceEnvRef[] resourceEnvRefs = new ResourceEnvRef[0];
055: private MessageDestination[] messageDestinations = new MessageDestination[0];
056:
057: WebAppDConfigBean(DDBean ddBean, GerWebAppType webApp) {
058: super (ddBean, webApp);
059:
060: ENCHelper.XmlEnvRefs envRefs = new ENCHelper.XmlEnvRefs(webApp
061: .getEjbRefArray(), webApp.getEjbLocalRefArray(), webApp
062: .getResourceRefArray(), webApp.getResourceEnvRefArray());
063:
064: //which version are we dealing with?
065: String version = ddBean.getRoot().getAttributeValue("version");
066: if ("2.4".equals(version)) {
067: encHelper = new ENCHelper(ddBean, envRefs,
068: getXPathsForJ2ee_1_4(ENCHelper.ENC_XPATHS),
069: getXPathsForJ2ee_1_4(ENCHelper.NAME_XPATHS));
070: } else {
071: encHelper = new ENCHelper(ddBean, envRefs,
072: getXPathsWithPrefix(null, ENCHelper.ENC_XPATHS),
073: getXPathsWithPrefix(null, ENCHelper.NAME_XPATHS));
074: }
075:
076: }
077:
078: GerWebAppType getWebApp() {
079: return (GerWebAppType) getXmlObject();
080: }
081:
082: public String getContextRoot() {
083: return getWebApp().getContextRoot();
084: }
085:
086: public void setContextRoot(String contextRoot) {
087: pcs.firePropertyChange("contextRoot", getContextRoot(),
088: contextRoot);
089: getWebApp().setContextRoot(contextRoot);
090: }
091:
092: public DConfigBean getDConfigBean(DDBean ddBean)
093: throws ConfigurationException {
094: return encHelper.getDConfigBean(ddBean);
095: }
096:
097: public void removeDConfigBean(DConfigBean dcBean)
098: throws BeanNotFoundException {
099: encHelper.removeDConfigBean(dcBean);
100: }
101:
102: public String[] getXpaths() {
103: return getXPathsForJ2ee_1_4(ENCHelper.ENC_XPATHS);
104: }
105:
106: protected SchemaTypeLoader getSchemaTypeLoader() {
107: return WebAppDConfigRoot.SCHEMA_TYPE_LOADER;
108: }
109:
110: // ----------------------- JavaBean Properties for web-app ----------------------
111:
112: public EnvironmentData getEnvironment() {
113: return environment;
114: }
115:
116: public void setEnvironment(EnvironmentData environment) {
117: EnvironmentData old = this .environment;
118: this .environment = environment;
119: if ((old == null && environment == null)
120: || (old != null && old == environment)) {
121: return;
122: }
123: if (old != null) {
124: getWebApp().unsetEnvironment();
125: }
126: if (environment != null) {
127: environment.configure(getWebApp().addNewEnvironment());
128: }
129: pcs.firePropertyChange("environment", old, environment);
130: }
131:
132: public EjbRef[] getEjbRefs() {
133: return ejbRefs;
134: }
135:
136: public void setEjbRefs(EjbRef[] ejbRefs) {
137: EjbRef[] old = this .ejbRefs;
138: Set before = new HashSet();
139: for (int i = 0; i < old.length; i++) {
140: before.add(old[i]);
141: }
142: this .ejbRefs = ejbRefs;
143: // Handle current or new ejbRefs
144: for (int i = 0; i < ejbRefs.length; i++) {
145: EjbRef ejbRef = ejbRefs[i];
146: //if(ejbRef.getEjbRef() == null) {
147: ejbRef.configure(getWebApp().addNewEjbRef());
148: //} else {
149: // before.remove(ejbRef);
150: //}
151: }
152: // Handle removed or new ejbRefs
153: for (Iterator it = before.iterator(); it.hasNext();) {
154: EjbRef adapter = (EjbRef) it.next();
155: GerEjbRefType all[] = getWebApp().getEjbRefArray();
156: for (int i = 0; i < all.length; i++) {
157: if (all[i] == adapter) {
158: getWebApp().removeEjbRef(i);
159: break;
160: }
161: }
162: }
163: pcs.firePropertyChange("ejb-ref", old, ejbRefs);
164: }
165:
166: public EjbLocalRef[] getEjbLocalRefs() {
167: return ejbLocalRefs;
168: }
169:
170: public void setEjbLocalRefs(EjbLocalRef[] ejbLocalRefs) {
171: EjbLocalRef[] old = this .ejbLocalRefs;
172: Set before = new HashSet();
173: for (int i = 0; i < old.length; i++) {
174: before.add(old[i]);
175: }
176: this .ejbLocalRefs = ejbLocalRefs;
177: // Handle current or new ejbLocalRefs
178: for (int i = 0; i < ejbLocalRefs.length; i++) {
179: EjbLocalRef ejbLocalRef = ejbLocalRefs[i];
180: //if(ejbLocalRef.getEjbLocalRef() == null) {
181: ejbLocalRef.configure(getWebApp().addNewEjbLocalRef());
182: //} else {
183: // before.remove(ejbLocalRef);
184: //}
185: }
186: // Handle removed or new ejbLocalRefs
187: for (Iterator it = before.iterator(); it.hasNext();) {
188: EjbLocalRef adapter = (EjbLocalRef) it.next();
189: GerEjbLocalRefType all[] = getWebApp()
190: .getEjbLocalRefArray();
191: for (int i = 0; i < all.length; i++) {
192: if (all[i] == adapter) {
193: getWebApp().removeEjbLocalRef(i);
194: break;
195: }
196: }
197: }
198: pcs.firePropertyChange("ejb-local-ref", old, ejbLocalRefs);
199: }
200:
201: public ResourceRef[] getResourceRefs() {
202: return resourceRefs;
203: }
204:
205: public void setResourceRefs(ResourceRef[] resourceRefs) {
206: ResourceRef[] old = this .resourceRefs;
207: Set before = new HashSet();
208: for (int i = 0; i < old.length; i++) {
209: before.add(old[i]);
210: }
211: this .resourceRefs = resourceRefs;
212: // Handle current or new resourceRefs
213: for (int i = 0; i < resourceRefs.length; i++) {
214: ResourceRef resourceRef = resourceRefs[i];
215: //if(resourceRef.getResourceRef() == null) {
216: resourceRef.configure(getWebApp().addNewResourceRef());
217: //} else {
218: // before.remove(resourceRef);
219: //}
220: }
221: // Handle removed or new resourceRefs
222: for (Iterator it = before.iterator(); it.hasNext();) {
223: ResourceRef adapter = (ResourceRef) it.next();
224: GerResourceRefType all[] = getWebApp()
225: .getResourceRefArray();
226: for (int i = 0; i < all.length; i++) {
227: if (all[i] == adapter) {
228: getWebApp().removeResourceRef(i);
229: break;
230: }
231: }
232: }
233: pcs.firePropertyChange("resource-ref", old, resourceRefs);
234: }
235:
236: public ResourceEnvRef[] getResourceEnvRefs() {
237: return resourceEnvRefs;
238: }
239:
240: public void setResourceEnvRefs(ResourceEnvRef[] resourceEnvRefs) {
241: ResourceEnvRef[] old = this .resourceEnvRefs;
242: Set before = new HashSet();
243: for (int i = 0; i < old.length; i++) {
244: before.add(old[i]);
245: }
246: this .resourceEnvRefs = resourceEnvRefs;
247: // Handle current or new resourceEnvRefs
248: for (int i = 0; i < resourceEnvRefs.length; i++) {
249: ResourceEnvRef resourceEnvRef = resourceEnvRefs[i];
250: //if(resourceEnvRef.getResourceEnvRef() == null) {
251: resourceEnvRef
252: .configure(getWebApp().addNewResourceEnvRef());
253: //} else {
254: // before.remove(resourceEnvRef);
255: //}
256: }
257: // Handle removed or new resourceEnvRefs
258: for (Iterator it = before.iterator(); it.hasNext();) {
259: ResourceEnvRef adapter = (ResourceEnvRef) it.next();
260: GerResourceEnvRefType all[] = getWebApp()
261: .getResourceEnvRefArray();
262: for (int i = 0; i < all.length; i++) {
263: if (all[i] == adapter) {
264: getWebApp().removeResourceEnvRef(i);
265: break;
266: }
267: }
268: }
269: pcs
270: .firePropertyChange("resource-env-ref", old,
271: resourceEnvRefs);
272: }
273:
274: public MessageDestination[] getMessageDestinations() {
275: return messageDestinations;
276: }
277:
278: public void setMessageDestinations(
279: MessageDestination[] messageDestinations) {
280: MessageDestination[] old = this .messageDestinations;
281: Set before = new HashSet();
282: for (int i = 0; i < old.length; i++) {
283: before.add(old[i]);
284: }
285: this .messageDestinations = messageDestinations;
286: // Handle current or new messageDestinations
287: for (int i = 0; i < messageDestinations.length; i++) {
288: MessageDestination messageDestination = messageDestinations[i];
289: //if(messageDestination.getMessageDestination() == null) {
290: messageDestination.configure(getWebApp()
291: .addNewMessageDestination());
292: //} else {
293: // before.remove(messageDestination);
294: //}
295: }
296: // Handle removed or new messageDestinations
297: for (Iterator it = before.iterator(); it.hasNext();) {
298: MessageDestination adapter = (MessageDestination) it.next();
299: GerMessageDestinationType all[] = getWebApp()
300: .getMessageDestinationArray();
301: for (int i = 0; i < all.length; i++) {
302: if (all[i] == adapter) {
303: getWebApp().removeMessageDestination(i);
304: break;
305: }
306: }
307: }
308: pcs.firePropertyChange("message-destination", old,
309: messageDestinations);
310: }
311:
312: public String getSecurityRealmName() {
313: return getWebApp().getSecurityRealmName();
314: }
315:
316: public void setSecurityRealmName(String securityRealmName) {
317: pcs.firePropertyChange("securityRealmName",
318: getSecurityRealmName(), securityRealmName);
319: getWebApp().setSecurityRealmName(securityRealmName);
320: }
321:
322: //TODO Method to be updated once DConfigBean for "security" is available
323: public GerAbstractSecurityType getSecurity() {
324: return getWebApp().getSecurity();
325: }
326:
327: //TODO Method to be updated once DConfigBean for "security" is available
328: public void setSecurity(GerAbstractSecurityType security) {
329: pcs.firePropertyChange("security", getSecurity(), security);
330: getWebApp().setSecurity(security);
331: }
332:
333: //TODO Method to be updated once DConfigBean for "service-ref" is available
334: public GerServiceRefType[] getServiceRefs() {
335: return getWebApp().getServiceRefArray();
336: }
337:
338: //TODO Method to be updated once DConfigBean for "service-ref" is available
339: public void setServiceRefs(GerServiceRefType[] serviceRefArray) {
340: pcs.firePropertyChange("service-ref", getServiceRefs(),
341: serviceRefArray);
342: getWebApp().setServiceRefArray(serviceRefArray);
343: }
344: // ----------------------- End of JavaBean Properties ----------------------
345: }
|