geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r463693 - in /geronimo/xbean/sandbox: xbean-apt/ xbean-apt/src/main/java/org/apache/xbean/factory/ xbean-apt/src/main/resources/org/ xbean-apt/src/main/resources/org/apache/ xbean-apt/src/main/resources/org/apache/xbean/ xbean-apt/src/main/...
Date Fri, 13 Oct 2006 14:48:59 GMT
Author: jstrachan
Date: Fri Oct 13 07:48:58 2006
New Revision: 463693

URL: http://svn.apache.org/viewvc?view=rev&rev=463693
Log:
a bunch of changes after a very productive plane journey; now we've got a <beans> tag that you can nest in your <foo b:id="whatnot"/> tags which seems to work. We also dynamically resolve classes as we parse, using a similar technique to xbean-spring using META-INF/services. Also I've added test cases for using references or for using inheritence

Added:
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/ClassResolverImpl.java
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/NamespacePrefixMapperImpl.java
    geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/
    geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/
    geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/
    geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/factory/
    geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/factory/jaxb.index
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/factory/
    geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/factory/jaxb.index
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/BeansTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/InheritenceTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ReferenceTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/column
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/dataType
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/user
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/column.xml
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/log4.properties
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/user-with-ref.xml
Modified:
    geronimo/xbean/sandbox/xbean-apt/pom.xml
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java
    geronimo/xbean/sandbox/xbean-factory/pom.xml
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/ArrayDataType.java
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomArrayDataTypeFactory.java
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml

Modified: geronimo/xbean/sandbox/xbean-apt/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/pom.xml?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/pom.xml (original)
+++ geronimo/xbean/sandbox/xbean-apt/pom.xml Fri Oct 13 07:48:58 2006
@@ -2,11 +2,14 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
+    <parent>
+    <groupId>org.apache.xbean</groupId>
+    <artifactId>xbean-factory-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
 
-  <groupId>org.apache.xbean</groupId>
   <artifactId>xbean-apt</artifactId>
   <name>XBean APT Processor</name>
-  <version>1.0-SNAPSHOT</version>
   <build>
     <pluginManagement>
       <plugins>
@@ -48,7 +51,7 @@
     <dependency>
       <groupId>com.sun.xml.bind</groupId>
       <artifactId>jaxb-impl</artifactId>
-      <version>2.0.1</version>
+      <version>dev-20060914</version>
       <exclusions>
         <exclusion>
           <groupId>javax.xml</groupId>
@@ -67,7 +70,7 @@
     <dependency>
       <groupId>javax.xml</groupId>
       <artifactId>jaxb-api</artifactId>
