[jboss-cvs] JBossAS SVN: r104556 - in projects/metadata/ejb/trunk/src: main/java/org/jboss/metadata/ejb/util and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 7 04:52:20 EDT 2010


Author: wolfc
Date: 2010-05-07 04:52:17 -0400 (Fri, 07 May 2010)
New Revision: 104556

Added:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Child.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildClassAdapter.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildrenList.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Parent.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/ChildrenListTestCase.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockChild.java
   projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockParent.java
Removed:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java
Modified:
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java
   projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java
Log:
JBMETA-281: removed reflection of setOwner method

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Child.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Child.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Child.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.util;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface Child<P extends Parent>
+{
+   P getParent();
+
+   void setParent(P parent);
+}

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildClassAdapter.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildClassAdapter.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildClassAdapter.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.util;
+
+/**
+ * Because the child object might not implement Child, we need
+ * a ChildClassAdapter.
+ * 
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface ChildClassAdapter<C, P>
+{
+   P getParent(C child);
+   
+   void setParent(C child, P parent);
+}

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildrenList.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildrenList.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/ChildrenList.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.util;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * List of elements that represent Child objects.
+ *
+ * Note that the list does not truly contain Child objects, but rather
+ * objects which are adapted to become Child objects via a ChildClassAdapter.
+ * 
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class ChildrenList<E, P> extends AbstractList<E>
+{
+   private static ChildClassAdapter<?, ?> defaultChildClassAdapter = new ChildClassAdapter<Child<Parent>, Parent<?>>() {
+      @Override
+      public Parent<?> getParent(Child<Parent> child)
+      {
+         return child.getParent();
+      }
+
+      @Override
+      public void setParent(Child<Parent> child, Parent<?> parent)
+      {
+         child.setParent(parent);
+      }
+   };
+   
+   private ChildClassAdapter<E, P> childClassAdapter;
+   
+   private List<E> delegate;
+
+   private P parent;
+
+   public ChildrenList(P parent)
+   {
+      this(parent, (ChildClassAdapter<E, P>) defaultChildClassAdapter);
+   }
+
+   public ChildrenList(P parent, ChildClassAdapter<E, P> childClassAdapter)
+   {
+      this.childClassAdapter = childClassAdapter;
+      this.delegate = new ArrayList<E>();
+      this.parent = parent;
+   }
+
+   @Override
+   public boolean add(E e)
+   {
+      boolean success = delegate.add(e);
+      if(success)
+      {
+         childClassAdapter.setParent(e, parent);
+      }
+      return success;
+   }
+
+   @Override
+   public E get(int index)
+   {
+      return delegate.get(index);
+   }
+
+   @Override
+   public int size()
+   {
+      return delegate.size();
+   }
+}

Added: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Parent.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Parent.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/ejb/util/Parent.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.util;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public interface Parent<C extends Child>
+{
+   Collection<C> getChildren();
+}

Deleted: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java	2010-05-07 07:43:34 UTC (rev 104555)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/OwnerReferencePatchingList.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -1,193 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2010, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.metadata.jpa.spec;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- * List of elements, where the Object holding the list (or logically owning it), is
- * passed to each List element (as they are added to the list).
- *
- * The owner of the list is specified via the OwnerReferencePatchingList.setOwner(Object).
- *
- * The owner of the list is passed to each element via reflection.  OwnerReferencePatchingList.add(T t) will
- * invoke the t.setOwner(Object) method (passing the owner).  A IllegalArgumentException is thrown if that doesn't work.
- * 
- * @author <a href="mailto:smarlow at redhat.com">Scott Marlow</a>
- */
-public class OwnerReferencePatchingList<T> implements List<T>
-{
-   private List<T> list = new ArrayList();
-   private Object owner;
-
-   protected void setOwner(Object owner) {
-      if (owner == null)
-         throw new IllegalArgumentException("Null owner");
-      this.owner = owner;
-   }
-
-   public boolean add(T t)
-   {
-      Method setOwner = null;
-      try {
-         setOwner = t.getClass().getMethod("setOwner",Object.class);
-      } catch (NoSuchMethodException e) {
-         throw new IllegalArgumentException("cannot add type " + t.getClass().getName() + ", must have setOwner(Object) method", e);
-      }
-      try {
-         setOwner.invoke(t, owner );
-      } catch (IllegalAccessException e) {
-         throw new IllegalArgumentException("cannot add type " + t.getClass().getName() + ", couldn't call setOwner(Object) method", e);
-      } catch (InvocationTargetException e) {
-         throw new IllegalArgumentException("cannot add type " + t.getClass().getName() + ", could not call setOwner(Object) method", e);
-      }
-      return list.add(t);
-   }
-
-   public boolean addAll(Collection<? extends T> c)
-   {
-      //return list.addAll(c);
-      throw new UnsupportedOperationException("addAll(Collection) is not implemented");
-   }
-
-   public boolean addAll(int index, Collection<? extends T> c)
-   {
-      // return list.addAll(index, c);
-      throw new UnsupportedOperationException("addAll(int, Collection) is not implemented");
-   }
-
-   public int size()
-   {
-      return list.size();
-   }
-
-   public boolean isEmpty()
-   {
-      return list.isEmpty();
-   }
-
-   public boolean contains(Object o)
-   {
-      return list.contains(o);
-   }
-
-   public Iterator<T> iterator()
-   {
-      return list.iterator();
-   }
-
-   public Object[] toArray()
-   {
-      return list.toArray();
-   }
-
-   public <T> T[] toArray(T[] a)
-   {
-      return list.toArray(a);
-   }
-
-   public boolean remove(Object o)
-   {
-      return list.remove(o);
-   }
-
-   public boolean containsAll(Collection<?> c)
-   {
-      return list.containsAll(c);
-   }
-
-   public boolean removeAll(Collection<?> c)
-   {
-      return list.removeAll(c);
-   }
-
-   public boolean retainAll(Collection<?> c)
-   {
-      return list.retainAll(c);
-   }
-
-   public void clear()
-   {
-      list.clear();
-   }
-
-   public boolean equals(Object o)
-   {
-      return list.equals(o);
-   }
-
-   public int hashCode()
-   {
-      return list.hashCode();
-   }
-
-   public T get(int index)
-   {
-      return list.get(index);
-   }
-
-   public T set(int index, T element)
-   {
-      return list.set(index, element);
-   }
-
-   public void add(int index, T element)
-   {
-      list.add(index, element);
-   }
-
-   public T remove(int index)
-   {
-      return list.remove(index);
-   }
-
-   public int indexOf(Object o)
-   {
-      return list.indexOf(o);
-   }
-
-   public int lastIndexOf(Object o)
-   {
-      return list.lastIndexOf(o);
-   }
-
-   public ListIterator<T> listIterator()
-   {
-      return list.listIterator();
-   }
-
-   public ListIterator<T> listIterator(int index)
-   {
-      return list.listIterator(index);
-   }
-
-   public List<T> subList(int fromIndex, int toIndex)
-   {
-      return list.subList(fromIndex, toIndex);
-   }
-}

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java	2010-05-07 07:43:34 UTC (rev 104555)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceMetaData.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -21,18 +21,15 @@
 */
 package org.jboss.metadata.jpa.spec;
 
