1 19 20 package org.netbeans.modules.j2ee.ejbjarproject; 21 22 import java.io.File ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 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 35 public class EjbJarSharabilityQuery implements SharabilityQueryImplementation, PropertyChangeListener { 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 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 67 public int getSharability(final File file) { 68 Integer ret = (Integer ) ProjectManager.mutex().readAccess( new Mutex.Action() { 69 public Object run() { 70 synchronized (EjbJarSharabilityQuery.this) { 71 if (delegate == null) { 72 delegate = createDelegate (); 73 } 74 return new Integer (delegate.getSharability (file)); 75 } 76 } 77 }); 78 return ret.intValue(); 79 } 80 81 public void propertyChange(PropertyChangeEvent 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 [] srcProps = srcRoots.getRootProperties(); 91 String [] testProps = testRoots.getRootProperties(); 92 String [] props = new String [srcProps.length + testProps.length + 1]; 93 for (int i=0; i<srcProps.length; i++) { 94 props[i] = "${"+srcProps[i]+"}"; } 96 for (int i=0; i<testProps.length; i++) { 97 props[srcProps.length+i] = "${"+testProps[i]+"}"; } 99 props[props.length - 1] = "${" + EjbJarProjectProperties.META_INF + "}"; 100 return helper.createSharabilityQuery(this.evaluator, props, 101 new String [] { 102 "${" + EjbJarProjectProperties.DIST_DIR + "}", "${" + EjbJarProjectProperties.BUILD_DIR + "}", }); 105 } 106 } 107 | Popular Tags |