@Override
  public ResourceList getChildren() throws NotAuthorizedException, BadRequestException {
    if (children == null) {
      children = new ResourceList();
      Set<AnnoResource> set = annoFactory.childrenOfAnnotationHandler.execute(this);
      for (AnnoResource r : set) {
        children.add(r);
      }

      // Now add any temp lock resources
      for (LockHolder holder : annoFactory.getTempResourcesForParent(this)) {
        CommonResource cr = annoFactory.instantiate(holder, this);
        children.add(cr);
      }

      // if there are singly loaded items we must replace their dopple-ganger in children
      // because there might already be references to those resource objects elsewhere in code
      // and having two objects representing the same resource causes unpredictable chaos!!!
      if (singlyLoadedChildItems != null) {
        for (CommonResource r : singlyLoadedChildItems) {
          children.remove(r.getName());
          children.add(r);
        }
      }
    }
    return children;
  }
 @Override
 public Resource createNew(
     String newName, InputStream inputStream, Long length, String contentType)
     throws IOException, ConflictException, NotAuthorizedException, BadRequestException {
   Object newChildSource =
       annoFactory.putChildAnnotationHandler.execute(
           source, newName, inputStream, length, contentType);
   AnnoCollectionResource newRes = new AnnoCollectionResource(annoFactory, newChildSource, this);
   if (children != null) {
     CommonResource oldRes = children.get(newName);
     if (oldRes != null) {
       children.remove(oldRes);
     }
     children.add(newRes);
   }
   return newRes;
 }
 @Override
 public LockToken createAndLock(String name, LockTimeout timeout, LockInfo lockInfo)
     throws NotAuthorizedException {
   LockHolder r = annoFactory.createLockHolder(this, name, timeout, lockInfo);
   if (children != null) {
     CommonResource cr = annoFactory.instantiate(r, parent);
     children.add(cr);
   }
   return new LockToken(r.getId().toString(), lockInfo, timeout);
 }
 @Override
 public CollectionResource createCollection(String newName)
     throws NotAuthorizedException, ConflictException, BadRequestException {
   Object newlyCreatedSource = annoFactory.makCollectionAnnotationHandler.execute(source, newName);
   AnnoCollectionResource r = new AnnoCollectionResource(annoFactory, newlyCreatedSource, this);
   if (children != null) {
     children.add(r);
   }
   return r;
 }
Example #5
0
  /**
   * Reads a line of text. The line of text is passed to the parseText method where it is parsed and
   * a Resource object is returned. The Resource object is then added to the list. When a null is
   * read from the Resource file the method terminates and returns the list to the caller. A list
   * that points to null is an empty list.
   *
   * @param inputFile
   * @return The list of drivers
   */
  public ResourceList readResourceListFromFile(String inputFile) {

    String text; // Line of text from the file
    boolean done; // End of the file - stop processing

    // New resorce list object - this will contain all of the resources in
    // the file

    ResourceList listObject = new ResourceList();

    if (openFile(inputFile)) {

      done = false;

      while (!done) {

        try {

          text = readLineOfText();

          if (text == null) {

            done = true;

          } else {

            listObject.addResource(parseText(text));
          } // if

        } // try
        catch (Exception Error) {

          return (null);
        } // catch
      } // while

    } else {

      return (null);
    } // if

    return (listObject);
  } // readTeacherListFromFile
 void removeLockHolder(String name) {
   if (children != null) {
     Iterator<CommonResource> it = children.iterator();
     while (it.hasNext()) {
       Resource r = it.next();
       if (r instanceof LockNullResource && r.getName().equals(name)) {
         it.remove();
       }
     }
   }
 }
  @Override
  public Resource child(String childName) throws NotAuthorizedException, BadRequestException {
    if (children == null) {
      // attempt to locate singly, ie without loading entire list of children
      // first check if it has already been loaded singly
      if (singlyLoadedChildItems != null && singlyLoadedChildItems.hasChild(childName)) {
        return singlyLoadedChildItems.get(childName);
      }
      // try to load singly using ChildOf annotation, if present
      // childTriValue can be null, the child source object, or a special value indicating no search
      Object childTriValue = annoFactory.childOfAnnotationHandler.execute(this, childName);
      if (childTriValue == null) {
        // return null; // definitely not found

        // well, actually. ChildOf can just apply to a certain sort of child, so if its not found
        // that doesnt mean that there might not be some othe child
        // so we can't assume in any circumstance that a null means not found. Must always fall
        // through to ChildrenOf
      } else if (childTriValue.equals(ChildOfAnnotationHandler.NOT_ATTEMPTED)) {
        // there is no ChildOf method, so fall through to iterating over all children
      } else {
        // got one!
        AnnoResource r = (AnnoResource) childTriValue;
        if (singlyLoadedChildItems == null) {
          singlyLoadedChildItems = new ResourceList();
        }
        singlyLoadedChildItems.add(r);
        return r;
      }
    }

    for (Resource r : getChildren()) {
      if (r.getName().equals(childName)) {
        return r;
      }
    }
    return null;
  }
 private Collection<String> validateActions(
     ResourceList actions, Map<String, String> dimensionMap, String name)
     throws CloudWatchException {
   Collection<String> actionsCollection = null;
   if (actions != null) {
     actionsCollection = actions.getMember();
     ;
   }
   if (actionsCollection == null) {
     return actionsCollection;
   }
   if (actionsCollection.size() > 5) {
     throw new InvalidParameterValueException(
         "The collection " + name + " must not have a size greater than 5.");
   }
   int ctr = 1;
   for (String action : actionsCollection) {
     validateAction(action, dimensionMap, name + ".member." + ctr);
     ctr++;
   }
   return actionsCollection;
 }