-import java.io.Serializable;
-
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlNsForm;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
+import org.jboss.metadata.ejb.util.ChildrenList;
 import org.jboss.util.JBossObject;
 import org.jboss.util.JBossStringBuilder;
 import org.jboss.xb.annotations.JBossXmlSchema;
 
+import javax.xml.bind.annotation.*;
+import java.io.Serializable;
+import java.util.List;
+
 /**
  * The persistence metadata.
  * 
@@ -48,7 +45,7 @@
 public class PersistenceMetaData extends JBossObject implements Serializable
 {
    private String version;
-   private OwnerReferencePatchingList<PersistenceUnitMetaData> persistenceUnits;
+   private ChildrenList<PersistenceUnitMetaData, PersistenceMetaData> persistenceUnits = new ChildrenList<PersistenceUnitMetaData, PersistenceMetaData>(this, PersistenceUnitMetaData.adapter);
 
    public String getVersion()
    {
@@ -61,20 +58,12 @@
       this.version = version;
    }
 
-   public OwnerReferencePatchingList<PersistenceUnitMetaData> getPersistenceUnits()
+   @XmlElement(name = "persistence-unit")
+   public List<PersistenceUnitMetaData> getPersistenceUnits()
    {
       return persistenceUnits;
    }
 
-   @XmlElement(name = "persistence-unit")
-   public void setPersistenceUnits(OwnerReferencePatchingList<PersistenceUnitMetaData> persistenceUnits)
-   {
-      if(  persistenceUnits == null)
-         throw new IllegalArgumentException("Null persistenceUnits");
-      this.persistenceUnits = persistenceUnits;
-      this.persistenceUnits.setOwner(this);
-   }
-
    protected void toString(JBossStringBuilder builder)
    {
       builder.append("version=").append(version);
@@ -85,12 +74,9 @@
    public PersistenceMetaData clone()
    {
       PersistenceMetaData clone = (PersistenceMetaData)super.clone();
-      clone.setPersistenceUnits(new OwnerReferencePatchingList<PersistenceUnitMetaData>());
-      if (persistenceUnits != null)
-      {
-         for (PersistenceUnitMetaData unit : persistenceUnits)
-            clone.getPersistenceUnits().add(unit.clone());
-      }
+      clone.persistenceUnits = new ChildrenList<PersistenceUnitMetaData, PersistenceMetaData>(clone, PersistenceUnitMetaData.adapter);
+      for (PersistenceUnitMetaData unit : persistenceUnits)
+         clone.persistenceUnits.add(unit.clone());
       return clone;
    }
 }

Modified: projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java
===================================================================
--- projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java	2010-05-07 07:43:34 UTC (rev 104555)
+++ projects/metadata/ejb/trunk/src/main/java/org/jboss/metadata/jpa/spec/PersistenceUnitMetaData.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -21,23 +21,23 @@
 */
 package org.jboss.metadata.jpa.spec;
 
