Class AbstractRepositoryImpl
- java.lang.Object
-
- com.sun.enterprise.module.common_impl.AbstractRepositoryImpl
-
- All Implemented Interfaces:
Repository
- Direct Known Subclasses:
DirectoryBasedRepository
public abstract class AbstractRepositoryImpl extends java.lang.Object implements Repository
Partial implementation ofRepositorythat statically enumerates allModuleDefinitionupfront.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.net.URI>librariesprotected java.util.List<RepositoryChangeListener>listenersprivate java.net.URIlocationprivate java.util.Map<ModuleId,ModuleDefinition>moduleDefsprivate java.lang.Stringname
-
Constructor Summary
Constructors Constructor Description AbstractRepositoryImpl(java.lang.String name, java.net.URI location)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidadd(ModuleDefinition def)protected voidaddLibrary(java.net.URI location)booleanaddListener(RepositoryChangeListener listener)Add a listener to changes happening to this repository.ModuleDefinitionfind(java.lang.String name, java.lang.String version)Finds and returns aDefaultModuleDefinitioninstance for a module given the name and version constraints.java.util.List<ModuleDefinition>findAll()Returns a list of all modules available in this repositoryjava.util.List<ModuleDefinition>findAll(java.lang.String name)Finds and returns a list of all the available versions of a module given its name.java.util.List<java.net.URI>getJarLocations()Returns the plain jar files installed in this repository.java.net.URIgetLocation()Returns the repository locationjava.lang.StringgetName()Returns the repository namevoidinitialize()Initialize the repository for use.protected ModuleDefinitionloadJar(java.io.File jar)Loads a jar file and builds aModuleDefinition.protected abstract voidloadModuleDefs(java.util.Map<ModuleId,ModuleDefinition> moduleDefs, java.util.List<java.net.URI> libraries)Called frominitialize()to load allModuleDefinitions and libraries defintionsprotected ModuleDefinitionnewModuleDefinition(java.io.File jar, java.util.jar.Attributes attr)Extensibility point for subclasses to create a different instance ofModuleDefinition.protected voidremove(ModuleDefinition def)protected voidremoveLibrary(java.net.URI location)booleanremoveListener(RepositoryChangeListener listener)Removes a previously registered listenervoidshutdown()Shutdown the repository.java.lang.StringtoString()
-
-
-
Field Detail
-
name
private final java.lang.String name
-
location
private final java.net.URI location
-
moduleDefs
private java.util.Map<ModuleId,ModuleDefinition> moduleDefs
-
libraries
private java.util.List<java.net.URI> libraries
-
listeners
protected java.util.List<RepositoryChangeListener> listeners
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:RepositoryReturns the repository name- Specified by:
getNamein interfaceRepository- Returns:
- repository name
-
getLocation
public java.net.URI getLocation()
Description copied from interface:RepositoryReturns the repository location- Specified by:
getLocationin interfaceRepository- Returns:
- the URI for the repository location
-
find
public ModuleDefinition find(java.lang.String name, java.lang.String version)
Description copied from interface:RepositoryFinds and returns aDefaultModuleDefinitioninstance for a module given the name and version constraints.- Specified by:
findin interfaceRepository- Parameters:
name- the requested module nameversion- the module version. Can be null if the caller doesn't care about the version.- Returns:
- a
DefaultModuleDefinitionor null if not found in this repository.
-
findAll
public java.util.List<ModuleDefinition> findAll()
Description copied from interface:RepositoryReturns a list of all modules available in this repository- Specified by:
findAllin interfaceRepository- Returns:
- a list of available modules
-
findAll
public java.util.List<ModuleDefinition> findAll(java.lang.String name)
Description copied from interface:RepositoryFinds and returns a list of all the available versions of a module given its name.- Specified by:
findAllin interfaceRepository- Parameters:
name- the requested module name
-
initialize
public void initialize() throws java.io.IOExceptionDescription copied from interface:RepositoryInitialize the repository for use. This need to be called at least once before any find methods is invoked.- Specified by:
initializein interfaceRepository- Throws:
java.io.IOException- if an error occur accessing the repository
-
loadModuleDefs
protected abstract void loadModuleDefs(java.util.Map<ModuleId,ModuleDefinition> moduleDefs, java.util.List<java.net.URI> libraries) throws java.io.IOException
Called frominitialize()to load allModuleDefinitions and libraries defintions- Throws:
java.io.IOException
-
loadJar
protected ModuleDefinition loadJar(java.io.File jar) throws java.io.IOException
Loads a jar file and builds aModuleDefinition.The system allows
ModuleDefinitions to be built in any way, but in practice module jars need to be built in a way agnostic toRepositoryimplementations (so that same module could be used in differentRepositorys), so it makes sense to try to stick to the "common" loading scheme.- Parameters:
jar- Either a jar file or a directory that has the same structure as a jar file.- Throws:
java.io.IOException
-
add
protected void add(ModuleDefinition def)
-
remove
protected void remove(ModuleDefinition def)
-
addLibrary
protected void addLibrary(java.net.URI location)
-
removeLibrary
protected void removeLibrary(java.net.URI location)
-
shutdown
public void shutdown() throws java.io.IOExceptionDescription copied from interface:RepositoryShutdown the repository. After this call return, the find methods cannot be used until initialize() is called again.- Specified by:
shutdownin interfaceRepository- Throws:
java.io.IOException- if an error occur accessing the repository
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getJarLocations
public java.util.List<java.net.URI> getJarLocations()
Returns the plain jar files installed in this repository. Plain jar files are not modules, they do not have the module's metadata and can only be used when referenced from a module dependency list or when added to a class loader directly- Specified by:
getJarLocationsin interfaceRepository- Returns:
- jar files location stored in this repository.
-
addListener
public boolean addListener(RepositoryChangeListener listener)
Add a listener to changes happening to this repository. Repository can change during the lifetime of an execution (files added/removed/changed)- Specified by:
addListenerin interfaceRepository- Parameters:
listener- implementation listening to this repository changes- Returns:
- true if the listener was added successfully
-
removeListener
public boolean removeListener(RepositoryChangeListener listener)
Removes a previously registered listener- Specified by:
removeListenerin interfaceRepository- Parameters:
listener- the previously registered listener- Returns:
- true if the listener was successfully unregistered
-
newModuleDefinition
protected ModuleDefinition newModuleDefinition(java.io.File jar, java.util.jar.Attributes attr) throws java.io.IOException
Extensibility point for subclasses to create a different instance ofModuleDefinition.- Parameters:
jar- The module jar file for whichModuleDefinitionwill be created. Never null.- Throws:
java.io.IOException
-
-