/shell-api/src/main/java/org/jboss/forge/resources/Resource.java

https://github.com/includeeasy/core · Java · 152 lines · 26 code · 22 blank · 104 comment · 0 complexity · 4dcffc7ac855349861578e9525b93e96 MD5 · raw file

  1. /*
  2. * JBoss, by Red Hat.
  3. * Copyright 2010, Red Hat, Inc., and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.forge.resources;
  23. import java.io.InputStream;
  24. import java.util.List;
  25. import java.util.Set;
  26. import org.jboss.forge.project.services.ResourceFactory;
  27. /**
  28. * A Resource is an abstraction on top of usable items within a Forge project. For instance, files, source code, etc.
  29. * Like a simplified virtual file system, a Resource is represented hierarchically with a parent and children. This
  30. * allows plugins to say, direct access to project elements within a consistent API from files to class members. </br>
  31. * However, Resource instances should be treated as representative query result objects. A modification to an instance
  32. * variable in a resource will not be persisted. Rather than thinking of the Resource object as meta-data (which it is
  33. * not), it is better conceptualized as a wrapper or "view" of an underlying resource such as a File. For this reason,
  34. * custom Resource types should never implement any sort of static cache and should preferably lazily initialize their
  35. * data.
  36. *
  37. * @author Mike Brock
  38. * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
  39. */
  40. public interface Resource<T>
  41. {
  42. /**
  43. * Delete this resource, return true if successful, false if not.
  44. *
  45. * @throws UnsupportedOperationException if deleting is not supported by the underlying implementation.
  46. */
  47. public boolean delete() throws UnsupportedOperationException;
  48. /**
  49. * Delete this resource, return true if successful, false if not.
  50. *
  51. * @param recursive if false and this resource both supports recursive deletion and contains children, deletion will
  52. * not occur; otherwise, if true, deletion will propagate to all child resources. Implementations may
  53. * choose simply to delegate to {@link #delete()}
  54. * @throws UnsupportedOperationException if deleting is not supported by the underlying implementation.
  55. */
  56. public boolean delete(boolean recursive) throws UnsupportedOperationException;
  57. /**
  58. * Return the common name of the resource. If it's a file, for instance, just the file name.
  59. *
  60. * @return The name of the resource.
  61. */
  62. public String getName();
  63. /**
  64. * Return the fully qualified name of the resource (if applicable). In the case of a file, this would normally be the
  65. * full path name.
  66. *
  67. * @return The fully qualified name.
  68. */
  69. public String getFullyQualifiedName();
  70. /**
  71. * Get the parent of the current resource. Returns null if the current resource is the project root.
  72. *
  73. * @return An instance of the resource parent.
  74. */
  75. public Resource<?> getParent();
  76. /**
  77. * Create a new resource instance for the target resource reference of the type that this current resource is.
  78. *
  79. * @param file The target reference to create the resource instance from.
  80. * @return A new resource.
  81. */
  82. public Resource<T> createFrom(T file);
  83. /**
  84. * Return a list of child resources of the current resource.
  85. */
  86. public List<Resource<?>> listResources();
  87. /**
  88. * Return a list of child resources of the current resource matching the given {@link ResourceFilter}.
  89. */
  90. public List<Resource<?>> listResources(ResourceFilter filter);
  91. /**
  92. * Get the underlying object represented by this {@link Resource}
  93. */
  94. public T getUnderlyingResourceObject();
  95. /**
  96. * Get the {@link InputStream} represented by this {@link Resource}.
  97. */
  98. public InputStream getResourceInputStream();
  99. /**
  100. * Get a child of this resource. Returns null if no child by the given name can be found.
  101. */
  102. public Resource<?> getChild(String name);
  103. /**
  104. * Set the given {@link ResourceFlag}.
  105. */
  106. public void setFlag(ResourceFlag flag);
  107. /**
  108. * Unset the given {@link ResourceFlag}.
  109. */
  110. public void unsetFlag(ResourceFlag flag);
  111. /**
  112. * Return true if the given {@link ResourceFlag} is set.
  113. */
  114. public boolean isFlagSet(ResourceFlag flag);
  115. /**
  116. * Return true if this {@link Resource} exists, return false if not.
  117. */
  118. public boolean exists();
  119. public Set<ResourceFlag> getFlags();
  120. /**
  121. * Ask this {@link Resource} if it is actually a resource of the given type; if it is, return a new reference to the
  122. * resource as the given type, otherwise return null.
  123. */
  124. public <R extends Resource<?>> R reify(final Class<R> type);
  125. /**
  126. * Return the {@link ResourceFactory} with which this {@link Resource} was created. If no factory was used, return
  127. * null.
  128. */
  129. public ResourceFactory getResourceFactory();
  130. }