1 19 20 package org.netbeans.modules.j2ee.persistence.dd; 21 22 import java.lang.ref.Reference ; 23 import java.lang.ref.WeakReference ; 24 import java.util.Collections ; 25 import org.netbeans.api.java.classpath.ClassPath; 26 import org.netbeans.modules.j2ee.metadata.MetadataUnit; 27 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 28 import org.netbeans.spi.java.classpath.PathResourceImplementation; 29 import org.openide.filesystems.FileObject; 30 31 44 public final class WeakMetadataUnit implements MetadataUnit { 45 46 private FileObject deploymentDescriptor; 47 48 private Object classPath; 50 51 public WeakMetadataUnit(FileObject deploymentDescriptor, ClassPath classPath) { 52 synchronized (this) { 53 this.deploymentDescriptor = deploymentDescriptor; 54 if (classPath != null) { 55 this.classPath = new WeakReference <ClassPath>(classPath); 56 } else { 57 this.classPath = ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList()); 58 } 59 } 60 } 61 62 public synchronized FileObject getDeploymentDescriptor() { 63 return deploymentDescriptor; 64 } 65 66 public synchronized ClassPath getClassPath() { 67 ClassPath result; 68 69 if (classPath instanceof Reference ) { 70 Reference ref = (Reference )classPath; 71 result = (ClassPath)ref.get(); 72 if (result == null) { 73 result = ClassPathSupport.createClassPath(Collections.<PathResourceImplementation>emptyList()); 74 classPath = result; 75 } 76 } else { 77 result = (ClassPath)classPath; 78 } 79 80 return result; 81 } 82 83 public synchronized void setDeploymentDescriptor(FileObject deploymentDescriptor) { 84 this.deploymentDescriptor = deploymentDescriptor; 86 } 87 } 88 | Popular Tags |