📄 extensionvalidator.java
字号:
ManifestResource.SYSTEM);
containerManifestResources.add(mre);
}
}
// -------------------------------------------------------- Private Methods
/**
* Validates a <code>ArrayList</code> of <code>ManifestResource</code>
* objects. This method requires an application name (which is the
* context root of the application at runtime).
*
* <code>false</false> is returned if the extension dependencies
* represented by any given <code>ManifestResource</code> objects
* is not met.
*
* This method should also provide static validation of a Web Applicaiton
* if provided with the necessary parameters.
*
* @param appName The name of the Application that will appear in the
* error messages
* @param resources A list of <code>ManifestResource</code> objects
* to be validated.
*
* @return true if manifest resource file requirements are met
*/
private static boolean validateManifestResources(String appName,
ArrayList resources) {
boolean passes = true;
int failureCount = 0;
ArrayList availableExtensions = null;
Iterator it = resources.iterator();
while (it.hasNext()) {
ManifestResource mre = (ManifestResource)it.next();
ArrayList requiredList = mre.getRequiredExtensions();
if (requiredList == null) {
continue;
}
// build the list of available extensions if necessary
if (availableExtensions == null) {
availableExtensions = buildAvailableExtensionsList(resources);
}
// load the container level resource map if it has not been built
// yet
if (containerAvailableExtensions == null) {
containerAvailableExtensions
= buildAvailableExtensionsList(containerManifestResources);
}
// iterate through the list of required extensions
Iterator rit = requiredList.iterator();
while (rit.hasNext()) {
boolean found = false;
Extension requiredExt = (Extension)rit.next();
// check the applicaion itself for the extension
if (availableExtensions != null) {
Iterator ait = availableExtensions.iterator();
while (ait.hasNext()) {
Extension targetExt = (Extension) ait.next();
if (targetExt.isCompatibleWith(requiredExt)) {
requiredExt.setFulfilled(true);
found = true;
break;
}
}
}
// check the container level list for the extension
if (!found && containerAvailableExtensions != null) {
Iterator cit = containerAvailableExtensions.iterator();
while (cit.hasNext()) {
Extension targetExt = (Extension) cit.next();
if (targetExt.isCompatibleWith(requiredExt)) {
requiredExt.setFulfilled(true);
found = true;
break;
}
}
}
if (!found) {
// Failure
log.info(sm.getString(
"extensionValidator.extension-not-found-error",
appName, mre.getResourceName(),
requiredExt.getExtensionName()));
passes = false;
failureCount++;
}
}
}
if (!passes) {
log.info(sm.getString(
"extensionValidator.extension-validation-error", appName,
failureCount + ""));
}
return passes;
}
/*
* Build this list of available extensions so that we do not have to
* re-build this list every time we iterate through the list of required
* extensions. All available extensions in all of the
* <code>MainfestResource</code> objects will be added to a
* <code>HashMap</code> which is returned on the first dependency list
* processing pass.
*
* The key is the name + implementation version.
*
* NOTE: A list is built only if there is a dependency that needs
* to be checked (performance optimization).
*
* @param resources A list of <code>ManifestResource</code> objects
*
* @return HashMap Map of available extensions
*/
private static ArrayList buildAvailableExtensionsList(ArrayList resources) {
ArrayList availableList = null;
Iterator it = resources.iterator();
while (it.hasNext()) {
ManifestResource mre = (ManifestResource)it.next();
ArrayList list = mre.getAvailableExtensions();
if (list != null) {
Iterator values = list.iterator();
while (values.hasNext()) {
Extension ext = (Extension) values.next();
if (availableList == null) {
availableList = new ArrayList();
availableList.add(ext);
} else {
availableList.add(ext);
}
}
}
}
return availableList;
}
/**
* Return the Manifest from a jar file or war file
*
* @param inStream Input stream to a WAR or JAR file
* @return The WAR's or JAR's manifest
*/
private static Manifest getManifest(InputStream inStream)
throws IOException {
Manifest manifest = null;
JarInputStream jin = null;
try {
jin = new JarInputStream(inStream);
manifest = jin.getManifest();
jin.close();
jin = null;
} finally {
if (jin != null) {
try {
jin.close();
} catch (Throwable t) {
// Ignore
}
}
}
return manifest;
}
/**
* Add the JARs specified to the extension list.
*/
private static void addFolderList(String property) {
// get the files in the extensions directory
String extensionsDir = System.getProperty(property);
if (extensionsDir != null) {
StringTokenizer extensionsTok
= new StringTokenizer(extensionsDir, File.pathSeparator);
while (extensionsTok.hasMoreTokens()) {
File targetDir = new File(extensionsTok.nextToken());
if (!targetDir.exists() || !targetDir.isDirectory()) {
continue;
}
File[] files = targetDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].getName().toLowerCase().endsWith(".jar")) {
try {
addSystemResource(files[i]);
} catch (IOException e) {
log.error
(sm.getString
("extensionValidator.failload", files[i]), e);
}
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -