net.sf.mmm.util.reflect.base
Class ManifestLoader

java.lang.Object
  extended by net.sf.mmm.util.reflect.base.ManifestLoader

public class ManifestLoader
extends Object

This class loads all Manifests from your classpath. After construction an instance of this class allows you to get the list of Manifests. This allows you to determine details (e.g. the name and version) about the libraries in your classpath.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private static String JAR_SUFFIX
          The JAR suffix.
static Attributes.Name MANIFEST_SOURCE
          The Name of the source of the Manifest.
private  List<Manifest> manifests
          the list of the manifests
 
Constructor Summary
  ManifestLoader()
          The constructor.
private ManifestLoader(ClassLoader classloader)
          The constructor.
 
Method Summary
private static void completeManifest(Manifest manifest, URL url)
          This method adds dynamic attributes to the given manifest.
 List<Manifest> getManifests()
          This method gets an unmodifiable list with all available Manifests.
static String getValue(Manifest manifest, Attributes.Name name)
          This method gets an attribute-value from a Manifest in a pragmatic way.
static Manifest loadManifest(Class<?> type)
          This method tries to load the Manifest for the given Class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANIFEST_SOURCE

public static final Attributes.Name MANIFEST_SOURCE
The Name of the source of the Manifest. This is a property that is NOT intended to be defined in the manifest file itself but is set dynamically as main-property to the source of the manifest (e.g. the name of the JAR-file) if loaded via ManifestLoader.


JAR_SUFFIX

private static final String JAR_SUFFIX
The JAR suffix.

See Also:
Constant Field Values

manifests

private final List<Manifest> manifests
the list of the manifests

Constructor Detail

ManifestLoader

public ManifestLoader()
               throws RuntimeIoException
The constructor.

Throws:
RuntimeIoException - if a general I/O error occurred while reflectively reading the manifests.

ManifestLoader

private ManifestLoader(ClassLoader classloader)
                throws RuntimeIoException
The constructor.

Parameters:
classloader - is the ClassLoader used to find and load the Manifests.
Throws:
RuntimeIoException - if a general I/O error occurred while reflectively reading the manifests.
Method Detail

completeManifest

private static void completeManifest(Manifest manifest,
                                     URL url)
This method adds dynamic attributes to the given manifest.

Parameters:
manifest - is the Manifest to modify.
url - is the URL with the source of the manifest.

getManifests

public List<Manifest> getManifests()
This method gets an unmodifiable list with all available Manifests. On a Manifest you may call something like this:
 manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION)
 

Returns:
the list with the manifests.
See Also:
Manifest.getMainAttributes(), Attributes.Name, MANIFEST_SOURCE

loadManifest

public static Manifest loadManifest(Class<?> type)
This method tries to load the Manifest for the given Class. E.g. if the given Class comes from a JarFile the Manifest of that JarFile is returned.

Parameters:
type - is the Class for which the according Manifest is requested.
Returns:
the according Manifest or null if NOT available.
Since:
2.0.0

getValue

public static String getValue(Manifest manifest,
                              Attributes.Name name)
This method gets an attribute-value from a Manifest in a pragmatic way. It tries to get the value from the main-attributes. If NOT available it searches all other available attribute entries for the value and returns the first one found in deterministic but unspecified order.

Parameters:
manifest - is the Manifest where to get the attribute-value from.
name - is the Name of the requested attribute.
Returns:
the requested value or null if NOT available.
Since:
2.0.0


Copyright © 2001-2010 mmm-Team. All Rights Reserved.