Package org.ringojs.repository
Class AbstractRepository
- java.lang.Object
-
- org.ringojs.repository.AbstractRepository
-
- All Implemented Interfaces:
java.io.Serializable
,Repository
,Trackable
- Direct Known Subclasses:
FileRepository
,WebappRepository
,ZipRepository
public abstract class AbstractRepository extends java.lang.Object implements Repository
Provides common methods and fields for the default implementations of the repository interface- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.ringojs.repository.Repository
SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description AbstractRepository()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AbstractRepository
createChildRepository(java.lang.String name)
Create a new child reposiotory with the given name.AbstractRepository
getChildRepository(java.lang.String subpath)
Get a child repository with the given namejava.lang.String
getModuleName()
Utility method to get the name for the module defined by this resource.java.lang.String
getName()
Get the local name that identifies this repository locally within its parent repositoryAbstractRepository
getParentRepository()
Get this repository's parent repository.java.lang.String
getPath()
Get the full name that identifies this repository globallyjava.lang.String
getRelativePath()
Get the path of this repository relative to its root repository.Resource
getResource(java.lang.String subpath)
Get a resource contained in this repository identified by the given local name.Resource[]
getResources()
Get a list of resources contained in this repository identified by the given local name.Resource[]
getResources(boolean recursive)
Get a list of resources contained in this repository identified by the given local name.Resource[]
getResources(java.lang.String resourcePath, boolean recursive)
Get a list of resources contained in this repository identified by the given local name.protected abstract void
getResources(java.util.List<Resource> list, boolean recursive)
Add the repository's resources into the list, optionally descending into nested repositories.Repository
getRootRepository()
Get the repository's root repositoryboolean
isAbsolute()
Return true if this Repository is in absolute mode.protected AbstractRepository
lookupRepository(java.lang.String name)
protected abstract Resource
lookupResource(java.lang.String name)
Called to create a child resource for this repository if it exists.protected java.lang.String[]
resolve(java.lang.String path, boolean absolute)
Resolve path relative to this repository.void
setAbsolute(boolean absolute)
Set this Repository to absolute mode.void
setRoot()
Mark this repository as root repository.java.lang.String
toString()
Returns the repositories full path as string representation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.ringojs.repository.Repository
getRepositories
-
Methods inherited from interface org.ringojs.repository.Trackable
exists, getChecksum, getUrl, lastModified
-
-
-
-
Method Detail
-
lookupResource
protected abstract Resource lookupResource(java.lang.String name) throws java.io.IOException
Called to create a child resource for this repository if it exists.- Parameters:
name
- the name of the child resource- Returns:
- the child resource, or null if no resource with the given name exists
- Throws:
java.io.IOException
- an I/O error occurred
-
createChildRepository
protected abstract AbstractRepository createChildRepository(java.lang.String name) throws java.io.IOException
Create a new child reposiotory with the given name.- Parameters:
name
- the name- Returns:
- the new child repository
- Throws:
java.io.IOException
- an I/O error occurred
-
getResources
protected abstract void getResources(java.util.List<Resource> list, boolean recursive) throws java.io.IOException
Add the repository's resources into the list, optionally descending into nested repositories.- Parameters:
list
- the list to add the resources torecursive
- whether to descend into nested repositories- Throws:
java.io.IOException
- an I/O related error occurred
-
getPath
public java.lang.String getPath()
Get the full name that identifies this repository globally
-
getName
public java.lang.String getName()
Get the local name that identifies this repository locally within its parent repository
-
setRoot
public void setRoot()
Mark this repository as root repository.- Specified by:
setRoot
in interfaceRepository
-
setAbsolute
public void setAbsolute(boolean absolute)
Set this Repository to absolute mode. This will cause all its relative path operations to use absolute paths instead.- Specified by:
setAbsolute
in interfaceTrackable
- Parameters:
absolute
- true to operate in absolute mode
-
isAbsolute
public boolean isAbsolute()
Return true if this Repository is in absolute mode.- Specified by:
isAbsolute
in interfaceTrackable
- Returns:
- true if absolute mode is on
-
getRelativePath
public java.lang.String getRelativePath()
Get the path of this repository relative to its root repository.- Specified by:
getRelativePath
in interfaceRepository
- Specified by:
getRelativePath
in interfaceTrackable
- Returns:
- the repository path
-
getModuleName
public java.lang.String getModuleName()
Utility method to get the name for the module defined by this resource.- Specified by:
getModuleName
in interfaceTrackable
- Returns:
- the module name according to the securable module spec
-
resolve
protected java.lang.String[] resolve(java.lang.String path, boolean absolute)
Resolve path relative to this repository.- Parameters:
path
- a path stringabsolute
- whether to return an absolute path that can be used without this repository- Returns:
- a List containing the path elements resolved relative to this repository
-
getResource
public Resource getResource(java.lang.String subpath) throws java.io.IOException
Get a resource contained in this repository identified by the given local name. If the name can't be resolved to a resource, a resource object is returned for whichexists()
returnsfalse
.- Specified by:
getResource
in interfaceRepository
- Parameters:
subpath
- name of the child resource to return- Returns:
- specified child resource
- Throws:
java.io.IOException
-
getChildRepository
public AbstractRepository getChildRepository(java.lang.String subpath) throws java.io.IOException
Get a child repository with the given name- Specified by:
getChildRepository
in interfaceRepository
- Parameters:
subpath
- the name of the repository- Returns:
- the child repository
- Throws:
java.io.IOException
- an IOException occurred
-
lookupRepository
protected AbstractRepository lookupRepository(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
getParentRepository
public AbstractRepository getParentRepository()
Get this repository's parent repository.- Specified by:
getParentRepository
in interfaceTrackable
- Returns:
- parent repository
-
getRootRepository
public Repository getRootRepository()
Get the repository's root repository- Specified by:
getRootRepository
in interfaceTrackable
- Returns:
- root repository
-
getResources
public Resource[] getResources() throws java.io.IOException
Description copied from interface:Repository
Get a list of resources contained in this repository identified by the given local name.- Specified by:
getResources
in interfaceRepository
- Returns:
- a list of all direct child resources
- Throws:
java.io.IOException
-
getResources
public Resource[] getResources(boolean recursive) throws java.io.IOException
Description copied from interface:Repository
Get a list of resources contained in this repository identified by the given local name.- Specified by:
getResources
in interfaceRepository
- Parameters:
recursive
- whether to include nested resources- Returns:
- a list of all nested child resources
- Throws:
java.io.IOException
-
getResources
public Resource[] getResources(java.lang.String resourcePath, boolean recursive) throws java.io.IOException
Description copied from interface:Repository
Get a list of resources contained in this repository identified by the given local name.- Specified by:
getResources
in interfaceRepository
- Parameters:
resourcePath
- the repository pathrecursive
- whether to include nested resources- Returns:
- a list of all nested child resources
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
Returns the repositories full path as string representation.- Overrides:
toString
in classjava.lang.Object
- See Also:
getPath()
-
-