-      <version>2.0</version>
+      <version>dev-20060914</version>
       <exclusions>
         <exclusion>
           <groupId>javax.xml</groupId>

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java (original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java Fri Oct 13 07:48:58 2006
@@ -22,24 +22,62 @@
 import javax.xml.bind.JAXBContext;
 import java.io.OutputStream;
 import java.io.InputStream;
+import java.util.*;
 
 /**
  * @version $Revision: $
  */
 public class BeanMarshaller {
 
+    private JAXBContext context;
+
+    public BeanMarshaller() {
+    }
+
+    public BeanMarshaller(JAXBContext context) {
+        this.context = context;
+    }
+
+    public BeanMarshaller(String packages) throws JAXBException {
+        this(JAXBContext.newInstance(packages));
+    }
+
     public void write(OutputStream out, Beans beans) throws JAXBException {
-        Marshaller marshaller = createJAXBContext().createMarshaller();
-        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        System.out.println("About to write: " + beans + " with factories: " + beans.getBeans());
+        
+        Marshaller marshaller = createJAXBContext(beans).createMarshaller();
+        FactoryBeanSupport.configureMarshaller(marshaller);
         marshaller.marshal(beans, out);
     }
 
     public Beans read(InputStream in) throws JAXBException {
         Unmarshaller unmarshaller = createJAXBContext().createUnmarshaller();
+        FactoryBeanSupport.configureUnmarshaller(unmarshaller);
         return (Beans) unmarshaller.unmarshal(in);
     }
 
+    public JAXBContext getContext() throws JAXBException {
+        if (context == null) {
+            context = createJAXBContext();
+        }
+        return context;
+    }
+
     protected JAXBContext createJAXBContext() throws JAXBException {
-        return JAXBContext.newInstance(getClass());
+        return JAXBContext.newInstance(Beans.class);
     }
+
+    private JAXBContext createJAXBContext(Beans beans) throws JAXBException {
+        List<Class> list = new ArrayList<Class>();
+        list.add(Beans.class);
+        Iterator iter = beans.getBeans().iterator();
+        while (iter.hasNext()) {
+            Object factory = iter.next();
+            list.add(factory.getClass());
+        }
+        Class[] array = new Class[list.size()];
+        list.toArray(array);
+        return JAXBContext.newInstance(array);
+    }
+
 }

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java (original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java Fri Oct 13 07:48:58 2006
@@ -16,33 +16,58 @@
  */
 package org.apache.xbean.factory;
 
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
+import javax.xml.bind.annotation.*;
+import java.util.*;
 
 /**
  * @version $Revision: $
  */
-@XmlRootElement(namespace="http://www.springframework/beans/TODO")
+@XmlRootElement(namespace = "http://www.springframework/beans/TODO")
+@XmlAccessorType(value= XmlAccessType.FIELD)
 public class Beans {
-    private List<FactoryBeanSupport> beans = new ArrayList<FactoryBeanSupport>();
-    private Map<String, FactoryBeanSupport> map = new HashMap<String, FactoryBeanSupport>();
+    @XmlAnyElement(lax = true)
+    private List<Object> beans = new ArrayList<Object>();
+    @XmlTransient
+    private Map<String, FactoryBeanSupport> map;
 
     public FactoryBeanSupport getBeanFactory(String id) {
-        return map.get(id);
+        return (FactoryBeanSupport) getMap().get(id);
     }
 
-    public List<FactoryBeanSupport> getBeans() {
+    public List<Object> getBeans() {
         return beans;
     }
 
-    public void setBeans(List<FactoryBeanSupport> beans) {
+    public void setBeans(List<Object> beans) {
         this.beans = beans;
-        map.clear();
-        for (FactoryBeanSupport bean : beans) {
-            map.put(bean.get_id(), bean);
+        reloadMap();
+    }
+
+    public void addBean(FactoryBeanSupport bean) {
+        beans.add(bean);
+        getMap().put(bean.get_id(), bean);
+    }
+
+
+    protected Map<String, FactoryBeanSupport> getMap() {
+        if (map == null) {
+            reloadMap();
+        }
+        return map;
+    }
+
+    protected void reloadMap() {
+        map = new HashMap<String, FactoryBeanSupport>();
+        for (Iterator iter = beans.iterator(); iter.hasNext();) {
+            Object object = iter.next();
+            if (object instanceof FactoryBeanSupport) {
+                FactoryBeanSupport bean = (FactoryBeanSupport) object;
+                System.out.println("Found factory!!! with id: " + bean.get_id());
+                map.put(bean.get_id(), bean);
+            }
+            else {
+                System.out.println("Found: " + object + " of type: " + object.getClass());
+            }
         }
     }
 }

Added: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/ClassResolverImpl.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/ClassResolverImpl.java?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/ClassResolverImpl.java (added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/ClassResolverImpl.java Fri Oct 13 07:48:58 2006
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xbean.factory;
+
+import com.sun.xml.bind.api.ClassResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.*;
+
+/**
+ * @version $Revision: $
+ */
+public class ClassResolverImpl extends ClassResolver {
+    public static final String META_INF_PREFIX = "META-INF/services/org/apache/xbean/factory/";
+    private static final String JAVA_PACKAGE_PREFIX = "java://";
+
+    private static final Log log = LogFactory.getLog(ClassResolverImpl.class);
+
+    public Class<?> resolveElementName(String namespaceURI, String localName) throws Exception {
+        if (namespaceURI != null && namespaceURI.startsWith(JAVA_PACKAGE_PREFIX)) {
+            String packageName = namespaceURI.substring(JAVA_PACKAGE_PREFIX.length());
+
+            Class answer = tryLoadClassName(packageName, localName);
+            if (answer == null) {
+                String name = localName + "FactoryBean";
+                answer = tryLoadClassName(packageName, name);
+                if (answer == null) {
+                    name = name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
+                    answer = tryLoadClassName(packageName, name);
+                }
+            }
+            if (answer != null) {
+                return answer;
+            }
+        }
+
+
+        String uri = createDiscoveryPathName(namespaceURI, localName);
+        InputStream in = loadResource(uri);
+        if (in != null) {
+            try {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+                String name = reader.readLine();
+                if (name != null) {
+                    name = name.trim();
+                    if (name.length() > 0) {
+                        return tryLoadClassName(name);
+                    }
+                }
+            }
+            catch (IOException e) {
+                log.warn("Failed to load resource from uri: " + uri, e);
+            }
+        }
+        return null;
+    }
+
+
+    /**
+     * Converts the namespace and localName into a valid path name we can use on
+     * the classpath to discover a text file
+     */
+    public static String createDiscoveryPathName(String uri, String localName) {
+        if (isEmpty(uri)) {
+            return META_INF_PREFIX + localName;
+        }
+        return createDiscoveryPathName(uri) + "/" + localName;
+    }
+
+    /**
+     * Converts the namespace and localName into a valid path name we can use on
+     * the classpath to discover a text file
+     */
+    public static String createDiscoveryPathName(String uri) {
+        // lets replace any dodgy characters
+        return META_INF_PREFIX + uri.replaceAll("://", "/").replace(':', '/').replace(' ', '_');
+    }
+
+    public static boolean isEmpty(String uri) {
+        return uri == null || uri.length() == 0;
+    }
+
+
+    /**
+     * Loads the resource from the given URI
+     */
+    protected InputStream loadResource(String uri) {
+        if (System.getProperty("xbean.dir") != null) {
+            File f = new File(System.getProperty("xbean.dir") + uri);
+            try {
+                return new FileInputStream(f);
+            }
+            catch (FileNotFoundException e) {
+                // Ignore
+            }
+        }
+        // lets try the thread context class loader first
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri);
+        if (in == null) {
+            if (in == null) {
+                in = getClass().getClassLoader().getResourceAsStream(uri);
+                if (in == null) {
+                    log.debug("Could not find resource: " + uri);
+                }
+            }
+        }
+        return in;
+    }
+
+
+    protected Class tryLoadClassName(String packageName, String localName) {
+        String name = localName;
+        if (!isEmpty(packageName)) {
+            name = packageName + "." + localName;
+        }
+        return tryLoadClassName(name);
+    }
+
+    protected Class tryLoadClassName(String name) {
+        try {
+            return Thread.currentThread().getContextClassLoader().loadClass(name);
+        }
+        catch (ClassNotFoundException e) {
+            try {
+                return getClass().getClassLoader().loadClass(name);
+            }
+            catch (ClassNotFoundException e1) {
+                return null;
+            }
+        }
+    }
+
+}

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java (original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java Fri Oct 13 07:48:58 2006
@@ -16,16 +16,17 @@
  */
 package org.apache.xbean.factory;
 
-import java.io.InputStream;
-import java.io.OutputStream;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.*;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlID;
 import javax.xml.bind.annotation.XmlTransient;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 
 /**
  * A base class for a code generated factory bean
@@ -34,14 +35,26 @@
  */
 public abstract class FactoryBeanSupport<T> {
 
+    private static final Log log = LogFactory.getLog(FactoryBeanSupport.class);
+
     private String _id;
     private Boolean _singleton;
+    private Class _objectType;
+
+    public FactoryBeanSupport() {
+        ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
+        Type[] typeArguments = genericSuperclass.getActualTypeArguments();
+        this._objectType = (Class) typeArguments[0];
+    }
+
+    public FactoryBeanSupport(Class _objectType) {
+        this._objectType = _objectType;
+    }
 
     @XmlTransient
-    abstract public Class get_objectType();
-    
-    @XmlTransient
-    abstract public T getObject();
+    public Class get_objectType() {
+        return _objectType;
+    }
 
     @XmlAttribute(name = "singleton", namespace = "http://www.springframework/beans/TODO", required = false)
     public Boolean get_singleton() {
@@ -62,15 +75,19 @@
         this._id = _id;
     }
 
+    @XmlTransient
+    public abstract T getObject();
+
     public void write(OutputStream out) throws JAXBException {
         Marshaller marshaller = createJAXBContext().createMarshaller();
-        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        configureMarshaller(marshaller);
         marshaller.marshal(this, out);
     }
 
-    @SuppressWarnings("unchecked")
-	public FactoryBeanSupport<T> read(InputStream in) throws JAXBException {
+
+    public FactoryBeanSupport<T> read(InputStream in) throws JAXBException {
         Unmarshaller unmarshaller = createJAXBContext().createUnmarshaller();
+        configureUnmarshaller(unmarshaller);
         return (FactoryBeanSupport<T>) unmarshaller.unmarshal(in);
     }
 
@@ -78,4 +95,25 @@
         return JAXBContext.newInstance(getClass());
     }
 
+    public static void configureMarshaller(Marshaller marshaller) {
+        try {
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+            marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
+        }
+        catch (PropertyException e) {
+            // lets not worry about it if the JAXB provider doesn't support
+            // vendor extensions
+        }
+    }
+
+    public static void configureUnmarshaller(Unmarshaller unmarshaller) {
+        try {
+            unmarshaller.setProperty("com.sun.xml.bind.api.ClassResolver", new ClassResolverImpl());
+        }
+        catch (PropertyException e) {
+            // lets not worry about it if the JAXB provider doesn't support
+            // vendor extensions
+            log.warn("This JAXB provider does not support pluggable Class resolving: "+ e, e);
+        }
+    }
 }

Added: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/NamespacePrefixMapperImpl.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/NamespacePrefixMapperImpl.java?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/NamespacePrefixMapperImpl.java (added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/NamespacePrefixMapperImpl.java Fri Oct 13 07:48:58 2006
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xbean.factory;
+
+import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
+
+/**
+ * @version $Revision: $
+ */
+public class NamespacePrefixMapperImpl extends NamespacePrefixMapper {
+
+    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
+        if ("http://www.springframework/beans/TODO".equals(namespaceUri)) {
+            return "b";
+        }
+        return suggestion;
+    }
+
+    public String[] getPreDeclaredNamespaceUris() {
+        return new String[]{};
+    }
+}

Added: geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/factory/jaxb.index
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/factory/jaxb.index?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/factory/jaxb.index (added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/resources/org/apache/xbean/factory/jaxb.index Fri Oct 13 07:48:58 2006
@@ -0,0 +1 @@
+Beans
\ No newline at end of file

Modified: geronimo/xbean/sandbox/xbean-factory/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/pom.xml?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/pom.xml (original)
+++ geronimo/xbean/sandbox/xbean-factory/pom.xml Fri Oct 13 07:48:58 2006
@@ -1,10 +1,14 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.xbean</groupId>
+  <parent>
+    <groupId>org.apache.xbean</groupId>
+    <artifactId>xbean-factory-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
   <artifactId>xbean-factory</artifactId>
   <packaging>jar</packaging>
-  <version>1.0-SNAPSHOT</version>
   <name>XBean :: JaxB Factory</name>
   <url>http://geronimo.apache.org/xbean</url>
   <dependencies>
@@ -23,7 +27,7 @@
     <dependency>
       <groupId>com.sun.xml.bind</groupId>
       <artifactId>jaxb-impl</artifactId>
-      <version>2.0.1</version>
+      <version>dev-20060914</version>
       <exclusions>
         <exclusion>
           <groupId>javax.xml</groupId>
@@ -42,7 +46,7 @@
     <dependency>
       <groupId>javax.xml</groupId>
       <artifactId>jaxb-api</artifactId>
-      <version>2.0</version>
+      <version>dev-20060914</version>
       <exclusions>
         <exclusion>
           <groupId>javax.xml</groupId>

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/ArrayDataType.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/ArrayDataType.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/ArrayDataType.java (original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/ArrayDataType.java Fri Oct 13 07:48:58 2006
@@ -20,12 +20,12 @@
  * @version $Revision: $
  */
 public class ArrayDataType extends DataType {
-	
+
     private int dimensions;
 
     public ArrayDataType() {
     }
-    
+
     public boolean equals(Object o) {
         if (this == o) return true;
         if (o == null || getClass() != o.getClass()) return false;
@@ -33,26 +33,26 @@
         final ArrayDataType that = (ArrayDataType) o;
 
         if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) return false;
-        if (dimensions!= that.dimensions ) return false;
+        if (dimensions != that.dimensions) return false;
 
         return true;
     }
 
     public int hashCode() {
-        return super.hashCode(); 
+        return super.hashCode();
     }
 
+    public String toString() {
+        return "ArrayDataType[name: " + getName() + ", dimensions: " + dimensions + "]";
+    }
 
-	public int getDimensions() {
-		return dimensions;
-	}
-
-	public void setDimensions(int dimensions) {
-		this.dimensions = dimensions;
-	}
+    public int getDimensions() {
+        return dimensions;
+    }
 
-    public String toString() {
-        return "ArrayDataType[name: " + getName() +", dimensions"+dimensions+"]";
+    public void setDimensions(int dimensions) {
+        this.dimensions = dimensions;
     }
+
 
 }

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomArrayDataTypeFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomArrayDataTypeFactory.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomArrayDataTypeFactory.java (original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomArrayDataTypeFactory.java Fri Oct 13 07:48:58 2006
@@ -16,51 +16,40 @@
  */
 package org.apache.xbean.factory.model.factory;
 
+import org.apache.xbean.factory.model.ArrayDataType;
+
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-import javax.xml.bind.annotation.XmlType;
-
-import org.apache.xbean.factory.FactoryBeanSupport;
-import org.apache.xbean.factory.model.ArrayDataType;
 
 /**
  * @version $Revision: $
  */
-@XmlRootElement(name="bar")
-//@XmlType(name="bar")
+@XmlRootElement(name = "arrayDataType")
 public class CustomArrayDataTypeFactory extends CustomDataTypeFactory {
-	
-	private int dimensions;
+    private int dimensions;
 
     public CustomArrayDataTypeFactory() {
+        super(ArrayDataType.class);
     }
 
     public CustomArrayDataTypeFactory(ArrayDataType value) {
-        setName(value.getName());
-        setDimensions(value.getDimensions());
+        super(value);
+        dimensions = value.getDimensions();
     }
-    
-	@XmlTransient
-	@Override
-	public Class get_objectType() {
-		return ArrayDataType.class;
-	}
-    
-	@XmlTransient
-	@Override
+
     public ArrayDataType getObject() {
-		ArrayDataType datatype = new ArrayDataType();
+        ArrayDataType datatype = new ArrayDataType();
         datatype.setName(getName());
-        datatype.setDimensions(getDimensions());
+        datatype.setDimensions(dimensions);
         return datatype;
     }
 
     @XmlAttribute
-	public int getDimensions() {
-		return dimensions;
-	}
-	public void setDimensions(int dimensions) {
-		this.dimensions = dimensions;
-	}
+    public int getDimensions() {
+        return dimensions;
+    }
+
+    public void setDimensions(int dimensions) {
+        this.dimensions = dimensions;
+    }
 }

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java (original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java Fri Oct 13 07:48:58 2006
@@ -16,16 +16,11 @@
  */
 package org.apache.xbean.factory.model.factory;
 
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementRef;
-import javax.xml.bind.annotation.XmlElementRefs;
-import javax.xml.bind.annotation.XmlIDREF;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
 import org.apache.xbean.factory.FactoryBeanSupport;
 import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.DataType;
+
+import javax.xml.bind.annotation.*;
 
 /**
  * @version $Revision: $
@@ -38,22 +33,18 @@
     private CustomDataTypeFactory dataTypeRef;
 
     public CustomColumnFactory() {
+        super(DataType.class);
     }
 
     public CustomColumnFactory(Column value) {
-    	dataType = value.getDataType()!=null ? new CustomDataTypeFactory(value.getDataType()) : null;
-    	secondDataType = value.getSecondDataType() != null ? new CustomDataTypeFactory(value.getSecondDataType()) : null;        
+        super(value.getClass());
+        dataType = CustomDataTypeFactory.convert(value.getDataType());
+
+        // TODO
+        //secondDataType = CustomDataTypeFactory.convert(value.getSecondDataType());
         name = value.getName();
     }
 
-	@XmlTransient
-	@Override
-	public Class get_objectType() {
-		return Column.class;
-	}
-
-	@XmlTransient
-	@Override
     public Column getObject() {
         Column column = new Column();
         if (dataType != null) {
@@ -67,13 +58,16 @@
     }
 
 
+    //@XmlElement(required = false)
+    @XmlAnyElement(lax = true)
+    @XmlElementRefs(value = {
+    @XmlElementRef(name = "dataType", type = CustomDataTypeFactory.class),
+    @XmlElementRef(name = "arrayDataType", type = CustomArrayDataTypeFactory.class)
+            })
     public CustomDataTypeFactory getDataType() {
         return dataType;
     }
 
-//    @XmlElement(required = false)
-//    @XmlElement
-    @XmlElementRef
     public void setDataType(CustomDataTypeFactory dataType) {
         this.dataType = dataType;
     }
@@ -86,7 +80,7 @@
         this.name = name;
     }
 
-    @XmlElement
+    /*
     public CustomDataTypeFactory getSecondDataType() {
 		return secondDataType;
 	}
@@ -94,7 +88,7 @@
 	public void setSecondDataType(CustomDataTypeFactory secondDataType) {
 		this.secondDataType = secondDataType;
 	}
-
+    */
 
     @XmlAttribute(required = false)
     @XmlIDREF

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java (original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java Fri Oct 13 07:48:58 2006
@@ -16,37 +16,50 @@
  */
 package org.apache.xbean.factory.model.factory;
 
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-import javax.xml.bind.annotation.XmlType;
-
 import org.apache.xbean.factory.FactoryBeanSupport;
+import org.apache.xbean.factory.model.ArrayDataType;
 import org.apache.xbean.factory.model.DataType;
 
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * @version $Revision: $
  */
-@XmlRootElement(name = "bar")
-//@XmlType(name="bar")
-public class CustomDataTypeFactory extends FactoryBeanSupport {
+@XmlRootElement(name = "dataType")
+public class CustomDataTypeFactory extends FactoryBeanSupport<DataType> {
     private String name;
 
+    public static CustomDataTypeFactory convert(DataType dataType) {
+        if (dataType == null) {
+            return null;
+        }
+        if (dataType instanceof ArrayDataType) {
+            return new CustomArrayDataTypeFactory((ArrayDataType) dataType);
+        }
+        else {
+            return new CustomDataTypeFactory(dataType);
+        }
+    }
+
     public CustomDataTypeFactory() {
     }
 
+
+    public CustomDataTypeFactory(Class _objectType) {
+        super(_objectType);
+    }
+
+    public CustomDataTypeFactory(Class _objectType, String name) {
+        super(_objectType);
+        this.name = name;
+    }
+
     public CustomDataTypeFactory(DataType value) {
+        super(value.getClass());
         name = value.getName();
     }
-    
-	@XmlTransient
-	@Override
-	public Class get_objectType() {
-		return DataType.class;
-	}
 
-	@XmlTransient
-	@Override
     public DataType getObject() {
         DataType datatype = new DataType();
         datatype.setName(name);

Added: geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/factory/jaxb.index
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/factory/jaxb.index?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/factory/jaxb.index (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/resources/org/apache/xbean/factory/model/factory/jaxb.index Fri Oct 13 07:48:58 2006
@@ -0,0 +1,3 @@
+CustomColumnFactory
+CustomDataTypeFactory
+CustomUserFactory

Added: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/BeansTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/BeansTest.java?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/BeansTest.java (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/BeansTest.java Fri Oct 13 07:48:58 2006
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xbean.factory;
+
+import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.User;
+import org.apache.xbean.factory.model.factory.CustomColumnFactory;
+import org.apache.xbean.factory.model.factory.CustomUserFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * @version $Revision: $
+ */
+public class BeansTest extends JaxbColumnTest {
+
+    protected String dir = "target/data";
+    protected String file = dir + "/beans.xml";
+
+    public void testReadUser() throws Exception {
+        InputStream in = getClass().getClassLoader().getResourceAsStream("user-with-ref.xml");
+        assertNotNull("Could not find xml!", in);
+
+        BeanMarshaller marshaller = new BeanMarshaller("org.apache.xbean.factory:org.apache.xbean.factory.model.factory");
+        Beans newBeans = marshaller.read(in);
+
+        List beanList = newBeans.getBeans();
+        System.out.println("Read beans: " + beanList);
+
+        assertTrue("Should have found beans: " + beanList, !beanList.isEmpty());
+
+        FactoryBeanSupport factory = newBeans.getBeanFactory("cheese");
+        assertNotNull(factory);
+
+        Object bean = factory.getObject();
+        assertNotNull(bean);
+
+        System.out.println("bean: " + bean);
+
+    }
+
+
+    public void testReadColumn() throws Exception {
+        Column column = createColumn();
+
+        InputStream in = getClass().getClassLoader().getResourceAsStream("column.xml");
+        assertNotNull("Could not find xml!", in);
+
+        BeanMarshaller marshaller = new BeanMarshaller("org.apache.xbean.factory:org.apache.xbean.factory.model.factory");
+        Beans newBeans = marshaller.read(in);
+
+        List beanList = newBeans.getBeans();
+        System.out.println("Read beans: " + beanList);
+
+        assertTrue("Should have found beans: " + beanList, !beanList.isEmpty());
+
+        // in case there's caching, lets make another
+        CustomColumnFactory factory = (CustomColumnFactory) newBeans.getBeanFactory("cheese");
+        Column answer = factory.getObject();
+
+        System.out.println("Created: " + column);
+        System.out.println("Parsed:  " + answer);
+
+        assertNotNull(answer);
+        assertEquals(column, answer);
+    }
+
+    public void testWriteAndRead() throws Exception {
+        new File(dir).mkdirs();
+
+        Column column = createColumn();
+        CustomColumnFactory factory = new CustomColumnFactory(column);
+        factory.set_singleton(Boolean.TRUE);
+        factory.set_id("cheese");
+
+        Beans beans = new Beans();
+        beans.addBean(factory);
+
+        BeanMarshaller marshaller = new BeanMarshaller();
+        marshaller.write(new FileOutputStream(file), beans);
+
+        Beans newBeans = marshaller.read(new FileInputStream(file));
+
+        System.out.println("Read beans: " + newBeans.getBeans());
+
+        // in case there's caching, lets make another
+        factory = (CustomColumnFactory) newBeans.getBeanFactory("cheese");
+        assertNotNull("Should have found a factory for name 'cheese'", factory);
+        Column answer = factory.getObject();
+
+        System.out.println("Created: " + column);
+        System.out.println("Parsed:  " + answer);
+
+        assertNotNull(answer);
+        assertEquals(column, answer);
+    }
+
+
+    public void testWriteAndReadUser() throws Exception {
+        new File(dir).mkdirs();
+
+        User testUser = new User(42, "dain", "Dain Sundstrom");
+        testUser.setPhoneNumber("(310) XXX-XXXX");
+        CustomUserFactory factory = new CustomUserFactory(testUser);
+        factory.set_singleton(Boolean.TRUE);
+        factory.set_id("beer");
+
+        Beans beans = new Beans();
+        beans.addBean(factory);
+
+        BeanMarshaller marshaller = new BeanMarshaller();
+        String fileName = dir + "/beans-user.xml";
+        marshaller.write(new FileOutputStream(fileName), beans);
+
+        Beans newBeans = marshaller.read(new FileInputStream(fileName));
+
+        System.out.println("Read beans: " + newBeans.getBeans());
+
+        // in case there's caching, lets make another
+        factory = (CustomUserFactory) newBeans.getBeanFactory("beer");
+        assertNotNull("Should have found a factory for name 'beer'", factory);
+        User answer = factory.getObject();
+
+        System.out.println("Created: " + testUser);
+        System.out.println("Parsed:  " + answer);
+
+        assertNotNull(answer);
+        assertEquals(testUser, answer);
+    }
+
+
+}

Added: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/InheritenceTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/InheritenceTest.java?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/InheritenceTest.java (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/InheritenceTest.java Fri Oct 13 07:48:58 2006
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xbean.factory;
+
+import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.ArrayDataType;
+import org.apache.xbean.factory.model.factory.CustomColumnFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+/**
+ * @version $Revision: $
+ */
+public class InheritenceTest extends JaxbColumnTest {
+
+    protected String dir = "target/data";
+    protected String file = dir + "/inheritence.xml";
+
+    public void testWriteAndRead() throws Exception {
+        new File(dir).mkdirs();
+
+        Column column = createColumn();
+        ArrayDataType dataType = new ArrayDataType();
+        dataType.setDimensions(6);
+        dataType.setName("int");
+        column.setDataType(dataType);
+
+        CustomColumnFactory factory = new CustomColumnFactory(column);
+        factory.set_singleton(Boolean.TRUE);
+        factory.set_id("cheese");
+
+        Beans beans = new Beans();
+        beans.addBean(factory);
+
+        BeanMarshaller marshaller = new BeanMarshaller();
+        marshaller.write(new FileOutputStream(file), beans);
+
+        Beans newBeans = marshaller.read(new FileInputStream(file));
+
+        System.out.println("Read beans: " + newBeans.getBeans());
+
+        // in case there's caching, lets make another
+        factory = (CustomColumnFactory) newBeans.getBeanFactory("cheese");
+        assertNotNull("Should have found a factory for name 'cheese'", factory);
+        Column answer = factory.getObject();
+
+        System.out.println("Created: " + column);
+        System.out.println("Created data type: " + column.getDataType());
+
+        System.out.println("Parsed:  " + answer);
+        System.out.println("Parsed data type: " + answer.getDataType());
+
+        assertNotNull(answer);
+        assertEquals(column, answer);
+        assertEquals(column.getDataType(), answer.getDataType());
+
+    }
+
+}

Added: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ReferenceTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ReferenceTest.java?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ReferenceTest.java (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ReferenceTest.java Fri Oct 13 07:48:58 2006
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.xbean.factory;
+
+import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.factory.CustomColumnFactory;
+
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * @version $Revision: $
+ */
+public class ReferenceTest extends JaxbColumnTest {
+
+    public void testReadColumn() throws Exception {
+        Column column = createColumn();
+
+        InputStream in = getClass().getClassLoader().getResourceAsStream("column-with-ref.xml");
+        assertNotNull("Could not find xml!", in);
+
+        BeanMarshaller marshaller = new BeanMarshaller("org.apache.xbean.factory:org.apache.xbean.factory.model.factory");
+        Beans newBeans = marshaller.read(in);
+
+        List beanList = newBeans.getBeans();
+        System.out.println("Read beans: " + beanList);
+
+        assertTrue("Should have found beans: " + beanList, !beanList.isEmpty());
+
+        // in case there's caching, lets make another
+        CustomColumnFactory factory = (CustomColumnFactory) newBeans.getBeanFactory("cheese");
+        Column answer = factory.getObject();
+
+        System.out.println("Created: " + column);
+        System.out.println("Parsed:  " + answer);
+
+        assertNotNull(answer);
+        assertEquals(column, answer);
+
+        System.out.println("Parsed data type: " + answer.getDataType());
+        assertEquals(column.getDataType(), answer.getDataType());
+    }
+
+}

Added: geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/column
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/column?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/column (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/column Fri Oct 13 07:48:58 2006
@@ -0,0 +1 @@
+org.apache.xbean.factory.model.factory.CustomColumnFactory

Added: geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/dataType
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/dataType?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/dataType (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/dataType Fri Oct 13 07:48:58 2006
@@ -0,0 +1 @@
+org.apache.xbean.factory.model.factory.CustomDataTypeFactory

Added: geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/user
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/user?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/user (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/META-INF/services/org/apache/xbean/factory/user Fri Oct 13 07:48:58 2006
@@ -0,0 +1 @@
+org.apache.xbean.factory.model.factory.CustomUserFactory

Modified: geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml?view=diff&rev=463693&r1=463692&r2=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml (original)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml Fri Oct 13 07:48:58 2006
@@ -1,8 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <b:beans xmlns:b="http://www.springframework/beans/TODO">
 
-  <column b:singleton="true" b:id="cheese">
-    <dataType name="String"/>
+  <column b:singleton="true" b:id="cheese" dataTypeRef="foo">
     <name>cheeseColumn</name>
   </column>
+
+  <dataType name="String" b:id="foo"/>
+
 </b:beans>

Added: geronimo/xbean/sandbox/xbean-factory/src/test/resources/column.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/column.xml?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/column.xml (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/column.xml Fri Oct 13 07:48:58 2006
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<b:beans xmlns:b="http://www.springframework/beans/TODO">
+
+  <column b:singleton="true" b:id="cheese">
+    <dataType name="String"/>
+    <name>cheeseColumn</name>
+  </column>
+  
+</b:beans>

Added: geronimo/xbean/sandbox/xbean-factory/src/test/resources/log4.properties
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/log4.properties?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/log4.properties (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/log4.properties Fri Oct 13 07:48:58 2006
@@ -0,0 +1,37 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, stdout
+
+#log4j.logger.com.opensymphony.able=DEBUG
+
+#log4j.logger.org.apache.activemq.spring=WARN
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/activemq-test.log
+log4j.appender.out.append=true

Added: geronimo/xbean/sandbox/xbean-factory/src/test/resources/user-with-ref.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/resources/user-with-ref.xml?view=auto&rev=463693
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/user-with-ref.xml (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/user-with-ref.xml Fri Oct 13 07:48:58 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<b:beans xmlns:b="http://www.springframework/beans/TODO">
+
+  <user b:id="cheese">
+    <fullName>Dain Sundstrom</fullName>
+    <name>dain</name>
+    <phoneNumber>(310) XXX-XXXX</phoneNumber>
+    <pk>42</pk>
+  </user>
+
+</b:beans>



Mime
View raw message