📄 defaultbundlearchive.java
字号:
Map map = getManifestHeader(revision); if (map == null) { map = new HashMap(); } // Find class path meta-data. String classPath = null; Iterator iter = map.entrySet().iterator(); while ((classPath == null) && iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); if (entry.getKey().toString().toLowerCase().equals( OscarConstants.BUNDLE_CLASSPATH.toLowerCase())) { classPath = entry.getValue().toString(); } } // Parse the class path into strings. String[] classPathStrings = TextUtil.parseCommaDelimitedString(classPath); if (classPathStrings == null) { classPathStrings = new String[0]; } for (int i = 0; i < classPathStrings.length; i++) { if (!classPathStrings[i].equals(OscarConstants.CLASS_PATH_DOT)) { extractEmbeddedJar(revisionDir, classPathStrings[i]); } } } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } /** * This method extracts an embedded JAR file from the bundle's * JAR file. * <p> * Security: This method must be called from within a <tt>doPrivileged()</tt> * block since it accesses the disk. * @param id the identifier of the bundle that owns the embedded JAR file. * @param jarPath the path to the embedded JAR file inside the bundle JAR file. **/ private void extractEmbeddedJar(File revisionDir, String jarPath) throws Exception { // Remove leading slash if present. jarPath = (jarPath.charAt(0) == '/') ? jarPath.substring(1) : jarPath; // Get only the JAR file name. String jarName = (jarPath.lastIndexOf('/') >= 0) ? jarPath.substring(jarPath.lastIndexOf('/') + 1) : jarPath; // If JAR is already extracted, then don't // re-extract it... File embedFile = new File( revisionDir, EMBEDDED_DIRECTORY + File.separatorChar + jarName); if (!embedFile.exists()) { JarFile jarFile = null; InputStream is = null; try { jarFile = openBundleJarUnchecked(revisionDir); ZipEntry ze = jarFile.getEntry(jarPath); if (ze == null) { throw new IOException("No JAR entry: " + jarPath); } is = new BufferedInputStream(jarFile.getInputStream(ze), DefaultBundleCache.BUFSIZE); if (is == null) { throw new IOException("No input stream: " + jarPath); } // Create the file. copy(is, embedFile); } finally { if (jarFile != null) jarFile.close(); if (is != null) is.close(); } } } // INCREASES THE REVISION COUNT. protected void update(InputStream is) throws Exception { if (System.getSecurityManager() != null) { try { AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.UPDATE_ACTION, this, is)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { updateUnchecked(is); } } // INCREASES THE REVISION COUNT. private void updateUnchecked(InputStream is) throws Exception { File revisionDir = null; try { // Create the new revision directory. int revision = getRevisionCountUnchecked(); revisionDir = new File( m_dir, REVISION_DIRECTORY + getRefreshCount() + "." + revision); if (!revisionDir.mkdir()) { throw new IOException("Unable to create revision directory."); } // Save the new revision bundle jar file. File file = new File(revisionDir, BUNDLE_JAR_FILE); copy(is, file); preprocessBundleJar(revision, revisionDir); } catch (Exception ex) { if ((revisionDir != null) && revisionDir.exists()) { try { deleteDirectoryTree(revisionDir); } catch (Exception ex2) { // There is very little we can do here. Oscar.error("Unable to remove partial revision directory.", ex2); } } throw ex; } // If everything was successful, then update // the revision count. m_revisionCount++; // Clear the cached revision header, since it is // no longer the current revision. m_currentHeader = null; } // DECREASES THE REVISION COUNT. protected void purge() throws Exception { if (System.getSecurityManager() != null) { try { AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.PURGE_ACTION, this)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { purgeUnchecked(); } } // DECREASES THE REVISION COUNT. private void purgeUnchecked() throws Exception { // Get the current update count. long update = getRefreshCount(); // Get the current revision count. int count = getRevisionCountUnchecked(); File revisionDir = null; for (int i = 0; i < count - 1; i++) { revisionDir = new File(m_dir, REVISION_DIRECTORY + update + "." + i); if (revisionDir.exists()) { deleteDirectoryTree(revisionDir); } } // Increment the update count. setRefreshCount(update + 1); // Rename the current revision to be the current update. File currentDir = new File(m_dir, REVISION_DIRECTORY + (update + 1) + ".0"); revisionDir = new File(m_dir, REVISION_DIRECTORY + update + "." + (count - 1)); revisionDir.renameTo(currentDir); // If everything is successful, then set the revision // count to one. m_revisionCount = 1; // Although the cached current header should stay the same // here, clear it for consistency. m_currentHeader = null; } protected void remove() throws Exception { if (System.getSecurityManager() != null) { try { AccessController.doPrivileged( new PrivilegedAction( PrivilegedAction.REMOVE_ACTION, this)); } catch (PrivilegedActionException ex) { throw ((PrivilegedActionException) ex).getException(); } } else { removeUnchecked(); } } private void removeUnchecked() throws Exception { deleteDirectoryTree(m_dir); } // // Utility class for performing privileged actions. // private static class PrivilegedAction implements PrivilegedExceptionAction { private static final int INITIALIZE_ACTION = 0; private static final int UPDATE_ACTION = 1; private static final int PURGE_ACTION = 2; private static final int REMOVE_ACTION = 3; private static final int GET_REVISION_COUNT_ACTION = 4; private static final int GET_LOCATION_ACTION = 5; private static final int GET_PERSISTENT_STATE_ACTION = 6; private static final int SET_PERSISTENT_STATE_ACTION = 7; private static final int GET_START_LEVEL_ACTION = 8; private static final int SET_START_LEVEL_ACTION = 9; private static final int OPEN_BUNDLE_JAR_ACTION = 10; private static final int CREATE_DATA_DIR_ACTION = 11; private static final int GET_CLASS_PATH_ACTION = 12; private static final int GET_ACTIVATOR_ACTION = 13; private static final int SET_ACTIVATOR_ACTION = 14; private int m_action = 0; private DefaultBundleArchive m_archive = null; private InputStream m_isArg = null; private String m_strArg = null; private int m_intArg = 0; private File m_fileArg = null; private ClassLoader m_loaderArg = null; private Object m_objArg = null; public PrivilegedAction(int action, DefaultBundleArchive archive) { m_action = action; m_archive = archive; } public PrivilegedAction(int action, DefaultBundleArchive archive, InputStream isArg) { m_action = action; m_archive = archive; m_isArg = isArg; } public PrivilegedAction(int action, DefaultBundleArchive archive, int intArg) { m_action = action; m_archive = archive; m_intArg = intArg; } public PrivilegedAction(int action, DefaultBundleArchive archive, File fileArg) { m_action = action; m_archive = archive; m_fileArg = fileArg; } public PrivilegedAction(int action, DefaultBundleArchive archive, ClassLoader loaderArg) { m_action = action; m_archive = archive; m_loaderArg = loaderArg; } public PrivilegedAction(int action, DefaultBundleArchive archive, Object objArg) { m_action = action; m_archive = archive; m_objArg = objArg; } public Object run() throws Exception { switch (m_action) { case INITIALIZE_ACTION: m_archive.initializeUnchecked(m_isArg); return null; case UPDATE_ACTION: m_archive.updateUnchecked(m_isArg); return null; case PURGE_ACTION: m_archive.purgeUnchecked(); return null; case REMOVE_ACTION: m_archive.removeUnchecked(); return null; case GET_REVISION_COUNT_ACTION: return new Integer(m_archive.getRevisionCountUnchecked()); case GET_LOCATION_ACTION: return m_archive.getLocationUnchecked(); case GET_PERSISTENT_STATE_ACTION: return new Integer(m_archive.getPersistentStateUnchecked()); case SET_PERSISTENT_STATE_ACTION: m_archive.setPersistentStateUnchecked(m_intArg); return null; case GET_START_LEVEL_ACTION: return new Integer(m_archive.getStartLevelUnchecked()); case SET_START_LEVEL_ACTION: m_archive.setStartLevelUnchecked(m_intArg); return null; case OPEN_BUNDLE_JAR_ACTION: return m_archive.openBundleJarUnchecked(m_fileArg); case CREATE_DATA_DIR_ACTION: m_archive.createDataDirectoryUnchecked(m_fileArg); return null; case GET_CLASS_PATH_ACTION: return m_archive.getClassPathUnchecked(m_intArg); case GET_ACTIVATOR_ACTION: return m_archive.getActivatorUnchecked(m_loaderArg); case SET_ACTIVATOR_ACTION: m_archive.setActivatorUnchecked(m_objArg); return null; } throw new IllegalArgumentException("Invalid action specified."); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -