You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by js...@apache.org on 2006/10/11 19:44:07 UTC

svn commit: r462875 - in /geronimo/xbean/sandbox: xbean-apt/src/main/java/org/apache/xbean/factory/ xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/ xbean-factory/src/test/resources/

Author: jstrachan
Date: Wed Oct 11 10:44:03 2006
New Revision: 462875

URL: http://svn.apache.org/viewvc?view=rev&rev=462875
Log:
added early test case for optional references

Added:
    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-factory/src/test/resources/
    geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml
Modified:
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomColumnFactory.java

Added: 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=auto&rev=462875
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java (added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/BeanMarshaller.java Wed Oct 11 10:44:03 2006
@@ -0,0 +1,45 @@
+/*
+ * 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 javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.JAXBContext;
+import java.io.OutputStream;
+import java.io.InputStream;
+
+/**
+ * @version $Revision: $
+ */
+public class BeanMarshaller {
+
+    public void write(OutputStream out, Beans beans) throws JAXBException {
+        Marshaller marshaller = createJAXBContext().createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        marshaller.marshal(beans, out);
+    }
+
+    public Beans read(InputStream in) throws JAXBException {
+        Unmarshaller unmarshaller = createJAXBContext().createUnmarshaller();
+        return (Beans) unmarshaller.unmarshal(in);
+    }
+
+    protected JAXBContext createJAXBContext() throws JAXBException {
+        return JAXBContext.newInstance(getClass());
+    }
+}

Added: 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=auto&rev=462875
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java (added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/Beans.java Wed Oct 11 10:44:03 2006
@@ -0,0 +1,48 @@
+/*
+ * 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 javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @version $Revision: $
+ */
+@XmlRootElement(namespace="http://www.springframework/beans/TODO")
+public class Beans {
+    private List<FactoryBeanSupport> beans = new ArrayList<FactoryBeanSupport>();
+    private Map<String, FactoryBeanSupport> map = new HashMap<String, FactoryBeanSupport>();
+
+    public FactoryBeanSupport getBeanFactory(String id) {
+        return map.get(id);
+    }
+
+    public List<FactoryBeanSupport> getBeans() {
+        return beans;
+    }
+
+    public void setBeans(List<FactoryBeanSupport> beans) {
+        this.beans = beans;
+        map.clear();
+        for (FactoryBeanSupport bean : beans) {
+            map.put(bean.get_id(), bean);
+        }
+    }
+}

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=462875&r1=462874&r2=462875
==============================================================================
--- 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 Wed Oct 11 10:44:03 2006
@@ -19,6 +19,9 @@
 import org.apache.xbean.factory.FactoryBeanSupport;
 import org.apache.xbean.factory.model.Column;
 
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlIDREF;
 import javax.xml.bind.annotation.XmlRootElement;
 
 /**
@@ -28,6 +31,7 @@
 public class CustomColumnFactory extends FactoryBeanSupport<Column> {
     private CustomDataTypeFactory dataType;
     private String name;
+    private CustomDataTypeFactory dataTypeRef;
 
     public CustomColumnFactory() {
     }
@@ -39,7 +43,12 @@
 
     public Column getObject() {
         Column column = new Column();
-        column.setDataType(dataType.getObject());
+        if (dataType != null) {
+            column.setDataType(dataType.getObject());
+        }
+        else if (dataTypeRef != null) {
+            column.setDataType(dataTypeRef.getObject());
+        }
         column.setName(name);
         return column;
     }
@@ -49,6 +58,7 @@
         return dataType;
     }
 
+    @XmlElement(required = false)
     public void setDataType(CustomDataTypeFactory dataType) {
         this.dataType = dataType;
     }
@@ -59,5 +69,15 @@
 
     public void setName(String name) {
         this.name = name;
+    }
+
+    @XmlAttribute(required = false)
+    @XmlIDREF
+    public CustomDataTypeFactory getDataTypeRef() {
+        return dataTypeRef;
+    }
+
+    public void setDataTypeRef(CustomDataTypeFactory dataTypeRef) {
+        this.dataTypeRef = dataTypeRef;
     }
 }

Added: 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=auto&rev=462875
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml (added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/resources/column-with-ref.xml Wed Oct 11 10:44:03 2006
@@ -0,0 +1,8 @@
+<?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>