geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r155858 - in geronimo/trunk/modules: assembly/src/plan/ deployment/src/java/org/apache/geronimo/deployment/ service-builder/ service-builder/src/java/org/apache/geronimo/deployment/service/ service-builder/src/schema/ service-builder/src/test-resources/services/ service-builder/src/test/org/apache/geronimo/deployment/ service-builder/src/test/org/apache/geronimo/deployment/service/
Date Wed, 02 Mar 2005 02:57:41 GMT
Author: djencks
Date: Tue Mar  1 18:57:37 2005
New Revision: 155858

URL: http://svn.apache.org/viewcvs?view=rev&rev=155858
Log:
GERONIMO-599. Implement xml-attribute in gbeans, with an example java bean xml attribute editor

Added:
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/JavaBeanXmlAttributeBuilder.java
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlAttributeBuilder.java
    geronimo/trunk/modules/service-builder/src/schema/geronimo-javabean-xmlattribute.xsd
    geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/FooBarBean.java
    geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
Modified:
    geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml
    geronimo/trunk/modules/assembly/src/plan/j2ee-runtime-deployer-plan.xml
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
    geronimo/trunk/modules/service-builder/maven.xml
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
    geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
    geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd
    geronimo/trunk/modules/service-builder/src/schema/xmlconfig.xml
    geronimo/trunk/modules/service-builder/src/test-resources/services/plan1.xml
    geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/MockGBean.java
    geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ConfigPlanTest.java

Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml (original)
+++ geronimo/trunk/modules/assembly/src/plan/j2ee-deployer-plan.xml Tue Mar  1 18:57:37 2005
@@ -132,6 +132,7 @@
     <gbean namePart="ServiceBuilder" class="org.apache.geronimo.deployment.service.ServiceConfigBuilder">
         <attribute name="defaultParentId">org/apache/geronimo/Server</attribute>
         <reference name="Repository">*:name=Repository,*</reference>
+        <reference name="XmlAttributeBuilders">*:j2eeType=XmlAttributeBuilder,*</reference>
     </gbean>
 
     <gbean namePart="EARBuilder" class="org.apache.geronimo.j2ee.deployment.EARConfigBuilder">

Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-runtime-deployer-plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-runtime-deployer-plan.xml?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/assembly/src/plan/j2ee-runtime-deployer-plan.xml (original)
+++ geronimo/trunk/modules/assembly/src/plan/j2ee-runtime-deployer-plan.xml Tue Mar  1 18:57:37
2005
@@ -73,6 +73,7 @@
     <gbean namePart="ServiceBuilder" class="org.apache.geronimo.deployment.service.ServiceConfigBuilder">
         <attribute name="defaultParentId">org/apache/geronimo/Server</attribute>
         <reference name="Repository">*:name=Repository,*</reference>
+        <reference name="XmlAttributeBuilders">*:j2eeType=XmlAttributeBuilder,*</reference>
     </gbean>
 
     <gbean namePart="EARBuilder" class="org.apache.geronimo.j2ee.deployment.EARConfigBuilder">

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java
Tue Mar  1 18:57:37 2005
@@ -523,4 +523,12 @@
     public GBeanData getConfigurationGBeanData() {
         return new GBeanData(config);
     }
+
+    /**
+     * @deprecated REALLY deprecated.  Only use in tests, please.
+     * @return
+     */
+    public GBeanData[] getGBeans() {
+        return gbeans.getGBeans();
+    }
 }

Modified: geronimo/trunk/modules/service-builder/maven.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/maven.xml?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/maven.xml (original)
+++ geronimo/trunk/modules/service-builder/maven.xml Tue Mar  1 18:57:37 2005
@@ -25,7 +25,7 @@
     <preGoal name="java:compile">
         <xmlbeans:schema2java
             sourcedir="${basedir}/src"
-            sourceschema="schema/geronimo-config.xsd,schema/geronimo-service.xsd"
+            sourceschema="schema/geronimo-config.xsd,schema/geronimo-service.xsd,schema/geronimo-javabean-xmlattribute.xsd"
             xmlconfigs="${basedir}/src/schema/xmlconfig.xml"
             targetdir="${basedir}/target/xmlbeans"
             cataloglocation="${basedir}/../../specs/schema/src/catalog/resolver-catalog.xml"/>

