📄 defaultbundlearchive.java
字号:
throw ex; } finally { if (bw != null) bw.close(); if (fw != null) fw.close(); } } public int getStartLevel() throws Exception { if (m_startLevel >= 0) { return m_startLevel; } else if (System.getSecurityManager() != null) { try { return ((Integer) AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.GET_START_LEVEL_ACTION, this))).intValue(); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { return getStartLevelUnchecked(); } } private int getStartLevelUnchecked() throws Exception { // Get bundle start level file. File levelFile = new File(m_dir, BUNDLE_START_LEVEL_FILE); // If the start level file doesn't exist, then // return an error. if (!levelFile.exists()) { return -1; } // Read the bundle start level. FileReader fr = null; BufferedReader br= null; try { fr = new FileReader(levelFile); br = new BufferedReader(fr); m_startLevel = Integer.parseInt(br.readLine()); return m_startLevel; } finally { if (br != null) br.close(); if (fr != null) fr.close(); } } public void setStartLevel(int level) throws Exception { if (System.getSecurityManager() != null) { try { AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.SET_START_LEVEL_ACTION, this, level)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { setStartLevelUnchecked(level); } } private void setStartLevelUnchecked(int level) throws Exception { // Get bundle start level file. File levelFile = new File(m_dir, BUNDLE_START_LEVEL_FILE); // Write the bundle start level. FileWriter fw = null; BufferedWriter bw = null; try { fw = new FileWriter(levelFile); bw = new BufferedWriter(fw); String s = Integer.toString(level); bw.write(s, 0, s.length()); m_startLevel = level; } catch (IOException ex) { Oscar.error("DefaultBundleArchive: Unable to record start leel: " + ex); throw ex; } finally { if (bw != null) bw.close(); if (fw != null) fw.close(); } } public File getDataFile(String fileName) throws Exception { // Do some sanity checking. if ((fileName.length() > 0) && (fileName.charAt(0) == File.separatorChar)) throw new IllegalArgumentException("The data file path must be relative, not absolute."); else if (fileName.indexOf("..") >= 0) throw new IllegalArgumentException("The data file path cannot contain a reference to the \"..\" directory."); // Get bundle data directory. File dataDir = new File(m_dir, DATA_DIRECTORY); if (System.getSecurityManager() != null) { try { AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.CREATE_DATA_DIR_ACTION, this, dataDir)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { createDataDirectoryUnchecked(dataDir); } // Return the data file. return new File(dataDir, fileName); } private void createDataDirectoryUnchecked(File dir) throws Exception { // Create data directory if necessary. if (!dir.exists()) { if (!dir.mkdir()) { throw new IOException("Unable to create bundle data directory."); } } } public BundleActivator getActivator(ClassLoader loader) throws Exception { if (System.getSecurityManager() != null) { try { return (BundleActivator) AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.GET_ACTIVATOR_ACTION, this, loader)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { return getActivatorUnchecked(loader); } } private BundleActivator getActivatorUnchecked(ClassLoader loader) throws Exception { // Get bundle activator file. File activatorFile = new File(m_dir, BUNDLE_ACTIVATOR_FILE); // If the activator file doesn't exist, then // assume there isn't one. if (!activatorFile.exists()) return null; // Deserialize the activator object. InputStream is = null; ObjectInputStreamX ois = null; try { is = new FileInputStream(activatorFile); ois = new ObjectInputStreamX(is, loader); Object o = ois.readObject(); return (BundleActivator) o; } catch (Exception ex) { Oscar.error("DefaultBundleArchive: Trying to deserialize."); Oscar.error("DefaultBundleArchive: " + ex); } finally { if (ois != null) ois.close(); if (is != null) is.close(); } return null; } public void setActivator(Object obj) throws Exception { if (System.getSecurityManager() != null) { try { AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.SET_ACTIVATOR_ACTION, this, obj)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { setActivatorUnchecked(obj); } } private void setActivatorUnchecked(Object obj) throws Exception { if (!(obj instanceof Serializable)) { return; } // Get bundle activator file. File activatorFile = new File(m_dir, BUNDLE_ACTIVATOR_FILE); // Serialize the activator object. OutputStream os = null; ObjectOutputStream oos = null; try { os = new FileOutputStream(activatorFile); oos = new ObjectOutputStream(os); oos.writeObject(obj); } catch (IOException ex) { Oscar.error("DefaultBundleArchive: Unable to serialize activator."); Oscar.error("DefaultBundleArchive: " + ex); throw ex; } finally { if (oos != null) oos.close(); if (os != null) os.close(); } } public int getRevisionCount() throws Exception { if (System.getSecurityManager() != null) { try { return ((Integer) AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.GET_REVISION_COUNT_ACTION, this))).intValue(); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { return getRevisionCountUnchecked(); } } public int getRevisionCountUnchecked() { // We should always have at least one revision // directory, so try to count them if the value // has not been initialized yet. if (m_revisionCount <= 0) { m_revisionCount = 0; File[] children = m_dir.listFiles(); for (int i = 0; (children != null) && (i < children.length); i++) { if (children[i].getName().startsWith(REVISION_DIRECTORY)) { m_revisionCount++; } } } return m_revisionCount; } public Map getManifestHeader(int revision) throws Exception { // If the request is for the current revision header, // then return the cached copy if it is present. if ((revision == (getRevisionCount() - 1)) && (m_currentHeader != null)) { return m_currentHeader; } // Get the revision directory. File revisionDir = new File( m_dir, REVISION_DIRECTORY + getRefreshCount() + "." + revision); // Get the embedded resource. JarFile jarFile = null; try { // Create JarFile object using privileged block. if (System.getSecurityManager() != null) { jarFile = (JarFile) AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.OPEN_BUNDLE_JAR_ACTION, this, revisionDir)); } else { jarFile = openBundleJarUnchecked(revisionDir); } // Error if no jar file. if (jarFile == null) { throw new IOException("No JAR file found."); } // Get manifest. Manifest mf = jarFile.getManifest(); // Create a case insensitive map of manifest attributes. Map map = new CaseInsensitiveMap(mf.getMainAttributes()); // If the request is for the current revision's header, // then cache it. if (revision == (getRevisionCount() - 1)) { m_currentHeader = map; } return map; } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } finally { if (jarFile != null) jarFile.close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -