1 19 20 package org.netbeans.modules.j2ee.persistence.dd; 21 22 import java.util.Map ; 23 import java.util.WeakHashMap ; 24 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.Persistence; 25 import org.openide.filesystems.FileObject; 26 27 34 public final class PersistenceMetadata { 35 private static final PersistenceMetadata instance = new PersistenceMetadata(); 36 private Map ddMap; 37 38 private PersistenceMetadata() { 39 ddMap = new WeakHashMap (5); 40 } 41 42 47 public static PersistenceMetadata getDefault() { 48 return instance; 49 } 50 51 61 public synchronized Persistence getRoot(FileObject fo) throws java.io.IOException { 62 if (fo == null) { 63 return null; 64 } 65 Persistence persistence = null; 66 synchronized (ddMap) { 67 persistence = (Persistence) ddMap.get(fo); 68 if (persistence == null) { 69 persistence = Persistence.createGraph(fo.getInputStream()); 70 ddMap.put(fo, persistence); 71 } 72 } 73 return persistence; 74 } 75 76 } | Popular Tags |