KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > WebSharabilityQuery


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

35 public class WebSharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener JavaDoc {
36
37     private final AntProjectHelper helper;
38     private final PropertyEvaluator evaluator;
39     private final SourceRoots srcRoots;
40     private final SourceRoots testRoots;
41     private SharabilityQueryImplementation delegate;
42
43     /**
44      * Creates new WebSharabilityQuery
45      * @param helper AntProjectHelper
46      * @param evaluator PropertyEvaluator
47      * @param srcRoots sources
48      * @param testRoots tests
49      */

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

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