geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r462793 - in /geronimo/xbean/sandbox: xbean-apt/ xbean-apt/src/main/java/org/apache/xbean/factory/ xbean-apt/src/main/java/org/apache/xbean/jaxb/ xbean-factory/ xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/ xbean-facto...
Date Wed, 11 Oct 2006 13:08:58 GMT
Author: jstrachan
Date: Wed Oct 11 06:08:56 2006
New Revision: 462793

URL: http://svn.apache.org/viewvc?view=rev&rev=462793
Log:
added a hand-crafted factory bean so that we have something to work from to code generate
stuff

Added:
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java
    geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/jaxb/
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/
    geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java
Modified:
    geronimo/xbean/sandbox/xbean-apt/pom.xml
    geronimo/xbean/sandbox/xbean-factory/pom.xml
    geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/UserTest.java

Modified: geronimo/xbean/sandbox/xbean-apt/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-apt/pom.xml?view=diff&rev=462793&r1=462792&r2=462793
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/pom.xml (original)
+++ geronimo/xbean/sandbox/xbean-apt/pom.xml Wed Oct 11 06:08:56 2006
@@ -22,6 +22,12 @@
   </build>
   <dependencies>
     <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring</artifactId>
+      <version>2.0</version>
+    </dependency>
+    
+    <dependency>
       <groupId>velocity</groupId>
       <artifactId>velocity</artifactId>
       <version>1.4</version>
@@ -37,6 +43,48 @@
       <version>1.1</version>
       <type>jar</type>
     </dependency>
+
+    <!-- jaxb -->
+    <dependency>
+      <groupId>com.sun.xml.bind</groupId>
+      <artifactId>jaxb-impl</artifactId>
+      <version>2.0.1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.xml</groupId>
+          <artifactId>jsr173</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.jws</groupId>
+          <artifactId>jsr181-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.activation</groupId>
+          <artifactId>activation</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>javax.xml</groupId>
+      <artifactId>jaxb-api</artifactId>
+      <version>2.0</version>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.xml</groupId>
+          <artifactId>jsr173</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>javax.activation</groupId>
+          <artifactId>activation</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>stax</groupId>
+      <artifactId>stax-api</artifactId>
+      <version>1.0.1</version>
+    </dependency>
+
   </dependencies>
   <profiles>
     <profile>

Added: 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=auto&rev=462793
==============================================================================
--- geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java
(added)
+++ geronimo/xbean/sandbox/xbean-apt/src/main/java/org/apache/xbean/factory/FactoryBeanSupport.java
Wed Oct 11 06:08:56 2006
@@ -0,0 +1,87 @@
+/*
+ * 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.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 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
+ *
+ * @version $Revision: $
+ */
+public abstract class FactoryBeanSupport<T> implements FactoryBean {
+
+    private Class objectType;
+    private boolean singleton;
+
+    public FactoryBeanSupport() {
+        ParameterizedType genericSuperclass = (ParameterizedType) getClass().getGenericSuperclass();
+        Type[] typeArguments = genericSuperclass.getActualTypeArguments();
+        this.objectType = (Class) typeArguments[0];
+    }
+
+    @XmlTransient
+    public Class getObjectType() {
+        return objectType;
+    }
+
+    @XmlTransient
+    public boolean isSingleton() {
+        return singleton;
+    }
+
+    public void setSingleton(boolean singleton) {
+        this.singleton = singleton;
+    }
+
+    @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);
+        Marshaller marshaller = createJAXBContext().createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        marshaller.marshal(this, out);
+    }
+
+    public FactoryBeanSupport<T> read(InputStream in) throws JAXBException {
+        Unmarshaller unmarshaller = createJAXBContext().createUnmarshaller();
+        return (FactoryBeanSupport<T>) unmarshaller.unmarshal(in);
+    }
+
+    protected JAXBContext createJAXBContext() throws JAXBException {
+        return JAXBContext.newInstance(getClass());
+    }
+}

