1 11 12 package org.eclipse.osgi.framework.adaptor.core; 13 14 import java.io.*; 15 import java.io.File ; 16 import java.io.IOException ; 17 import java.security.ProtectionDomain ; 18 import java.util.Enumeration ; 19 import org.eclipse.osgi.framework.adaptor.BundleClassLoader; 20 import org.eclipse.osgi.framework.adaptor.ClassLoaderDelegate; 21 import org.eclipse.osgi.framework.debug.Debug; 22 import org.eclipse.osgi.framework.internal.core.Constants; 23 import org.eclipse.osgi.framework.util.Headers; 24 import org.eclipse.osgi.service.resolver.Version; 25 import org.osgi.framework.BundleException; 26 27 public class SystemBundleData extends AbstractBundleData { 28 public static final String OSGI_FRAMEWORK = "osgi.framework"; private BundleFile baseBundleFile; 30 31 public SystemBundleData(AbstractFrameworkAdaptor adaptor) throws BundleException { 32 super(adaptor, 0); 33 File osgiBase = getOsgiBase(); 34 manifest = createManifest(osgiBase); 35 createBundleFile(osgiBase); 36 setMetaData(); 37 } 38 39 private File getOsgiBase() { 40 String frameworkLocation = System.getProperty(OSGI_FRAMEWORK); 41 if (frameworkLocation != null) 42 return new File (frameworkLocation.substring(5)); 44 frameworkLocation = System.getProperty("user.dir"); if (frameworkLocation != null) 46 return new File (frameworkLocation); 47 return null; 48 } 49 50 private Headers createManifest(File osgiBase) throws BundleException { 51 InputStream in = null; 52 53 if (osgiBase != null && osgiBase.exists()) { 54 try { 55 in = new FileInputStream(new File (osgiBase, Constants.OSGI_BUNDLE_MANIFEST)); 56 } catch (FileNotFoundException e) { 57 } 59 } 60 61 if (in == null) { 64 in = getClass().getResourceAsStream(Constants.OSGI_SYSTEMBUNDLE_MANIFEST); 65 } 66 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 67 if (in == null) { 68 Debug.println("Unable to find system bundle manifest " + Constants.OSGI_SYSTEMBUNDLE_MANIFEST); } 70 } 71 72 if (in == null) 73 throw new BundleException(AdaptorMsg.formatter.getString("SYSTEMBUNDLE_MISSING_MANIFEST")); 75 Headers systemManifest = Headers.parseManifest(in); 76 String systemExportProp = System.getProperty(Constants.OSGI_SYSTEMPACKAGES); 78 if (systemExportProp != null) 79 appendManifestValue(systemManifest, Constants.EXPORT_PACKAGE, systemExportProp); 80 String exportPackages = adaptor.getExportPackages(); 83 String exportServices = adaptor.getExportServices(); 84 String providePackages = adaptor.getProvidePackages(); 85 if (exportPackages != null) 86 appendManifestValue(systemManifest, Constants.EXPORT_PACKAGE, exportPackages); 87 if (exportServices != null) 88 appendManifestValue(systemManifest, Constants.EXPORT_SERVICE, exportServices); 89 if (providePackages != null) 90 appendManifestValue(systemManifest, Constants.PROVIDE_PACKAGE, providePackages); 91 return systemManifest; 92 } 93 94 private void appendManifestValue(Headers systemManifest, String header, String append) { 95 String newValue = (String ) systemManifest.get(header); 96 if (newValue == null) { 97 newValue = append; 98 } else { 99 newValue += "," + append; } 101 systemManifest.set(header, null); 102 systemManifest.set(header, newValue); 103 } 104 105 private void createBundleFile(File osgiBase) { 106 if (osgiBase != null) 107 try { 108 baseBundleFile = adaptor.createBundleFile(osgiBase, this); 109 } catch (IOException e) { 110 } 112 else 113 baseBundleFile = new BundleFile(osgiBase) { 114 public File getFile(String path) { 115 return null; 116 } 117 118 public BundleEntry getEntry(String path) { 119 return null; 120 } 121 122 public Enumeration getEntryPaths(String path) { 123 return null; 124 } 125 126 public void close() throws IOException { 127 } 128 129 public void open() throws IOException { 130 } 131 132 public boolean containsDir(String dir) { 133 return false; 134 } 135 }; 136 } 137 138 private void setMetaData() { 139 setActivator((String ) manifest.get(Constants.BUNDLE_ACTIVATOR)); 140 setClassPath((String ) manifest.get(Constants.BUNDLE_CLASSPATH)); 141 setDynamicImports((String ) manifest.get(Constants.DYNAMICIMPORT_PACKAGE)); 142 setExecutionEnvironment((String ) manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT)); 143 setLocation(Constants.SYSTEM_BUNDLE_LOCATION); 144 setSymbolicName(AbstractBundleData.parseSymbolicName(manifest)); 145 String sVersion = (String ) manifest.get(Constants.BUNDLE_VERSION); 146 if (sVersion != null) 147 setVersion(new Version(sVersion)); 148 } 149 150 public BundleClassLoader createClassLoader(ClassLoaderDelegate delegate, ProtectionDomain domain, String [] bundleclasspath) { 151 return null; 152 } 153 154 public File createGenerationDir() { 155 return null; 156 } 157 158 public BundleFile getBaseBundleFile() { 159 return baseBundleFile; 160 } 161 162 public String findLibrary(String libname) { 163 return null; 164 } 165 166 public void installNativeCode(String [] nativepaths) throws BundleException { 167 } 168 169 public File getDataFile(String path) { 170 return null; 171 } 172 173 public int getStartLevel() { 174 return 0; 175 } 176 177 public int getStatus() { 178 return 0; 179 } 180 181 public void close() throws IOException { 182 } 183 184 public void open() throws IOException { 185 } 186 187 public void save() throws IOException { 188 } 189 } | Popular Tags |