View Javadoc

    1   /*
    2    * joey-gen and its relative products are published under the terms
    3    * of the Apache Software License.
    4    *
    5    * Created on 2004/11/08 12:59:29
    6    */
    7   package org.asyrinx.joey.gen.model.java;
    8
    9   import java.util.ArrayList;
    10  import java.util.Iterator;
    11  import java.util.List;
    12
    13  import org.asyrinx.joey.gen.model.ElementSet;
    14
    15  /***
    16   * @author takeshi
    17   */
    18  public class ReferenceSet extends ElementSet {
    19
    20      /***
    21       * @param parent
    22       */
    23      public ReferenceSet(Entity parent) {
    24          super(parent);
    25      }
    26
    27      /*
    28       * (non-Javadoc)
    29       *
    30       * @see org.asyrinx.joey.gen.model.Element#isEntity()
    31       */
    32      public boolean isEntity() {
    33          return false;
    34      }
    35
    36      public void add(Reference reference) {
    37          super.add(reference);
    38      }
    39
    40      /*
    41       * (non-Javadoc)
    42       *
    43       * @see org.asyrinx.joey.gen.model.ElementSet#contains(org.asyrinx.joey.gen.model.Element)
    44       */
    45      public boolean contains(Reference reference) {
    46          return super.contains(reference);
    47      }
    48
    49      /*
    50       * (non-Javadoc)
    51       *
    52       * @see org.asyrinx.joey.gen.model.ElementSet#getElement(int)
    53       */
    54      public Reference getReference(int index) {
    55          return (Reference) super.getElement(index);
    56      }
    57
    58      /*
    59       * (non-Javadoc)
    60       *
    61       * @see org.asyrinx.joey.gen.model.ElementSet#get(java.lang.String)
    62       */
    63      public Reference getReference(String name) {
    64          return (Reference) super.getElement(name);
    65      }
    66
    67      /*
    68       * (non-Javadoc)
    69       *
    70       * @see org.asyrinx.joey.gen.model.ElementSet#remove(java.lang.String)
    71       */
    72      public Reference removeReference(String name) {
    73          return (Reference) super.removeElement(name);
    74      }
    75
    76      /***
    77       * @param property
    78       * @return
    79       */
    80      public List getReferencesContainedAsLocal(Property property) {
    81          final List result = new ArrayList();
    82          for (Iterator i = this.iterator(); i.hasNext();) {
    83              final Reference reference = (Reference) i.next();
    84              if (reference.containsAsLocal(property))
    85                  result.add(reference);
    86          }
    87          return result;
    88      }
    89
    90      /***
    91       * @param property
    92       * @return
    93       */
    94      public List getReferencesContainedAsForeign(Entity javaClass) {
    95          final List result = new ArrayList();
    96          for (Iterator i = this.iterator(); i.hasNext();) {
    97              final Reference reference = (Reference) i.next();
    98              if (reference.getReferenceClass() == javaClass)
    99                  result.add(reference);
    100         }
    101         return result;
    102     }
    103
    104     /***
    105      * @param javaClass
    106      * @param dest
    107      */
    108     public void findReferencesContainedAsForeign(Entity javaClass, List dest) {
    109         for (Iterator i = this.iterator(); i.hasNext();) {
    110             final Reference reference = (Reference) i.next();
    111             if (reference.getType() == ReferenceType.EXTENDS)
    112                 continue;
    113             if (reference.getReferenceClass() == javaClass)
    114                 dest.add(reference);
    115         }
    116     }
    117
    118     /***
    119      * @param javaClass
    120      * @param dest
    121      */
    122     public void findReferencesContainedAsLocal(Entity javaClass, List dest) {
    123         for (Iterator i = this.iterator(); i.hasNext();) {
    124             final Reference reference = (Reference) i.next();
    125             if (reference.getType() == ReferenceType.EXTENDS)
    126                 continue;
    127             if (reference.getParent() == javaClass)
    128                 dest.add(reference);
    129         }
    130     }
    131 }