Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  *
  * <p>Provide a string that describes the content of this container.
  */
 @Override
 public String describe() {
   final StringBuilder sb =
       new StringBuilder(Container.HEADER).append(DataAccessObject.SEP_MEMBER);
   for (final FingerprintedElement e : this.elements) {
     sb.append(e.getDescriptor()).append(DataAccessObject.SEP_MEMBER);
   }
   return sb.toString();
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  *
  * <p>Refresh the container's fingerprint to account for any changed content.
  */
 @Override
 public boolean refreshFingerprint() {
   boolean success = true;
   for (final FingerprintedElement e : this.elements) {
     if (!e.refreshFingerprint()) {
       success = false;
     }
     if (e.getHash() == null) {
       this.logger.warning("Null Fingerprint Detected - Removing Element [" + e + "].");
       this.removeElement(e);
     }
   }
   this.fingerprint.setHash(this.fingerprint.calculateHash(this.describe()));
   return success;
 }
Exemplo n.º 3
0
 /**
  * Adds the direct sub element.
  *
  * @param element the element
  * @return true, if successful
  */
 private boolean addDirectSubElement(final FingerprintedElement element) {
   if (this.elements.add(element)) {
     this.fingerprint = new Fingerprint(this.describe());
     return true;
   }
   this.logger.exception("Unable to Add Element [" + element.toString() + "].");
   return false;
 }
Exemplo n.º 4
0
 /**
  * Removes the deep sub element.
  *
  * @param element the element
  * @return true, if successful
  */
 private boolean removeDeepSubElement(final FingerprintedElement element) {
   final File eFile = FileUtilities.findCanonicalLocation(element.cloneWorkspaceFile());
   final String[] splitPath =
       FileUtilities.findSubPath(this.workspaceFile, eFile).substring(1).split("\\\\|\\/");
   Container ptr = this;
   for (int i = 0; i < (splitPath.length - 1); i++) {
     ptr = (Container) ptr.getElement(splitPath[i]);
     if (ptr == null) return false;
   }
   return ptr.removeElement(element);
 }
Exemplo n.º 5
0
 /**
  * Return a given named element.
  *
  * @param eName String.
  * @return element FingerprintedElement.
  */
 public FingerprintedElement getElement(final String eName) {
   final String SEPARATOR = File.separator;
   final String searchPath = eName.replace(this.workspaceFile.getPath() + SEPARATOR, "");
   final int nextSeparatorIndex = searchPath.indexOf(SEPARATOR);
   String subElementName = null;
   if (nextSeparatorIndex != -1) {
     subElementName = searchPath.substring(0, nextSeparatorIndex);
   } else {
     subElementName = searchPath;
   }
   for (final FingerprintedElement e : this.elements) {
     // Search For Direct SubElement
     if (subElementName.equals(e.getName())) {
       // If Direct SubElement is Target Return
       if (nextSeparatorIndex == -1) return e;
       // Else Continue Search Along Search Path
       else return ((Container) e).getElement(searchPath.substring(nextSeparatorIndex + 1));
     }
   }
   return null;
 }
Exemplo n.º 6
0
 /**
  * Adds the deep sub element.
  *
  * @param element the element
  * @return true, if successful
  */
 private boolean addDeepSubElement(final FingerprintedElement element) {
   final String SEPARATOR = File.separator;
   final File eFile = FileUtilities.findCanonicalLocation(element.cloneWorkspaceFile());
   final String[] splitPath =
       FileUtilities.findSubPath(this.workspaceFile, eFile).substring(1).split("\\\\|\\/");
   final StringBuilder sbPath = new StringBuilder(this.workspaceFile + SEPARATOR);
   Container ptr = this;
   for (int i = 0; i < (splitPath.length - 1); i++) {
     if (!splitPath[i].equals("")) {
       sbPath.append(splitPath[i] + SEPARATOR);
       if (ptr.getElement(splitPath[i]) == null) {
         try {
           ptr.addElement(new Container(new File(sbPath.toString())));
         } catch (final Exception e) {
           this.logger.exception("Unable to Add Container [" + sbPath.toString() + "].", e);
           return false;
         }
       }
       ptr = (Container) ptr.getElement(splitPath[i]);
     }
   }
   return ptr.addElement(element);
 }
Exemplo n.º 7
0
 /**
  * Checks if is direct sub element.
  *
  * @param element the element
  * @return true, if is direct sub element
  */
 private boolean isDirectSubElement(final FingerprintedElement element) {
   final File eFile = FileUtilities.findCanonicalLocation(element.cloneWorkspaceFile());
   return eFile.getParentFile().equals(FileUtilities.findCanonicalLocation(this.workspaceFile));
 }