1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.maven.plugin.eclipse;
21
22 import org.codehaus.plexus.util.xml.XMLWriter;
23 import org.codehaus.plexus.util.xml.Xpp3Dom;
24
25
26
27
28
29
30 public class LinkedResource
31 {
32
33 private String name;
34
35
36 private String type;
37
38
39 private String location;
40
41
42 private String locationURI;
43
44 public String getName()
45 {
46 return name;
47 }
48
49 public void setName( String name )
50 {
51 this.name = name;
52 }
53
54 public String getType()
55 {
56 return type;
57 }
58
59 public void setType( String type )
60 {
61 this.type = type;
62 }
63
64 public String getLocation()
65 {
66 return location;
67 }
68
69 public void setLocation( String location )
70 {
71 this.location = location;
72 }
73
74 public String getLocationURI()
75 {
76 return locationURI;
77 }
78
79 public void setLocationURI( String locationURI )
80 {
81 this.locationURI = locationURI;
82 }
83
84
85
86
87 public LinkedResource()
88 {
89 super();
90 }
91
92
93
94
95
96
97
98
99 public LinkedResource( Xpp3Dom node )
100 {
101 Xpp3Dom nameNode = node.getChild( "name" );
102
103 if ( nameNode == null )
104 {
105 throw new IllegalArgumentException( "No name node." );
106 }
107
108 name = nameNode.getValue();
109
110 Xpp3Dom typeNode = node.getChild( "type" );
111
112 if ( typeNode == null )
113 {
114 throw new IllegalArgumentException( "No type node." );
115 }
116
117 type = typeNode.getValue();
118
119 Xpp3Dom locationNode = node.getChild( "location" );
120 Xpp3Dom locationURINode = node.getChild( "locationURI" );
121
122 if ( locationNode == null && locationURINode == null )
123 {
124 throw new IllegalArgumentException( "No location or locationURI node." );
125 }
126 else if ( locationNode != null && locationURINode != null )
127 {
128 throw new IllegalArgumentException( "Both location and locationURI nodes are set." );
129 }
130
131 if (locationNode != null)
132 {
133 location = locationNode.getValue();
134 }
135
136 if (locationURINode != null)
137 {
138 locationURI = locationURINode.getValue();
139 }
140 }
141
142 public void print( XMLWriter writer )
143 {
144 writer.startElement( "link" );
145
146 writer.startElement( "name" );
147 writer.writeText( name );
148 writer.endElement();
149
150 writer.startElement( "type" );
151 writer.writeText( type );
152 writer.endElement();
153
154 if ( location != null )
155 {
156 writer.startElement( "location" );
157 writer.writeText( location );
158 writer.endElement();
159 }
160 else if ( locationURI != null )
161 {
162 writer.startElement( "locationURI" );
163 writer.writeText( locationURI );
164 writer.endElement();
165 }
166 writer.endElement();
167 }
168
169 public boolean equals( Object obj )
170 {
171 if ( obj instanceof LinkedResource )
172 {
173 LinkedResource b = (LinkedResource) obj;
174
175 return name.equals( b.name ) && ( type == null ? b.type == null : type.equals( b.type ) )
176 && ( location == null ? b.location == null : location.equals( b.location ) )
177 && ( locationURI == null ? b.locationURI == null : locationURI.equals( b.locationURI ) );
178 }
179 else
180 {
181 return false;
182 }
183 }
184
185 public int hashCode()
186 {
187 return name.hashCode() + ( type == null ? 0 : 13 * type.hashCode() )
188 + ( location == null ? 0 : 17 * location.hashCode() )
189 + ( locationURI == null ? 0 : 19 * locationURI.hashCode() );
190 }
191 }