Modified: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
(original)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/GBeanBuilder.java
Tue Mar  1 18:57:37 2005
@@ -20,6 +20,7 @@
 import java.beans.PropertyEditor;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Map;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -28,6 +29,8 @@
 import org.apache.geronimo.gbean.GAttributeInfo;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlCursor;
 
 /**
  *
@@ -37,11 +40,13 @@
 public class GBeanBuilder {
     private final GBeanData gbean;
     private final ClassLoader classLoader;
+    private final Map xmlAttributeBuilderMap;
 
-    public GBeanBuilder(ObjectName objectName, GBeanInfo gBeanInfo, ClassLoader classLoader)
{
+    GBeanBuilder(ObjectName objectName, GBeanInfo gBeanInfo, ClassLoader classLoader, Map
xmlAttributeBuilderMap) {
 
         this.classLoader = classLoader;
         this.gbean = new GBeanData(objectName, gBeanInfo);
+        this.xmlAttributeBuilderMap = xmlAttributeBuilderMap;
     }
 
     public void setAttribute(String name, String type, String text) throws DeploymentException
{
@@ -72,6 +77,22 @@
         } catch (Exception e) {
             throw new DeploymentException("Unable to set attribute " + name + " to " + text,
e);
         }
+    }
+
+    public void setXmlAttribute(String name, XmlCursor xmlCursor) throws DeploymentException
{
+        String namespace = xmlCursor.getName().getNamespaceURI();
+        XmlAttributeBuilder builder = (XmlAttributeBuilder) xmlAttributeBuilderMap.get(namespace);
+        if (builder == null) {
+            throw new DeploymentException("No builder deployed for namespace: " + namespace);
+        }
+        XmlObject xmlObject = xmlCursor.getObject();
+        GAttributeInfo attribute = gbean.getGBeanInfo().getAttribute(name);
+        if (attribute == null) {
+            throw new DeploymentException("Unknown attribute " + name + " on " + gbean.getName());
+        }
+        String type = attribute.getType();
+        Object value = builder.getValue(xmlObject, type, classLoader);
+        gbean.setAttribute(name, value);
     }
 
     public void setReference(String name, String pattern) throws DeploymentException {

Added: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/JavaBeanXmlAttributeBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/JavaBeanXmlAttributeBuilder.java?view=auto&rev=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/JavaBeanXmlAttributeBuilder.java
(added)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/JavaBeanXmlAttributeBuilder.java
Tue Mar  1 18:57:37 2005
@@ -0,0 +1,137 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.deployment.service;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.beans.PropertyEditor;
+import java.lang.reflect.Method;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.common.propertyeditor.PropertyEditors;
+import org.apache.geronimo.deployment.javabean.xbeans.JavabeanType;
+import org.apache.geronimo.deployment.javabean.xbeans.PropertyType;
+import org.apache.geronimo.deployment.javabean.xbeans.BeanPropertyType;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.xmlbeans.XmlObject;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class JavaBeanXmlAttributeBuilder implements XmlAttributeBuilder {
+
+    private static final String NAMESPACE = "http://geronimo.apache.org/xml/ns/deployment/javabean";
+
+    public String getNamespace() {
+        return NAMESPACE;
+    }
+
+    public Object getValue(XmlObject xmlObject, String type, ClassLoader cl) throws DeploymentException
{
+        JavabeanType javabean = (JavabeanType) xmlObject.copy().changeType(JavabeanType.type);
+        return getValue(javabean, type, cl);
+    }
+
+    private Object getValue(JavabeanType javabean, String className, ClassLoader cl) throws
DeploymentException {
+        Class clazz = null;
+        try {
+            clazz = cl.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new DeploymentException("Could not load alleged javabean class " + className,
e);
+        }
+        Object instance = null;
+        try {
+            instance = clazz.newInstance();
+        } catch (Exception e) {
+            throw new DeploymentException("Could not create java bean instance", e);
+        }
+        PropertyDescriptor[] propertyDescriptors;
+        try {
+            BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
+            propertyDescriptors = beanInfo.getPropertyDescriptors();
+        } catch (IntrospectionException e) {
+            throw new DeploymentException("Could not analyze java bean class", e);
+        }
+
+        PropertyType[] properties = javabean.getPropertyArray();
+        for (int i = 0; i < properties.length; i++) {
+            PropertyType property = properties[i];
+            String propertyName = Introspector.decapitalize(property.getName());
+            String propertyString = property.getStringValue().trim();
+            for (int j = 0; j < propertyDescriptors.length; j++) {
+                PropertyDescriptor propertyDescriptor = propertyDescriptors[j];
+                if (propertyName.equals(propertyDescriptor.getName())) {
+                    String type = propertyDescriptor.getPropertyType().getName();
+                    PropertyEditor propertyEditor = null;
+                    try {
+                        propertyEditor = PropertyEditors.findEditor(type, cl);
+                    } catch (ClassNotFoundException e) {
+                        throw new DeploymentException("Could not load editor for type " +
type, e);
+                    }
+                    if (propertyEditor == null) {
+                        throw new DeploymentException("Unable to find PropertyEditor for
" + type);
+                    }
+                    propertyEditor.setAsText(propertyString);
+                    Object value = propertyEditor.getValue();
+                    Method m = propertyDescriptor.getWriteMethod();
+                    try {
+                        m.invoke(instance, new Object[] {value});
+                    } catch (Exception e) {
+                        throw new DeploymentException("Could not set property value for property
named " + propertyName, e);
+                    }
+                    break;
+                }
+            }
+        }
+
+        BeanPropertyType[] beanProperties = javabean.getBeanPropertyArray();
+        for (int i = 0; i < beanProperties.length; i++) {
+            BeanPropertyType beanProperty = beanProperties[i];
+            String propertyName = Introspector.decapitalize(beanProperty.getName().trim());
+            JavabeanType innerBean = beanProperty.getJavabean();
+            for (int j = 0; j < propertyDescriptors.length; j++) {
+                PropertyDescriptor propertyDescriptor = propertyDescriptors[j];
+                if (propertyName.equals(propertyDescriptor.getName())) {
+                    String propertyType = propertyDescriptor.getPropertyType().getName();
+                    Object value = getValue(innerBean, propertyType, cl);
+                    Method m = propertyDescriptor.getWriteMethod();
+                    try {
+                        m.invoke(instance, new Object[] {value});
+                    } catch (Exception e) {
+                        throw new DeploymentException("Could not set property value for property
named " + propertyName, e);
+                    }
+                    break;
+                }
+            }
+        }
+        return instance;
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(JavaBeanXmlAttributeBuilder.class,
"XmlAttributeBuilder");
+        infoBuilder.addInterface(XmlAttributeBuilder.class);
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Modified: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
(original)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
Tue Mar  1 18:57:37 2005
@@ -29,6 +29,10 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.jar.JarFile;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
@@ -44,9 +48,13 @@
 import org.apache.geronimo.deployment.xbeans.ReferenceType;
 import org.apache.geronimo.deployment.xbeans.ReferencesType;
 import org.apache.geronimo.deployment.xbeans.ServiceDocument;
+import org.apache.geronimo.deployment.xbeans.XmlAttributeType;
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.ReferenceCollection;
+import org.apache.geronimo.gbean.ReferenceCollectionListener;
+import org.apache.geronimo.gbean.ReferenceCollectionEvent;
 import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
 import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
@@ -55,6 +63,7 @@
 import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
 import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlCursor;
 
 /**
  * @version $Rev$ $Date$
@@ -64,14 +73,40 @@
     private final Repository repository;
     private final Kernel kernel;
 
+    //TODO this being static is a really good argument that all other builders should have
a reference to this gbean, not use static methods on it.
+    private static final Map xmlAttributeBuilderMap = new HashMap();
+
     public ServiceConfigBuilder(URI defaultParentId, Repository repository) {
-        this(defaultParentId, repository, null);
+        this(defaultParentId, repository, null, null);
     }
 
-    public ServiceConfigBuilder(URI defaultParentId, Repository repository, Kernel kernel)
{
+    public ServiceConfigBuilder(URI defaultParentId, Repository repository, Collection xmlAttributeBuilders,
Kernel kernel) {
         this.defaultParentId = defaultParentId;
         this.repository = repository;
         this.kernel = kernel;
+        if (xmlAttributeBuilders != null) {
+            ReferenceCollection builders = (ReferenceCollection)xmlAttributeBuilders;
+            ReferenceCollectionListener listener = new ReferenceCollectionListener() {
+
+                public void memberAdded(ReferenceCollectionEvent event) {
+                    XmlAttributeBuilder attributeBuilder = (XmlAttributeBuilder) event.getMember();
+                    String namespace = attributeBuilder.getNamespace();
+                    xmlAttributeBuilderMap.put(namespace, attributeBuilder);
+                }
+
+                public void memberRemoved(ReferenceCollectionEvent event) {
+                    XmlAttributeBuilder attributeBuilder = (XmlAttributeBuilder) event.getMember();
+                    String namespace = attributeBuilder.getNamespace();
+                    xmlAttributeBuilderMap.remove(namespace);
+                }
+            };
+            builders.addReferenceCollectionListener(listener);
+            for (Iterator iterator = builders.iterator(); iterator.hasNext();) {
+                Object o = iterator.next();
+                ReferenceCollectionEvent e = new ReferenceCollectionEvent(null, o);
+                listener.memberAdded(e);
+            }
+        }
     }
 
     public Object getDeploymentPlan(File planFile, JarFile module) throws DeploymentException
{
@@ -234,7 +269,7 @@
                 throw new DeploymentException("Invalid ObjectName: " + namePart, e);
             }
         }
-        GBeanBuilder builder = new GBeanBuilder(objectName, gBeanInfo, cl);
+        GBeanBuilder builder = new GBeanBuilder(objectName, gBeanInfo, cl, xmlAttributeBuilderMap);
 
         // set up attributes
         AttributeType[] attributeArray = gbean.getAttributeArray();
@@ -244,6 +279,21 @@
             }
         }
 
+        XmlAttributeType[] xmlAttributeArray = gbean.getXmlAttributeArray();
+        if (xmlAttributeArray != null) {
+            for (int i = 0; i < xmlAttributeArray.length; i++) {
+                XmlAttributeType xmlAttributeType = xmlAttributeArray[i];
+                String name = xmlAttributeType.getName().trim();
+                XmlCursor xmlCursor = xmlAttributeType.newCursor();
+                try {
+                    xmlCursor.toFirstChild();
+                    builder.setXmlAttribute(name, xmlCursor);
+                } finally {
+                    xmlCursor.dispose();
+                }
+            }
+        }
+
         // set up all single pattern references
         ReferenceType[] referenceArray = gbean.getReferenceArray();
         if (referenceArray != null) {
@@ -296,9 +346,10 @@
 
         infoFactory.addAttribute("defaultParentId", URI.class, true);
         infoFactory.addReference("Repository", Repository.class);
+        infoFactory.addReference("XmlAttributeBuilders", XmlAttributeBuilder.class);
         infoFactory.addAttribute("kernel", Kernel.class, false);
 
-        infoFactory.setConstructor(new String[]{"defaultParentId", "Repository", "kernel"});
+        infoFactory.setConstructor(new String[]{"defaultParentId", "Repository", "XmlAttributeBuilders",
"kernel"});
 
         GBEAN_INFO = infoFactory.getBeanInfo();
     }

Added: geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlAttributeBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlAttributeBuilder.java?view=auto&rev=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlAttributeBuilder.java
(added)
+++ geronimo/trunk/modules/service-builder/src/java/org/apache/geronimo/deployment/service/XmlAttributeBuilder.java
Tue Mar  1 18:57:37 2005
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.deployment.service;
+
+import org.apache.xmlbeans.XmlObject;
+import org.apache.geronimo.common.DeploymentException;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public interface XmlAttributeBuilder {
+
+    String getNamespace();
+
+    Object getValue(XmlObject xmlObject, String type, ClassLoader cl) throws DeploymentException;
+
+}

Modified: geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd (original)
+++ geronimo/trunk/modules/service-builder/src/schema/geronimo-config.xsd Tue Mar  1 18:57:37
2005
@@ -32,8 +32,6 @@
         </xs:documentation>
     </xs:annotation>
 
-    <!--    <xs:include schemaLocation="geronimo-common.xsd"/>-->
-
     <xs:element name="configuration" type="sys:configurationType"/>
 
     <xs:complexType name="configurationType">
@@ -72,6 +70,7 @@
     <xs:complexType name="gbeanType">
         <xs:choice minOccurs="0" maxOccurs="unbounded">
             <xs:element name="attribute" type="sys:attributeType"/>
+            <xs:element name="xml-attribute" type="sys:xml-attributeType"/>
             <xs:element name="reference" type="sys:referenceType"/>
             <xs:element name="references" type="sys:referencesType"/>
         </xs:choice>
@@ -87,6 +86,13 @@
                 <xs:attribute name="type" type="xs:string"/>
             </xs:extension>
         </xs:simpleContent>
+    </xs:complexType>
+
+    <xs:complexType name="xml-attributeType">
+        <xs:sequence>
+           <xs:any namespace="##other"/>
+        </xs:sequence>
+        <xs:attribute name="name" type="xs:string"/>
     </xs:complexType>
 
     <xs:complexType name="referenceType">

Added: geronimo/trunk/modules/service-builder/src/schema/geronimo-javabean-xmlattribute.xsd
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/schema/geronimo-javabean-xmlattribute.xsd?view=auto&rev=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/schema/geronimo-javabean-xmlattribute.xsd (added)
+++ geronimo/trunk/modules/service-builder/src/schema/geronimo-javabean-xmlattribute.xsd Tue
Mar  1 18:57:37 2005
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright 2004 The Apache Software Foundation
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+  
+       http://www.apache.org/licenses/LICENSE-2.0
+  
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<xs:schema
+    targetNamespace="http://geronimo.apache.org/xml/ns/deployment/javabean"
+    xmlns:javabean="http://geronimo.apache.org/xml/ns/deployment/javabean"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    elementFormDefault="qualified"
+    attributeFormDefault="unqualified"
+    >
+    <xs:annotation>
+        <xs:documentation>
+            Schema for javabean xml attributes
+
+            &gt;gbeans xmlns="http://geronimo.apache.org/xml/ns/deployment/javabean"&lt;
+        </xs:documentation>
+    </xs:annotation>
+
+    <xs:element name="javabean" type="javabean:javabeanType"/>
+
+    <xs:complexType name="javabeanType">
+        <xs:sequence>
+            <xs:element name="property" type="javabean:propertyType" minOccurs="0" maxOccurs="unbounded"/>
+            <xs:element name="bean-property" type="javabean:bean-propertyType" minOccurs="0"
maxOccurs="unbounded"/>
+        </xs:sequence>
+    </xs:complexType>
+
+    <xs:complexType name="propertyType">
+        <xs:simpleContent>
+            <xs:extension base="xs:string">
+                <xs:attribute name="name" type="xs:string"/>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+
+    <xs:complexType name="bean-propertyType">
+        <xs:sequence>
+            <xs:element ref="javabean:javabean"/>
+        </xs:sequence>
+        <xs:attribute name="name" type="xs:string"/>
+    </xs:complexType>
+
+</xs:schema>
\ No newline at end of file

Modified: geronimo/trunk/modules/service-builder/src/schema/xmlconfig.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/schema/xmlconfig.xml?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/schema/xmlconfig.xml (original)
+++ geronimo/trunk/modules/service-builder/src/schema/xmlconfig.xml Tue Mar  1 18:57:37 2005
@@ -4,4 +4,8 @@
         <xb:package>org.apache.geronimo.deployment.xbeans</xb:package>
     </xb:namespace>
 
+    <xb:namespace uri="http://geronimo.apache.org/xml/ns/deployment/javabean">
+        <xb:package>org.apache.geronimo.deployment.javabean.xbeans</xb:package>
+    </xb:namespace>
+
 </xb:config>

Modified: geronimo/trunk/modules/service-builder/src/test-resources/services/plan1.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/test-resources/services/plan1.xml?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/test-resources/services/plan1.xml (original)
+++ geronimo/trunk/modules/service-builder/src/test-resources/services/plan1.xml Tue Mar 
1 18:57:37 2005
@@ -28,8 +28,20 @@
     </dependency>
     
     <gbean name="geronimo.test:name=MyMockGMBean" class="org.apache.geronimo.deployment.MockGBean">
-        <attribute name="Value">1234</attribute>
-        <attribute name="IntValue">1234</attribute>
+        <attribute name="value">1234</attribute>
+        <attribute name="intValue">1234</attribute>
+        <xml-attribute name="fooBarBean">
+            <ns:javabean xmlns:ns="http://geronimo.apache.org/xml/ns/deployment/javabean">
+                <ns:property name="Foo">foo</ns:property>
+                <ns:property name="Bar">10</ns:property>
+                <ns:bean-property name="Bean">
+                    <ns:javabean>
+                        <ns:property name="Foo">foo2</ns:property>
+                        <ns:property name="Bar">100</ns:property>           
                              
+                    </ns:javabean>
+                </ns:bean-property>
+            </ns:javabean>
+        </xml-attribute>
         <reference name="MockEndpoint">geronimo.test:name=MyMockGMBean</reference>
     </gbean>
-</configuration>
\ No newline at end of file
+</configuration>

Added: geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/FooBarBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/FooBarBean.java?view=auto&rev=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/FooBarBean.java
(added)
+++ geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/FooBarBean.java
Tue Mar  1 18:57:37 2005
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.deployment;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class FooBarBean {
+
+    private String foo;
+    private int bar;
+    private FooBarBean bean;
+
+    public String getFoo() {
+        return foo;
+    }
+
+    public void setFoo(String foo) {
+        this.foo = foo;
+    }
+
+    public int getBar() {
+        return bar;
+    }
+
+    public void setBar(int bar) {
+        this.bar = bar;
+    }
+
+    public FooBarBean getBean() {
+        return bean;
+    }
+
+    public void setBean(FooBarBean bean) {
+        this.bean = bean;
+    }
+}

Modified: geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/MockGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/MockGBean.java?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/MockGBean.java
(original)
+++ geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/MockGBean.java
Tue Mar  1 18:57:37 2005
@@ -30,6 +30,8 @@
     private String value;
     private int intValue;
 
+    private FooBarBean fooBarBean;
+
     private MockEndpoint endpoint;
 
     public MockGBean(String name) {
@@ -56,6 +58,14 @@
         this.intValue = intValue;
     }
 
+    public FooBarBean getFooBarBean() {
+        return fooBarBean;
+    }
+
+    public void setFooBarBean(FooBarBean fooBarBean) {
+        this.fooBarBean = fooBarBean;
+    }
+
     public MockEndpoint getMockEndpoint() {
         return endpoint;
     }
@@ -83,6 +93,7 @@
         infoFactory.addAttribute("name", String.class, true);
         infoFactory.addAttribute("value", String.class, true);
         infoFactory.addAttribute("intValue", int.class, true);
+        infoFactory.addAttribute("fooBarBean", FooBarBean.class, true);
 
         infoFactory.addOperation("checkEndpoint");
         infoFactory.addOperation("doSomething", new Class[]{String.class});

Modified: geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ConfigPlanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ConfigPlanTest.java?view=diff&r1=155857&r2=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ConfigPlanTest.java
(original)
+++ geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ConfigPlanTest.java
Tue Mar  1 18:57:37 2005
@@ -25,6 +25,7 @@
 import org.apache.geronimo.deployment.xbeans.GbeanType;
 import org.apache.geronimo.deployment.xbeans.ReferenceType;
 import org.apache.geronimo.deployment.xbeans.DependencyType;
+import org.apache.geronimo.deployment.FooBarBean;
 
 import junit.framework.TestCase;
 
@@ -52,9 +53,9 @@
         assertEquals("geronimo.test:name=MyMockGMBean", gbeans[0].getName());
         AttributeType[] attrs = gbeans[0].getAttributeArray();
         assertEquals(2, attrs.length);
-        assertEquals("Value", attrs[0].getName());
+        assertEquals("value", attrs[0].getName());
         assertEquals("1234", attrs[0].getStringValue());
-        assertEquals("IntValue", attrs[1].getName());
+        assertEquals("intValue", attrs[1].getName());
         assertEquals("1234", attrs[1].getStringValue());
 
         ReferenceType[] refs = gbeans[0].getReferenceArray();

Added: geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java?view=auto&rev=155858
==============================================================================
--- geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
(added)
+++ geronimo/trunk/modules/service-builder/src/test/org/apache/geronimo/deployment/service/ServiceConfigBuilderTest.java
Tue Mar  1 18:57:37 2005
@@ -0,0 +1,104 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.deployment.service;
+
+import java.net.URI;
+import java.net.URL;
+import java.io.File;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.deployment.xbeans.ConfigurationDocument;
+import org.apache.geronimo.deployment.xbeans.ConfigurationType;
+import org.apache.geronimo.deployment.xbeans.GbeanType;
+import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.deployment.FooBarBean;
+import org.apache.geronimo.kernel.config.ConfigurationModuleType;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
+import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.ReferenceCollection;
+import org.apache.geronimo.gbean.ReferenceCollectionListener;
+
+/**
+ * @version $Rev:  $ $Date:  $
+ */
+public class ServiceConfigBuilderTest extends TestCase {
+
+    public void testJavaBeanXmlAttribute() throws Exception {
+        ReferenceCollection referenceCollection = new MockReferenceCollection();
+        JavaBeanXmlAttributeBuilder javaBeanXmlAttributeBuilder = new JavaBeanXmlAttributeBuilder();
+        //this is kind of cheating, we rely on the builder to iterate through existing members
of the collection.
+        referenceCollection.add(javaBeanXmlAttributeBuilder);
+        ServiceConfigBuilder builder = new ServiceConfigBuilder(URI.create("test/foo"), null,
referenceCollection, null);
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        URL plan1 = cl.getResource("services/plan1.xml");
+        ConfigurationDocument doc = ConfigurationDocument.Factory.parse(plan1);
+        ConfigurationType plan = doc.getConfiguration();
+        File outFile = File.createTempFile("foo", "bar");
+        outFile.delete();
+        if (!outFile.mkdirs()) {
+            fail("could not create temp dir");
+        }
+        try {
+            DeploymentContext context = new DeploymentContext(outFile, URI.create("foo/bar"),
ConfigurationModuleType.SERVICE, URI.create("foo"), "domain", "server", null);
+            J2eeContext j2eeContext = new J2eeContextImpl("domain", "server", "null", "test",
"configtest", "foo", NameFactory.J2EE_MODULE);
+            GbeanType[] gbeans = plan.getGbeanArray();
+            ServiceConfigBuilder.addGBeans(gbeans, cl, j2eeContext, context);
+            GBeanData[] beanDatas = context.getGBeans();
+            assertEquals(1, beanDatas.length);
+            GBeanData data = beanDatas[0];
+            FooBarBean fooBarBean = (FooBarBean) data.getAttribute("fooBarBean");
+            assertNotNull(fooBarBean);
+            assertEquals("foo", fooBarBean.getFoo());
+            assertEquals(10, fooBarBean.getBar());
+            FooBarBean inner = fooBarBean.getBean();
+            assertNotNull(inner);
+            assertEquals("foo2", inner.getFoo());
+            assertEquals(100, inner.getBar());
+            assertNull(inner.getBean());
+        } finally {
+            recursiveDelete(outFile);
+        }
+    }
+
+    private void recursiveDelete(File file) {
+
+        File[] list = file.listFiles();
+        if (list != null) {
+            for (int i = 0; i < list.length; i++) {
+                File file1 = list[i];
+                if (file1.isDirectory()) {
+                    recursiveDelete(file1);
+                }
+            }
+        }
+        file.delete();
+    }
+
+    private static class MockReferenceCollection extends ArrayList implements ReferenceCollection
{
+
+        public void addReferenceCollectionListener(ReferenceCollectionListener listener)
{
+
+        }
+
+        public void removeReferenceCollectionListener(ReferenceCollectionListener listener)
{
+
+        }
+    }
+}



Mime
View raw message