djencks     2004/02/18 12:57:08

  Modified:    
modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean
                        AdminObjectDConfigBean.java
                        ConfigPropertiesHelper.java
                        ConnectionDefinitionDConfigBean.java
                        ConnectionDefinitionInstance.java
                        ResourceAdapterDConfigBean.java
               
modules/connector/src/test/org/apache/geronimo/connector/deployment
                        Connector_1_5Test.java
  Added:       
modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean
                        AdminObjectInstance.java
  Removed:     
modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean
                        AdminObjectInstanceDConfigBean.java
                        ConnectionDefinitionInstanceDConfigBean.java
  Log:
  Continue implementation of improvements suggested by amulder
  
  Revision  Changes    Path
  1.2       +43 -33    
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/AdminObjectDConfigBean.java
  
  Index: AdminObjectDConfigBean.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/AdminObjectDConfigBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AdminObjectDConfigBean.java       9 Feb 2004 23:13:27 -0000       1.1
  +++ AdminObjectDConfigBean.java       18 Feb 2004 20:57:07 -0000      1.2
  @@ -59,8 +59,8 @@
   import javax.enterprise.deploy.model.DDBean;
   
   import org.apache.geronimo.deployment.plugin.DConfigBeanSupport;
  -import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
   import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
  +import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
   import org.apache.xmlbeans.SchemaTypeLoader;
   import org.apache.xmlbeans.XmlBeans;
   
  @@ -72,7 +72,7 @@
    * */
   public class AdminObjectDConfigBean extends DConfigBeanSupport {
       private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = 
XmlBeans.getContextTypeLoader();
  -    private final static String[] ADMIN_OBJECT_XPATHS = {};
  +    private AdminObjectInstance[] instances = new AdminObjectInstance[0];
   
       public AdminObjectDConfigBean(DDBean ddBean, GerAdminobjectType 
adminObject) {
           super(ddBean, adminObject, SCHEMA_TYPE_LOADER);
  @@ -88,46 +88,56 @@
           } else {
               assert 
adminObjectClass.equals(adminObject.getAdminobjectClass().getStringValue());
           }
  +        // Get initial list of instances
  +        GerAdminobjectInstanceType[] xmlInstances = 
getAdminObject().getAdminobjectInstanceArray();
  +        instances = new AdminObjectInstance[xmlInstances.length];
  +        for (int i = 0; i < instances.length; i++) {
  +            instances[i] = new AdminObjectInstance();
  +            instances[i].initialize(xmlInstances[i], this);
  +        }
       }
   
       GerAdminobjectType getAdminObject() {
  -        return (GerAdminobjectType)getXmlObject();
  +        return (GerAdminobjectType) getXmlObject();
       }
   
  -    public AdminObjectInstanceDConfigBean[] getAdminObjectInstance() {
  -        GerAdminobjectInstanceType[] adminobjectInstances = 
getAdminObject().getAdminobjectInstanceArray();
  -        AdminObjectInstanceDConfigBean[] adminObjectInstanceDConfigBeans = 
new AdminObjectInstanceDConfigBean[adminobjectInstances.length];
  -        for (int i = 0; i < adminobjectInstances.length; i++) {
  -            GerAdminobjectInstanceType adminobjectInstance = 
adminobjectInstances[i];
  -            adminObjectInstanceDConfigBeans[i] = new 
AdminObjectInstanceDConfigBean(getDDBean(), adminobjectInstance);
  -        }
  -        return adminObjectInstanceDConfigBeans;
  +    public AdminObjectInstance[] getAdminObjectInstance() {
  +        return instances;
       }
   
  -    public void setAdminObjectInstance(AdminObjectInstanceDConfigBean[] 
adminObjectInstanceDConfigBeans) {
  -        GerAdminobjectInstanceType[] adminobjectInstances = new 
GerAdminobjectInstanceType[adminObjectInstanceDConfigBeans.length];
  -        for (int i = 0; i < adminObjectInstanceDConfigBeans.length; i++) {
  -            AdminObjectInstanceDConfigBean adminObjectInstanceDConfigBean = 
adminObjectInstanceDConfigBeans[i];
  -            if (adminObjectInstanceDConfigBean == null) {
  -                throw new IllegalStateException("the " + i + "th adminobject 
instance was null");
  -            }
  -            adminobjectInstances[i] = 
adminObjectInstanceDConfigBean.getAdminobjectInstance();
  -            if (adminobjectInstances[i] == null) {
  -                adminobjectInstances[i] = 
GerAdminobjectInstanceType.Factory.newInstance();
  +    public void setAdminObjectInstance(AdminObjectInstance[] instances) {
  +        AdminObjectInstance[] old = getAdminObjectInstance();
  +        this.instances = instances;
  +        for (int i = 0; i < instances.length; i++) { // catch additions
  +            AdminObjectInstance instance = instances[i];
  +            if (!instance.hasParent()) {
  +                GerAdminobjectInstanceType xmlObject = 
getAdminObject().addNewAdminobjectInstance();
  +                instance.initialize(xmlObject, this);
               }
           }
  -        //this will copy all the xmlobjects.
  -        getAdminObject().setAdminobjectInstanceArray(adminobjectInstances);
  -        //get the new copies
  -        GerAdminobjectInstanceType[] newAdminobjectInstances = 
getAdminObject().getAdminobjectInstanceArray();
  -        for (int i = 0; i < newAdminobjectInstances.length; i++) {
  -            GerAdminobjectInstanceType newAdminobjectInstance = 
newAdminobjectInstances[i];
  -            adminObjectInstanceDConfigBeans[i].setParent(getDDBean(), 
newAdminobjectInstance);
  +        for (int i = 0; i < old.length; i++) { // catch removals
  +            AdminObjectInstance instance = old[i];
  +            boolean found = false;
  +            for (int j = 0; j < instances.length; j++) {
  +                if (instances[j] == instance) {
  +                    found = true;
  +                    break;
  +                }
  +            }
  +            if (!found) {
  +                // remove the XmlBean
  +                for (int j = 0; j < 
getAdminObject().getAdminobjectInstanceArray().length; j++) {
  +                    GerAdminobjectInstanceType test = 
getAdminObject().getAdminobjectInstanceArray(j);
  +                    if (test == instance.getAdminobjectInstance()) {
  +                        getAdminObject().removeAdminobjectInstance(j);
  +                        break;
  +                    }
  +                }
  +                // clean up the removed JavaBean
  +                instance.dispose();
  +            }
           }
  -    }
  -
  -    public String[] getXpaths() {
  -        return ADMIN_OBJECT_XPATHS;
  +        pcs.firePropertyChange("connectionDefinitionInstance", old, 
instances);
       }
   
   }
  
  
  
  1.2       +91 -2     
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ConfigPropertiesHelper.java
  
  Index: ConfigPropertiesHelper.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ConfigPropertiesHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigPropertiesHelper.java       9 Feb 2004 23:13:27 -0000       1.1
  +++ ConfigPropertiesHelper.java       18 Feb 2004 20:57:07 -0000      1.2
  @@ -1,10 +1,15 @@
   package org.apache.geronimo.connector.deployment.dconfigbean;
   
  +import java.util.Arrays;
  +import java.util.HashSet;
  +import java.util.Iterator;
   import java.util.Map;
  +import java.util.Set;
   
   import javax.enterprise.deploy.model.DDBean;
  +import javax.enterprise.deploy.model.XpathEvent;
  +import javax.enterprise.deploy.model.XpathListener;
   
  -import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
   import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
   
   /**
  @@ -42,8 +47,92 @@
           }
       }
   
  +    public static XpathListener initialize(DDBean parentDDBean, final 
ConfigPropertiesHelper.ConfigPropertiesSource configPropertiesSource) {
  +        DDBean[] beans = parentDDBean.getChildBean("config-property");
  +        ConfigPropertySettings[] configs = new 
ConfigPropertySettings[beans.length];
  +        Set xmlBeans = new 
HashSet(Arrays.asList(configPropertiesSource.getConfigPropertySettingArray()));
  +        for (int i = 0; i < beans.length; i++) {
  +            DDBean bean = beans[i];
  +            String[] names = bean.getText("config-property-name");
  +            String name = names.length == 1 ? names[0] : "";
  +            GerConfigPropertySettingType target = null;
  +            for (Iterator it = xmlBeans.iterator(); it.hasNext();) {
  +                GerConfigPropertySettingType setting = 
(GerConfigPropertySettingType) it.next();
  +                if (setting.getName().equals(name)) {
  +                    target = setting;
  +                    xmlBeans.remove(target);
  +                    break;
  +                }
  +            }
  +            if (target == null) {
  +                target = 
configPropertiesSource.addNewConfigPropertySetting();
  +            }
  +            configs[i] = new ConfigPropertySettings();
  +            configs[i].initialize(target, bean);
  +        }
  +        for (Iterator it = xmlBeans.iterator(); it.hasNext();) { // used to 
be in XmlBeans, no longer anything matching in J2EE DD
  +            GerConfigPropertySettingType target = 
(GerConfigPropertySettingType) it.next();
  +            GerConfigPropertySettingType[] xmlConfigs = 
configPropertiesSource.getConfigPropertySettingArray();
  +            for (int i = 0; i < xmlConfigs.length; i++) {
  +                if (xmlConfigs[i] == target) {
  +                    configPropertiesSource.removeConfigPropertySetting(i);
  +                    break;
  +                }
  +            }
  +        }
  +        configPropertiesSource.setConfigPropertySettings(configs);
  +        XpathListener configListener = new XpathListener() {
  +            public void fireXpathEvent(XpathEvent xpe) {
  +                ConfigPropertySettings[] configs = 
configPropertiesSource.getConfigPropertySettings();
  +                if (xpe.isAddEvent()) {
  +                    ConfigPropertySettings[] bigger = new 
ConfigPropertySettings[configs.length + 1];
  +                    System.arraycopy(configs, 0, bigger, 0, configs.length);
  +                    bigger[configs.length] = new ConfigPropertySettings();
  +                    
bigger[configs.length].initialize(configPropertiesSource.addNewConfigPropertySetting(),
 xpe.getBean());
  +                    configPropertiesSource.setConfigPropertySettings(bigger);
  +                } else if (xpe.isRemoveEvent()) {
  +                    int index = -1;
  +                    for (int i = 0; i < configs.length; i++) {
  +                        if (configs[i].matches(xpe.getBean())) {
  +                            // remove the XMLBean
  +                            GerConfigPropertySettingType[] xmlConfigs = 
configPropertiesSource.getConfigPropertySettingArray();
  +                            for (int j = 0; j < xmlConfigs.length; j++) {
  +                                GerConfigPropertySettingType test = 
xmlConfigs[j];
  +                                if (test == 
configs[i].getConfigPropertySetting()) {
  +                                    
configPropertiesSource.removeConfigPropertySetting(j);
  +                                    break;
  +                                }
  +                            }
  +                            // clean up the JavaBean
  +                            configs[i].dispose();
  +                            index = i;
  +                            break;
  +                        }
  +                    }
  +                    // remove the JavaBean from my list
  +                    if (index > -1) {
  +                        ConfigPropertySettings[] smaller = new 
ConfigPropertySettings[configs.length - 1];
  +                        System.arraycopy(configs, 0, smaller, 0, index);
  +                        System.arraycopy(configs, index + 1, smaller, index, 
smaller.length - index);
  +                        
configPropertiesSource.setConfigPropertySettings(smaller);
  +                    }
  +                }
  +                // ignore change event (no contents, no attributes)
  +            }
  +        };
  +        parentDDBean.addXpathListener("config-property", configListener);
  +        return configListener;
  +    }
  +
       public interface ConfigPropertiesSource {
           GerConfigPropertySettingType[] getConfigPropertySettingArray();
  +
           GerConfigPropertySettingType addNewConfigPropertySetting();
  +
  +        void removeConfigPropertySetting(int j);
  +
  +        ConfigPropertySettings[] getConfigPropertySettings();
  +
  +        void setConfigPropertySettings(ConfigPropertySettings[] configs);
       }
   }
  
  
  
  1.3       +1 -7      
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ConnectionDefinitionDConfigBean.java
  
  Index: ConnectionDefinitionDConfigBean.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ConnectionDefinitionDConfigBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionDefinitionDConfigBean.java      15 Feb 2004 17:46:21 -0000      
1.2
  +++ ConnectionDefinitionDConfigBean.java      18 Feb 2004 20:57:07 -0000      
1.3
  @@ -73,7 +73,6 @@
    **/
   public class ConnectionDefinitionDConfigBean extends DConfigBeanSupport {
       private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = 
XmlBeans.getContextTypeLoader();
  -    private final static String[] CONNECTION_DEFINITION_XPATHS = {};
       private ConnectionDefinitionInstance[] instances = new 
ConnectionDefinitionInstance[0];
   
       public ConnectionDefinitionDConfigBean(DDBean ddBean, 
GerConnectionDefinitionType connectionDefinition) {
  @@ -135,10 +134,5 @@
           }
           pcs.firePropertyChange("connectionDefinitionInstance", old, 
instances);
       }
  -
  -    public String[] getXpaths() {
  -        return CONNECTION_DEFINITION_XPATHS;
  -    }
  -
   
   }
  
  
  
  1.3       +28 -76    
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ConnectionDefinitionInstance.java
  
  Index: ConnectionDefinitionInstance.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ConnectionDefinitionInstance.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionDefinitionInstance.java 15 Feb 2004 17:53:22 -0000      1.2
  +++ ConnectionDefinitionInstance.java 18 Feb 2004 20:57:07 -0000      1.3
  @@ -55,21 +55,17 @@
    */
   package org.apache.geronimo.connector.deployment.dconfigbean;
   
  -import org.apache.xmlbeans.SchemaTypeLoader;
  -import org.apache.xmlbeans.XmlBeans;
  -import 
org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
  -import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
  -import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
  -import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
  +import java.math.BigInteger;
   
   import javax.enterprise.deploy.model.DDBean;
   import javax.enterprise.deploy.model.XpathListener;
  -import javax.enterprise.deploy.model.XpathEvent;
  -import java.math.BigInteger;
  -import java.util.Set;
  -import java.util.HashSet;
  -import java.util.Arrays;
  -import java.util.Iterator;
  +
  +import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
  +import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
  +import 
org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
  +import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
  +import org.apache.xmlbeans.SchemaTypeLoader;
  +import org.apache.xmlbeans.XmlBeans;
   
   /**
    * @version $Revision 1.0$  $Date$
  @@ -87,75 +83,31 @@
       void initialize(GerConnectiondefinitionInstanceType xmlObject, 
ConnectionDefinitionDConfigBean parent) {
           setXmlObject(xmlObject);
           this.parent = parent;
  -        DDBean[] beans = parent.getDDBean().getChildBean("config-property");
  -        configs = new ConfigPropertySettings[beans.length];
  -        Set xmlBeans = new 
HashSet(Arrays.asList(getConnectiondefinitionInstance().getConfigPropertySettingArray()));
  -        for (int i = 0; i < beans.length; i++) {
  -            DDBean bean = beans[i];
  -            String[] names = bean.getText("config-property-name");
  -            String name = names.length == 1 ? names[0] : "";
  -            GerConfigPropertySettingType target = null;
  -            for (Iterator it = xmlBeans.iterator(); it.hasNext();) {
  -                GerConfigPropertySettingType setting = 
(GerConfigPropertySettingType) it.next();
  -                if(setting.getName().equals(name)) {
  -                    target = setting;
  -                    xmlBeans.remove(target);
  -                    break;
  -                }
  +        DDBean parentDDBean = parent.getDDBean();
  +        configListener = ConfigPropertiesHelper.initialize(parentDDBean, new 
ConfigPropertiesHelper.ConfigPropertiesSource() {
  +            public GerConfigPropertySettingType[] 
getConfigPropertySettingArray() {
  +                return 
getConnectiondefinitionInstance().getConfigPropertySettingArray();
               }
  -            if(target == null) {
  -                target = 
getConnectiondefinitionInstance().addNewConfigPropertySetting();
  +
  +            public GerConfigPropertySettingType 
addNewConfigPropertySetting() {
  +                return 
getConnectiondefinitionInstance().addNewConfigPropertySetting();
               }
  -            configs[i] = new ConfigPropertySettings();
  -            configs[i].initialize(target, bean);
  -        }
  -        for (Iterator it = xmlBeans.iterator(); it.hasNext();) { // used to 
be in XmlBeans, no longer anything matching in J2EE DD
  -            GerConfigPropertySettingType target = 
(GerConfigPropertySettingType) it.next();
  -            for (int i = 0; i < 
getConnectiondefinitionInstance().getConfigPropertySettingArray().length; i++) {
  -                
if(getConnectiondefinitionInstance().getConfigPropertySettingArray(i) == 
target) {
  -                    
getConnectiondefinitionInstance().removeConfigPropertySetting(i);
  -                    break;
  -                }
  +
  +            public void removeConfigPropertySetting(int j) {
  +                
getConnectiondefinitionInstance().removeConfigPropertySetting(j);
               }
  -        }
  -        parent.getDDBean().addXpathListener("config-property", 
configListener = new XpathListener() {
  -            public void fireXpathEvent(XpathEvent xpe) {
  -                if(xpe.isAddEvent()) {
  -                    ConfigPropertySettings[] bigger = new 
ConfigPropertySettings[configs.length+1];
  -                    System.arraycopy(configs, 0, bigger, 0, configs.length);
  -                    bigger[configs.length] = new ConfigPropertySettings();
  -                    
bigger[configs.length].initialize(getConnectiondefinitionInstance().addNewConfigPropertySetting(),
 xpe.getBean());
  -                    setConfigProperty(bigger);
  -                } else if(xpe.isRemoveEvent()) {
  -                    int index = -1;
  -                    for (int i = 0; i < configs.length; i++) {
  -                        if(configs[i].matches(xpe.getBean())) {
  -                            // remove the XMLBean
  -                            for (int j = 0; j < 
getConnectiondefinitionInstance().getConfigPropertySettingArray().length; j++) {
  -                                GerConfigPropertySettingType test = 
getConnectiondefinitionInstance().getConfigPropertySettingArray(j);
  -                                if(test == 
configs[i].getConfigPropertySetting()) {
  -                                    
getConnectiondefinitionInstance().removeConfigPropertySetting(j);
  -                                    break;
  -                                }
  -                            }
  -                            // clean up the JavaBean
  -                            configs[i].dispose();
  -                            index = i;
  -                            break;
  -                        }
  -                    }
  -                    // remove the JavaBean from my list
  -                    if(index > -1) {
  -                        ConfigPropertySettings[] smaller = new 
ConfigPropertySettings[configs.length-1];
  -                        System.arraycopy(configs, 0, smaller, 0, index);
  -                        System.arraycopy(configs, index+1, smaller, index, 
smaller.length-index);
  -                        setConfigProperty(smaller);
  -                    }
  -                }
  -                // ignore change event (no contents, no attributes)
  +
  +            public ConfigPropertySettings[] getConfigPropertySettings() {
  +                return configs;
  +            }
  +
  +            public void setConfigPropertySettings(ConfigPropertySettings[] 
configs) {
  +                setConfigProperty(configs);
               }
  +
           });
       }
  +
   
       boolean hasParent() {
           return parent != null;
  
  
  
  1.4       +11 -1     
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ResourceAdapterDConfigBean.java
  
  Index: ResourceAdapterDConfigBean.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/ResourceAdapterDConfigBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ResourceAdapterDConfigBean.java   11 Feb 2004 08:02:20 -0000      1.3
  +++ ResourceAdapterDConfigBean.java   18 Feb 2004 20:57:07 -0000      1.4
  @@ -100,6 +100,16 @@
                   return resourceadapter.addNewConfigPropertySetting();
               }
   
  +            public void removeConfigPropertySetting(int j) {
  +            }
  +
  +            public ConfigPropertySettings[] getConfigPropertySettings() {
  +                return new ConfigPropertySettings[0];
  +            }
  +
  +            public void setConfigPropertySettings(ConfigPropertySettings[] 
configs) {
  +            }
  +
           }, configPropertiesMap);
           //initialize connection definitions
           GerOutboundResourceadapterType outboundResourceadapter = 
resourceadapter.getOutboundResourceadapter();
  
  
  
  1.1                  
incubator-geronimo/modules/connector/src/java/org/apache/geronimo/connector/deployment/dconfigbean/AdminObjectInstance.java
  
  Index: AdminObjectInstance.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.connector.deployment.dconfigbean;
  
  import javax.enterprise.deploy.model.DDBean;
  import javax.enterprise.deploy.model.XpathListener;
  
  import org.apache.geronimo.deployment.plugin.XmlBeanSupport;
  import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
  import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
  import org.apache.xmlbeans.SchemaTypeLoader;
  import org.apache.xmlbeans.XmlBeans;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/18 20:57:07 $
   *
   * */
  public class AdminObjectInstance extends XmlBeanSupport{
      private final static SchemaTypeLoader SCHEMA_TYPE_LOADER = 
XmlBeans.getContextTypeLoader();
      private AdminObjectDConfigBean parent;
      private ConfigPropertySettings[] configs;
      private XpathListener configListener;
  
      public AdminObjectInstance() {
          super(null, SCHEMA_TYPE_LOADER);
      }
  
      void initialize(GerAdminobjectInstanceType xmlObject, 
AdminObjectDConfigBean parent) {
          setXmlObject(xmlObject);
          this.parent = parent;
          DDBean parentDDBean = parent.getDDBean();
          configListener = ConfigPropertiesHelper.initialize(parentDDBean, new 
ConfigPropertiesHelper.ConfigPropertiesSource() {
              public GerConfigPropertySettingType[] 
getConfigPropertySettingArray() {
                  return 
getAdminobjectInstance().getConfigPropertySettingArray();
              }
  
              public GerConfigPropertySettingType addNewConfigPropertySetting() 
{
                  return getAdminobjectInstance().addNewConfigPropertySetting();
              }
  
              public void removeConfigPropertySetting(int j) {
                  getAdminobjectInstance().removeConfigPropertySetting(j);
              }
  
              public ConfigPropertySettings[] getConfigPropertySettings() {
                  return configs;
              }
  
              public void setConfigPropertySettings(ConfigPropertySettings[] 
configs) {
                  setConfigProperty(configs);
              }
  
          });
      }
  
      boolean hasParent() {
          return parent != null;
      }
  
      void dispose() {
          if(configs != null) {
              for (int i = 0; i < configs.length; i++) {
                  configs[i].dispose();
              }
          }
          if(parent != null) {
              parent.getDDBean().removeXpathListener("config-property", 
configListener);
          }
          configs = null;
          configListener = null;
          parent = null;
      }
  
  // JavaBean properties for this object (with a couple helper methods)
      GerAdminobjectInstanceType getAdminobjectInstance() {
          return (GerAdminobjectInstanceType)getXmlObject();
      }
  
      public ConfigPropertySettings[] getConfigProperty() {
          return configs;
      }
  
      private void setConfigProperty(ConfigPropertySettings[] configs) { // can 
only be changed by adding a new DDBean
          ConfigPropertySettings[] old = getConfigProperty();
          this.configs = configs;
          pcs.firePropertyChange("configProperty", old, configs);
      }
  
      public String getAdminObjectName() {
          return getAdminobjectInstance().getAdminobjectName();
      }
  
      public void setAdminObjectName(String adminObjectName) {
          getAdminobjectInstance().setAdminobjectName(adminObjectName);
      }
  
  }
  
  
  
  1.8       +50 -46    
incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/deployment/Connector_1_5Test.java
  
  Index: Connector_1_5Test.java
  ===================================================================
  RCS file: 
/home/cvs/incubator-geronimo/modules/connector/src/test/org/apache/geronimo/connector/deployment/Connector_1_5Test.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Connector_1_5Test.java    15 Feb 2004 17:46:21 -0000      1.7
  +++ Connector_1_5Test.java    18 Feb 2004 20:57:08 -0000      1.8
  @@ -56,46 +56,52 @@
   
   package org.apache.geronimo.connector.deployment;
   
  -import java.io.File;
  -import java.io.InputStream;
  -import java.io.IOException;
  -import java.io.ByteArrayOutputStream;
   import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
  +import java.io.File;
   import java.io.FileNotFoundException;
  -import java.net.URL;
  +import java.io.IOException;
  +import java.io.InputStream;
   import java.net.URI;
  -import java.util.Map;
  -import java.util.HashMap;
  -import java.util.List;
  +import java.net.URL;
   import java.util.ArrayList;
   import java.util.Enumeration;
  -import java.util.zip.ZipEntry;
  +import java.util.HashMap;
  +import java.util.List;
  +import java.util.Map;
   import java.util.jar.JarOutputStream;
  +import java.util.zip.ZipEntry;
   
  -import javax.management.ObjectName;
  -import javax.enterprise.deploy.model.DeployableObject;
  -import javax.enterprise.deploy.model.DDBeanRoot;
   import javax.enterprise.deploy.model.DDBean;
  +import javax.enterprise.deploy.model.DDBeanRoot;
  +import javax.enterprise.deploy.model.DeployableObject;
   import javax.enterprise.deploy.model.exceptions.DDBeanCreateException;
   import javax.enterprise.deploy.shared.ModuleType;
  -import javax.enterprise.deploy.spi.DeploymentConfiguration;
   import javax.enterprise.deploy.spi.DConfigBeanRoot;
  +import javax.enterprise.deploy.spi.DeploymentConfiguration;
  +import javax.management.ObjectName;
   
   import junit.framework.TestCase;
  -import org.apache.geronimo.xbeans.j2ee.ConnectorDocument;
  -import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
  -import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
  -import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
  -import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.AdminObjectDConfigBean;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.AdminObjectInstance;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettingDConfigBean;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.ConfigPropertySettings;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionDConfigBean;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.ConnectionDefinitionInstance;
  +import 
org.apache.geronimo.connector.deployment.dconfigbean.ResourceAdapterDConfigBean;
  +import org.apache.geronimo.deployment.ConfigurationCallback;
  +import org.apache.geronimo.deployment.DeploymentModule;
  +import org.apache.geronimo.deployment.tools.DDBeanRootImpl;
  +import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.xbeans.geronimo.GerAdminobjectInstanceType;
  +import org.apache.geronimo.xbeans.geronimo.GerAdminobjectType;
  +import org.apache.geronimo.xbeans.geronimo.GerConfigPropertySettingType;
   import org.apache.geronimo.xbeans.geronimo.GerConnectionDefinitionType;
   import 
org.apache.geronimo.xbeans.geronimo.GerConnectiondefinitionInstanceType;
   import org.apache.geronimo.xbeans.geronimo.GerConnectionmanagerType;
  -import org.apache.geronimo.deployment.DeploymentModule;
  -import org.apache.geronimo.deployment.ConfigurationCallback;
  -import org.apache.geronimo.deployment.tools.DDBeanRootImpl;
  -import org.apache.geronimo.gbean.jmx.GBeanMBean;
  -import org.apache.geronimo.connector.deployment.dconfigbean.*;
  +import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument;
  +import org.apache.geronimo.xbeans.geronimo.GerResourceadapterType;
  +import org.apache.geronimo.xbeans.j2ee.ConnectorDocument;
   import org.apache.xmlbeans.XmlOptions;
   
   /**
  @@ -154,17 +160,15 @@
           assertEquals(1, adminObjectdds.length);
           AdminObjectDConfigBean adminObjectDConfigBean = 
(AdminObjectDConfigBean)resourceAdapterDConfigBean.getDConfigBean(adminObjectdds[0]);
           assertNotNull(adminObjectDConfigBean);
  -        AdminObjectInstanceDConfigBean adminObjectInstanceDConfigBean1 = new 
AdminObjectInstanceDConfigBean();
  -        adminObjectDConfigBean.setAdminObjectInstance(new 
AdminObjectInstanceDConfigBean[] {adminObjectInstanceDConfigBean1});
  -        DDBean[] adminObjectConfigPropDDs = 
adminObjectdds[0].getChildBean(adminObjectInstanceDConfigBean1.getXpaths()[0]);
  -        assertEquals(1, adminObjectConfigPropDDs.length);
  -        ConfigPropertySettingDConfigBean adminObjectSetting1 = 
(ConfigPropertySettingDConfigBean) 
adminObjectInstanceDConfigBean1.getDConfigBean(adminObjectConfigPropDDs[0]);
  +        AdminObjectInstance adminObjectInstance1 = new AdminObjectInstance();
  +        adminObjectDConfigBean.setAdminObjectInstance(new 
AdminObjectInstance[] {adminObjectInstance1});
  +        ConfigPropertySettings adminObjectSetting1 = 
adminObjectInstance1.getConfigProperty()[0];
           adminObjectSetting1.setConfigPropertyValue("TestAOValue1");
   
           //add a second admin object in first position
  -        AdminObjectInstanceDConfigBean adminObjectInstanceDConfigBean2 = new 
AdminObjectInstanceDConfigBean();
  -        adminObjectDConfigBean.setAdminObjectInstance(new 
AdminObjectInstanceDConfigBean[] {adminObjectInstanceDConfigBean2, 
adminObjectInstanceDConfigBean1});
  -        ConfigPropertySettingDConfigBean adminObjectSetting2 = 
(ConfigPropertySettingDConfigBean) 
adminObjectInstanceDConfigBean2.getDConfigBean(adminObjectConfigPropDDs[0]);
  +        AdminObjectInstance adminObjectInstance2 = new AdminObjectInstance();
  +        adminObjectDConfigBean.setAdminObjectInstance(new 
AdminObjectInstance[] {adminObjectInstance2, adminObjectInstance1});
  +        ConfigPropertySettings adminObjectSetting2 = 
adminObjectInstance2.getConfigProperty()[0];
           adminObjectSetting2.setConfigPropertyValue("TestAOValue2");
   
           //outbound
  @@ -176,7 +180,7 @@
           connectionDefinitionDConfigBean.setConnectionDefinitionInstance(new 
ConnectionDefinitionInstance[] {connectionDefinitionInstance1});
           DDBean[] connectionDefinitionConfigPropDDs = 
connectionDefinitiondds[0].getChildBean("config-property");
           assertEquals(4, connectionDefinitionConfigPropDDs.length);
  -        ConfigPropertySettings connectionDefinitionSetting1 = 
(ConfigPropertySettings) connectionDefinitionInstance1.getConfigProperty()[0];
  +        ConfigPropertySettings connectionDefinitionSetting1 = 
connectionDefinitionInstance1.getConfigProperty()[0];
           connectionDefinitionSetting1.setConfigPropertyValue("TestCDValue1");
           //connection manager properties
           connectionDefinitionInstance1.setBlockingTimeout(3000);
  @@ -197,9 +201,9 @@
           //admin object
           GerAdminobjectType adminobjectType1 = ra.getAdminobjectArray(0);
           GerAdminobjectInstanceType adminobjectInstanceType2 = 
adminobjectType1.getAdminobjectInstanceArray(0);
  -        assertEquals("TestAOValue2", 
adminobjectInstanceType2.getConfigPropertySettingArray(0).getStringValue());
  +        assertEquals("TestAOValue1", 
adminobjectInstanceType2.getConfigPropertySettingArray(0).getStringValue());
           GerAdminobjectInstanceType adminobjectInstanceType1 = 
adminobjectType1.getAdminobjectInstanceArray(1);
  -        assertEquals("TestAOValue1", 
adminobjectInstanceType1.getConfigPropertySettingArray(0).getStringValue());
  +        assertEquals("TestAOValue2", 
adminobjectInstanceType1.getConfigPropertySettingArray(0).getStringValue());
   
           //connection definition
           GerConnectionDefinitionType connectionDefinitionType = 
ra.getOutboundResourceadapter().getConnectionDefinitionArray(0);
  @@ -222,23 +226,23 @@
           //admin objects
           adminObjectDConfigBean = 
(AdminObjectDConfigBean)resourceAdapterDConfigBean.getDConfigBean(adminObjectdds[0]);
           assertNotNull(adminObjectDConfigBean);
  -        AdminObjectInstanceDConfigBean[] adminObjectInstanceDConfigBeans = 
adminObjectDConfigBean.getAdminObjectInstance();
  -        assertEquals(2, adminObjectInstanceDConfigBeans.length);
  -        adminObjectSetting1 = (ConfigPropertySettingDConfigBean) 
adminObjectInstanceDConfigBeans[1].getDConfigBean(adminObjectConfigPropDDs[0]);
  -        assertEquals("TestAOValue1", 
adminObjectSetting1.getConfigPropertyValue());
  -
  -        //second admin object is in first position
  -        adminObjectSetting2 = (ConfigPropertySettingDConfigBean) 
adminObjectInstanceDConfigBeans[0].getDConfigBean(adminObjectConfigPropDDs[0]);
  -        assertEquals("TestAOValue2", 
adminObjectSetting2.getConfigPropertyValue());
  +        AdminObjectInstance[] adminObjectInstances = 
adminObjectDConfigBean.getAdminObjectInstance();
  +        assertEquals(2, adminObjectInstances.length);
  +        adminObjectSetting1 = adminObjectInstances[1].getConfigProperty()[0];
  +        assertEquals("TestAOValue2", 
adminObjectSetting1.getConfigPropertyValue());
  +
  +        //second admin object is in first position ..not any longer:-(((
  +        adminObjectSetting2 = adminObjectInstances[0].getConfigProperty()[0];
  +        assertEquals("TestAOValue1", 
adminObjectSetting2.getConfigPropertyValue());
   
           //outbound
           connectionDefinitionDConfigBean = 
(ConnectionDefinitionDConfigBean)resourceAdapterDConfigBean.getDConfigBean(connectionDefinitiondds[0]);
           assertNotNull(connectionDefinitionDConfigBean);
  -        ConnectionDefinitionInstance[] 
connectionDefinitionInstanceDConfigBeans = 
connectionDefinitionDConfigBean.getConnectionDefinitionInstance();
  -        connectionDefinitionSetting1 = (ConfigPropertySettings) 
connectionDefinitionInstanceDConfigBeans[0].getConfigProperty()[0];
  +        ConnectionDefinitionInstance[] connectionDefinitionInstances = 
connectionDefinitionDConfigBean.getConnectionDefinitionInstance();
  +        connectionDefinitionSetting1 = 
connectionDefinitionInstances[0].getConfigProperty()[0];
           assertEquals("TestCDValue1", 
connectionDefinitionSetting1.getConfigPropertyValue());
           //connection manager
  -        assertEquals(3000, 
connectionDefinitionInstanceDConfigBeans[0].getBlockingTimeout());
  +        assertEquals(3000, 
connectionDefinitionInstances[0].getBlockingTimeout());
   
       }
   
  
  
  

Reply via email to