Class JavaResource

java.lang.Object
overit.geocall.platform.JavaResource
All Implemented Interfaces:
Serializable

public class JavaResource extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    protected Class<?>
     
    protected final String
     
    protected boolean
     
    protected boolean
     
    protected final String
     
    static final String
    the path of the original framework resource, the one in which all the components, that can be customized/extended, are defined
    protected final String
     
    protected boolean
     
    protected URL
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a resource from a class taken as a reference
    Creates a resource by deducting its package, name and extension from the path passed in input
    JavaResource(String pkg, String name, String ext)
    Create a resource by taking as reference a package, a file name and its extension
    Create a resource by cloning information from another resource
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    boolean
    Checks whether or not an asset exists on the classpath
     
     
     
    Returns a URL to the resource that is mapped to this resource.
    Returns the URLs to the resources that are mapped to this resource.
    int
     
    boolean
    Check if the resource refers to a java class file
    boolean
    Check if the resource is a substitute for an original resource
    Loads the class related to the resource searching it inside the classpath.
    static String
    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
    static String
    Normalize the path of a resource by correcting the characters / at the beginning and end path
    Opens a connection to this resource and returns an InputStream for reading from that connection.
    Returns the resource anchor, i.e. the resource identified by the java class with the same name that is in the same package
    Converts the resource's path to a string representing a java package.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ORIGINAL_ROOT

      public static final String 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

      protected final String pkg
    • name

      protected final String name
    • ext

      protected final String ext
    • url

      protected URL url
    • clz

      protected Class<?> clz
    • loadedURL

      protected boolean loadedURL
    • loadedClass

      protected boolean loadedClass
    • substitute

      protected boolean substitute
  • Constructor Details

    • JavaResource

      public JavaResource(Class<?> c)
      Create a resource from a class taken as a reference
      Parameters:
      c - the reference class. Null value is not allowed.
    • JavaResource

      public JavaResource(JavaResource jr)
      Create a resource by cloning information from another resource
      Parameters:
      jr - the resource to clone. Null value is not allowed.
    • JavaResource

      public JavaResource(String pkg, String name, String ext)
      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 resource
      ext - the extent of the resource (e.g. .txt, .csv, ...)
    • JavaResource

      public JavaResource(String res)
      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

      public static String normalizePackage(String pkg)
      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

      public static String normalizeName(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 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:
      true if the resource is a java class file; false otherwise
    • getPkg

      public String getPkg()
      Returns:
      the resource package
    • getName

      public String getName()
      Returns:
      the resource name
    • getExt

      public String getExt()
      Returns:
      the resource extension (e.g. .txt, .csv, ...)
    • loadClass

      public Class<?> 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

      public URL 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

      public InputStream openStream() throws IOException
      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

      public Set<URL> getURLs() throws IOException
      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

      public String toString()
      Overrides:
      toString in class Object
    • toJavaString

      public String toJavaString()
      Converts the resource's path to a string representing a java package. for example if the resource refers to the following path
      /overit/geocall/basic
      this method returns the string
      overit.geocall.basic
      Returns:
      the resource's java package
    • toAnchor

      public JavaResource 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:
      true if the resource actually exists
    • isSubstitute

      public boolean isSubstitute()
      Check if the resource is a substitute for an original resource
      Returns:
      true if the resource substitute another resource
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object