Forge - Shell API 1.2.0.Final

org.jboss.forge.resources
Interface Resource<T>

All Known Implementing Classes:
AbstractResource, DependencyResource, DirectoryResource, EntryResource, EnumConstantResource, FileResource, JavaFieldResource, JavaMemberResource, JavaMethodResource, JavaResource, PropertiesFileResource, UnknownFileResource, URLResource, VirtualResource

public interface Resource<T>

A Resource is an abstraction on top of usable items within a Forge project. For instance, files, source code, etc. Like a simplified virtual file system, a Resource is represented hierarchically with a parent and children. This allows plugins to say, direct access to project elements within a consistent API from files to class members.
However, Resource instances should be treated as representative query result objects. A modification to an instance variable in a resource will not be persisted. Rather than thinking of the Resource object as meta-data (which it is not), it is better conceptualized as a wrapper or "view" of an underlying resource such as a File. For this reason, custom Resource types should never implement any sort of static cache and should preferably lazily initialize their data.

Author:
Mike Brock, Lincoln Baxter, III

Method Summary
 Resource<T> createFrom(T file)
          Create a new resource instance for the target resource reference of the type that this current resource is.
 boolean delete()
          Delete this resource, return true if successful, false if not.
 boolean delete(boolean recursive)
          Delete this resource, return true if successful, false if not.
 boolean exists()
          Return true if this Resource exists, return false if not.
 Resource<?> getChild(String name)
          Get a child of this resource.
 Set<ResourceFlag> getFlags()
           
 String getFullyQualifiedName()
          Return the fully qualified name of the resource (if applicable).
 String getName()
          Return the common name of the resource.
 Resource<?> getParent()
          Get the parent of the current resource.
 ResourceFactory getResourceFactory()
          Return the ResourceFactory with which this Resource was created.
 InputStream getResourceInputStream()
          Get the InputStream represented by this Resource.
 T getUnderlyingResourceObject()
          Get the underlying object represented by this Resource
 boolean isFlagSet(ResourceFlag flag)
          Return true if the given ResourceFlag is set.
 List<Resource<?>> listResources()
          Return a list of child resources of the current resource.
 List<Resource<?>> listResources(ResourceFilter filter)
          Return a list of child resources of the current resource matching the given ResourceFilter.
<R extends Resource<?>>
R
reify(Class<R> type)
          Ask this Resource if it is actually a resource of the given type; if it is, return a new reference to the resource as the given type, otherwise return null.
 void setFlag(ResourceFlag flag)
          Set the given ResourceFlag.
 void unsetFlag(ResourceFlag flag)
          Unset the given ResourceFlag.
 

Method Detail

delete

boolean delete()
               throws UnsupportedOperationException
Delete this resource, return true if successful, false if not.

Throws:
UnsupportedOperationException - if deleting is not supported by the underlying implementation.

delete

boolean delete(boolean recursive)
               throws UnsupportedOperationException
Delete this resource, return true if successful, false if not.

Parameters:
recursive - if false and this resource both supports recursive deletion and contains children, deletion will not occur; otherwise, if true, deletion will propagate to all child resources. Implementations may choose simply to delegate to delete()
Throws:
UnsupportedOperationException - if deleting is not supported by the underlying implementation.

getName

String getName()
Return the common name of the resource. If it's a file, for instance, just the file name.

Returns:
The name of the resource.

getFullyQualifiedName

String getFullyQualifiedName()
Return the fully qualified name of the resource (if applicable). In the case of a file, this would normally be the full path name.

Returns:
The fully qualified name.

getParent

Resource<?> getParent()
Get the parent of the current resource. Returns null if the current resource is the project root.

Returns:
An instance of the resource parent.

createFrom

Resource<T> createFrom(T file)
Create a new resource instance for the target resource reference of the type that this current resource is.

Parameters:
file - The target reference to create the resource instance from.
Returns:
A new resource.

listResources

List<Resource<?>> listResources()
Return a list of child resources of the current resource.


listResources

List<Resource<?>> listResources(ResourceFilter filter)
Return a list of child resources of the current resource matching the given ResourceFilter.


getUnderlyingResourceObject

T getUnderlyingResourceObject()
Get the underlying object represented by this Resource


getResourceInputStream

InputStream getResourceInputStream()
Get the InputStream represented by this Resource.


getChild

Resource<?> getChild(String name)
Get a child of this resource. Returns null if no child by the given name can be found.


setFlag

void setFlag(ResourceFlag flag)
Set the given ResourceFlag.


unsetFlag

void unsetFlag(ResourceFlag flag)
Unset the given ResourceFlag.


isFlagSet

boolean isFlagSet(ResourceFlag flag)
Return true if the given ResourceFlag is set.


exists

boolean exists()
Return true if this Resource exists, return false if not.


getFlags

Set<ResourceFlag> getFlags()

reify

<R extends Resource<?>> R reify(Class<R> type)
Ask this Resource if it is actually a resource of the given type; if it is, return a new reference to the resource as the given type, otherwise return null.


getResourceFactory

ResourceFactory getResourceFactory()
Return the ResourceFactory with which this Resource was created. If no factory was used, return null.


Forge - Shell API 1.2.0.Final

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.