geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r463325 - in /geronimo/xbean/sandbox: xbean-apt/src/main/java/org/apache/xbean/apt/ xbean-apt/src/main/resources/ xbean-factory/src/main/java/org/apache/xbean/factory/model/ xbean-factory/src/test/java/org/apache/xbean/factory/
Date Thu, 12 Oct 2006 17:07:39 GMT
Author: dain
Date: Thu Oct 12 10:07:38 2006
New Revision: 463325

URL: http://svn.apache.org/viewvc?view=rev&rev=463325
Log:
Added factory bean type linking

Added:
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/MirrorLinker.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ColumnTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanColumnTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanUserTest.java
      - copied, changed from r462987, geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanJaxbTest.java
Removed:
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanJaxbTest.java
Modified:
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Factory.java
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Property.java
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/XBeanAnnotationProcessor.java
    geronimo/xbean/sandbox/xbean-apt/src/main/resources/FactoryBean.vm
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Column.java
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/UserTest.java

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Factory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Factory.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Factory.java (original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Factory.java Thu Oct
12 10:07:38 2006
@@ -20,6 +20,7 @@
 import com.sun.mirror.declaration.MethodDeclaration;
 import com.sun.mirror.declaration.ParameterDeclaration;
 import com.sun.mirror.type.VoidType;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
 
 import java.util.Map;
 import java.util.TreeMap;

Added: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/MirrorLinker.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/MirrorLinker.java?view=auto&rev=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/MirrorLinker.java
(added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/MirrorLinker.java
Thu Oct 12 10:07:38 2006
@@ -0,0 +1,355 @@
+/**
+ *
+ * Copyright 2006 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.xbean.apt;
+
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.FieldDeclaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.Modifier;
+import com.sun.mirror.declaration.PackageDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.declaration.TypeParameterDeclaration;
+import com.sun.mirror.type.ArrayType;
+import com.sun.mirror.type.DeclaredType;
+import com.sun.mirror.type.InterfaceType;
+import com.sun.mirror.type.ReferenceType;
+import com.sun.mirror.type.TypeMirror;
+import com.sun.mirror.type.WildcardType;
+import com.sun.mirror.util.DeclarationVisitor;
+import com.sun.mirror.util.SourcePosition;
+import com.sun.mirror.util.TypeVisitor;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MirrorLinker {
+    public static void link(Map<String, Factory> factories) {
+        for (Factory factory : factories.values()) {
+            for (Property property : factory.getProperties()) {
+                TypeMirror type = property.getType();
+                TypeMirror newType = link(type, factories);
+                if (newType != type) {
+                    property.setType(newType);
+                }
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public static boolean isMapped(Collection<? extends TypeMirror> types) {
+        for (TypeMirror type : types) {
+            if (isMapped(type)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean isMapped(TypeMirror type) {
+        if (type instanceof WildcardType) {
+            WildcardType wildcardType = (WildcardType) type;
+            if (isMapped(wildcardType.getUpperBounds())) {
+                return true;
+            }
+            return isMapped(wildcardType.getLowerBounds());
+        } else if (type instanceof ArrayType) {
+            ArrayType arrayType = (ArrayType) type;
+            return isMapped(arrayType.getComponentType());
+        } else if (type instanceof DeclaredType) {
+            DeclaredType declaredType = (DeclaredType) type;
+
+            TypeDeclaration declaration = declaredType.getDeclaration();
+            if (declaration instanceof XTypeDeclaration) {
+                return true;
+            }
+
+            if (isMapped(declaredType.getContainingType())) {
+                return true;
+            }
+
+            return isMapped(declaredType.getActualTypeArguments());
+        }
+        return false;
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T extends TypeMirror> List<T> link(Collection<T> types,
Map<String, Factory> factories) {
+        List<T> newTypes = new ArrayList<T>();
+        for (TypeMirror type : types) {
+            T newType = (T) link(type, factories);
+            newTypes.add(newType);
+        }
+        return newTypes;
+    }
+
+    public static TypeMirror link(TypeMirror type, Map<String, Factory> factories)
{
+        if (type instanceof WildcardType) {
+            WildcardType wildcardType = (WildcardType) type;
+            Collection<ReferenceType> upperBounds = link(wildcardType.getUpperBounds(),
factories);
+            Collection<ReferenceType> lowerBounds = link(wildcardType.getLowerBounds(),
factories);
+            wildcardType = new XWildcardType(upperBounds, lowerBounds);
+            return wildcardType;
+        } else if (type instanceof ArrayType) {
+            ArrayType arrayType = (ArrayType) type;
+            TypeMirror componentType = link(arrayType.getComponentType(), factories);
+            arrayType = new XArrayType(componentType);
+            return arrayType;
+        } else if (type instanceof DeclaredType) {
+            DeclaredType declaredType = (DeclaredType) type;
+
+            TypeDeclaration declaration = declaredType.getDeclaration();
+            Factory factory = factories.get(declaration.getQualifiedName());
+            if (factory != null) {
+                declaration = new XTypeDeclaration(factory);
+            }
+
+            DeclaredType containingType = (DeclaredType) link(declaredType.getContainingType(),
factories);
+
+            Collection<TypeMirror> actualTypeArguments = link(declaredType.getActualTypeArguments(),
factories);
+
+            declaredType = new XDeclaredType(containingType, declaration, actualTypeArguments);
+            return declaredType;
+        }
+        if (type != null) {
+            System.err.println("Type=" + type.getClass().getName());
+        }
+        return type;
+    }
+
+    public static class XWildcardType implements WildcardType {
+        private Collection<ReferenceType> upperBounds = Collections.emptySet();
+        private Collection<ReferenceType> lowerBounds = Collections.emptySet();
+
+        public XWildcardType() {
+        }
+
+        public XWildcardType(Collection<ReferenceType> upperBounds, Collection<ReferenceType>
lowerBounds) {
+            this.upperBounds = upperBounds;
+            this.lowerBounds = lowerBounds;
+        }
+
+        public Collection<ReferenceType> getUpperBounds() {
+            return upperBounds;
+        }
+
+        public void setUpperBounds(Collection<ReferenceType> upperBounds) {
+            this.upperBounds = upperBounds;
+        }
+
+        public Collection<ReferenceType> getLowerBounds() {
+            return lowerBounds;
+        }
+
+        public void setLowerBounds(Collection<ReferenceType> lowerBounds) {
+            this.lowerBounds = lowerBounds;
+        }
+
+        public void accept(TypeVisitor typeVisitor) {
+            throw new UnsupportedOperationException();
+        }
+        public String toString() {
+            String value = "?";
+            if (!upperBounds.isEmpty()) {
+                value += " extends ";
+                for (Iterator<ReferenceType> iterator = upperBounds.iterator(); iterator.hasNext();)
{
+                    ReferenceType referenceType = iterator.next();
+                    value += referenceType;
+                    if (iterator.hasNext()) value += ", ";
+                }
+            } else if (!lowerBounds.isEmpty()) {
+                value += " super";
+                for (Iterator<ReferenceType> iterator = lowerBounds.iterator(); iterator.hasNext();)
{
+                    ReferenceType referenceType = iterator.next();
+                    value += referenceType;
+                    if (iterator.hasNext()) value += ", ";
+                }
+            }
+            return value;
+        }
+    }
+
+    public static class XArrayType implements ArrayType {
+        private TypeMirror componentType;
+
+        public XArrayType() {
+        }
+
+        public XArrayType(TypeMirror componentType) {
+            this.componentType = componentType;
+        }
+
+        public TypeMirror getComponentType() {
+            return componentType;
+        }
+
+        public void setComponentType(TypeMirror componentType) {
+            this.componentType = componentType;
+        }
+
+        public void accept(TypeVisitor typeVisitor) {
+            throw new UnsupportedOperationException();
+        }
+
+        public String toString() {
+            return componentType.toString() + "[]";
+        }
+    }
+
+    public static class XDeclaredType implements DeclaredType {
+        public DeclaredType containingType;
+        public TypeDeclaration declaration;
+        public Collection<TypeMirror> actualTypeArguments;
+        public Collection<InterfaceType> superinterfaces;
+
+        public XDeclaredType(DeclaredType containingType, TypeDeclaration declaration, Collection<TypeMirror>
actualTypeArguments) {
+            this.containingType = containingType;
+            this.declaration = declaration;
+            this.actualTypeArguments = actualTypeArguments;
+        }
+
+        public TypeDeclaration getDeclaration() {
+            return declaration;
+        }
+
+        public void setDeclaration(TypeDeclaration declaration) {
+            this.declaration = declaration;
+        }
+
+        public DeclaredType getContainingType() {
+            return containingType;
+        }
+
+        public void setContainingType(DeclaredType containingType) {
+            this.containingType = containingType;
+        }
+
+        public Collection<TypeMirror> getActualTypeArguments() {
+            return actualTypeArguments;
+        }
+
+        public void setActualTypeArguments(Collection<TypeMirror> actualTypeArguments)
{
+            this.actualTypeArguments = actualTypeArguments;
+        }
+
+        public Collection<InterfaceType> getSuperinterfaces() {
+            return superinterfaces;
+        }
+
+        public void setSuperinterfaces(Collection<InterfaceType> superinterfaces) {
+            this.superinterfaces = superinterfaces;
+        }
+
+        public void accept(TypeVisitor typeVisitor) {
+            throw new UnsupportedOperationException();
+        }
+
+        public String toString() {
+            String value;
+            if (containingType != null) {
+                value = containingType + "." + declaration.getSimpleName();
+            } else  {
+                value = declaration.getQualifiedName();
+            }
+            if (!actualTypeArguments.isEmpty()) {
+                value += "<";
+                for (Iterator<TypeMirror> iterator = actualTypeArguments.iterator();
iterator.hasNext();) {
+                    TypeMirror typeMirror = iterator.next();
+                    value += typeMirror;
+                    if (iterator.hasNext()) value += ", ";
+                }
+                value += ">";
+            }
+            return value;
+        }
+    }
+
+    public static class XTypeDeclaration implements TypeDeclaration {
+        private final Factory factory;
+
+        public XTypeDeclaration(Factory factory) {
+            this.factory = factory;
+        }
+
+        public PackageDeclaration getPackage() {
+            throw new UnsupportedOperationException();
+        }
+
+        public String getSimpleName() {
+            return factory.getFactoryName();
+        }
+
+        public String getQualifiedName() {
+            return factory.getFactoryFqn();
+        }
+
+        public Collection<TypeParameterDeclaration> getFormalTypeParameters() {
+            throw new UnsupportedOperationException();
+        }
+
+        public Collection<InterfaceType> getSuperinterfaces() {
+            throw new UnsupportedOperationException();
+        }
+
+        public Collection<FieldDeclaration> getFields() {
+            throw new UnsupportedOperationException();
+        }
+
+        public Collection<? extends MethodDeclaration> getMethods() {
+            throw new UnsupportedOperationException();
+        }
+
+        public Collection<TypeDeclaration> getNestedTypes() {
+            throw new UnsupportedOperationException();
+        }
+
+        public TypeDeclaration getDeclaringType() {
+            throw new UnsupportedOperationException();
+        }
+
+        public String getDocComment() {
+            throw new UnsupportedOperationException();
+        }
+
+        public Collection<AnnotationMirror> getAnnotationMirrors() {
+            throw new UnsupportedOperationException();
+        }
+
+        public <A extends Annotation> A getAnnotation(Class<A> aClass) {
+            throw new UnsupportedOperationException();
+        }
+
+        public Collection<Modifier> getModifiers() {
+            throw new UnsupportedOperationException();
+        }
+
+        public SourcePosition getPosition() {
+            throw new UnsupportedOperationException();
+        }
+
+        public void accept(DeclarationVisitor declarationVisitor) {
+            throw new UnsupportedOperationException();
+        }
+    }
+}

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Property.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Property.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Property.java (original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/Property.java Thu
Oct 12 10:07:38 2006
@@ -16,8 +16,9 @@
  */
 package org.apache.xbean.apt;
 
-import com.sun.mirror.type.TypeMirror;
 import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.TypeMirror;
+import com.sun.mirror.type.PrimitiveType;
 
 /**
  * @version $Rev$ $Date$
@@ -58,5 +59,13 @@
 
     public void setSetter(MethodDeclaration setter) {
         this.setter = setter;
+    }
+
+    public boolean isMapped() {
+        return MirrorLinker.isMapped(type);
+    }
+
+    public boolean isPrimitive() {
+        return type instanceof PrimitiveType;
     }
 }

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/XBeanAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/XBeanAnnotationProcessor.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/XBeanAnnotationProcessor.java
(original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/apt/XBeanAnnotationProcessor.java
Thu Oct 12 10:07:38 2006
@@ -40,10 +40,25 @@
     }
 
     public void process() {
+        VelocityClassVisitor velocityClassVisitor = visit();
+        link(velocityClassVisitor);
+        generate(velocityClassVisitor);
+    }
+
+    private VelocityClassVisitor visit() {
         VelocityClassVisitor velocityClassVisitor = new VelocityClassVisitor();
         for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) {
             typeDecl.accept(getDeclarationScanner(velocityClassVisitor, NO_OP));
         }
+        return velocityClassVisitor;
+    }
+
+    private void link(VelocityClassVisitor velocityClassVisitor) {
+        MirrorLinker mirrorLinker = new MirrorLinker();
+        mirrorLinker.link(velocityClassVisitor.getFactories());
+    }
+
+    private void generate(VelocityClassVisitor velocityClassVisitor) {
         Map<String, Factory> factories = velocityClassVisitor.getFactories();
         for (Factory factory : factories.values()) {
             generate(factory);

Modified: geronimo/xbean/sandbox/xbean-apt/src/main/resources/FactoryBean.vm
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/src/main/resources/FactoryBean.vm?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/resources/FactoryBean.vm (original)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/resources/FactoryBean.vm Thu Oct 12 10:07:38
2006
@@ -12,8 +12,24 @@
  */
 @XmlRootElement
 public class $f.factoryName extends FactoryBeanSupport<$f.className> {
+#foreach ( $prop in $f.properties)
+    private $prop.type $prop.name;
+#end
 
-	@XmlTransient
+    public ${f.factoryName}() {
+    }
+
+    public ${f.factoryName}(${f.className} _object) {
+#foreach ( $prop in $f.properties)
+#if ( $prop.mapped )
+        ${prop.name} = _object.get${prop.name}() !=null ? new ${prop.type}(_object.get${prop.name}())
: null;
+#else
+        ${prop.name} = _object.get${prop.name}();
+#end
+#end
+    }
+
+    @XmlTransient
 	@Override
 	public Class get_objectType() {
 		return ${f.className}.class;
@@ -24,25 +40,29 @@
     public $f.className getObject() {
         ${f.className} _object = new ${f.className}();
 #foreach ( $prop in $f.properties)
+#if ( $prop.primitive )
         _object.set${prop.name}(${prop.name});
+#else
+        if (${prop.name} != null) {
+#if ( $prop.mapped )
+            _object.set${prop.name}(${prop.name}.getObject());
+#else
+            _object.set${prop.name}(${prop.name});
+#end
+        }
+#end
 #end
         return _object;
     }
 
-    public void configure($f.className _object) {
 #foreach ( $prop in $f.properties)
-        ${prop.name} = _object.get${prop.name}();
-#end
-    }
 
-#foreach ( $prop in $f.properties)
-    private $prop.type $prop.name;
     public ${prop.type} get${prop.name}() {
         return $prop.name;
     }
+
     public void set${prop.name}(${prop.type} ${prop.name}) {
         this.${prop.name} = ${prop.name};
     }
-
 #end
 }

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Column.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Column.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Column.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Column.java
Thu Oct 12 10:07:38 2006
@@ -16,9 +16,12 @@
  */
 package org.apache.xbean.factory.model;
 
+import org.apache.xbean.annotations.XmlRootElement;
+
 /**
  * @version $Rev$ $Date$
  */
+@XmlRootElement
 public class Column {
     private String name;
     private DataType dataType;
@@ -73,11 +76,11 @@
         return "Column[name: " + name + ", dataType: " + dataType + ", secondDataType: "
+ secondDataType + "]";
     }
 
-	public DataType getSecondDataType() {
-		return secondDataType;
-	}
-
-	public void setSecondDataType(DataType secondDataType) {
-		this.secondDataType = secondDataType;
-	}
+    public DataType getSecondDataType() {
+        return secondDataType;
+    }
+
+    public void setSecondDataType(DataType secondDataType) {
+        this.secondDataType = secondDataType;
+    }
 }

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java
Thu Oct 12 10:07:38 2006
@@ -16,9 +16,12 @@
  */
 package org.apache.xbean.factory.model;
 
+import org.apache.xbean.annotations.XmlRootElement;
+
 /**
  * @version $Revision: $
  */
+@XmlRootElement
 public class DataType {
     private String name;
 

Added: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ColumnTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ColumnTest.java?view=auto&rev=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ColumnTest.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/ColumnTest.java
Thu Oct 12 10:07:38 2006
@@ -0,0 +1,62 @@
+/**
+ *
+ * Copyright 2006 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.xbean.factory;
+
+import junit.framework.TestCase;
+import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.DataType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ColumnTest extends TestCase {
+    private Column column;
+    public void testWriteAndRead() throws Exception {
+        Column answer = loadColumn();
+
+        System.out.println("Created: " + column);
+        System.out.println("Parsed:  " + answer);
+
+        assertNotNull(answer);
+        assertEquals(column, answer);
+    }
+
+    public Column loadColumn() throws Exception {
+        return createColumn();
+    }
+
+    protected Column createColumn() {
+        Column column = new Column();
+        column.setName("cheeseColumn");
+
+        DataType dataType = new DataType();
+        dataType.setName("String");
+        column.setDataType(dataType);
+
+//        ArrayDataType secondDataType = new ArrayDataType();
+//        secondDataType.setName("Integer");
+//        secondDataType.setDimensions(50);
+//        column.setSecondDataType(secondDataType);
+
+        return column;
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        column = createColumn();
+    }
+}

Modified: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java
Thu Oct 12 10:07:38 2006
@@ -16,26 +16,25 @@
  */
 package org.apache.xbean.factory;
 
-import junit.framework.TestCase;
-
-import org.apache.xbean.factory.model.ArrayDataType;
 import org.apache.xbean.factory.model.Column;
 import org.apache.xbean.factory.model.DataType;
 import org.apache.xbean.factory.model.factory.CustomColumnFactory;
 
+import javax.xml.bind.JAXBException;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 
 /**
  * @version $Revision: $
  */
-public class JaxbColumnTest extends TestCase {
+public class JaxbColumnTest extends ColumnTest {
 
     protected String dir = "target/data";
     protected String file = dir + "/column.xml";
 
-    public void testWriteAndRead() throws Exception {
+    public Column loadColumn() throws JAXBException, FileNotFoundException {
         new File(dir).mkdirs();
 
         Column column = createColumn();
@@ -48,28 +47,6 @@
         factory = new CustomColumnFactory();
         FactoryBeanSupport<Column> newFactory = factory.read(new FileInputStream(file));
         Column answer = newFactory.getObject();
-
-        System.out.println("Created: " + column);
-        System.out.println("Parsed:  " + answer);
-        
-        assertNotNull(answer);
-        assertEquals(column, answer);
+        return answer;
     }
-
-    protected Column createColumn() {
-        Column column = new Column();
-        column.setName("cheeseColumn");
-        
-        DataType dataType = new DataType();
-        dataType.setName("String");
-        column.setDataType(dataType);
-        
-//        ArrayDataType secondDataType = new ArrayDataType();
-//        secondDataType.setName("Integer");
-//        secondDataType.setDimensions(50);
-//        column.setSecondDataType(secondDataType);
-        
-        return column;
-    }
-
 }

Modified: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
Thu Oct 12 10:07:38 2006
@@ -34,7 +34,7 @@
     public User loadUser() throws Exception {
         new File(dir).mkdirs();
         
-        User user = super.loadUser();
+        User user = createUser();
         CustomUserFactory factory = new CustomUserFactory(user);
         factory.set_id("cheese");
         factory.write(new FileOutputStream(file));

Modified: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/UserTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/UserTest.java?view=diff&rev=463325&r1=463324&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/UserTest.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/UserTest.java
Thu Oct 12 10:07:38 2006
@@ -36,6 +36,10 @@
     }
 
     public User loadUser() throws Exception {
+        return createUser();
+    }
+
+    protected User createUser() {
         User testUser = new User(42, "dain", "Dain Sundstrom");
         testUser.setPhoneNumber("(310) XXX-XXXX");
         return testUser;
@@ -44,7 +48,6 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        user = new User(42, "dain", "Dain Sundstrom");
-        user.setPhoneNumber("(310) XXX-XXXX");
+        user = createUser();
     }
 }

Added: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanColumnTest.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanColumnTest.java?view=auto&rev=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanColumnTest.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanColumnTest.java
Thu Oct 12 10:07:38 2006
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2006 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.xbean.factory;
+
+import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.factory.CustomColumnFactory;
+import org.apache.xbean.factory.model.factory.ColumnFactoryBean;
+
+import javax.xml.bind.JAXBException;
+import java.io.FileNotFoundException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+
+/**
+ * @version $Revision: $
+ */
+public class XBeanColumnTest extends ColumnTest {
+
+    protected String dir = "target/data";
+    protected String file = dir + "/column.xml";
+
+    public Column loadColumn() throws JAXBException, FileNotFoundException {
+        new File(dir).mkdirs();
+
+        Column column = createColumn();
+        ColumnFactoryBean factory = new ColumnFactoryBean(column);
+        factory.set_singleton(Boolean.TRUE);
+        factory.set_id("cheese");
+        factory.write(new FileOutputStream(file));
+
+        // in case there's caching, lets make another
+        factory = new ColumnFactoryBean();
+        FactoryBeanSupport<Column> newFactory = factory.read(new FileInputStream(file));
+        Column answer = newFactory.getObject();
+        return answer;
+    }
+
+}

Copied: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanUserTest.java
(from r462987, geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanJaxbTest.java)
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanUserTest.java?view=diff&rev=463325&p1=geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanJaxbTest.java&r1=462987&p2=geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanUserTest.java&r2=463325
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanJaxbTest.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/XBeanUserTest.java
Thu Oct 12 10:07:38 2006
@@ -27,7 +27,7 @@
 /**
  * @version $Revision: $
  */
-public class XBeanJaxbTest extends UserTest {
+public class XBeanUserTest extends UserTest {
 
     protected String dir = "target/data";
     protected String file = dir + "/user.xml";
@@ -35,9 +35,8 @@
     public User loadUser() throws Exception {
         new File(dir).mkdirs();
 
-        User user = super.loadUser();
-        UserFactoryBean factory = new UserFactoryBean();
-        factory.configure(user);
+        User user = createUser();
+        UserFactoryBean factory = new UserFactoryBean(user);
         factory.write(new FileOutputStream(file));
 
         // in case there's caching, lets make another



Mime
View raw message