KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > DefaultDependencyArtifactDescriptor


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy;
7
8 import java.net.URL JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Collection JavaDoc;
11
12 import fr.jayasoft.ivy.matcher.PatternMatcher;
13
14 public class DefaultDependencyArtifactDescriptor implements DependencyArtifactDescriptor {
15
16     private DefaultDependencyDescriptor _dd;
17     private ArtifactId _id;
18     private Collection JavaDoc _confs = new ArrayList JavaDoc();
19     private boolean _includes;
20     private PatternMatcher _patternMatcher;
21     private URL JavaDoc _url;
22     
23
24     
25     public DefaultDependencyArtifactDescriptor(DefaultDependencyDescriptor dd,
26             String JavaDoc name, String JavaDoc type, String JavaDoc ext, boolean includes, PatternMatcher matcher) {
27         this(dd, name, type, ext, null, includes, matcher);
28     }
29     /**
30      * @param dd
31      * @param name
32      * @param type
33      * @param url
34      */

35     public DefaultDependencyArtifactDescriptor(DefaultDependencyDescriptor dd,
36             String JavaDoc name, String JavaDoc type, String JavaDoc ext, URL JavaDoc url, boolean includes, PatternMatcher matcher) {
37         if (dd == null) {
38             throw new NullPointerException JavaDoc("dependency descriptor must not be null");
39         }
40         if (name == null) {
41             throw new NullPointerException JavaDoc("name must not be null");
42         }
43         if (type == null) {
44             throw new NullPointerException JavaDoc("type must not be null");
45         }
46         _dd = dd;
47         _id = new ArtifactId(dd.getDependencyId(), name, type, ext);
48         _includes = includes;
49         _url = url;
50         _patternMatcher = matcher;
51     }
52     
53     public DefaultDependencyArtifactDescriptor(DefaultDependencyDescriptor dd, ArtifactId aid, boolean includes, PatternMatcher matcher) {
54         if (dd == null) {
55             throw new NullPointerException JavaDoc("dependency descriptor must not be null");
56         }
57         _dd = dd;
58         _id = aid;
59         _includes = includes;
60         _patternMatcher = matcher;
61     }
62
63     public boolean equals(Object JavaDoc obj) {
64         if (!(obj instanceof DependencyArtifactDescriptor)) {
65             return false;
66         }
67         DependencyArtifactDescriptor dad = (DependencyArtifactDescriptor)obj;
68         return getId().equals(dad.getId());
69     }
70     
71     public int hashCode() {
72         return getId().hashCode();
73     }
74     
75     /**
76      * Add a configuration for this artifact (includes or excludes depending on this type dependency artifact descriptor).
77      * This method also updates the corresponding dependency descriptor
78      * @param conf
79      */

80     public void addConfiguration(String JavaDoc conf) {
81         _confs.add(conf);
82         if (_includes) {
83             _dd.addDependencyArtifactIncludes(conf, this);
84         } else {
85             _dd.addDependencyArtifactExcludes(conf, this);
86         }
87     }
88         
89     public DependencyDescriptor getDependency() {
90         return _dd;
91     }
92     
93     public ArtifactId getId() {
94         return _id;
95     }
96
97     public String JavaDoc getName() {
98         return _id.getName();
99     }
100
101     public String JavaDoc getType() {
102         return _id.getType();
103     }
104     public String JavaDoc getExt() {
105         return _id.getExt();
106     }
107
108     public String JavaDoc[] getConfigurations() {
109         return (String JavaDoc[])_confs.toArray(new String JavaDoc[_confs.size()]);
110     }
111
112     public PatternMatcher getMatcher() {
113         return _patternMatcher;
114     }
115
116     public URL JavaDoc getUrl() {
117         return _url;
118     }
119
120     public String JavaDoc toString() {
121         return (_includes?"I":"E")+":"+_id+"("+_confs+")"+(_url==null?"":_url.toString());
122     }
123 }
124
Popular Tags