KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > project > Depend


1 package net.sf.invicta.project;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import net.sf.invicta.api.ProductContainer;
7  
8 /**
9  * A depenency defined in a component definition.
10  * Acts as a java bean filled by the digester with the elements of a depend
11  * definition.
12  */

13 public class Depend extends DependItemImpl {
14     
15     // Resolve related members
16
private boolean isResolved;
17     private ProductContainer dependProducts = new ProductContainerImpl();
18     private ProductContainer recursiveProducts = new ProductContainerImpl();
19     private HashMap JavaDoc recursiveComponentNames = new HashMap JavaDoc();
20     private HashMap JavaDoc recursiveComponents = new HashMap JavaDoc();
21     private ComponentDefinition dependentComponent = null;
22
23     /**
24      * Constructor for Depend.
25      */

26     public Depend() {
27         super();
28     }
29
30     /**
31      *
32      * @param name
33      * @param export
34      */

35     public Depend(String JavaDoc name, boolean export) {
36         super(name, export);
37     }
38     
39     /**
40      * Resolve the dependency by finiding the dependent component and getting
41      * its products.
42      */

43     public void resolve(ProjectDefinition components, int level) throws InvictaProjectException {
44         if (this.isResolved)
45             return;
46         
47         // Resolve the dependent component.
48
this.dependentComponent =
49                 components.resolveComponent(this.name, level+1);
50
51         // If specific products were given, then add only them
52
// Otherwise, add all exported products of the dependent component.
53
if (this.getProductsList().size() > 0) {
54             addDependProducts(dependentComponent.getRecursiveSelfProducts(getProductsList()));
55             this.recursiveProducts.insertAll(dependentComponent.getRecursiveSelfProducts(getProductsList()));
56         } else {
57             addDependProducts(dependentComponent.getDependExportedProducts());
58             this.recursiveProducts.insertAll(dependentComponent.getRecursiveProducts());
59         }
60         
61         this.recursiveComponentNames.putAll(dependentComponent.getRecursiveDependComponentNamesMap());
62         this.recursiveComponentNames.put(dependentComponent.getName(), dependentComponent.getName());
63         this.recursiveComponents.putAll(dependentComponent.getRecursiveDependComponentsMap());
64         this.recursiveComponents.put(dependentComponent.getName(), dependentComponent);
65                 
66         isResolved = true;
67     }
68         
69             
70     /**
71      * If this depend is 'export' then returns an empty map, otherwise returns a
72      * map of the products.
73      *
74      * @return Map
75      */

76     public ProductContainer getPrivateProducts() {
77         if (this.export)
78             return new ProductContainerImpl();
79         else
80             return this.dependProducts;
81     }
82
83     /**
84      * If this depend is not 'export' then returns a map of the products,
85      * otherwise returns an empty map.
86      */

87     public ProductContainer getExportedProducts() {
88         if (!this.export)
89             return new ProductContainerImpl();
90         else
91             return this.dependProducts;
92     }
93
94     /**
95      *
96      * @return ProductContainer
97      */

98     public ProductContainer getRecursiveProducts() {
99         return this.recursiveProducts;
100     }
101
102     /**
103      *
104      * @return ProductContainer
105      */

106     public Map JavaDoc getRecursiveComponents() {
107         return this.recursiveComponentNames;
108     }
109
110     
111     /**
112      *
113      * @return ComponentDefinition
114      */

115     public ComponentDefinition getComponent() {
116         return this.dependentComponent;
117     }
118         
119     /**
120      *
121      * @param moreProducts
122      */

123     private void addDependProducts(ProductContainer moreProducts) {
124         this.dependProducts.insertAll(moreProducts);
125     }
126 }
127
Popular Tags