PageRenderTime 84ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/poifs/filesystem/EntryNode.java

http://github.com/openmicroscopy/bioformats
Java | 213 lines | 56 code | 34 blank | 123 comment | 4 complexity | d74a9faeb8afbeacf8184ac046144902 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.poifs.filesystem;
  38. import loci.poi.poifs.property.Property;
  39. /**
  40. * Abstract implementation of Entry
  41. *
  42. * Extending classes should override isDocument() or isDirectory(), as
  43. * appropriate
  44. *
  45. * Extending classes must override isDeleteOK()
  46. *
  47. * @author Marc Johnson (mjohnson at apache dot org)
  48. */
  49. public abstract class EntryNode
  50. implements Entry
  51. {
  52. // the DocumentProperty backing this object
  53. private Property _property;
  54. // this object's parent Entry
  55. private DirectoryNode _parent;
  56. /**
  57. * create a DocumentNode. This method is not public by design; it
  58. * is intended strictly for the internal use of extending classes
  59. *
  60. * @param property the Property for this Entry
  61. * @param parent the parent of this entry
  62. */
  63. protected EntryNode(final Property property, final DirectoryNode parent)
  64. {
  65. _property = property;
  66. _parent = parent;
  67. }
  68. /**
  69. * grant access to the property
  70. *
  71. * @return the property backing this entry
  72. */
  73. protected Property getProperty()
  74. {
  75. return _property;
  76. }
  77. /**
  78. * is this the root of the tree?
  79. *
  80. * @return true if so, else false
  81. */
  82. protected boolean isRoot()
  83. {
  84. // only the root Entry has no parent ...
  85. return (_parent == null);
  86. }
  87. /**
  88. * extensions use this method to verify internal rules regarding
  89. * deletion of the underlying store.
  90. *
  91. * @return true if it's ok to delete the underlying store, else
  92. * false
  93. */
  94. protected abstract boolean isDeleteOK();
  95. /* ********** START implementation of Entry ********** */
  96. /**
  97. * get the name of the Entry
  98. *
  99. * @return name
  100. */
  101. public String getName()
  102. {
  103. return _property.getName();
  104. }
  105. /**
  106. * is this a DirectoryEntry?
  107. *
  108. * @return true if the Entry is a DirectoryEntry, else false
  109. */
  110. public boolean isDirectoryEntry()
  111. {
  112. return false;
  113. }
  114. /**
  115. * is this a DocumentEntry?
  116. *
  117. * @return true if the Entry is a DocumentEntry, else false
  118. */
  119. public boolean isDocumentEntry()
  120. {
  121. return false;
  122. }
  123. /**
  124. * get this Entry's parent (the DocumentEntry that owns this
  125. * Entry). All Entry objects, except the root Entry, has a parent.
  126. *
  127. * @return this Entry's parent; null iff this is the root Entry
  128. */
  129. public DirectoryEntry getParent()
  130. {
  131. return _parent;
  132. }
  133. /**
  134. * Delete this Entry. This operation should succeed, but there are
  135. * special circumstances when it will not:
  136. *
  137. * If this Entry is the root of the Entry tree, it cannot be
  138. * deleted, as there is no way to create another one.
  139. *
  140. * If this Entry is a directory, it cannot be deleted unless it is
  141. * empty.
  142. *
  143. * @return true if the Entry was successfully deleted, else false
  144. */
  145. public boolean delete()
  146. {
  147. boolean rval = false;
  148. if ((!isRoot()) && isDeleteOK())
  149. {
  150. rval = _parent.deleteEntry(this);
  151. }
  152. return rval;
  153. }
  154. /**
  155. * Rename this Entry. This operation will fail if:
  156. *
  157. * There is a sibling Entry (i.e., an Entry whose parent is the
  158. * same as this Entry's parent) with the same name.
  159. *
  160. * This Entry is the root of the Entry tree. Its name is dictated
  161. * by the Filesystem and many not be changed.
  162. *
  163. * @param newName the new name for this Entry
  164. *
  165. * @return true if the operation succeeded, else false
  166. */
  167. public boolean renameTo(final String newName)
  168. {
  169. boolean rval = false;
  170. if (!isRoot())
  171. {
  172. rval = _parent.changeName(getName(), newName);
  173. }
  174. return rval;
  175. }
  176. /* ********** END implementation of Entry ********** */
  177. } // end public class EntryNode