KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > reflect > factory > SubFactory


1 package spoon.reflect.factory;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.Collection JavaDoc;
5
6 import spoon.reflect.Factory;
7 import spoon.reflect.declaration.CtElement;
8
9 /**
10  * This class is the superclass for all the sub-factories of
11  * {@link spoon.reflect.Factory}.
12  */

13 public abstract class SubFactory implements Serializable JavaDoc {
14
15     private static final long serialVersionUID = 1L;
16
17     Factory factory;
18
19     /**
20      * The sub-factory constructor takes an instance of the parent factory.
21      */

22     public SubFactory(Factory factory) {
23         super();
24         this.factory = factory;
25     }
26
27     /**
28      * Sets the parent factory (discouraged).
29      */

30     public void setFactory(Factory factory) {
31         this.factory = factory;
32     }
33
34     /**
35      * Generically sets the parent of a set of elements or lists of elements.
36      *
37      * @param parent
38      * the parent
39      * @param elements
40      * some {@link CtElement} or lists of {@link CtElement}
41      */

42     protected void setParent(CtElement parent, Object JavaDoc... elements) {
43         for (Object JavaDoc o : elements) {
44             if (o instanceof CtElement) {
45                 ((CtElement) o).setParent(parent);
46             } else if (o instanceof Collection JavaDoc) {
47                 for (Object JavaDoc o2 : (Collection JavaDoc) o) {
48                     ((CtElement) o2).setParent(parent);
49                 }
50             }
51         }
52     }
53
54 }
55
Popular Tags