Package overit.geocall.platform
Class JavaResource
java.lang.Object
overit.geocall.platform.JavaResource
- All Implemented Interfaces:
Serializable
Class that represents a generic resource present in the class path. A resource may refer to a specific file, or a package.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Class<?> protected final Stringprotected booleanprotected booleanprotected final Stringstatic final Stringthe path of the original framework resource, the one in which all the components, that can be customized/extended, are definedprotected final Stringprotected booleanprotected URL -
Constructor Summary
ConstructorsConstructorDescriptionJavaResource(Class<?> c) Create a resource from a class taken as a referenceJavaResource(String res) Creates a resource by deducting its package, name and extension from the path passed in inputJavaResource(String pkg, String name, String ext) Create a resource by taking as reference a package, a file name and its extensionCreate a resource by cloning information from another resource -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanexists()Checks whether or not an asset exists on the classpathgetExt()getName()getPkg()getURL()Returns a URL to the resource that is mapped to this resource.getURLs()Returns the URLs to the resources that are mapped to this resource.inthashCode()booleanisClass()Check if the resource refers to a java class filebooleanCheck if the resource is a substitute for an original resourceClass<?> Loads the class related to the resource searching it inside the classpath.static StringnormalizeName(String name) Normalize the name of a resource by replacing the +/ character with the basic framework path and correcting the characters / at the beginning and end pathstatic StringnormalizePackage(String pkg) Normalize the path of a resource by correcting the characters / at the beginning and end pathOpens a connection to this resource and returns an InputStream for reading from that connection.toAnchor()Returns the resource anchor, i.e. the resource identified by the java class with the same name that is in the same packageConverts the resource's path to a string representing a java package.toString()
-
Field Details
-
ORIGINAL_ROOT
the path of the original framework resource, the one in which all the components, that can be customized/extended, are defined- See Also:
-
pkg
-
name
-
ext
-
url
-
clz
-
loadedURL
protected boolean loadedURL -
loadedClass
protected boolean loadedClass -
substitute
protected boolean substitute
-
-
Constructor Details
-
JavaResource
Create a resource from a class taken as a reference- Parameters:
c- the reference class. Null value is not allowed.
-
JavaResource
Create a resource by cloning information from another resource- Parameters:
jr- the resource to clone. Null value is not allowed.
-
JavaResource
Create a resource by taking as reference a package, a file name and its extension- Parameters:
pkg- the package containing the resource. Null value is not allowed.name- the name of the resourceext- the extent of the resource (e.g. .txt, .csv, ...)
-
JavaResource
Creates a resource by deducting its package, name and extension from the path passed in input- Parameters:
res- the resource path. Null value is not allowed.
-
-
Method Details
-
normalizePackage
Normalize the path of a resource by correcting the characters / at the beginning and end path- Parameters:
pkg- the string containing the path to be normalize- Returns:
- the normalized path string
-
normalizeName
Normalize the name of a resource by replacing the +/ character with the basic framework path and correcting the characters / at the beginning and end path- Parameters:
name- the string containing the path (including the file name) to be normalize- Returns:
- the normalized resource path string
-
isClass
public boolean isClass()Check if the resource refers to a java class file- Returns:
trueif the resource is a java class file;falseotherwise
-
getPkg
- Returns:
- the resource package
-
getName
- Returns:
- the resource name
-
getExt
- Returns:
- the resource extension (e.g. .txt, .csv, ...)
-
loadClass
Loads the class related to the resource searching it inside the classpath.- Returns:
- the class reference of this resource, or null if the class cannot be found.
-
getURL
Returns a URL to the resource that is mapped to this resource. If there are more resources that can be resolved from the resource path, the first one is returned depending on the classloader loading order.- Returns:
- a URL to the resource that is mapped to this resource or null if the resource cannot be resolved inside the classpath.
-
openStream
Opens a connection to this resource and returns an InputStream for reading from that connection.- Returns:
- an InputStream for reading the resource.
- Throws:
IOException- if an I/O exception occurs.
-
getURLs
Returns the URLs to the resources that are mapped to this resource.- Returns:
- a URLs to the resources that are mapped to this resource or an empty set if there's no resources that can be resolved inside the classpath.
- Throws:
IOException- if an I/O exception occurs.
-
toString
-
toJavaString
Converts the resource's path to a string representing a java package. for example if the resource refers to the following path
this method returns the string/overit/geocall/basicoverit.geocall.basic- Returns:
- the resource's java package
-
toAnchor
Returns the resource anchor, i.e. the resource identified by the java class with the same name that is in the same package- Returns:
- return the anchor or the same resource if it already refers to a java class
-
exists
public boolean exists()Checks whether or not an asset exists on the classpath- Returns:
trueif the resource actually exists
-
isSubstitute
public boolean isSubstitute()Check if the resource is a substitute for an original resource- Returns:
trueif the resource substitute another resource
-
hashCode
public int hashCode() -
equals
-