+import org.jboss.metadata.ejb.util.ChildClassAdapter;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+import org.jboss.xb.annotations.JBossXmlMapEntry;
+import org.jboss.xb.annotations.JBossXmlMapKeyAttribute;
+import org.jboss.xb.annotations.JBossXmlMapValueAttribute;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlType;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.XmlType;
-
-import org.jboss.util.JBossObject;
-import org.jboss.util.JBossStringBuilder;
-import org.jboss.xb.annotations.JBossXmlMapEntry;
-import org.jboss.xb.annotations.JBossXmlMapKeyAttribute;
-import org.jboss.xb.annotations.JBossXmlMapValueAttribute;
-
 /**
  * The persistence unit metadata.
  *
@@ -63,6 +63,24 @@
 
    private PersistenceMetaData persistenceMetaData;
 
+   static class Adapter implements ChildClassAdapter<PersistenceUnitMetaData, PersistenceMetaData>
+   {
+      @Override
+      public PersistenceMetaData getParent(PersistenceUnitMetaData child)
+      {
+         return child.persistenceMetaData;
+      }
+
+      @Override
+      public void setParent(PersistenceUnitMetaData child, PersistenceMetaData parent)
+      {
+         if(child.persistenceMetaData != null && parent != null)
+            throw new IllegalArgumentException("Can't set parent " + parent + " already got " + child.persistenceMetaData);
+         child.persistenceMetaData = parent;
+      }
+   }
+   static Adapter adapter = new Adapter();
+
    @XmlElement
    public SharedCacheMode getSharedCacheMode()
    {
@@ -214,15 +232,6 @@
       return persistenceMetaData;
    }
 
-   /**
-    * Do not call directly (should only be called by OwnerReferencePatchingList).
-    * @param owner is expected to be a PersistenceMetaData
-    */
-   public void setOwner(Object owner)
-   {
-      this.persistenceMetaData = (PersistenceMetaData) owner;
-   }
-
    protected void toString(JBossStringBuilder builder)
    {
       builder.append("provider=").append(provider);
@@ -253,6 +262,8 @@
          clone.setClasses(new HashSet<String>(classes));
       if (properties != null)
          clone.setProperties(new HashMap<String, String>(properties));
+      // make the clone an orphan
+      clone.persistenceMetaData = null;
       return clone;
    }
 }

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/ChildrenListTestCase.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/ChildrenListTestCase.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/ChildrenListTestCase.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.test.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class ChildrenListTestCase
+{
+   @Test
+   public void testAddChild()
+   {
+      MockParent parent = new MockParent();
+      // first an orphan
+      MockChild child = new MockChild();
+      // now adopted
+      boolean success = parent.getChildren().add(child);
+      assertTrue(success);
+      assertEquals(parent, child.getParent());
+   }
+}

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockChild.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockChild.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockChild.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.test.util;
+
+import org.jboss.metadata.ejb.util.Child;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class MockChild implements Child<MockParent>
+{
+   private MockParent parent;
+   
+   @Override
+   public MockParent getParent()
+   {
+      return parent;
+   }
+
+   @Override
+   public void setParent(MockParent parent)
+   {
+      if(this.parent != null && parent != null)
+         throw new IllegalArgumentException("Can't set parent " + parent + " already got " + this.parent);
+      this.parent = parent;
+   }
+}

Added: projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockParent.java
===================================================================
--- projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockParent.java	                        (rev 0)
+++ projects/metadata/ejb/trunk/src/test/java/org/jboss/metadata/ejb/test/util/MockParent.java	2010-05-07 08:52:17 UTC (rev 104556)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.metadata.ejb.test.util;
+
+import org.jboss.metadata.ejb.util.ChildrenList;
+import org.jboss.metadata.ejb.util.Parent;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class MockParent implements Parent<MockChild>
+{
+   private List<MockChild> children = new ChildrenList<MockChild, MockParent>(this);
+   
+   @Override
+   public Collection<MockChild> getChildren()
+   {
+      return children;
+   }
+}




More information about the jboss-cvs-commits mailing list