Package io.microsphere.classloading
Class StreamArtifactResourceResolver
- java.lang.Object
-
- io.microsphere.classloading.AbstractArtifactResourceResolver
-
- io.microsphere.classloading.StreamArtifactResourceResolver
-
- All Implemented Interfaces:
ArtifactResourceResolver
,Prioritized
,java.lang.Comparable<Prioritized>
- Direct Known Subclasses:
ManifestArtifactResourceResolver
,MavenArtifactResourceResolver
public abstract class StreamArtifactResourceResolver extends AbstractArtifactResourceResolver
An abstract base class for implementingArtifactResourceResolver
that provides a skeletal implementation to resolve artifact resources from either a streamable resource (like a URL) or an archive file (like a JAR). This class handles common concerns such as:- Stream Handling: Reads and processes artifact metadata from various sources including URLs, JAR files, and directories.
- Error Handling: Provides consistent error logging when reading or resolving artifacts fails.
- Archive Support: Offers utility methods to extract metadata from JARs or files within a directory structure.
- Extensibility: Declares abstract methods that subclasses must implement to define custom logic for identifying metadata locations and constructing artifact instances.
Key Abstract Methods
isArtifactMetadata(String)
: Determines if the given relative path represents an artifact metadata file.resolve(URL, InputStream, ClassLoader)
: Constructs an artifact from the provided metadata stream.
Example Usage
{@code public class CustomStreamArtifactResourceResolver extends StreamArtifactResourceResolver { public CustomStreamArtifactResourceResolver(ClassLoader classLoader, int priority) { super(classLoader, priority); }
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
ArtifactResourceResolver
,AbstractArtifactResourceResolver
-
-
Field Summary
-
Fields inherited from class io.microsphere.classloading.AbstractArtifactResourceResolver
classLoader, logger, priority
-
Fields inherited from interface io.microsphere.lang.Prioritized
COMPARATOR, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description StreamArtifactResourceResolver(int priority)
StreamArtifactResourceResolver(java.lang.ClassLoader classLoader, int priority)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.io.File
findArtifactMetadata(java.io.File directory)
protected java.util.jar.JarEntry
findArtifactMetadataEntry(java.util.jar.JarFile jarFile)
protected abstract boolean
isArtifactMetadata(java.lang.String relativePath)
protected boolean
isArtifactMetadataEntry(java.util.jar.JarEntry jarEntry)
protected boolean
isArtifactMetadataFile(java.io.File directory, java.io.File file)
protected java.io.InputStream
readArtifactMetadataDataFromArchiveFile(java.io.File archiveFile)
protected java.io.InputStream
readArtifactMetadataDataFromDirectory(java.io.File directory)
protected java.io.InputStream
readArtifactMetadataDataFromFile(java.io.File archiveFile)
protected java.io.InputStream
readArtifactMetadataDataFromResource(java.net.URL resourceURL, java.lang.ClassLoader classLoader)
Artifact
resolve(java.net.URL resourceURL)
Resolve an instanceArtifact
fromthe resource
of artifact.protected abstract Artifact
resolve(java.net.URL resourceURL, java.io.InputStream artifactMetadataData, java.lang.ClassLoader classLoader)
-
Methods inherited from class io.microsphere.classloading.AbstractArtifactResourceResolver
getPriority, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.microsphere.lang.Prioritized
compareTo
-
-
-
-
Method Detail
-
resolve
public final Artifact resolve(java.net.URL resourceURL)
Description copied from interface:ArtifactResourceResolver
Resolve an instanceArtifact
fromthe resource
of artifact.- Parameters:
resourceURL
-the resource
of artifact, it may the archive file or the directory- Returns:
- an instance
Artifact
if found, otherwisenull
-
readArtifactMetadataDataFromResource
@Nullable protected java.io.InputStream readArtifactMetadataDataFromResource(java.net.URL resourceURL, java.lang.ClassLoader classLoader) throws java.io.IOException
- Throws:
java.io.IOException
-
readArtifactMetadataDataFromArchiveFile
@Nullable protected java.io.InputStream readArtifactMetadataDataFromArchiveFile(java.io.File archiveFile) throws java.io.IOException
- Throws:
java.io.IOException
-
readArtifactMetadataDataFromFile
@Nullable protected java.io.InputStream readArtifactMetadataDataFromFile(java.io.File archiveFile) throws java.io.IOException
- Throws:
java.io.IOException
-
readArtifactMetadataDataFromDirectory
@Nullable protected java.io.InputStream readArtifactMetadataDataFromDirectory(java.io.File directory) throws java.io.IOException
- Throws:
java.io.IOException
-
findArtifactMetadataEntry
protected java.util.jar.JarEntry findArtifactMetadataEntry(java.util.jar.JarFile jarFile) throws java.io.IOException
- Throws:
java.io.IOException
-
findArtifactMetadata
protected java.io.File findArtifactMetadata(java.io.File directory) throws java.io.IOException
- Throws:
java.io.IOException
-
isArtifactMetadataEntry
protected boolean isArtifactMetadataEntry(java.util.jar.JarEntry jarEntry)
-
isArtifactMetadataFile
protected boolean isArtifactMetadataFile(java.io.File directory, java.io.File file)
-
isArtifactMetadata
protected abstract boolean isArtifactMetadata(java.lang.String relativePath)
-
resolve
protected abstract Artifact resolve(java.net.URL resourceURL, java.io.InputStream artifactMetadataData, java.lang.ClassLoader classLoader) throws java.io.IOException
- Throws:
java.io.IOException
-
-