Home » geronimo-2.2-source-release » org.apache.geronimo.web.deployment » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.web.deployment;
   19   
   20   import java.util.HashSet;
   21   import java.util.Iterator;
   22   import java.util.Set;
   23   
   24   import javax.enterprise.deploy.model.DDBean;
   25   import javax.enterprise.deploy.spi.DConfigBean;
   26   import javax.enterprise.deploy.spi.exceptions.BeanNotFoundException;
   27   import javax.enterprise.deploy.spi.exceptions.ConfigurationException;
   28   
   29   import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
   30   import org.apache.geronimo.deployment.service.jsr88.EnvironmentData;
   31   import org.apache.geronimo.naming.deployment.ENCHelper;
   32   import org.apache.geronimo.naming.deployment.jsr88.EjbLocalRef;
   33   import org.apache.geronimo.naming.deployment.jsr88.EjbRef;
   34   import org.apache.geronimo.naming.deployment.jsr88.MessageDestination;
   35   import org.apache.geronimo.naming.deployment.jsr88.ResourceEnvRef;
   36   import org.apache.geronimo.naming.deployment.jsr88.ResourceRef;
   37   import org.apache.geronimo.xbeans.geronimo.j2ee.GerAbstractSecurityType;
   38   import org.apache.geronimo.xbeans.geronimo.naming.GerEjbLocalRefType;
   39   import org.apache.geronimo.xbeans.geronimo.naming.GerEjbRefType;
   40   import org.apache.geronimo.xbeans.geronimo.naming.GerMessageDestinationType;
   41   import org.apache.geronimo.xbeans.geronimo.naming.GerResourceEnvRefType;
   42   import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType;
   43   import org.apache.geronimo.xbeans.geronimo.naming.GerServiceRefType;
   44   import org.apache.geronimo.xbeans.geronimo.web.GerWebAppType;
   45   import org.apache.xmlbeans.SchemaTypeLoader;
   46   
   47   /**
   48    * @version $Rev: 594759 $ $Date: 2007-11-13 20:32:35 -0800 (Tue, 13 Nov 2007) $
   49    */
   50   public class WebAppDConfigBean extends DConfigBeanSupport {
   51       private final ENCHelper encHelper;
   52       private EnvironmentData environment;
   53       private EjbRef[] ejbRefs = new EjbRef[0];
   54       private EjbLocalRef[] ejbLocalRefs = new EjbLocalRef[0];
   55       private ResourceRef[] resourceRefs = new ResourceRef[0];
   56       private ResourceEnvRef[] resourceEnvRefs = new ResourceEnvRef[0];
   57       private MessageDestination[] messageDestinations = new MessageDestination[0];
   58   
   59       WebAppDConfigBean(DDBean ddBean, GerWebAppType webApp) {
   60           super(ddBean, webApp);
   61   
   62           ENCHelper.XmlEnvRefs envRefs = new ENCHelper.XmlEnvRefs(webApp.getEjbRefArray(), webApp.getEjbLocalRefArray(), webApp.getResourceRefArray(), webApp.getResourceEnvRefArray()); 
   63   
   64           //which version are we dealing with?
   65           String version = ddBean.getRoot().getAttributeValue("version");
   66           if ("2.4".equals(version)) {
   67               encHelper = new ENCHelper(ddBean, envRefs, getXPathsForJ2ee_1_4(ENCHelper.ENC_XPATHS), getXPathsForJ2ee_1_4(ENCHelper.NAME_XPATHS));
   68           } else {
   69               encHelper = new ENCHelper(ddBean, envRefs, getXPathsWithPrefix(null, ENCHelper.ENC_XPATHS), getXPathsWithPrefix(null, ENCHelper.NAME_XPATHS));
   70           }
   71   
   72       }
   73   
   74       GerWebAppType getWebApp() {
   75           return (GerWebAppType) getXmlObject();
   76       }
   77   
   78       public String getContextRoot() {
   79           return getWebApp().getContextRoot();
   80       }
   81   
   82       public void setContextRoot(String contextRoot) {
   83           pcs.firePropertyChange("contextRoot", getContextRoot(), contextRoot);
   84           getWebApp().setContextRoot(contextRoot);
   85       }
   86   
   87       public DConfigBean getDConfigBean(DDBean ddBean) throws ConfigurationException {
   88           return encHelper.getDConfigBean(ddBean);
   89       }
   90   
   91       public void removeDConfigBean(DConfigBean dcBean) throws BeanNotFoundException {
   92           encHelper.removeDConfigBean(dcBean);
   93       }
   94   
   95       public String[] getXpaths() {
   96           return getXPathsForJ2ee_1_4(ENCHelper.ENC_XPATHS);
   97       }
   98   
   99       protected SchemaTypeLoader getSchemaTypeLoader() {
  100           return WebAppDConfigRoot.SCHEMA_TYPE_LOADER;
  101       }
  102   
  103       // ----------------------- JavaBean Properties for web-app ----------------------
  104   
  105       public EnvironmentData getEnvironment() {
  106           return environment;
  107       }
  108   
  109       public void setEnvironment(EnvironmentData environment) {
  110           EnvironmentData old = this.environment;
  111           this.environment = environment;
  112           if ((old == null && environment == null) || (old != null && old == environment)) {
  113               return;
  114           }
  115           if (old != null) {
  116               getWebApp().unsetEnvironment();
  117           }
  118           if (environment != null) {
  119               environment.configure(getWebApp().addNewEnvironment());
  120           }
  121           pcs.firePropertyChange("environment", old, environment);
  122       }
  123   
  124       public EjbRef[] getEjbRefs() {
  125           return ejbRefs;
  126       }
  127   
  128       public void setEjbRefs(EjbRef[] ejbRefs) {
  129           EjbRef[] old = this.ejbRefs;
  130           Set before = new HashSet();
  131           for (int i = 0; i < old.length; i++) {
  132               before.add(old[i]);
  133           }
  134           this.ejbRefs = ejbRefs;
  135           // Handle current or new ejbRefs
  136           for (int i = 0; i < ejbRefs.length; i++) {
  137               EjbRef ejbRef = ejbRefs[i];
  138               //if(ejbRef.getEjbRef() == null) {
  139                   ejbRef.configure(getWebApp().addNewEjbRef());
  140               //} else {
  141               //    before.remove(ejbRef);
  142               //}
  143           }
  144           // Handle removed or new ejbRefs
  145           for (Iterator it = before.iterator(); it.hasNext();) {
  146               EjbRef adapter = (EjbRef) it.next();
  147               GerEjbRefType all[] = getWebApp().getEjbRefArray();
  148               for (int i = 0; i < all.length; i++) {
  149                   if(all[i] == adapter) {
  150                       getWebApp().removeEjbRef(i);
  151                       break;
  152                   }
  153               }
  154           }
  155           pcs.firePropertyChange("ejb-ref", old, ejbRefs);
  156       }
  157   
  158       public EjbLocalRef[] getEjbLocalRefs() {
  159           return ejbLocalRefs;
  160       }
  161   
  162       public void setEjbLocalRefs(EjbLocalRef[] ejbLocalRefs) {
  163           EjbLocalRef[] old = this.ejbLocalRefs;
  164           Set before = new HashSet();
  165           for (int i = 0; i < old.length; i++) {
  166               before.add(old[i]);
  167           }
  168           this.ejbLocalRefs = ejbLocalRefs;
  169           // Handle current or new ejbLocalRefs
  170           for (int i = 0; i < ejbLocalRefs.length; i++) {
  171               EjbLocalRef ejbLocalRef = ejbLocalRefs[i];
  172               //if(ejbLocalRef.getEjbLocalRef() == null) {
  173                   ejbLocalRef.configure(getWebApp().addNewEjbLocalRef());
  174               //} else {
  175               //    before.remove(ejbLocalRef);
  176               //}
  177           }
  178           // Handle removed or new ejbLocalRefs
  179           for (Iterator it = before.iterator(); it.hasNext();) {
  180               EjbLocalRef adapter = (EjbLocalRef) it.next();
  181               GerEjbLocalRefType all[] = getWebApp().getEjbLocalRefArray();
  182               for (int i = 0; i < all.length; i++) {
  183                   if(all[i] == adapter) {
  184                       getWebApp().removeEjbLocalRef(i);
  185                       break;
  186                   }
  187               }
  188           }
  189           pcs.firePropertyChange("ejb-local-ref", old, ejbLocalRefs);
  190       }
  191   
  192       public ResourceRef[] getResourceRefs() {
  193           return resourceRefs;
  194       }
  195   
  196       public void setResourceRefs(ResourceRef[] resourceRefs) {
  197           ResourceRef[] old = this.resourceRefs;
  198           Set before = new HashSet();
  199           for (int i = 0; i < old.length; i++) {
  200               before.add(old[i]);
  201           }
  202           this.resourceRefs = resourceRefs;
  203           // Handle current or new resourceRefs
  204           for (int i = 0; i < resourceRefs.length; i++) {
  205               ResourceRef resourceRef = resourceRefs[i];
  206               //if(resourceRef.getResourceRef() == null) {
  207               resourceRef.configure(getWebApp().addNewResourceRef());
  208               //} else {
  209               //    before.remove(resourceRef);
  210               //}
  211           }
  212           // Handle removed or new resourceRefs
  213           for (Iterator it = before.iterator(); it.hasNext();) {
  214               ResourceRef adapter = (ResourceRef) it.next();
  215               GerResourceRefType all[] = getWebApp().getResourceRefArray();
  216               for (int i = 0; i < all.length; i++) {
  217                   if(all[i] == adapter) {
  218                       getWebApp().removeResourceRef(i);
  219                       break;
  220                   }
  221               }
  222           }
  223           pcs.firePropertyChange("resource-ref", old, resourceRefs);
  224       }
  225   
  226       public ResourceEnvRef[] getResourceEnvRefs() {
  227           return resourceEnvRefs;
  228       }
  229   
  230       public void setResourceEnvRefs(ResourceEnvRef[] resourceEnvRefs) {
  231           ResourceEnvRef[] old = this.resourceEnvRefs;
  232           Set before = new HashSet();
  233           for (int i = 0; i < old.length; i++) {
  234               before.add(old[i]);
  235           }
  236           this.resourceEnvRefs = resourceEnvRefs;
  237           // Handle current or new resourceEnvRefs
  238           for (int i = 0; i < resourceEnvRefs.length; i++) {
  239               ResourceEnvRef resourceEnvRef = resourceEnvRefs[i];
  240               //if(resourceEnvRef.getResourceEnvRef() == null) {
  241               resourceEnvRef.configure(getWebApp().addNewResourceEnvRef());
  242               //} else {
  243               //    before.remove(resourceEnvRef);
  244               //}
  245           }
  246           // Handle removed or new resourceEnvRefs
  247           for (Iterator it = before.iterator(); it.hasNext();) {
  248               ResourceEnvRef adapter = (ResourceEnvRef) it.next();
  249               GerResourceEnvRefType all[] = getWebApp().getResourceEnvRefArray();
  250               for (int i = 0; i < all.length; i++) {
  251                   if(all[i] == adapter) {
  252                       getWebApp().removeResourceEnvRef(i);
  253                       break;
  254                   }
  255               }
  256           }
  257           pcs.firePropertyChange("resource-env-ref", old, resourceEnvRefs);
  258       }
  259   
  260       public MessageDestination[] getMessageDestinations() {
  261           return messageDestinations;
  262       }
  263   
  264       public void setMessageDestinations(MessageDestination[] messageDestinations) {
  265           MessageDestination[] old = this.messageDestinations;
  266           Set before = new HashSet();
  267           for (int i = 0; i < old.length; i++) {
  268               before.add(old[i]);
  269           }
  270           this.messageDestinations = messageDestinations;
  271           // Handle current or new messageDestinations
  272           for (int i = 0; i < messageDestinations.length; i++) {
  273               MessageDestination messageDestination = messageDestinations[i];
  274               //if(messageDestination.getMessageDestination() == null) {
  275               messageDestination.configure(getWebApp().addNewMessageDestination());
  276               //} else {
  277               //    before.remove(messageDestination);
  278               //}
  279           }
  280           // Handle removed or new messageDestinations
  281           for (Iterator it = before.iterator(); it.hasNext();) {
  282               MessageDestination adapter = (MessageDestination) it.next();
  283               GerMessageDestinationType all[] = getWebApp().getMessageDestinationArray();
  284               for (int i = 0; i < all.length; i++) {
  285                   if(all[i] == adapter) {
  286                       getWebApp().removeMessageDestination(i);
  287                       break;
  288                   }
  289               }
  290           }
  291           pcs.firePropertyChange("message-destination", old, messageDestinations);
  292       }
  293   
  294       public String getSecurityRealmName() {
  295           return getWebApp().getSecurityRealmName();
  296       }
  297   
  298       public void setSecurityRealmName(String securityRealmName) {
  299           pcs.firePropertyChange("securityRealmName", getSecurityRealmName(), securityRealmName);
  300           getWebApp().setSecurityRealmName(securityRealmName);
  301       }
  302   
  303       //TODO Method to be updated once DConfigBean for "security" is available
  304       public GerAbstractSecurityType getSecurity() {
  305           return getWebApp().getSecurity();
  306       }
  307   
  308       //TODO Method to be updated once DConfigBean for "security" is available
  309       public void setSecurity(GerAbstractSecurityType security) {
  310           pcs.firePropertyChange("security", getSecurity(), security);
  311           getWebApp().setSecurity(security);
  312       }
  313   
  314       //TODO Method to be updated once DConfigBean for "service-ref" is available
  315       public GerServiceRefType[] getServiceRefs() {
  316           return getWebApp().getServiceRefArray();
  317       }
  318   
  319       //TODO Method to be updated once DConfigBean for "service-ref" is available
  320       public void setServiceRefs(GerServiceRefType[] serviceRefArray){
  321           pcs.firePropertyChange("service-ref", getServiceRefs(), serviceRefArray);
  322           getWebApp().setServiceRefArray(serviceRefArray);
  323       }
  324       // ----------------------- End of JavaBean Properties ----------------------
  325   }

Home » geronimo-2.2-source-release » org.apache.geronimo.web.deployment » [javadoc | source]