KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > classpath > ClassPathSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbjarproject.classpath;
21
22 import java.io.File JavaDoc;
23 import java.net.URI JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.Arrays JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.LinkedList JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Set JavaDoc;
33 import org.openide.filesystems.FileObject;
34 import org.openide.filesystems.FileUtil;
35 import org.netbeans.api.project.ant.AntArtifact;
36 import org.netbeans.api.project.libraries.Library;
37 import org.netbeans.api.project.libraries.LibraryManager;
38 import org.netbeans.spi.project.support.ant.AntProjectHelper;
39 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
40 import org.netbeans.spi.project.support.ant.PropertyUtils;
41 import org.netbeans.spi.project.support.ant.ReferenceHelper;
42 import org.w3c.dom.Document JavaDoc;
43 import org.w3c.dom.Element JavaDoc;
44 import org.w3c.dom.Node JavaDoc;
45 import org.w3c.dom.NodeList JavaDoc;
46 import org.w3c.dom.Text JavaDoc;
47 import org.netbeans.modules.j2ee.ejbjarproject.EjbJarProjectType;
48 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
49
50 /**
51  *
52  * @author Petr Hrebejk
53  * @author Andrei Badea
54  */

55 public class ClassPathSupport {
56     
57     public final static String JavaDoc ELEMENT_INCLUDED_LIBRARIES = "included-library"; // NOI18N
58

59     private static String JavaDoc[] ejbjarElemOrder = new String JavaDoc[] { "name", "minimum-ant-version", "explicit-platform", "use-manifest", "included-library", "web-services", "source-roots", "test-roots" };
60     
61     private static final String JavaDoc ATTR_FILES = "files"; //NOI18N
62
private static final String JavaDoc ATTR_DIRS = "dirs"; //NOI18N
63

64     private PropertyEvaluator evaluator;
65     private ReferenceHelper referenceHelper;
66     private AntProjectHelper antProjectHelper;
67     private Set JavaDoc /*<String>*/ wellKnownPaths;
68     private String JavaDoc libraryPrefix;
69     private String JavaDoc librarySuffix;
70     private String JavaDoc antArtifactPrefix;
71         
72     /** Creates a new instance of ClassPathSupport */
73     public ClassPathSupport( PropertyEvaluator evaluator,
74                               ReferenceHelper referenceHelper,
75                               AntProjectHelper antProjectHelper,
76                               String JavaDoc wellKnownPaths[],
77                               String JavaDoc libraryPrefix,
78                               String JavaDoc librarySuffix,
79                               String JavaDoc antArtifactPrefix ) {
80         this.evaluator = evaluator;
81         this.referenceHelper = referenceHelper;
82         this.antProjectHelper = antProjectHelper;
83         this.wellKnownPaths = wellKnownPaths == null ? null : new HashSet JavaDoc( Arrays.asList( wellKnownPaths ) );
84         this.libraryPrefix = libraryPrefix;
85         this.librarySuffix = librarySuffix;
86         this.antArtifactPrefix = antArtifactPrefix;
87     }
88     
89     /** Creates list of <CODE>Items</CODE> from given property.
90      */

91     public Iterator JavaDoc /*<Item>*/ itemsIterator( String JavaDoc propertyValue, String JavaDoc includedLibrariesElement ) {
92         // XXX More performance frendly impl. would retrun a lazzy iterator.
93
return itemsList( propertyValue, includedLibrariesElement ).iterator();
94     }
95     
96     public List JavaDoc /*<Item>*/ itemsList( String JavaDoc propertyValue, String JavaDoc includedLibrariesElement ) {
97         
98         // Get the list of items which are included in deployment
99
List JavaDoc includedItems = ( includedLibrariesElement != null ) ?
100             getIncludedLibraries( antProjectHelper, includedLibrariesElement ) :
101             Collections.EMPTY_LIST;
102         
103         String JavaDoc pe[] = PropertyUtils.tokenizePath( propertyValue == null ? "": propertyValue ); // NOI18N
104
List JavaDoc items = new ArrayList JavaDoc( pe.length );
105         for( int i = 0; i < pe.length; i++ ) {
106             String JavaDoc property = EjbJarProjectProperties.getAntPropertyName( pe[i] );
107             Item item;
108
109             // First try to find out whether the item is well known classpath
110
if ( isWellKnownPath( pe[i] ) ) {
111                 // Some well know classpath
112
item = Item.create( pe[i], false );
113             }
114             else if ( isLibrary( pe[i] ) ) {
115                 //Library from library manager
116
String JavaDoc libraryName = pe[i].substring( libraryPrefix.length(), pe[i].lastIndexOf('.') ); //NOI18N
117
Library library = LibraryManager.getDefault().getLibrary( libraryName );
118                 if ( library == null ) {
119                     item = Item.createBroken( Item.TYPE_LIBRARY, pe[i], includedItems.contains( property ) );
120                 }
121                 else {
122                     item = Item.create( library, pe[i], includedItems.contains( property ) );
123                 }
124             }
125             else if ( isAntArtifact( pe[i] ) ) {
126                 // Ant artifact from another project
127
Object JavaDoc[] ret = referenceHelper.findArtifactAndLocation(pe[i]);
128                 if ( ret[0] == null || ret[1] == null ) {
129                     item = Item.createBroken( Item.TYPE_ARTIFACT, pe[i], includedItems.contains ( property ) );
130                 }
131                 else {
132                     //fix of issue #55391
133
AntArtifact artifact = (AntArtifact)ret[0];
134                     URI JavaDoc uri = (URI JavaDoc)ret[1];
135                     File JavaDoc usedFile = antProjectHelper.resolveFile(evaluator.evaluate(pe[i]));
136                     File JavaDoc artifactFile = new File JavaDoc (artifact.getScriptLocation().toURI().resolve(uri).normalize());
137                     if (usedFile.equals(artifactFile)) {
138                         item = Item.create( artifact, uri, pe[i], includedItems.contains ( property ) );
139                     }
140                     else {
141                         item = Item.createBroken( Item.TYPE_ARTIFACT, pe[i], includedItems.contains ( property ) );
142                     }
143                 }
144             } else {
145                 // Standalone jar or property
146
String JavaDoc eval = evaluator.evaluate( pe[i] );
147                 File JavaDoc f = null;
148                 if (eval != null) {
149                     f = antProjectHelper.resolveFile( eval );
150                 }
151                 
152                 if ( f == null || !f.exists() ) {
153                     item = Item.createBroken( Item.TYPE_JAR, pe[i], includedItems.contains ( property ) );
154                 }
155                 else {
156                     item = Item.create( f, pe[i], includedItems.contains ( property ) );
157                 }
158             }
159             
160             items.add( item );
161            
162         }
163
164         return items;
165         
166     }
167       
168     /** Converts list of classpath items into array of Strings.
169      * !! This method creates references in the project !!
170      * !! This method may add <included-library> items to project.xml !!
171      */

172     public String JavaDoc[] encodeToStrings( Iterator JavaDoc /*<Item>*/ classpath, String JavaDoc includedLibrariesElement ) {
173         
174         ArrayList JavaDoc result = new ArrayList JavaDoc();
175         ArrayList JavaDoc includedLibraries = new ArrayList JavaDoc();
176         
177         List JavaDoc cp = new LinkedList JavaDoc();
178         
179         while( classpath.hasNext() ) {
180
181             Item item = (Item)classpath.next();
182             cp.add(item);
183             String JavaDoc reference = null;
184             
185             switch( item.getType() ) {
186
187                 case Item.TYPE_JAR:
188                     reference = item.getReference();
189                     if ( item.isBroken() ) {
190                         break;
191                     }
192                     if (reference == null) {
193                         // New file
194
File JavaDoc file = item.getFile();
195                         // pass null as expected artifact type to always get file reference
196
reference = referenceHelper.createForeignFileReference(file, null);
197                         item.setReference(reference);
198                     }
199                     break;
200                 case Item.TYPE_LIBRARY:
201                     reference = item.getReference();
202                     if ( item.isBroken() ) {
203                         break;
204                     }
205                     Library library = item.getLibrary();
206                     if (reference == null) {
207                         if ( library == null ) {
208                             break;
209                         }
210                         reference = getLibraryReference( item );
211                         item.setReference(reference);
212                     }
213                     break;
214                 case Item.TYPE_ARTIFACT:
215                     reference = item.getReference();
216                     if ( item.isBroken() ) {
217                         break;
218                     }
219                     AntArtifact artifact = (AntArtifact)item.getArtifact();
220                     if ( reference == null) {
221                         if ( artifact == null ) {
222                             break;
223                         }
224                         reference = referenceHelper.addReference( item.getArtifact(), item.getArtifactURI());
225                         item.setReference(reference);
226                     }
227                     break;
228                 case Item.TYPE_CLASSPATH:
229                     reference = item.getReference();
230                     break;
231             }
232             
233             if ( reference != null ) {
234                 result.add( reference );
235                 
236                 // Add the item to the list of items included in deployment
237
if ( includedLibrariesElement != null && item.isIncludedInDeployment() ) {
238                     includedLibraries.add( EjbJarProjectProperties.getAntPropertyName( reference ) );
239                 }
240             }
241             
242         }
243         
244         if ( includedLibrariesElement != null )
245             putIncludedLibraries( includedLibraries, cp, antProjectHelper, includedLibrariesElement );
246
247         String JavaDoc[] items = new String JavaDoc[ result.size() ];
248         for( int i = 0; i < result.size(); i++) {
249             if ( i < result.size() - 1 ) {
250                 items[i] = result.get( i ) + ":";
251             }
252             else {
253                 items[i] = (String JavaDoc)result.get( i ); //NOI18N
254
}
255         }
256         
257         return items;
258     }
259     
260     public String JavaDoc getLibraryReference( Item item ) {
261         if ( item.getType() != Item.TYPE_LIBRARY ) {
262             throw new IllegalArgumentException JavaDoc( "Item must be of type LIBRARY" );
263         }
264         return libraryPrefix + item.getLibrary().getName() + librarySuffix;
265     }
266     
267     // Private methods ---------------------------------------------------------
268

269     private boolean isWellKnownPath( String JavaDoc property ) {
270         return wellKnownPaths == null ? false : wellKnownPaths.contains( property );
271     }
272     
273     private boolean isAntArtifact( String JavaDoc property ) {
274         return antArtifactPrefix == null ? false : property.startsWith( antArtifactPrefix );
275     }
276     
277     private boolean isLibrary( String JavaDoc property ) {
278         if ( libraryPrefix != null && property.startsWith( libraryPrefix ) ) {
279             return librarySuffix == null ? true : property.endsWith( librarySuffix );
280         }
281         else {
282             return false;
283         }
284         
285     }
286     
287     // Private static methods --------------------------------------------------
288

289     /**
290      * Returns a list with the classpath items which are to be included
291      * in deployment.
292      */

293     private static List JavaDoc /*<String>*/ getIncludedLibraries( AntProjectHelper antProjectHelper, String JavaDoc includedLibrariesElement ) {
294         assert antProjectHelper != null;
295         assert includedLibrariesElement != null;
296         
297         Element JavaDoc data = antProjectHelper.getPrimaryConfigurationData( true );
298         NodeList JavaDoc libs = data.getElementsByTagNameNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
299         List JavaDoc libraries = new ArrayList JavaDoc( libs.getLength() );
300         for ( int i = 0; i < libs.getLength(); i++ ) {
301             Element JavaDoc item = (Element JavaDoc)libs.item( i );
302             libraries.add( findText( item ));
303         }
304         return libraries;
305     }
306     
307     /**
308      * Updates the project helper with the list of classpath items which are to be
309      * included in deployment.
310      */

311     private static void putIncludedLibraries( List JavaDoc /*<String>*/ libraries, List JavaDoc /*<Item>*/ classpath, AntProjectHelper antProjectHelper, String JavaDoc includedLibrariesElement ) {
312         assert libraries != null;
313         assert antProjectHelper != null;
314         assert includedLibrariesElement != null;
315         
316         Element JavaDoc data = antProjectHelper.getPrimaryConfigurationData( true );
317         NodeList JavaDoc libs = data.getElementsByTagNameNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
318         while ( libs.getLength() > 0 ) {
319             Node JavaDoc n = libs.item( 0 );
320             n.getParentNode().removeChild( n );
321         }
322
323         Document JavaDoc doc = data.getOwnerDocument();
324         for (Iterator JavaDoc i = libraries.iterator(); i.hasNext();) {
325             String JavaDoc libraryName = (String JavaDoc)i.next();
326             //find a correcponding classpath item for the library
327
for(int idx = 0; idx < classpath.size(); idx++ ) {
328                 ClassPathSupport.Item item = (ClassPathSupport.Item)classpath.get(idx);
329                 String JavaDoc libraryPropName = "${" + libraryName + "}";
330                 if(libraryPropName.equals(item.getReference())) {
331                     appendChildElement(data, createLibraryElement(doc, libraryName, item, includedLibrariesElement), ejbjarElemOrder);
332                 }
333             }
334         }
335         
336         antProjectHelper.putPrimaryConfigurationData( data, true );
337     }
338     
339     /**
340      * Find all direct child elements of an element.
341      * More useful than {@link Element#getElementsByTagNameNS} because it does
342      * not recurse into recursive child elements.
343      * Children which are all-whitespace text nodes are ignored; others cause
344      * an exception to be thrown.
345      * @param parent a parent element in a DOM tree
346      * @return a list of direct child elements (may be empty)
347      * @throws IllegalArgumentException if there are non-element children besides whitespace
348      */

349     private static List JavaDoc/*<Element>*/ findSubElements(Element JavaDoc parent) throws IllegalArgumentException JavaDoc {
350         NodeList JavaDoc l = parent.getChildNodes();
351         List JavaDoc/*<Element>*/ elements = new ArrayList JavaDoc(l.getLength());
352         for (int i = 0; i < l.getLength(); i++) {
353             Node JavaDoc n = l.item(i);
354             if (n.getNodeType() == Node.ELEMENT_NODE) {
355                 elements.add((Element JavaDoc)n);
356             } else if (n.getNodeType() == Node.TEXT_NODE) {
357                 String JavaDoc text = ((Text JavaDoc)n).getNodeValue();
358                 if (text.trim().length() > 0) {
359                     throw new IllegalArgumentException JavaDoc("non-ws text encountered in " + parent + ": " + text); // NOI18N
360
}
361             } else if (n.getNodeType() == Node.COMMENT_NODE) {
362                 // skip
363
} else {
364                 throw new IllegalArgumentException JavaDoc("unexpected non-element child of " + parent + ": " + n); // NOI18N
365
}
366         }
367         return elements;
368     }
369     
370     /**
371      * Append child element to the correct position according to given
372      * order.
373      * @param parent parent to which the child will be added
374      * @param el element to be added
375      * @param order order of the elements which must be followed
376      */

377     private static void appendChildElement(Element JavaDoc parent, Element JavaDoc el, String JavaDoc[] order) {
378         Element JavaDoc insertBefore = null;
379         List JavaDoc l = Arrays.asList(order);
380         int index = l.indexOf(el.getLocalName());
381         assert index != -1 : el.getLocalName()+" was not found in "+l; // NOI18N
382
Iterator JavaDoc it = findSubElements(parent).iterator();
383         while (it.hasNext()) {
384             Element JavaDoc e = (Element JavaDoc)it.next();
385             int index2 = l.indexOf(e.getLocalName());
386             assert index2 != -1 : e.getLocalName()+" was not found in "+l; // NOI18N
387
if (index2 > index) {
388                 insertBefore = e;
389                 break;
390             }
391         }
392         parent.insertBefore(el, insertBefore);
393     }
394         
395     private static Element JavaDoc createLibraryElement(Document JavaDoc doc, String JavaDoc pathItem, Item item, String JavaDoc includedLibrariesElement ) {
396         Element JavaDoc libraryElement = doc.createElementNS( EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, includedLibrariesElement );
397         ArrayList JavaDoc files = new ArrayList JavaDoc ();
398         ArrayList JavaDoc dirs = new ArrayList JavaDoc ();
399         EjbJarProjectProperties.getFilesForItem(item, files, dirs);
400         if (files.size() > 0) {
401             libraryElement.setAttribute(ATTR_FILES, "" + files.size());
402         }
403         if (dirs.size() > 0) {
404             libraryElement.setAttribute(ATTR_DIRS, "" + dirs.size());
405         }
406         
407         libraryElement.appendChild( doc.createTextNode( pathItem ) );
408         return libraryElement;
409     }
410        
411     /**
412      * Extracts <b>the first</b> nested text from an element.
413      * Currently does not handle coalescing text nodes, CDATA sections, etc.
414      * @param parent a parent element
415      * @return the nested text, or null if none was found
416      */

417     private static String JavaDoc findText( Element JavaDoc parent ) {
418         NodeList JavaDoc l = parent.getChildNodes();
419         for ( int i = 0; i < l.getLength(); i++ ) {
420             if ( l.item(i).getNodeType() == Node.TEXT_NODE ) {
421                 Text JavaDoc text = (Text JavaDoc)l.item( i );
422                 return text.getNodeValue();
423             }
424         }
425         return null;
426     }
427         
428     // Innerclasses ------------------------------------------------------------
429

430     /** Item of the classpath.
431      */

432     public static class Item {
433         
434         // Types of the classpath elements
435
public static final int TYPE_JAR = 0;
436         public static final int TYPE_LIBRARY = 1;
437         public static final int TYPE_ARTIFACT = 2;
438         public static final int TYPE_CLASSPATH = 3;
439
440         // Reference to a broken object
441
private static final String JavaDoc BROKEN = "BrokenReference"; // NOI18N
442

443         private Object JavaDoc object;
444         private URI JavaDoc artifactURI;
445         private int type;
446         private String JavaDoc property;
447         private boolean includedInDeployment;
448         private String JavaDoc raw;
449         
450         private Item( int type, Object JavaDoc object, String JavaDoc property, boolean included, String JavaDoc raw ) {
451             this.type = type;
452             this.object = object;
453             this.property = property;
454             this.includedInDeployment = included;
455             this.raw = raw;
456         }
457         
458         private Item( int type, Object JavaDoc object, URI JavaDoc artifactURI, String JavaDoc property, boolean included ) {
459             this( type, object, property, included,null );
460             this.artifactURI = artifactURI;
461         }
462               
463         // Factory methods -----------------------------------------------------
464

465         
466         public static Item create( Library library, String JavaDoc property, boolean included ) {
467             if ( library == null ) {
468                 throw new IllegalArgumentException JavaDoc( "library must not be null" ); // NOI18N
469
}
470             String JavaDoc libraryName = library.getName();
471             return new Item( TYPE_LIBRARY, library, property, included, EjbJarProjectProperties.LIBRARY_PREFIX + libraryName + EjbJarProjectProperties.LIBRARY_SUFFIX);
472         }
473         
474         public static Item create( AntArtifact artifact, URI JavaDoc artifactURI, String JavaDoc property, boolean included ) {
475             if ( artifactURI == null ) {
476                 throw new IllegalArgumentException JavaDoc( "artifactURI must not be null" ); // NOI18N
477
}
478             if ( artifact == null ) {
479                 throw new IllegalArgumentException JavaDoc( "artifact must not be null" ); // NOI18N
480
}
481             return new Item( TYPE_ARTIFACT, artifact, artifactURI, property, included );
482         }
483         
484         public static Item create( File JavaDoc file, String JavaDoc property, boolean included ) {
485             if ( file == null ) {
486                 throw new IllegalArgumentException JavaDoc( "file must not be null" ); // NOI18N
487
}
488             return new Item( TYPE_JAR, file, property, included, null );
489         }
490         
491         public static Item create( String JavaDoc property, boolean included ) {
492             if ( property == null ) {
493                 throw new IllegalArgumentException JavaDoc( "property must not be null" ); // NOI18N
494
}
495             return new Item ( TYPE_CLASSPATH, null, property, included, null );
496         }
497         
498         public static Item createBroken( int type, String JavaDoc property, boolean included ) {
499             if ( property == null ) {
500                 throw new IllegalArgumentException JavaDoc( "property must not be null in broken items" ); // NOI18N
501
}
502             return new Item( type, BROKEN, property, included, null );
503         }
504         
505         // Instance methods ----------------------------------------------------
506

507         public String JavaDoc getRaw() {
508             return raw;
509         }
510         
511         public int getType() {
512             return type;
513         }
514         
515         public Library getLibrary() {
516             if ( getType() != TYPE_LIBRARY ) {
517                 throw new IllegalArgumentException JavaDoc( "Item is not of required type - LIBRARY" ); // NOI18N
518
}
519             if (isBroken()) {
520                 return null;
521             }
522             return (Library)object;
523         }
524         
525         public File JavaDoc getFile() {
526             if ( getType() != TYPE_JAR ) {
527                 throw new IllegalArgumentException JavaDoc( "Item is not of required type - JAR" ); // NOI18N
528
}
529             if (isBroken()) {
530                 return null;
531             }
532             return (File JavaDoc)object;
533         }
534         
535         public AntArtifact getArtifact() {
536             if ( getType() != TYPE_ARTIFACT ) {
537                 throw new IllegalArgumentException JavaDoc( "Item is not of required type - ARTIFACT" ); // NOI18N
538
}
539             if (isBroken()) {
540                 return null;
541             }
542             return (AntArtifact)object;
543         }
544         
545         public URI JavaDoc getArtifactURI() {
546             if ( getType() != TYPE_ARTIFACT ) {
547                 throw new IllegalArgumentException JavaDoc( "Item is not of required type - ARTIFACT" ); // NOI18N
548
}
549             return artifactURI;
550         }
551         
552         
553         public String JavaDoc getReference() {
554             return property;
555         }
556         
557         public void setReference(String JavaDoc property) {
558             this.property = property;
559         }
560
561         public boolean isIncludedInDeployment() {
562 // boolean result = includedInDeployment;
563
// if (getType() == TYPE_JAR) {
564
// at the moment we can't include folders in deployment
565
// FileObject fo = FileUtil.toFileObject(getFile());
566
// if (fo == null || fo.isFolder())
567
// return false;
568
// }
569
return includedInDeployment;
570         }
571         
572         public void setIncludedInDeployment(boolean includedInDeployment) {
573             this.includedInDeployment = includedInDeployment;
574         }
575         
576         public boolean isBroken() {
577             return object == BROKEN;
578         }
579         
580         public String JavaDoc toString() {
581             return "artifactURI=" + artifactURI
582                     + ", type=" + type
583                     + ", property=" + property
584                     + ", includedInDeployment=" + includedInDeployment
585                     + ", raw=" + raw
586                     + ", object=" + object;
587         }
588         
589         public int hashCode() {
590         
591             int hash = getType();
592
593             if ( object == BROKEN ) {
594                 return BROKEN.hashCode();
595             }
596             
597             switch ( getType() ) {
598                 case TYPE_ARTIFACT:
599                     hash += getArtifact().getType().hashCode();
600                     hash += getArtifact().getScriptLocation().hashCode();
601                     hash += getArtifactURI().hashCode();
602                     break;
603                 case TYPE_CLASSPATH:
604                     hash += property.hashCode();
605                     break;
606                 default:
607                     hash += object.hashCode();
608             }
609
610             return hash;
611         }
612     
613         public boolean equals( Object JavaDoc itemObject ) {
614
615             if ( !( itemObject instanceof Item ) ) {
616                 return false;
617             }
618             
619             Item item = (Item)itemObject;
620
621             if ( getType() != item.getType() ) {
622                 return false;
623             }
624             
625             if ( isBroken() != item.isBroken() ) {
626                 return false;
627             }
628             
629             if ( isBroken() ) {
630                 return getReference().equals( item.getReference() );
631             }
632
633             switch ( getType() ) {
634                 case TYPE_ARTIFACT:
635                     if ( getArtifact().getType() != item.getArtifact().getType() ) {
636                         return false;
637                     }
638
639                     if ( !getArtifact().getScriptLocation().equals( item.getArtifact().getScriptLocation() ) ) {
640                         return false;
641                     }
642
643                     if ( !getArtifactURI().equals( item.getArtifactURI() ) ) {
644                         return false;
645                     }
646                     return true;
647                 case TYPE_CLASSPATH:
648                     return property.equals( item.property );
649                 default:
650                     return this.object.equals( item.object );
651             }
652
653         }
654                 
655     }
656             
657 }
658
659
Popular Tags