KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > catalogsupport > util > ProjectReferenceUtility


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.xml.catalogsupport.util;
21
22 import java.net.URI JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.api.project.ProjectInformation;
25 import org.netbeans.api.project.ProjectUtils;
26 import org.netbeans.api.project.ant.AntArtifact;
27 import org.netbeans.spi.project.ant.AntArtifactProvider;
28 import org.netbeans.spi.project.support.ant.PropertyUtils;
29 import org.netbeans.spi.project.support.ant.ReferenceHelper;
30
31 /**
32  * Utility Class to provide project reference support.
33  * @author Ajit
34  */

35 public class ProjectReferenceUtility {
36     
37     /** Creates a new instance of ProjectReferenceUtility */
38     private ProjectReferenceUtility() {
39     }
40     
41     /**
42      * This api adds a project reference to another project.
43      * The api looks up AntArtifactProvider in referenced project's lookup,
44      * and find all the build artifacts to which reference is to be created,
45      * in the referencing project.
46      * @param refHelper The Reference Helper of the referencing project.
47      * @param refProject The referenced project.
48      * @see org.netbeans.spi.project.support.ant.ReferenceHelper
49      * @see org.netbeans.api.project.Project#getLookup
50      * @see org.netbeans.spi.project.ant.AntArtifactProvider
51      */

52     public static void addProjectReference(ReferenceHelper refHelper, Project refProject) {
53         AntArtifactProvider prov = (AntArtifactProvider)refProject.
54                 getLookup().lookup(AntArtifactProvider.class);
55         if(prov!=null) {
56             AntArtifact[] antArtifacts = prov.getBuildArtifacts();
57             for(AntArtifact artifact:antArtifacts) {
58                 for(URI JavaDoc uri:artifact.getArtifactLocations()) {
59                     refHelper.addReference(artifact,uri);
60                 }
61             }
62         }
63     }
64     /**
65      * This api removes a project reference from another project.
66      * The api looks up AntArtifactProvider in referenced project's lookup,
67      * and removes all the build artifacts's references from the referencing project.
68      * @param refHelper The Reference Helper of the referencing project.
69      * @param refProject The referenced project.
70      * @see org.netbeans.spi.project.support.ant.ReferenceHelper
71      * @see org.netbeans.api.project.Project#getLookup
72      * @see org.netbeans.spi.project.ant.AntArtifactProvider
73      */

74     public static void removeProjectReference(ReferenceHelper refHelper, Project refProject) {
75         AntArtifactProvider prov = (AntArtifactProvider)refProject.
76                 getLookup().lookup(AntArtifactProvider.class);
77         if(prov!=null) {
78             ProjectInformation pInfo = ProjectUtils.getInformation(refProject);
79             String JavaDoc refPrefix = "${reference."+PropertyUtils.
80                         getUsablePropertyName(pInfo.getName()).replace('.', '_')+".";
81             AntArtifact[] antArtifacts = prov.getBuildArtifacts();
82             for(AntArtifact artifact:antArtifacts) {
83                 refHelper.destroyReference(refPrefix+PropertyUtils.
84                         getUsablePropertyName(artifact.getID()).replace('.', '_')+"}");
85             }
86         }
87     }
88 }
89
Popular Tags