Package de.intarsys.tools.locator
Class ClassResourceLocator
- java.lang.Object
-
- de.intarsys.tools.locator.CommonLocator
-
- de.intarsys.tools.locator.ClassResourceLocator
-
- All Implemented Interfaces:
ISynchronizable
,ILocator
public class ClassResourceLocator extends CommonLocator
AnILocator
for java resources relative to a given class.
-
-
Constructor Summary
Constructors Constructor Description ClassResourceLocator(java.lang.Class clazz, java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
boolean
exists()
Answertrue
if the location designated by this exists.ILocator
getChild(java.lang.String childName)
The locator for the resourcename
within the context of this.java.lang.Class
getClazz()
TheClass
used to define this.protected java.lang.String
getEncoding()
java.lang.String
getFullName()
The full physical name of this.java.io.InputStream
getInputStream()
Return anInputStream
on the data represented by the receiver.java.lang.String
getLocalName()
The local name of the receiver within its parent.java.lang.String
getName()
The resource name used when constructing this.java.io.OutputStream
getOutputStream()
Return anOutputStream
on the location represented by the receiver.ILocator
getParent()
TheILocator
that is one hierarchy level up or null.IRandomAccess
getRandomAccess()
TheIRandomAccess
for this.java.io.Reader
getReader()
AReader
on the data represented by the receiver.java.io.Reader
getReader(java.lang.String newEncoding)
AReader
on the data represented by the receiver for the given encoding.protected java.lang.String
getResolvedName()
java.lang.String
getType()
The type of the resource.java.lang.String
getTypedName()
The qualified local name of the receiver within its parent that includes the type specification for the destination if appropriate.java.io.Writer
getWriter()
AWriter
on the location represented by the receiver.java.io.Writer
getWriter(java.lang.String pEncoding)
AWriter
on the location represented by the receiver for the given encoding.int
hashCode()
boolean
isDirectory()
Answertrue
if the location designated by this is a directory.boolean
isOutOfSynch()
true
if the component is out of synch.boolean
isReadOnly()
true
if the specified resource is read only.boolean
isSynchSynchronous()
ILocator[]
listLocators(ILocatorNameFilter filter)
Return an array ofILocator
that are children of the receiver that conform tofilter
.protected void
setEncoding(java.lang.String encoding)
void
synch()
Perform a synchronization with the components physical resources.java.lang.String
toString()
java.net.URL
toURL()
The location designated by this as anURL
.-
Methods inherited from class de.intarsys.tools.locator.CommonLocator
createTempFileLocator, delete, getLength, rename, setReadOnly
-
-
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
exists
public boolean exists()
Description copied from interface:ILocator
Answertrue
if the location designated by this exists.- Returns:
- Answer
true
if the location designated by this exists.
-
getChild
public ILocator getChild(java.lang.String childName)
Description copied from interface:ILocator
The locator for the resourcename
within the context of this. This may for example be anILocator
to a file within a directory.- Parameters:
childName
- The name of the resource to be located.- Returns:
- The
ILocator
for the resource with the name "name" within the context of this.
-
getClazz
public java.lang.Class getClazz()
TheClass
used to define this.The resource will be accessed the "getResourceAsStream" of this
Class
object.- Returns:
- The
Class
used to define this.
-
getEncoding
protected java.lang.String getEncoding()
-
getFullName
public java.lang.String getFullName()
Description copied from interface:ILocator
The full physical name of this.This method returns a representation that is proprietary to the underlying physical representation, for example a file name, a SQL statement or so on.
- Returns:
- The full physical name of the receiver.
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Description copied from interface:ILocator
Return anInputStream
on the data represented by the receiver.- Returns:
- An
InputStream
on the data represented by the receiver. - Throws:
java.io.IOException
-
getLocalName
public java.lang.String getLocalName()
Description copied from interface:ILocator
The local name of the receiver within its parent.- Returns:
- The local name of the receiver within its parent.
-
getName
public java.lang.String getName()
The resource name used when constructing this.- Returns:
- The resource name used when constructing this.
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException
Description copied from interface:ILocator
Return anOutputStream
on the location represented by the receiver.- Returns:
- An
OutputStream
on the location represented by the receiver. - Throws:
java.io.IOException
-
getParent
public ILocator getParent()
Description copied from interface:ILocator
TheILocator
that is one hierarchy level up or null. This may be for example the directory where the currently designated resource is found.- Returns:
- The
ILocator
that is one hierarchy level up or null.
-
getRandomAccess
public IRandomAccess getRandomAccess() throws java.io.IOException
Description copied from interface:ILocator
TheIRandomAccess
for this.- Returns:
- The
IRandomAccess
for this. - Throws:
java.io.IOException
-
getReader
public java.io.Reader getReader() throws java.io.IOException
Description copied from interface:ILocator
AReader
on the data represented by the receiver.- Returns:
- A
Reader
on the data represented by the receiver. - Throws:
java.io.IOException
-
getReader
public java.io.Reader getReader(java.lang.String newEncoding) throws java.io.IOException
Description copied from interface:ILocator
AReader
on the data represented by the receiver for the given encoding.- Parameters:
newEncoding
- The encoding.- Returns:
- A
Reader
on the data represented by the receiver for the given encoding. - Throws:
java.io.IOException
-
getResolvedName
protected java.lang.String getResolvedName()
-
getType
public java.lang.String getType()
Description copied from interface:ILocator
The type of the resource. This may be for example a mime type or the file extension of the underlying file.- Returns:
- The type of the resource
-
getTypedName
public java.lang.String getTypedName()
Description copied from interface:ILocator
The qualified local name of the receiver within its parent that includes the type specification for the destination if appropriate. This is for example a filename with its correct suffix. Some locator may return the same name as "getLocalName".- Returns:
- The qualified local name of the receiver within its parent that includes the type specification for the destination if appropriate.
-
getWriter
public java.io.Writer getWriter() throws java.io.IOException
Description copied from interface:ILocator
AWriter
on the location represented by the receiver.- Returns:
- A
Writer
on the location represented by the receiver. - Throws:
java.io.IOException
-
getWriter
public java.io.Writer getWriter(java.lang.String pEncoding) throws java.io.IOException
Description copied from interface:ILocator
AWriter
on the location represented by the receiver for the given encoding.- Parameters:
pEncoding
- The encoding.- Returns:
- A
Writer
on the location represented by the receiver for the given encoding. - Throws:
java.io.IOException
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isDirectory
public boolean isDirectory()
Description copied from interface:ILocator
Answertrue
if the location designated by this is a directory. A directory location serves as a container for other resources, you can nevergetInputStream
on this.- Returns:
- Answer
true
if the location designated by this is a directory.
-
isOutOfSynch
public boolean isOutOfSynch()
Description copied from interface:ISynchronizable
true
if the component is out of synch.- Returns:
true
if the component is out of synch.
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:ILocator
true
if the specified resource is read only.- Specified by:
isReadOnly
in interfaceILocator
- Overrides:
isReadOnly
in classCommonLocator
- Returns:
true
if the specified resource is read only.
-
isSynchSynchronous
public boolean isSynchSynchronous()
-
listLocators
public ILocator[] listLocators(ILocatorNameFilter filter) throws java.io.IOException
Description copied from interface:ILocator
Return an array ofILocator
that are children of the receiver that conform tofilter
. This method never returns null.- Parameters:
filter
- The filter used to examine the child resources.- Returns:
- An array of
ILocator
objects that conform to the filter argument. - Throws:
java.io.IOException
-
setEncoding
protected void setEncoding(java.lang.String encoding)
-
synch
public void synch()
Description copied from interface:ISynchronizable
Perform a synchronization with the components physical resources.In case of a scheduled synchronization this may be called by an external daemon.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toURL
public java.net.URL toURL()
Description copied from interface:ILocator
The location designated by this as anURL
.- Returns:
- The location designated by this as an
URL
.
-
-