geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r462843 - in /geronimo/xbean/sandbox: xbean-apt/src/main/java/org/apache/xbean/factory/ xbean-factory/src/main/java/org/apache/xbean/factory/model/ xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/ xbean-factory/src/test/j...
Date Wed, 11 Oct 2006 16:32:27 GMT
Author: jstrachan
Date: Wed Oct 11 09:32:25 2006
New Revision: 462843

URL: http://svn.apache.org/viewvc?view=rev&rev=462843
Log:
added an example of a nested object graph along with renaming the spring/xbean attributes
on the factory bean to use _foo so they don't clash with user properties

Added:
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.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/java/org/apache/xbean/factory/JaxbColumnTest.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
      - copied, changed from r462821, geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java
Removed:
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java
Modified:
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java
    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/Table.java
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java

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=462843&r1=462842&r2=462843
==============================================================================
--- 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
Wed Oct 11 09:32:25 2006
@@ -16,15 +16,13 @@
  */
 package org.apache.xbean.factory;
 
-import org.springframework.beans.factory.FactoryBean;
-
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlTransient;
 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;
@@ -35,55 +33,46 @@
  *
  * @version $Revision: $
  */
-public abstract class FactoryBeanSupport<T> implements FactoryBean {
+public abstract class FactoryBeanSupport<T> {
 
-    private String id;
-    private Class objectType;
-    private boolean singleton;
+    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];
+        this._objectType = (Class) typeArguments[0];
     }
 
     @XmlTransient
