com.sun.enterprise.module.common_impl
Class AbstractRepositoryImpl

java.lang.Object
  extended by com.sun.enterprise.module.common_impl.AbstractRepositoryImpl
All Implemented Interfaces:
Repository
Direct Known Subclasses:
DirectoryBasedRepository, MavenProjectRepository

public abstract class AbstractRepositoryImpl
extends Object
implements Repository

Partial implementation of Repository that statically enumerates all ModuleDefinition upfront.

Author:
Kohsuke Kawaguchi, Jerome Dochez, Sanjeeb.Sahoo@Sun.COM

Field Summary
protected  List<RepositoryChangeListener> listeners
           
 
Constructor Summary
AbstractRepositoryImpl(String name, URI location)
           
 
Method Summary
protected  void add(ModuleDefinition def)
           
protected  void addLibrary(URI location)
           
 boolean addListener(RepositoryChangeListener listener)
          Add a listener to changes happening to this repository.
 ModuleDefinition find(String name, String version)
          Finds and returns a DefaultModuleDefinition instance for a module given the name and version constraints.
 List<ModuleDefinition> findAll()
          Returns a list of all modules available in this repository
 List<ModuleDefinition> findAll(String name)
          Finds and returns a list of all the available versions of a module given its name.
 List<URI> getJarLocations()
          Returns the plain jar files installed in this repository.
 URI getLocation()
          Returns the repository location
 String getName()
          Returns the repository name
 void initialize()
          Initialize the repository for use.
protected  ModuleDefinition loadJar(File jar)
          Loads a jar file and builds a ModuleDefinition.
protected abstract  void loadModuleDefs(Map<ModuleId,ModuleDefinition> moduleDefs, List<URI> libraries)
          Called from initialize() to load all ModuleDefinitions and libraries defintions
protected  ModuleDefinition newModuleDefinition(File jar, Attributes attr)
          Extensibility point for subclasses to create a different instance of ModuleDefinition.
protected  void remove(ModuleDefinition def)
           
protected  void removeLibrary(URI location)
           
 boolean removeListener(RepositoryChangeListener listener)
          Removes a previously registered listener
 void shutdown()
          Shutdown the repository.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listeners

protected List<RepositoryChangeListener> listeners
Constructor Detail

AbstractRepositoryImpl

public AbstractRepositoryImpl(String name,
                              URI location)
Method Detail

getName

public String getName()
Description copied from interface: Repository
Returns the repository name

Specified by:
getName in interface Repository
Returns:
repository name

getLocation

public URI getLocation()
Description copied from interface: Repository
Returns the repository location

Specified by:
getLocation in interface Repository
Returns:
the URI for the repository location

find

public ModuleDefinition find(String name,
                             String version)
Description copied from interface: Repository
Finds and returns a DefaultModuleDefinition instance for a module given the name and version constraints.

Specified by:
find in interface Repository
Parameters:
name - the requested module name
version - the module version. Can be null if the caller doesn't care about the version.
Returns:
a DefaultModuleDefinition or null if not found in this repository.

findAll

public List<ModuleDefinition> findAll()
Description copied from interface: Repository
Returns a list of all modules available in this repository

Specified by:
findAll in interface Repository
Returns:
a list of available modules

findAll

public List<ModuleDefinition> findAll(String name)
Description copied from interface: Repository
Finds and returns a list of all the available versions of a module given its name.

Specified by:
findAll in interface Repository
Parameters:
name - the requested module name

initialize

public void initialize()
                throws IOException
Description copied from interface: Repository
Initialize the repository for use. This need to be called at least once before any find methods is invoked.

Specified by:
initialize in interface Repository
Throws:
IOException - if an error occur accessing the repository

loadModuleDefs

protected abstract void loadModuleDefs(Map<ModuleId,ModuleDefinition> moduleDefs,
                                       List<URI> libraries)
                                throws IOException
Called from initialize() to load all ModuleDefinitions and libraries defintions

Throws:
IOException

loadJar

protected ModuleDefinition loadJar(File jar)
                            throws IOException
Loads a jar file and builds a ModuleDefinition.

The system allows ModuleDefinitions to be built in any way, but in practice module jars need to be built in a way agnostic to Repository implementations (so that same module could be used in different Repositorys), 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:
IOException

add

protected void add(ModuleDefinition def)

remove

protected void remove(ModuleDefinition def)

addLibrary

protected void addLibrary(URI location)

removeLibrary

protected void removeLibrary(URI location)

shutdown

public void shutdown()
              throws IOException
Description copied from interface: Repository
Shutdown the repository. After this call return, the find methods cannot be used until initialize() is called again.

Specified by:
shutdown in interface Repository
Throws:
IOException - if an error occur accessing the repository

toString

public String toString()
Overrides:
toString in class Object

getJarLocations

public List<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:
getJarLocations in interface Repository
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:
addListener in interface Repository
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:
removeListener in interface Repository
Parameters:
listener - the previously registered listener
Returns:
true if the listener was successfully unregistered

newModuleDefinition

protected ModuleDefinition newModuleDefinition(File jar,
                                               Attributes attr)
                                        throws IOException
Extensibility point for subclasses to create a different instance of ModuleDefinition.

Parameters:
jar - The module jar file for which ModuleDefinition will be created. Never null.
Throws:
IOException


Copyright © 2013 Oracle Corporation. All Rights Reserved.