KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > AppClientSharabilityQuery


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.clientproject;
21
22
23 import java.io.File JavaDoc;
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import org.openide.util.Mutex;
27 import org.netbeans.api.project.ProjectManager;
28 import org.netbeans.spi.queries.SharabilityQueryImplementation;
29 import org.netbeans.spi.project.support.ant.AntProjectHelper;
30 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
31 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties;
32
33
34
35
36 /**
37  * SharabilityQueryImplementation for j2seproject with multiple sources
38  */

39 public class AppClientSharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener JavaDoc {
40
41     private final AntProjectHelper helper;
42     private final PropertyEvaluator evaluator;
43     private final SourceRoots srcRoots;
44     private final SourceRoots testRoots;
45     private SharabilityQueryImplementation delegate;
46
47
48     /**
49      * Creates new AppClientSharabilityQuery
50      *
51      * @param helper AntProjectHelper
52      * @param evaluator PropertyEvaluator
53      * @param srcRoots sources
54      * @param testRoots tests
55      */

56     AppClientSharabilityQuery (AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots srcRoots, SourceRoots testRoots) {
57         this.helper = helper;
58         this.evaluator = evaluator;
59         this.srcRoots = srcRoots;
60         this.testRoots = testRoots;
61         this.srcRoots.addPropertyChangeListener(this);
62         this.testRoots.addPropertyChangeListener(this);
63     }
64
65
66     /**
67      * Check whether a file or directory should be shared.
68      * If it is, it ought to be committed to a VCS if the user is using one.
69      * If it is not, it is either a disposable build product, or a per-user
70      * private file which is important but should not be shared.
71      * @param file a file to check for sharability (may or may not yet exist)
72      * @return one of {@link org.netbeans.api.queries.SharabilityQuery}'s constants
73      */

74     public int getSharability(final File JavaDoc file) {
75         Integer JavaDoc ret = (Integer JavaDoc) ProjectManager.mutex().readAccess( new Mutex.Action() {
76             public Object JavaDoc run() {
77                 synchronized (AppClientSharabilityQuery.this) {
78                     if (delegate == null) {
79                         delegate = createDelegate ();
80                     }
81                     return new Integer JavaDoc(delegate.getSharability (file));
82                 }
83             }
84         });
85         return ret.intValue();
86     }
87
88     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
89         if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) {
90             synchronized (this) {
91                 this.delegate = null;
92             }
93         }
94     }
95
96     private SharabilityQueryImplementation createDelegate () {
97         String JavaDoc[] srcProps = srcRoots.getRootProperties();
98         String JavaDoc[] testProps = testRoots.getRootProperties();
99         String JavaDoc[] props = new String JavaDoc [srcProps.length + testProps.length + 1];
100         for (int i=0; i<srcProps.length; i++) {
101             props[i] = "${"+srcProps[i]+"}"; // NOI18N
102
}
103         for (int i=0; i<testProps.length; i++) {
104             props[srcProps.length+i] = "${"+testProps[i]+"}"; // NOI18N
105
}
106         props[props.length - 1] = "${" + AppClientProjectProperties.META_INF + "}"; // NOI18N
107
return helper.createSharabilityQuery(this.evaluator, props,
108             new String JavaDoc[] {
109                 "${" + AppClientProjectProperties.DIST_DIR + "}", // NOI18N
110
"${" + AppClientProjectProperties.BUILD_DIR + "}", // NOI18N
111
});
112     }
113
114 }
115
Popular Tags