Class ArtifactFactory
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.artifactModel.ArtifactFactory
-
public class ArtifactFactory extends java.lang.ObjectA factory to create individual artifacts. Please note that this factory does not store an entire artifact model rather than it creates individual artifacts. SeecreateArtifactModel(File)for creating an artifact model instance. Callrelease(ArtifactModel)if an artifact model instance is not used anymore.- Author:
- Holger Eichelberger
-
-
Field Summary
Fields Modifier and Type Field Description private static ArtifactCreatorNodeARTIFACT_CREATORSStores a tree of artifact creator nodes.private static java.lang.StringDEFAULT_MODEL_BASEprivate static EASyLoggerFactory.EASyLoggerLOGGERprivate static java.util.List<ArtifactModel>MODELS
-
Constructor Summary
Constructors Modifier Constructor Description privateArtifactFactory()Prevents external creation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddArtifactCreator(IArtifactCreator creator)Add artifact creator to the set of artifact creators for automatic (default) creation of artifacts.static java.lang.StringcheckReplacement(java.lang.Class<?> registered, java.lang.Class<?> replacing)static voidclear()Clears the whole artifact model (for testing, failure case).static voidclearDefaultModel()Clears the default model containing unmatched artifacts.static java.util.List<Message>configureArtifactCreators(java.util.Properties properties)Configures the artifact creators.private static voidconfigureArtifactCreators(ArtifactCreatorNode node, java.util.Properties properties, java.util.List<Message> messages)Configures the givennodeand its children.static <T extends IArtifact>
TcreateArtifact(java.lang.Class<T> kind, java.lang.Object real, ArtifactModel model)Creates an artifact instance.static IArtifactcreateArtifact(java.lang.Object real)Creates an artifact instance.static ArtifactModelcreateArtifactModel(java.io.File base)Creates an artifact model which is linked to its artifact so that it is notified about relevant changes.static IFileSystemArtifactcreateFileSystemArtifact(java.io.File real)Creates an artifact instance.(package private) static IFileSystemArtifactcreateFileSystemArtifact(java.io.File real, ArtifactModel model)Creates an artifact instance.private static IArtifactCreatorfindCreator(java.lang.Class<? extends IArtifact> kind, java.lang.Object real)Returns a creator forreal.private static ArtifactCreatorNodefindCreator(java.lang.Class<? extends IArtifact> kind, java.lang.Object real, ArtifactCreatorNode node, ArtifactCreatorNode actualResult)Recursive search for a creator.static ArtifactModelfindModel(java.lang.Object real)Returns the artifact model which is most specific forreal.(package private) static ArtifactCreatorgetCreator(java.lang.Class<?> cls)Returns theArtifactCreatorannotation forcls.(package private) static ArtifactModelgetDefaultArtifactModel()Returns the default artifact model.private static voidinitialize()Initializes the artifact factory models with one default model storing unmatching artifacts.static voidregistered(java.lang.Class<?> cls)Is called to notify that the given classclswas registered inTypeRegistry.static voidrelease(ArtifactModel model)Releases and unregisters the given artifact model.static Set<FileArtifact>selectByType(Path path, java.lang.Class<?> type, boolean byKind, boolean negate)Searches for paths in the artifact model by type.
-
-
-
Field Detail
-
DEFAULT_MODEL_BASE
private static final java.lang.String DEFAULT_MODEL_BASE
- See Also:
- Constant Field Values
-
ARTIFACT_CREATORS
private static final ArtifactCreatorNode ARTIFACT_CREATORS
Stores a tree of artifact creator nodes. The top level tree node is the most generic (no creator) in order to simplify the algorithms.
-
LOGGER
private static final EASyLoggerFactory.EASyLogger LOGGER
-
MODELS
private static final java.util.List<ArtifactModel> MODELS
-
-
Method Detail
-
initialize
private static void initialize()
Initializes the artifact factory models with one default model storing unmatching artifacts.
-
clear
public static void clear()
Clears the whole artifact model (for testing, failure case).
-
createArtifactModel
public static ArtifactModel createArtifactModel(java.io.File base)
Creates an artifact model which is linked to its artifact so that it is notified about relevant changes. Each obtained artifact model must be released by callingrelease(ArtifactModel).- Parameters:
base- the base directory for file relocation, shall be the related project root- Returns:
- the instantiation environment
-
release
public static void release(ArtifactModel model)
Releases and unregisters the given artifact model.- Parameters:
model- the model to be released
-
clearDefaultModel
public static void clearDefaultModel()
Clears the default model containing unmatched artifacts.
-
createArtifact
public static IArtifact createArtifact(java.lang.Object real) throws VilException
Creates an artifact instance.- Parameters:
real- the real (underlying) artifact instance- Returns:
- the resulting handling artifact
- Throws:
VilException- in case that the creation fails, e.g.,realis null- See Also:
createArtifact(Class, Object, ArtifactModel)
-
createArtifact
public static <T extends IArtifact> T createArtifact(java.lang.Class<T> kind, java.lang.Object real, ArtifactModel model) throws VilException
Creates an artifact instance.- Type Parameters:
T- the type of the artifact to be returned- Parameters:
kind- the kind of artifact in terms of a class (typically the top-level interfaces)real- the real (underlying) artifact instance (must be instance of Comparable)model- the model to add the artifact to, null if the factory shall determine the artifact model- Returns:
- the resulting handling artifact
- Throws:
VilException- in case that the creation fails, e.g.,realis null
-
createFileSystemArtifact
public static IFileSystemArtifact createFileSystemArtifact(java.io.File real) throws VilException
Creates an artifact instance.- Parameters:
real- the real (underlying) artifact instance- Returns:
- the resulting handling artifact
- Throws:
VilException- in case that the creation fails, e.g.,realis null- See Also:
createArtifact(Class, Object, ArtifactModel)
-
createFileSystemArtifact
static IFileSystemArtifact createFileSystemArtifact(java.io.File real, ArtifactModel model) throws VilException
Creates an artifact instance.- Parameters:
real- the real (underlying) artifact instancemodel- the model to add the artifact to, null if the factory shall determine the artifact model- Returns:
- the resulting handling artifact
- Throws:
VilException- in case that the creation fails, e.g.,realis null- See Also:
createArtifact(Class, Object, ArtifactModel)
-
getCreator
static ArtifactCreator getCreator(java.lang.Class<?> cls)
Returns theArtifactCreatorannotation forcls.- Parameters:
cls- the class to be examined- Returns:
- the annotation instance of null
-
checkReplacement
public static java.lang.String checkReplacement(java.lang.Class<?> registered, java.lang.Class<?> replacing)- Parameters:
registered- the already registered classreplacing- the replacing class- Returns:
- an error message or null if replacement is ok
-
registered
public static void registered(java.lang.Class<?> cls)
Is called to notify that the given classclswas registered inTypeRegistry. A more loose coupling would be preferrable but this would require more explicit registration...- Parameters:
cls- the class which that registered
-
addArtifactCreator
public static void addArtifactCreator(IArtifactCreator creator)
Add artifact creator to the set of artifact creators for automatic (default) creation of artifacts.- Parameters:
creator- the creator to be added
-
findCreator
private static IArtifactCreator findCreator(java.lang.Class<? extends IArtifact> kind, java.lang.Object real)
Returns a creator forreal.- Parameters:
kind- the kind of artifact in terms of a class (typically the top-level interfaces)real- the real artifact instance- Returns:
- the creator, may be null if no artifact creator is able to handle
real
-
findCreator
private static ArtifactCreatorNode findCreator(java.lang.Class<? extends IArtifact> kind, java.lang.Object real, ArtifactCreatorNode node, ArtifactCreatorNode actualResult)
Recursive search for a creator.- Parameters:
kind- the kind of artifact in terms of a class (typically the top-level interfaces)real- the real artifact instancenode- the node to analyze (including children)actualResult- the actual result (in order to issue warnings in case of multiple results)- Returns:
- the actual (refined) result
-
configureArtifactCreators
private static void configureArtifactCreators(ArtifactCreatorNode node, java.util.Properties properties, java.util.List<Message> messages)
Configures the givennodeand its children.- Parameters:
node- the node to be configuredproperties- the properties containing the configurationmessages- configuration messages (to be modified as a side effect)
-
configureArtifactCreators
public static java.util.List<Message> configureArtifactCreators(java.util.Properties properties)
Configures the artifact creators. Each artifact creator may look for a property with its own single name and read a comma separated list of regular file path patterns for its configuration. If empty, the artifact creator shall be disabled. If IfIArtifactCreator.DEFAULT_PATTERNis contained, then the default implementation shall be called, otherwise only the configured entries shall be considered.
Please call this method when all types are registered so that all artifact creators are known.- Parameters:
properties- the properties for configuring the artifact creators- Returns:
- configuration messages, i.e., warnings and errors which occurred while configuring the artifact creators
-
selectByType
public static Set<FileArtifact> selectByType(Path path, java.lang.Class<?> type, boolean byKind, boolean negate)
Searches for paths in the artifact model by type.- Parameters:
path- the path denoting the artifacts to be selectedtype- the type of the artifacts to be returned (may be null if type selection does not apply)byKind- by subtyping (true) or by equality (false)negate- negate the selection- Returns:
- the found artifacts
-
findModel
public static ArtifactModel findModel(java.lang.Object real)
Returns the artifact model which is most specific forreal.- Parameters:
real- the real artifact (or its string path)- Returns:
- the matching artifact model
-
getDefaultArtifactModel
static ArtifactModel getDefaultArtifactModel()
Returns the default artifact model.- Returns:
- the default artifact model
-
-