KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > EjbJarSharabilityQuery


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;
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.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
31
32 /**
33  * SharabilityQueryImplementation for j2seproject with multiple sources
34  */

35 public class EjbJarSharabilityQuery 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 J2SESharabilityQuery
45      * @param helper AntProjectHelper
46      * @param evaluator PropertyEvaluator
47      * @param srcRoots sources
48      * @param testRoots tests
49      */

50     EjbJarSharabilityQuery (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      * Check whether a file or directory should be shared.
61      * If it is, it ought to be committed to a VCS if the user is using one.
62      * If it is not, it is either a disposable build product, or a per-user
63      * private file which is important but should not be shared.
64      * @param file a file to check for sharability (may or may not yet exist)
65      * @return one of {@link org.netbeans.api.queries.SharabilityQuery}'s constants
66      */

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