Modified: geronimo/xbean/sandbox/xbean-factory/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/xbean/sandbox/xbean-factory/pom.xml?view=diff&rev=462793&r1=462792&r2=462793
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/pom.xml (original)
+++ geronimo/xbean/sandbox/xbean-factory/pom.xml Wed Oct 11 06:08:56 2006
@@ -13,6 +13,11 @@
       <artifactId>xbean-apt</artifactId>
       <version>1.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring</artifactId>
+      <version>2.0</version>
+    </dependency>
 
     <!-- jaxb -->
     <dependency>
@@ -53,6 +58,11 @@
       <groupId>stax</groupId>
       <artifactId>stax-api</artifactId>
       <version>1.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>javax.activation</groupId>
+      <artifactId>activation</artifactId>
+      <version>1.1</version>
     </dependency>
 
     <dependency>

Added: 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=auto&rev=462793
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/main/java/org/apache/xbean/factory/model/factory/CustomUserFactory.java
Wed Oct 11 06:08:56 2006
@@ -0,0 +1,85 @@
+/*
+ * 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.User;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @version $Revision: $
+ */
+@XmlRootElement(name = "user")
+public class CustomUserFactory extends FactoryBeanSupport<User> {
+    private long pk;
+    private String name;
+    private String fullName;
+    private String phoneNumber;
+
+    public User getObject() {
+        User user = new User();
+        user.setFullName(fullName);
+        user.setName(name);
+        user.setPhoneNumber(phoneNumber);
+        user.setPk(pk);
+        return user;
+    }
+
+
+    public void configure(User value) {
+        fullName = value.getFullName();
+        name = value.getName();
+        phoneNumber = value.getPhoneNumber();
+        pk = value.getPk();
+    }
+
+    public long getPk() {
+        return pk;
+    }
+
+    public void setPk(long pk) {
+        this.pk = pk;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getFullName() {
+        return fullName;
+    }
+
+    public void setFullName(String fullName) {
+        this.fullName = fullName;
+    }
+
+    public String getPhoneNumber() {
+        return phoneNumber;
+    }
+
+    public void setPhoneNumber(String phoneNumber) {
+        this.phoneNumber = phoneNumber;
+    }
+
+
+
+}

Added: 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/JaxbTest.java?view=auto&rev=462793
==============================================================================
--- geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java
(added)
+++ geronimo/xbean/sandbox/xbean-factory/src/test/java/org/apache/xbean/factory/JaxbTest.java
Wed Oct 11 06:08:56 2006
@@ -0,0 +1,47 @@
+/*
+ * 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.User;
+import org.apache.xbean.factory.model.factory.CustomUserFactory;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.File;
+
+/**
+ * @version $Revision: $
+ */
+public class JaxbTest extends UserTest {
+
+    protected String dir = "target/data";
+    protected String file = dir + "/user.xml";
+
+    public User loadUser() throws Exception {
+        new File(dir).mkdirs();
+        
+        User user = super.loadUser();
+        CustomUserFactory factory = new CustomUserFactory();
+        factory.write(new FileOutputStream(file), user);
+
+        // in case there's caching, lets make another
+        factory = new CustomUserFactory();
+        FactoryBeanSupport<User> newFactory = factory.read(new FileInputStream(file));
+        return newFactory.getObject();
+    }
+
+}

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=462793&r1=462792&r2=462793
==============================================================================
--- 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
Wed Oct 11 06:08:56 2006
@@ -25,7 +25,7 @@
 public class UserTest extends TestCase {
     private User user;
 
-    public void test() {
+    public void test() throws Exception {
         User testUser = loadUser();
         assertNotNull(testUser);
         assertEquals(user.getPk(), testUser.getPk());
@@ -35,7 +35,7 @@
         assertEquals(user, testUser);
     }
 
-    public User loadUser() {
+    public User loadUser() throws Exception {
         User testUser = new User(42, "dain", "Dain Sundstrom");
         testUser.setPhoneNumber("(310) XXX-XXXX");
         return testUser;



Mime
View raw message