-    public Class getObjectType() {
-        return objectType;
+    public Class get_objectType() {
+        return _objectType;
     }
 
-    @XmlAttribute(namespace = "http://www.springframework/beans/TODO")
-    public boolean isSingleton() {
-        return singleton;
+    @XmlAttribute(name = "singleton", namespace = "http://www.springframework/beans/TODO",
required = false)
+    public Boolean get_singleton() {
+        return _singleton;
     }
 
-    public void setSingleton(boolean singleton) {
-        this.singleton = singleton;
+    public void set_singleton(Boolean _singleton) {
+        this._singleton = _singleton;
     }
 
     @XmlID
-    @XmlAttribute(namespace = "http://www.springframework/beans/TODO")
-    public String getId() {
-        return id;
+    @XmlAttribute(name = "id", namespace = "http://www.springframework/beans/TODO", required
= false)
+    public String get_id() {
+        return _id;
     }
 
-    public void setId(String id) {
-        this.id = id;
+    public void set_id(String _id) {
+        this._id = _id;
     }
 
     @XmlTransient
     public abstract T getObject();
 
-    /**
-     * Configures this factory with the values from the given type
-     */
-    public abstract void configure(T value);
-
-    public void write(OutputStream out, T value) throws JAXBException {
-        if (value == null) {
-            throw new IllegalArgumentException("Value must not be null");
-        }
-        configure(value);
+    public void write(OutputStream out) throws JAXBException {
         Marshaller marshaller = createJAXBContext().createMarshaller();
         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
         marshaller.marshal(this, out);

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=462843&r1=462842&r2=462843
==============================================================================
--- 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
Wed Oct 11 09:32:25 2006
@@ -21,12 +21,12 @@
  */
 public class Column {
     private String name;
-    private String dataType;
+    private DataType dataType;
 
     public Column() {
     }
 
-    public Column(String name, String dataType) {
+    public Column(String name, DataType dataType) {
         this.name = name;
         this.dataType = dataType;
     }
@@ -39,11 +39,11 @@
         this.name = name;
     }
 
-    public String getDataType() {
+    public DataType getDataType() {
         return dataType;
     }
 
-    public void setDataType(String dataType) {
+    public void setDataType(DataType dataType) {
         this.dataType = dataType;
     }
 
@@ -64,5 +64,9 @@
         result = (name != null ? name.hashCode() : 0);
         result = 29 * result + (dataType != null ? dataType.hashCode() : 0);
         return result;
+    }
+
+    public String toString() {
+        return "Column[name: " + name + ", dataType: " + dataType + "]";
     }
 }

Added: 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=auto&rev=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/DataType.java
Wed Oct 11 09:32:25 2006
@@ -0,0 +1,59 @@
+/*
+ * 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.model;
+
+/**
+ * @version $Revision: $
+ */
+public class DataType {
+    private String name;
+
+    public DataType() {
+    }
+
+    public DataType(String name) {
+        this.name = name;
+    }
+
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final DataType that = (DataType) o;
+
+        if (name != null ? !name.equals(that.name) : that.name != null) return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        return super.hashCode();    // TODO
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String toString() {
+        return "DataType[name: " + name + "]";
+    }
+}

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Table.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Table.java?view=diff&rev=462843&r1=462842&r2=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Table.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/Table.java
Wed Oct 11 09:32:25 2006
@@ -59,7 +59,7 @@
     }
 
     public Column addColumn(String name, String dataType) {
-        Column column = new Column(name, dataType);
+        Column column = new Column(name, new DataType(dataType));
         columns.put(name, column);
         return column;
     }

Added: 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=auto&rev=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java
Wed Oct 11 09:32:25 2006
@@ -0,0 +1,63 @@
+/*
+ * 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.model.factory;
+
+import org.apache.xbean.factory.FactoryBeanSupport;
+import org.apache.xbean.factory.model.Column;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @version $Revision: $
+ */
+@XmlRootElement(name = "column")
+public class CustomColumnFactory extends FactoryBeanSupport<Column> {
+    private CustomDataTypeFactory dataType;
+    private String name;
+
+    public CustomColumnFactory() {
+    }
+
+    public CustomColumnFactory(Column value) {
+        dataType = new CustomDataTypeFactory(value.getDataType());
+        name = value.getName();
+    }
+
+    public Column getObject() {
+        Column column = new Column();
+        column.setDataType(dataType.getObject());
+        column.setName(name);
+        return column;
+    }
+
+
+    public CustomDataTypeFactory getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(CustomDataTypeFactory dataType) {
+        this.dataType = dataType;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

Added: 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=auto&rev=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomDataTypeFactory.java
Wed Oct 11 09:32:25 2006
@@ -0,0 +1,53 @@
+/*
+ * 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.model.factory;
+
+import org.apache.xbean.factory.FactoryBeanSupport;
+import org.apache.xbean.factory.model.DataType;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlAttribute;
+
+/**
+ * @version $Revision: $
+ */
+@XmlRootElement(name = "dataType")
+public class CustomDataTypeFactory extends FactoryBeanSupport<DataType> {
+    private String name;
+
+    public CustomDataTypeFactory() {
+    }
+
+    public CustomDataTypeFactory(DataType value) {
+        name = value.getName();
+    }
+    
+    public DataType getObject() {
+        DataType datatype = new DataType();
+        datatype.setName(name);
+        return datatype;
+    }
+
+    @XmlAttribute
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

Modified: geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java?view=diff&rev=462843&r1=462842&r2=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java
Wed Oct 11 09:32:25 2006
@@ -31,6 +31,16 @@
     private String fullName;
     private String phoneNumber;
 
+    public CustomUserFactory() {
+    }
+
+    public CustomUserFactory(User value) {
+        fullName = value.getFullName();
+        name = value.getName();
+        phoneNumber = value.getPhoneNumber();
+        pk = value.getPk();
+    }
+
     public User getObject() {
         User user = new User();
         user.setFullName(fullName);
@@ -41,13 +51,6 @@
     }
 
 
-    public void configure(User value) {
-        fullName = value.getFullName();
-        name = value.getName();
-        phoneNumber = value.getPhoneNumber();
-        pk = value.getPk();
-    }
-
     public long getPk() {
         return pk;
     }
@@ -79,7 +82,6 @@
     public void setPhoneNumber(String phoneNumber) {
         this.phoneNumber = phoneNumber;
     }
-
 
 
 }

Added: 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=auto&rev=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbColumnTest.java
Wed Oct 11 09:32:25 2006
@@ -0,0 +1,66 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.xbean.factory.model.Column;
+import org.apache.xbean.factory.model.DataType;
+import org.apache.xbean.factory.model.factory.CustomColumnFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+/**
+ * @version $Revision: $
+ */
+public class JaxbColumnTest extends TestCase {
+
+    protected String dir = "target/data";
+    protected String file = dir + "/column.xml";
+
+    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");
+        factory.write(new FileOutputStream(file));
+
+        // in case there's caching, lets make another
+        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);
+    }
+
+    protected Column createColumn() {
+        Column column = new Column();
+        column.setName("cheeseColumn");
+        DataType dataType = new DataType();
+        dataType.setName("String");
+        column.setDataType(dataType);
+        return column;
+    }
+
+}

Copied: geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
(from r462821, geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java)
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java?view=diff&rev=462843&p1=geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java&r1=462821&p2=geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java&r2=462843
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java
(original)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbUserTest.java
Wed Oct 11 09:32:25 2006
@@ -26,7 +26,7 @@
 /**
  * @version $Revision: $
  */
-public class JaxbTest extends UserTest {
+public class JaxbUserTest extends UserTest {
 
     protected String dir = "target/data";
     protected String file = dir + "/user.xml";
@@ -35,9 +35,9 @@
         new File(dir).mkdirs();
         
         User user = super.loadUser();
-        CustomUserFactory factory = new CustomUserFactory();
-        factory.setId("cheese");
-        factory.write(new FileOutputStream(file), user);
+        CustomUserFactory factory = new CustomUserFactory(user);
+        factory.set_id("cheese");
+        factory.write(new FileOutputStream(file));
 
         // in case there's caching, lets make another
         factory = new CustomUserFactory();



Mime
View raw message