[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/test ...

Ben Wang bwang at jboss.com
Sat Jan 13 10:55:01 EST 2007


  User: bwang   
  Date: 07/01/13 10:55:01

  Added:       tests/functional/org/jboss/cache/pojo/test                     
                        NetworkAdmin.java SpecialSerializedAddress.java
                        CacheObject.java NetworkDomain.java
                        NodeManager.java NetworkNode.java
                        NetworkElement.java EnumPlanet.java
                        ValueObject.java Link.java ArrayObject.java
                        Student.java Resource.java SpecialAddress.java
                        Gadget.java NonSerializableObject.java
                        SerializedAddress.java Person.java IdObject.java
                        Address.java TestNode.java
  Log:
  JBCACHE-922 Merged src-50 and tests-50 into src and tests, respectively.
  
  Revision  Changes    Path
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/NetworkAdmin.java
  
  Index: NetworkAdmin.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  /**
   * Sample object that contains administration details.
   * <p>This object is used to illustrate the pojo cache capability of PojoCache. Note the absence of <code>Serializable</code>
   * interface.</p>
   *
   * @author <a href="mailto:ben.wang at jboss.com">Ben Wang</a>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class NetworkAdmin
  {
     String id_;
  
     public String getId()
     {
        return id_;
     }
  
     public void setId(String id)
     {
        id_ = id;
     }
  
     public String toString()
     {
        StringBuffer sb = new StringBuffer();
        sb.append(" id = ").append(getId());
        return sb.toString();
     }
  
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/SpecialSerializedAddress.java
  
  Index: SpecialSerializedAddress.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Test class for PojoCache.
   *
   * @version $Revision: 1.1 $
   */
  @org.jboss.cache.pojo.annotation.Replicable
  public class SpecialSerializedAddress implements Serializable
  {
     String street = null;
     String city = null;
     int zip = 0;
  
     List residents = new ArrayList();
  
     public List getResidents()
     {
        return residents;
     }
  
     public void setResidents(List residents)
     {
        this.residents = residents;
     }
  
     public void addResidents(String name)
     {
        residents.add(name);
     }
  
     public String getStreet()
     {
        return street;
     }
  
     public void setStreet(String street)
     {
        this.street = street;
     }
  
     public String getCity()
     {
        return city;
     }
  
     public void setCity(String city)
     {
        this.city = city;
     }
  
     public int getZip()
     {
        return zip;
     }
  
     public void setZip(int zip)
     {
        this.zip = zip;
     }
  
     public String toString()
     {
        return "street=" + getStreet() + ", city=" + getCity() + ", zip=" + getZip();
     }
  
  //    public Object writeReplace() {
  //	return this;
  //    }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/CacheObject.java
  
  Index: CacheObject.java
  ===================================================================
  package org.jboss.cache.pojo.test;
  
  import java.io.Serializable;
  import java.util.HashSet;
  import java.util.Set;
  
  /**
   * Object to bind in cache
   */
  public class CacheObject implements Serializable
  {
     private String id;
     private Set identities;
  
     public CacheObject(String id)
     {
        this.id = id;
        this.identities = new HashSet();
     }
  
     public String getId()
     {
        return id;
     }
  
     public Set getIdentities()
     {
        return identities;
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/NetworkDomain.java
  
  Index: NetworkDomain.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * <p>Top level sample Pojo for a sample network management software. It is a logical object that can be presented to
   * the user. Example of domain is like temperature or vibration sensor domains.</p>
   * <p>This object is used to illustrate the pojo cache capability of PojoCache. Note the absence of <code>Serializable</code>
   * interface.</p>
   *
   * @author <a href="mailto:ben.wang at jboss.com">Ben Wang</a>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class NetworkDomain
  {
     String name_;
     // The associated nodes from the elements
     List nodes_;
     // All the elements to be managed in this domain
     List elements_;
     // Adminstration such id, pass
     NetworkAdmin admin_;
  
     static final int TEMP_SENSOR = 0;
     static final int VIBRATION_SENSOR = 1;
  
     public String getName()
     {
        return name_;
     }
  
     public void setName(String name)
     {
        name_ = name;
     }
  
     public List getNodes()
     {
        return nodes_;
     }
  
     protected void setNodes(List nodes)
     {
        nodes_ = nodes;
     }
  
     public List getElements()
     {
        return nodes_;
     }
  
     protected void addNode(NetworkNode node)
     {
        if (nodes_ == null)
           nodes_ = new ArrayList();
  
        nodes_.add(node);
     }
  
     public void addElement(NetworkElement element)
     {
        if (elements_ == null)
           elements_ = new ArrayList();
  
        elements_.add(element);
  
        if (element.getParentNode() == null)
           throw new RuntimeException("NetworkDomain.addElement(): parent node of element is null: " + element);
  
        addNode(element.getParentNode());
     }
  
     public NetworkAdmin getAdmin()
     {
        return admin_;
     }
  
     public void setAdmin(NetworkAdmin admin)
     {
        admin_ = admin;
     }
  
     public String toString()
     {
        StringBuffer sb = new StringBuffer();
        sb.append("* Damain * name= ").append(getName()).append(" + admin +: ").append(getAdmin());
        sb.append(" + nodes +: ").append(getNodes());
        return sb.toString();
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/NodeManager.java
  
  Index: NodeManager.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  
  /**
   * Test class for PojoCache for circular references.
   * Link is a POJO that will be instrumentet with CacheFieldInterceptor
   *
   * @version $Revision: 1.1 $
   *          <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
   *          conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
   *          so a annoc Ant build target is needed to pre-compile it.</p>
   *          <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class NodeManager
  {
     private TestNode rootNode_;
  
     private Map nodeMap_ = new HashMap();
  
     public NodeManager()
     {
     }
  
     public void setRootNode(String rdn)
     {
        this.rootNode_ = new TestNode();
        rootNode_.setNodeFDN(rdn);
        rootNode_.setNodeRDN(rdn);
  
        registMap(rootNode_);
     }
  
     public void addNode(String parentFdn, String rdn)
     {
        TestNode parent = findNode(parentFdn);
        if (parent != null)
        {
           TestNode node = new TestNode();
           node.setNodeFDN(parentFdn + "." + rdn);
           node.setNodeRDN(rdn);
  
           node.setParentNode(parent);
           parent.addChildNode(node);
  
           registMap(node);
        }
     }
  
     public TestNode findNode(String fdn)
     {
        return (TestNode) nodeMap_.get(fdn);
     }
  
     private void registMap(TestNode node)
     {
        this.nodeMap_.put(node.getNodeFDN(), node);
     }
  
     public void printNodes()
     {
        printNode(rootNode_, "");
     }
  
     private void printNode(TestNode node, String prefix)
     {
        System.out.println(prefix + node.getNodeRDN());
  
        String childPrefix = prefix + " + ";
        List children = node.getChildren();
        int size = children.size();
        for (int idx = 0; idx < size; idx++)
        {
           TestNode child = (TestNode) children.get(idx);
           printNode(child, childPrefix);
        }
     }
  
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/NetworkNode.java
  
  Index: NetworkNode.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Usually corresponds to the physical machine that comparises of various devices.
   * <p>This object is used to illustrate the pojo cache capability of PojoCache. Note the absence of <code>Serializable</code>
   * interface.</p>
   *
   * @author <a href="mailto:ben.wang at jboss.com">Ben Wang</a>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class NetworkNode
  {
     String name_;
     List elements_;
     String ipAddress_;
  
     public String getName()
     {
        return name_;
     }
  
     public void setName(String name)
     {
        name_ = name;
     }
  
     public List getElements()
     {
        return elements_;
     }
  
     protected void setElements(List elements)
     {
        elements_ = elements;
     }
  
     public void addElement(NetworkElement element)
     {
        if (elements_ == null)
           elements_ = new ArrayList();
  
        elements_.add(element);
        element.setParentNode(this);
     }
  
     public String getIpAddress()
     {
        return ipAddress_;
     }
  
     public void setIpAddress(String ipAddress)
     {
        ipAddress_ = ipAddress;
     }
  
     public String toString()
     {
        StringBuffer sb = new StringBuffer();
        sb.append(" name= ").append(getName()).append(" ipAddress= ").append(getIpAddress());
        sb.append(" elements=").append(getElements());
        return sb.toString();
     }
  
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/NetworkElement.java
  
  Index: NetworkElement.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  import java.util.Date;
  
  /**
   * Can represent both software or devices (e.g., sensor).
   * <p>This object is used to illustrate the pojo cache capability of PojoCache. Note the absence of <code>Serializable</code>
   * interface.</p>
   *
   * @author <a href="mailto:ben.wang at jboss.com">Ben Wang</a>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class NetworkElement
  {
     // Unique id
     int id_;
     // Element type
     int type_;
     String name_;
     int status_;
     Date startDate_;
     NetworkNode parentNode_;
  
     public int getId()
     {
        return id_;
     }
  
     public void setId(int id)
     {
        id_ = id;
     }
  
     public int getType()
     {
        return type_;
     }
  
     public void setType(int type)
     {
        type_ = type;
     }
  
     public String getName()
     {
        return name_;
     }
  
     public void setName(String name)
     {
        name_ = name;
     }
  
     public int getStatus()
     {
        return status_;
     }
  
     public void setStatus(int status)
     {
        status_ = status;
     }
  
     public Date getStartDate()
     {
        return startDate_;
     }
  
     public void setStartDate(Date startDate)
     {
        startDate_ = startDate;
     }
  
     public NetworkNode getParentNode()
     {
        return parentNode_;
     }
  
     public void setParentNode(NetworkNode parentNode)
     {
        parentNode_ = parentNode;
     }
  
     public String toString()
     {
        StringBuffer sb = new StringBuffer();
        sb.append(" name= ").append(getName()).append(" status= ").append(getStatus());
        sb.append(" parentNode= ").append(getParentNode().getName());
        return sb.toString();
     }
  
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/EnumPlanet.java
  
  Index: EnumPlanet.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this software; if not, write to the Free
   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  /**
   * Test class for PojoCache Enum.
   *
   * @version $Revision: 1.1 $
   *          <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
   *          conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
   *          so a annoc Ant build target is needed to pre-compile it.</p>
   *          <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public enum EnumPlanet
  {
     MERCURY(3.303e+23, 2.4397e6),
     VENUS(4.869e+24, 6.0518e6),
     EARTH(5.976e+24, 6.37814e6),
     MARS(6.421e+23, 3.3972e6),
     JUPITER(1.9e+27, 7.1492e7),
     SATURN(5.688e+26, 6.0268e7),
     URANUS(8.686e+25, 2.5559e7),
     NEPTUNE(1.024e+26, 2.4746e7);
  
     private double mass;   // in kilograms
     private double radius; // in meters
  
     // Need this for PojoCache. Can be private as well!
     EnumPlanet() {;}
  
     EnumPlanet(double mass, double radius)
     {
        this.mass = mass;
        this.radius = radius;
     }
  
     public double mass()
     {
        return mass;
     }
  
     public double radius()
     {
        return radius;
     }
  
     public void setMass(double mass)
     {
        this.mass = mass;
     }
  
     public void setRadius(double radius)
     {
        this.radius = radius;
     }
  
     // universal gravitational constant  (m3 kg-1 s-2)
     public static final double G = 6.67300E-11;
  
     public double surfaceGravity()
     {
        return G * mass / (radius * radius);
     }
  
     public double surfaceWeight(double otherMass)
     {
        return otherMass * surfaceGravity();
     }
  
     public static void main(String[] args)
     {
        double earthWeight = Double.parseDouble(args[0]);
        double mass = earthWeight / EARTH.surfaceGravity();
        for (EnumPlanet p : EnumPlanet.values())
           System.out.printf("Weight on %s is %f%n",
                   p, p.surfaceWeight(mass));
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/ValueObject.java
  
  Index: ValueObject.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  /**
   * Object to test non-primitive key.
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class ValueObject
  {
  
     private IdObject idObj;
     private float value;
  
     public ValueObject()
     {
     } // ValueObject
  
     public ValueObject(IdObject aIdObj, float aValue)
     {
        idObj = aIdObj;
        value = aValue;
     } // ValueObject
  
     public IdObject getIdObj()
     {
        return idObj;
     }
  
     public float getValue()
     {
        return value;
     }
  
     public String toString()
     {
        return idObj + ": " + value;
     } // toString
  
     public boolean equals(Object aObject)
     {
        boolean result = false;
  
        if ((aObject != null) &&
                (aObject.getClass().getName().equals(this.getClass().getName())))
        {
           result = idObj.equals(((ValueObject) aObject).idObj);
        } // if
  
        return result;
     } // equals
  
     public int hashCode()
     {
        return idObj.hashCode();
     } // hashCode
  } // class ValueObject
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/Link.java
  
  Index: Link.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  
  /**
   * Test class for PojoCache for circular references.
   * Link is a POJO that will be instrumentet with CacheFieldInterceptor
   *
   * @version $Revision: 1.1 $
   *          <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
   *          conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
   *          so a annoc Ant build target is needed to pre-compile it.</p>
   *          <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class Link
  {
     Link link_;
     String name_;
  
     public Link()
     {
     }
  
     public Link(String name)
     {
        name_ = name;
     }
  
     public void setName(String linkName)
     {
        name_ = linkName;
     }
  
     public String getName()
     {
        return name_;
     }
  
     public void setLink(Link link)
     {
        link_ = link;
     }
  
     public Link getLink()
     {
        return link_;
     }
  
     public String toString()
     {
        StringBuffer buf = new StringBuffer();
        buf.append("Link: name " + name_);
        return buf.toString();
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/ArrayObject.java
  
  Index: ArrayObject.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  /**
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class ArrayObject
  {
     private Person[] team;
  
     public ArrayObject()
     {
        team = new Person[10];
     }
  
     public Person[] getTeam()
     {
        return team;
     }
  
     public void setTeam(Person[] t)
     {
        team = t;
     }
  
     public Person getPerson(int index)
     {
        return team[index];
     }
  
     public void setPerson(int index, Person p)
     {
        team[index] = p;
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/Student.java
  
  Index: Student.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  
  /**
   * Test class for PojoCache.
   * Student is a POJO that will be instrumentet with CacheFieldInterceptor
   *
   * @version $Revision: 1.1 $
   *          No need to declare annotation here since Person is an instanceof already.
   */
  public class Student extends Person
  {
  
     private String year;
     // co is Serializable not Advised
     private CacheObject co1;
     private CacheObject co2;
  
     public String getYear()
     {
        return year;
     }
  
     public void setYear(String year)
     {
        this.year = year;
     }
  
     public CacheObject getCO1()
     {
        return co1;
     }
  
     public void setCO1(CacheObject co)
     {
        this.co1 = co;
     }
  
     public CacheObject getCO2()
     {
        return co2;
     }
  
     public void setCO2(CacheObject co)
     {
        this.co2 = co;
     }
  
     public String toString()
     {
        return "year=" + getYear() + " " + super.toString();
     }
  
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/Resource.java
  
  Index: Resource.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  /**
   * Test class for PojoCache using annotation. This represents a special resource
   * type that can be declared @Transient. That is, it is neither Replicable nor
   * Serializable.
   *
   * @version $Revision: 1.1 $
   */
  @org.jboss.cache.pojo.annotation.Replicable
  public class Resource
  {
     String connection = null;
     String name = null;
  // Can turin it on for performance optimization
  //   @org.jboss.cache.pojo.annotation.Serializable
     byte[] bin = null;
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
  
     public String getConnection()
     {
        return connection;
     }
  
     public void setConnection(String connection)
     {
        this.connection = connection;
     }
  
     public byte[] getByte()
     {
        return bin;
     }
  
     public void setByte(byte[] b)
     {
        bin = b;
     }
  
     public String toString()
     {
        return "name=" + getName() + ", type=" + getConnection() + " bytes= " +bin.toString();
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/SpecialAddress.java
  
  Index: SpecialAddress.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  import java.io.Serializable;
  
  /**
   * Test class for PojoCache. Note that this pojo is both Replicable and Serializable. So
   * user can choose whether to treat this as a Pojo or just a serializable object.
   *
   * @version $Revision: 1.1 $
   */
  @org.jboss.cache.pojo.annotation.Replicable
  public class SpecialAddress implements Serializable
  {
     String addr = null;
  
     public String getAddr()
     {
        return addr;
     }
  
     public void setAddr(String address)
     {
        this.addr = address;
     }
  
     public String toString()
     {
        return "address=" + getAddr();
     }
  
  //    public Object writeReplace() {
  //	return this;
  //    }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/Gadget.java
  
  Index: Gadget.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  import org.jboss.cache.pojo.annotation.Serializable;
  import org.jboss.cache.pojo.annotation.Transient;
  
  /**
   * Test class for PojoCache using annotation. This object consists of sub-objects
   * that has special annotation.
   *
   * @version $Revision: 1.1 $
   */
  @org.jboss.cache.pojo.annotation.Replicable
  public class Gadget
  {
     String name;
     @Transient
     Resource resource;
     @Serializable
     SpecialAddress addr;
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
  
     public Resource getResource()
     {
        return resource;
     }
  
     public void setResource(Resource resource)
     {
        this.resource = resource;
     }
  
     public SpecialAddress getAddr()
     {
        return addr;
     }
  
     public void setAddr(SpecialAddress addr)
     {
        this.addr = addr;
     }
  
     public String toString()
     {
        return "name=" + getName() + ", resource=" + getResource() + ", SepcialAddress: " + getAddr();
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/NonSerializableObject.java
  
  Index: NonSerializableObject.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.cache.pojo.test;
  
  /**
   * A non-serializable object
   */
  public class NonSerializableObject {
  
     private String id;
  
     public String getId() {
        return id;
     }
  
     public void setId(String id) {
        this.id = id;
     }
  
    public NonSerializableObject()  {
    }
  
    public NonSerializableObject(String aId)  {
      id = aId;
    }
  
  
    public String toString()  {
      return id;
    }
  
    public boolean equals(Object aObject)  {
      boolean result = false;
  
      if ((aObject != null) &&
           (aObject.getClass().getName().equals( this.getClass().getName()))) {
        if (id.equals(((NonSerializableObject)aObject).id)) {
          result = true;
        } // if
      } // if
  
      return result;
    } // equals
  
    public int hashCode()  {
      return id.hashCode();
    } // hashCode
  } // class IdObject
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/SerializedAddress.java
  
  Index: SerializedAddress.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  import java.io.Serializable;
  
  
  /**
   * Test class for PojoCache.
   *
   * @version $Revision: 1.1 $
   */
  public class SerializedAddress implements Serializable
  {
     String street = null;
     String city = null;
     int zip = 0;
  
     public String getStreet()
     {
        return street;
     }
  
     public void setStreet(String street)
     {
        this.street = street;
     }
  
     public String getCity()
     {
        return city;
     }
  
     public void setCity(String city)
     {
        this.city = city;
     }
  
     public int getZip()
     {
        return zip;
     }
  
     public void setZip(int zip)
     {
        this.zip = zip;
     }
  
     public String toString()
     {
        return "street=" + getStreet() + ", city=" + getCity() + ", zip=" + getZip();
     }
  
  //    public Object writeReplace() {
  //	return this;
  //    }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/Person.java
  
  Index: Person.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  
  /**
   * Test class for PojoCache.
   * Person is a POJO that will be instrumented with CacheFieldInterceptor
   *
   * @version $Revision: 1.1 $
   *          <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
   *          conjunction with a special jboss-aop.xml (supplied by PojoCache). In addition, this is JDK1.4 style,
   *          so a annoc Ant build target is needed to pre-compile it.</p>
   *          <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class Person
  {
     String name = null;
     int age = 0;
     Map<String, String> hobbies = null;
     Address address = null;
     Set<String> skills;
     List<String> languages;
     // Test for transient field non-replication
     transient String currentStatus = "Active";
     // Test swapping out the Collection ref with proxy one
     // medication will be different when age limit is exceeded.
     List<String> medication = null;
     static final int AGE1 = 50;
     static final int AGE2 = 60;
  
     public Person()
     {
  
     }
  
     public String getName()
     {
        return name;
     }
  
     public void setName(String name)
     {
        this.name = name;
     }
  
     public void setCurrentStatus(String status)
     {
        currentStatus = status;
     }
  
     public String getCurrentStatus()
     {
        return currentStatus;
     }
  
     public void setName(Object obj)
     {
        this.name = (String) obj;
     }
  
     public int getAge()
     {
        return age;
     }
  
     public void setAge(int age)
     {
  
        this.age = age;
  
        // This will swap out the reference dynamically
        if (age < AGE1)
        {
           if (medication != null)
           {
              medication.clear();
              medication = null;
           }
        } else
        {
           if (age >= AGE1)
           {
              addMedication("Lipitor");
           }
  
           if (age >= AGE2)
           {
              addMedication("Vioxx");
           }
        }
  
  
     }
  
     void addMedication(String name)
     {
        if (medication == null)
           medication = new ArrayList();
        if (!medication.contains(name))
           medication.add(name);
     }
  
     public Map<String, String> getHobbies()
     {
        return hobbies;
     }
  
     public void setHobbies(Map hobbies)
     {
        this.hobbies = hobbies;
     }
  
     public Address getAddress()
     {
        return address;
     }
  
     public void setAddress(Address address)
     {
        this.address = address;
     }
  
     public Set<String> getSkills()
     {
        return skills;
     }
  
     public void setSkills(Set skills)
     {
        this.skills = skills;
     }
  
     public List<String> getMedication()
     {
        return medication;
     }
  
     public void setMedication(List medication)
     {
        this.medication = medication;
     }
  
     public List<String> getLanguages()
     {
        return languages;
     }
  
     public void setLanguages(List languages)
     {
        this.languages = languages;
     }
  
     public String toString()
     {
        StringBuffer sb = new StringBuffer();
        sb.append("name=").append(getName()).append(", age=").append(getAge()).append(", hobbies=")
                .append(print(getHobbies())).append(", address=").append(getAddress()).append(", skills=")
                .append(skills).append(", languages=").append(languages).toString();
        if (medication != null)
           sb.append(", medication=" + medication);
        return sb.toString();
     }
  
     public String print(Map m)
     {
        StringBuffer sb = new StringBuffer();
        Map.Entry entry;
        if (m != null)
        {
           for (Iterator it = m.entrySet().iterator(); it.hasNext();)
           {
              entry = (Map.Entry) it.next();
              sb.append(entry.getKey()).append(": ").append(entry.getValue());
              sb.append("\n");
           }
        }
        return sb.toString();
     }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/IdObject.java
  
  Index: IdObject.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  /**
   * Key object that overrides the hashCode that can cause problem for aop.
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class IdObject
  {
  
     private String id;
  
     public IdObject()
     {
     } // IdObject
  
     public IdObject(String aId)
     {
        id = aId;
     } // IdObject
  
  
     public String toString()
     {
        return id;
     } // toString
  
     public boolean equals(Object aObject)
     {
        boolean result = false;
  
        if ((aObject != null) &&
                (aObject.getClass().getName().equals(this.getClass().getName())))
        {
           if (id.equals(((IdObject) aObject).id))
           {
              result = true;
           } // if
        } // if
  
        return result;
     } // equals
  
     public int hashCode()
     {
        return id.hashCode();
     } // hashCode
  } // class IdObject
  
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/Address.java
  
  Index: Address.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.cache.pojo.test;
  
  
  /**
   * Test class for PojoCache.
   *
   * @version $Revision: 1.1 $
   *          <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
   *          conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
   *          so a annoc Ant build target is needed to pre-compile it.</p>
   *          <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
   */
  // We are using JDK1.5 annotation.
  @org.jboss.cache.pojo.annotation.Replicable
  public class Address
  {
     String street = null;
     String city = null;
     int zip = 0;
  
     public String getStreet()
     {
        return street;
     }
  
     public void setStreet(String street)
     {
        this.street = street;
     }
  
     public String getCity()
     {
        return city;
     }
  
     public void setCity(String city)
     {
        this.city = city;
     }
  
     public int getZip()
     {
        return zip;
     }
  
     public void setZip(int zip)
     {
        this.zip = zip;
     }
  
     public String toString()
     {
        return "street=" + getStreet() + ", city=" + getCity() + ", zip=" + getZip();
     }
  
  //    public Object writeReplace() {
  //	return this;
  //    }
  }
  
  
  
  1.1      date: 2007/01/13 15:55:01;  author: bwang;  state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/test/TestNode.java
  
  Index: TestNode.java
  ===================================================================
  package org.jboss.cache.pojo.test;
  
  import java.util.ArrayList;
  import java.util.List;
  
  @org.jboss.cache.pojo.annotation.Replicable
  public class TestNode
  {
     private String rdn_;
  
     private String fdn_;
  
     private List childNodes_ = new ArrayList();
  
     private TestNode parentNode_;
  
     public TestNode()
     {
     }
  
     public void setNodeRDN(String rdn)
     {
        this.rdn_ = rdn;
     }
  
     public String getNodeRDN()
     {
        return this.rdn_;
     }
  
     public void setNodeFDN(String fdn)
     {
        this.fdn_ = fdn;
     }
  
     public String getNodeFDN()
     {
        return this.fdn_;
     }
  
     public void addChildNode(TestNode child)
     {
        childNodes_.add(child);
     }
  
     public List getChildren()
     {
        return childNodes_;
     }
  
     public void setParentNode(TestNode parent)
     {
        parentNode_ = parent;
     }
  
     public TestNode getParentNode()
     {
        return this.parentNode_;
     }
  
     public String toString()
     {
        return getNodeFDN();
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list