org.rhq.core.util.file
Class JarContentFileInfo

java.lang.Object
  extended by org.rhq.core.util.file.ContentFileInfo
      extended by org.rhq.core.util.file.JarContentFileInfo

public class JarContentFileInfo
extends ContentFileInfo

Return the version of the jar file by inspecting the Manifest. The file does not necessarily need to be a jar but rather can be any archive satisfying jar file structure (e.g. an .ear or .war), exploded or not.

Author:
Jay Shaughnessy, John Mazzitelli

Constructor Summary
JarContentFileInfo(File file)
           
 
Method Summary
 String getAttributeValue(Attributes.Name attributeName, String defaultValue)
          Returns an attribute value as found in the manifest.
 String getAttributeValue(String attributeName, String defaultValue)
          Returns an attribute value as found in the manifest.
 String getDescription(String defaultValue)
          Return a description of the Jar file (or archive satisfying Jar file structure) by inspecting the Manifest.
 String getVersion(String defaultValue)
          Returns the version of the Jar file (or archive satisfying Jar file structure) by inspecting the Manifest.
 boolean isValid()
          Determines if the content file is a valid jar file (i.e.
 
Methods inherited from class org.rhq.core.util.file.ContentFileInfo
getContentFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JarContentFileInfo

public JarContentFileInfo(File file)
Method Detail

isValid

public boolean isValid()
Determines if the content file is a valid jar file (i.e. one that has a manifest). Even if this returns true, you still are not guaranteed the jar file has a non-null version because there may not be a version attribute in the manifest.

Specified by:
isValid in class ContentFileInfo
Returns:
true if the file is a valid jar file with a manifest

getVersion

public String getVersion(String defaultValue)
Returns the version of the Jar file (or archive satisfying Jar file structure) by inspecting the Manifest. The returned version will be the following, with this preference:

Specification-Version (Implementation-Version)
Implementation-Version
Specification-Version

Specified by:
getVersion in class ContentFileInfo
Parameters:
defaultValue - the default value
Returns:
the version or the default if it cannot be determined

getDescription

public String getDescription(String defaultValue)
Return a description of the Jar file (or archive satisfying Jar file structure) by inspecting the Manifest. The returned description will be the value of one of the following attributes, with this preference:

Implementation-Title
Specification-Title

Specified by:
getDescription in class ContentFileInfo
Parameters:
defaultValue - the default value
Returns:
description or null if it cannot be determined

getAttributeValue

public String getAttributeValue(Attributes.Name attributeName,
                                String defaultValue)
Returns an attribute value as found in the manifest.

Parameters:
attributeName - the attribute name
defaultValue - the default if the attribute does not exist in the manifest
Returns:
the attribute value or the default if it doesn't exist or cannot be retrieved

getAttributeValue

public String getAttributeValue(String attributeName,
                                String defaultValue)
Returns an attribute value as found in the manifest.

Parameters:
attributeName - the attribute name
defaultValue - the default if the attribute does not exist in the manifest
Returns:
the attribute value or the default if it doesn't exist or cannot be retrieved


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.