1 19 20 package org.netbeans.modules.settings; 21 22 import java.io.IOException ; 23 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileSystem; 26 import org.openide.filesystems.Repository; 27 import org.openide.loaders.DataObject; 28 import org.openide.loaders.Environment; 29 import org.openide.util.Lookup; 30 31 36 public final class Env implements Environment.Provider { 37 41 public final static String EA_CONVERTOR = "settings.convertor"; 47 public final static String EA_PROVIDER_PATH = "settings.providerPath"; 52 public final static String EA_PUBLICID = "hint.originalPublicID"; 57 public final static String EA_INSTANCE_CLASS_NAME = "settings.instanceClass"; 63 public final static String EA_INSTANCE_OF = "settings.instanceOf"; 70 public final static String EA_INSTANCE_CREATE = "settings.instanceCreate"; 75 public static final String EA_SUBCLASSES = "settings.subclasses"; 77 private final FileObject providerFO; 78 79 80 public static Environment.Provider create(FileObject fo) { 81 return new Env(fo); 82 } 83 84 private Env(FileObject fo) { 85 providerFO = fo; 86 } 87 88 public Lookup getEnvironment(DataObject dobj) { 89 if (!(dobj instanceof org.openide.loaders.InstanceDataObject)) return Lookup.EMPTY; 90 InstanceProvider icp = new InstanceProvider(dobj, providerFO); 91 return icp.getLookup(); 92 } 93 94 98 public static java.util.Set <String > parseAttribute(Object attr) { 99 if (attr != null && attr instanceof String ) { 100 java.util.StringTokenizer s = 101 new java.util.StringTokenizer ((String ) attr, ","); java.util.Set <String > set = new java.util.HashSet <String >(10); 103 while (s.hasMoreTokens()) { 104 set.add(s.nextToken().trim()); 105 } 106 return set; 107 } else { 108 return java.util.Collections.emptySet(); 109 } 110 } 111 112 113 public static FileObject findProvider(Class clazz) throws IOException { 114 String prefix = "xml/memory/"; FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); 116 FileObject memContext = sfs.findResource(prefix); 117 if (memContext == null) throw new java.io.FileNotFoundException ("SFS/xml/memory/"); Class c = clazz; 119 while (c != null) { 120 String name = c.getName().replace('.', '/'); 121 String convertorPath = new StringBuffer (200).append(prefix). 122 append(name).toString(); FileObject fo = sfs.findResource(convertorPath); 124 if (fo != null) { 125 String providerPath = (String ) fo.getAttribute(EA_PROVIDER_PATH); 126 if (providerPath != null) { 127 if (c.equals(clazz)) { 128 return sfs.findResource(providerPath); 129 } else { 130 Object inheritAttribute = fo.getAttribute(EA_SUBCLASSES); 132 if (inheritAttribute instanceof Boolean ) { 133 boolean subclasses = ((Boolean )inheritAttribute).booleanValue(); 134 if (subclasses) { 135 return sfs.findResource(providerPath); 136 } 137 } 138 } 139 } 140 } 141 c = c.getSuperclass(); 142 } 143 return null; 144 } 145 146 private static String xmlLookupsPrefix = "xml/lookups"; private static String xmlEntitiesPrefix = "xml/entities"; 149 153 public static FileObject findEntityRegistration(FileObject provider) { 154 String filename = provider.getPath(); 155 int i = filename.lastIndexOf('.'); 156 if (i != -1 && i > filename.lastIndexOf('/')) { 157 filename = filename.substring(0, i); 158 } 159 String resource = xmlEntitiesPrefix + 160 filename.substring(xmlLookupsPrefix.length(), filename.length()); 161 162 return Repository.getDefault().getDefaultFileSystem().findResource(resource); 163 } 164 } 165 | Popular Tags |