예제 #1
0
  @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;
  }