Methods Summary |
---|
private void | addExtJarsFromDirectory(java.util.Map map, int extensionDirNumber, java.io.File extDir)Adds entries for the extension files from one directory to the indicated Map.
File [] extJars = extDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
if (extJars != null) {
for (File file : extJars) {
Extension entry = buildExtensionForJar(file, extensionDirNumber);
if (entry != null) {
map.put(entry.extensionKey, entry);
}
}
}
|
private java.util.Vector | buildExtensionFileDirs()Constructs the collection of File objects, one for each extension directory.
Vector<File> result = new Vector<File>();
String extDirs = System.getProperty(EXT_DIRS_PROPERTY_NAME);
StringTokenizer stkn = new StringTokenizer(extDirs, File.pathSeparator);
while (stkn.hasMoreTokens()) {
String extensionDirPath = stkn.nextToken();
result.add(new File(extensionDirPath));
}
return result;
|
private java.util.Map | buildExtensionFileEntries(java.util.Vector dirs)Constructs the collection of extension files known to the app server.
/*
*For each extension directory, collect all jar files
*and add an entry (containing File and spec version string) for each
*file into the data structure.
*/
Map<ExtensionKey,Extension> result = new HashMap<ExtensionKey,Extension>();
for (int i = 0; i < dirs.size(); i++) {
addExtJarsFromDirectory(result, i, dirs.get(i));
}
return result;
|
private com.sun.enterprise.appclient.jws.ExtensionFileManager$Extension | buildExtensionForJar(java.io.File file, int extDirectoryNumber)Creates an extension Extension for a jar file if the jar is in fact an extension.
Extension result = null;
JarFile jarFile = null;
try {
jarFile = new JarFile(file);
ExtensionKey key = getDefinedExtensionKey(jarFile);
if (key != null) {
result = new Extension(key, file, extDirectoryNumber);
}
return result;
} finally {
if (jarFile != null) {
jarFile.close();
}
}
|
private java.util.Set | extensionsToFiles(java.util.Set extensions)Returns a Set of File objects corresponding to the supplied set of Extensions.
Set<File> result = new HashSet<File>();
for (Extension e : extensions) {
result.add(e.file);
}
return result;
|
public java.util.Set | findExtensionTransitiveClosure(java.io.File anchorDir, java.util.jar.Attributes mainAttrs)Constructs a List of Extension objects corresponding to jars required to
satisfy an extension chain.
The transitive closure includes any extensions required by the
initial jar, its Class-Path jars, and any extensions required
by extensions.
Set<Extension> result = new HashSet<Extension>();
Vector<File> filesToProcess = new Vector<File>();
filesToProcess.addAll(getClassPathJars(anchorDir, mainAttrs));
Set<Extension> extensionsUsedByApp = getReferencedExtensions(mainAttrs);
result.addAll(extensionsUsedByApp);
filesToProcess.addAll(extensionsToFiles(extensionsUsedByApp));
/**
*Do not use the for/each construct next because the loop may add
*elements to the vector and for/each would through a concurrent
*modification exception.
*/
for (int i = 0; i < filesToProcess.size(); i++) {
File nextFile = filesToProcess.get(i);
/*
*The Class-Path entry might point to a directory. If so, skip it
*because directories do not support extensions.
*/
if (nextFile.exists() && nextFile.isDirectory()) {
continue;
}
try {
JarFile nextJarFile = new JarFile(nextFile);
try {
Attributes attrs = getMainAttrs(nextJarFile);
Set<Extension> newExtensions = getReferencedExtensions(attrs);
result.addAll(newExtensions);
filesToProcess.addAll(extensionsToFiles(newExtensions));
} finally {
if (nextJarFile != null) {
nextJarFile.close();
}
}
} catch (Exception e) {
_logger.log(Level.WARNING, localStrings.getString("jws.extension.error", nextFile.getAbsolutePath()), e);
}
}
return result;
|
private java.util.List | getClassPathJars(java.io.File anchorDir, java.util.jar.Attributes mainAttrs)Returns the Files corresponding to the Class-Path entries (if any) in a
Jar file's main attributes.
List<File> result = new LinkedList<File>();
String classPathList = mainAttrs.getValue(Attributes.Name.CLASS_PATH);
if (classPathList != null) {
StringTokenizer stkn = new StringTokenizer(classPathList, " ");
while (stkn.hasMoreTokens()) {
String classPathJarPath = stkn.nextToken();
File classPathJarFile = new File(classPathJarPath);
if ( ! classPathJarFile.isAbsolute()) {
classPathJarFile = new File(anchorDir, classPathJarPath);
}
result.add(classPathJarFile);
}
}
return result;
|
private com.sun.enterprise.appclient.jws.ExtensionFileManager$ExtensionKey | getDefinedExtensionKey(java.util.jar.JarFile jarFile)Returns the ExtensionKey for the extension which the specified JarFile provides (if any).
ExtensionKey result = null;
Attributes mainAttrs = getMainAttrs(jarFile);
if (mainAttrs != null) {
String extName = mainAttrs.getValue(Attributes.Name.EXTENSION_NAME);
if (extName != null) {
String specVersion = mainAttrs.getValue(Attributes.Name.SPECIFICATION_VERSION);
result = new ExtensionKey(extName, specVersion);
}
}
return result;
|
public java.util.Map | getExtensionFileEntries()
return extensionFileInfo;
|
private java.util.jar.Attributes | getMainAttrs(java.util.jar.JarFile jarFile)Returns the main attributes (if any) object from a jar file.
Attributes result = null;
Manifest mf = jarFile.getManifest();
if (mf != null) {
result = mf.getMainAttributes();
}
return result;
|
private java.util.Set | getReferencedExtensionKeys(java.util.jar.Attributes mainAttrs)Returns the ExtensionKeys for the extension jars referenced by the specified main attributes
Set<ExtensionKey> result = new HashSet<ExtensionKey>();
if (mainAttrs != null) {
String extensionList = mainAttrs.getValue(Attributes.Name.EXTENSION_LIST);
if (extensionList != null) {
StringTokenizer stkn = new StringTokenizer(extensionList, " ");
while (stkn.hasMoreTokens()) {
/*
*For each extension jar in this jar's list, create a new
*ExtensionKey using the name and spec version.
*/
String token = stkn.nextToken().trim();
String extName = mainAttrs.getValue(token + "-" + Attributes.Name.EXTENSION_NAME);
String specVersion = mainAttrs.getValue(token + "-" + Attributes.Name.SPECIFICATION_VERSION);
ExtensionKey key = new ExtensionKey(extName, specVersion);
result.add(key);
}
}
}
return result;
|
private java.util.Set | getReferencedExtensions(java.util.jar.Attributes mainAttrs)Returns a Set of Extensions that are referenced by the jar file whose
main attributes are passed.
Set<Extension> result = new HashSet<Extension>();
Set<ExtensionKey> extensionKeys = getReferencedExtensionKeys(mainAttrs);
for (ExtensionKey key : extensionKeys) {
if ( ! result.contains(key)) {
Extension extension = extensionFileInfo.get(key);
/*
*Add this extension only if it does not already appear
*in the result collection. In that case, also add the
*file to the collection of files to be processed.
*/
if (extension != null) {
result.add(extension);
} else {
throw new IOException("Jar file requires the extension " + key + " but it is not in the known extensions " + extensionFileInfo);
}
}
}
return result;
|