  protected ResponseContext internalInvoke(
    RequestContext requestContext,
    ResponseContext responseContext) 
      throws AbderaServerException {
    Target target = requestContext.getTarget();
    String method = requestContext.getMethod();
    if (target != null) {
      switch(target.getResourceType()) {
        case SERVICE: {
          try {
            if (requestContext.getIfNoneMatch().equals("\"service\"")) 
              throw new AbderaServerException(
                AbderaServerException.Code.NOTMODIFIED, 
                "Not Modified", "");
          } catch (NullPointerException npe) {}
          return getServiceDocument();
        }
        case COLLECTION: {
          if (method.equals("GET")) {
            if (!target.getValue(1).equals("foo")) 
              throw new AbderaServerException(
                AbderaServerException.Code.NOTFOUND, 
                "Not Found", "");
            return getFeedDocument();
          } else if (method.equals("POST")) {
            try {
              Document<Entry> entry_doc = 
                getEntryFromRequestContext(requestContext);
              if (entry_doc != null) {
                Entry entry = (Entry) entry_doc.getRoot().clone();
                if (!isValidEntry(entry))
                  throw new AbderaServerException(
                    AbderaServerException.Code.BADREQUEST, "Invalid Entry", "");
                entry.setUpdated(new Date());
                entry.setModified(entry.getUpdated());
                entry.getIdElement().setValue(FOMHelper.generateUuid());
                entry.addLink("foo/" + entry.getId().toString(), "edit");
                getFeed().getRoot().insertEntry((Entry) entry.clone());
                BaseResponseContext rc = getEntryDocument(entry);
                rc.setStatus(201);
                String elink = entry.getEditLink().getHref().toString();
                rc.setLocation(elink);
                rc.setContentLocation(elink);
                return rc;
              } else {
                throw new AbderaServerException(
                  AbderaServerException.Code.UNSUPPORTEDMEDIATYPE, 
                  "Unsupported Media Type", "");
              }
            } catch (AbderaServerException e) {
              throw e;
            } catch (Exception e) {
              throw new AbderaServerException(e);
            }
          }
        }
        case ENTRY_EDIT: {
          Entry entry = getEntryFromFeed(requestContext);
          if (entry == null)
            throw new AbderaServerException(
              AbderaServerException.Code.NOTFOUND, "Not Found", "");
          if (method.equals("GET")) {
            Entry e = (Entry) entry.clone();
            return new BaseResponseContext(e.getDocument());
          } else if (method.equals("PUT")) {
            try {
              Document<Entry> entry_doc = getEntryFromRequestContext(requestContext);
              if (entry_doc == null) 
                throw new AbderaServerException(
                  AbderaServerException.Code.UNSUPPORTEDMEDIATYPE, 
                  "Unsupported Media Type", "");
              Document<Feed> feed_doc = getFeed();
              Entry e = (Entry) entry_doc.getRoot().clone();
              if (!isValidEntry(entry))
                throw new AbderaServerException(
                  AbderaServerException.Code.BADREQUEST, "Invalid Entry", "");
              if (!e.getId().equals(entry.getId()))
                throw new AbderaServerException(
                  AbderaServerException.Code.CONFLICT, "Conflict. Cannot change atom:id", "");
              e.setUpdated(new Date());
              e.setModified(e.getUpdated());
              Link editLink = e.getEditLink();
              if (editLink == null) 
                e.addLink("foo/" + e.getId().toString(), "edit");
              else editLink.setHref("foo/" + e.getId().toString());
              entry.discard();
              feed_doc.getRoot().insertEntry((Entry) e.clone());
              return new EmptyResponseContext(204);
            } catch (Exception e) {
              throw new AbderaServerException(e);
            }
          } else if (method.equals("DELETE")) {
            entry.discard();
            return new EmptyResponseContext(204);
          }
        }
      }
      return null;
    } else {
      throw new AbderaServerException(
        AbderaServerException.Code.NOTFOUND, 
        "Not Found", "");
    }
  }

  protected ResponseContext internalInvoke(
    RequestContext requestContext,
    ResponseContext responseContext) 
      throws AbderaServerException {
    Target target = requestContext.getTarget();
    String method = requestContext.getMethod();
    if (target != null) {
      ResourceType type = target.getResourceType();
      if (type == ResourceType.SERVICE) {
          try {
            if (requestContext.getIfNoneMatch().equals("\"service\"")) 
              throw new AbderaServerException(
                AbderaServerException.Code.NOTMODIFIED, 
                "Not Modified", "");
          } catch (NullPointerException npe) {}
          return getServiceDocument();
      } else if (type == ResourceType.COLLECTION) {
          if (method.equals("GET")) {
            if (!target.getValue(1).equals("foo")) 
              throw new AbderaServerException(
                AbderaServerException.Code.NOTFOUND, 
                "Not Found", "");
            return getFeedDocument();
          } else if (method.equals("POST")) {
            try {
              Document<Entry> entry_doc = 
                getEntryFromRequestContext(requestContext);
              if (entry_doc != null) {
                Entry entry = (Entry) entry_doc.getRoot().clone();
                if (!isValidEntry(entry))
                  throw new AbderaServerException(
                    AbderaServerException.Code.BADREQUEST, "Invalid Entry", "");
                entry.setUpdated(new Date());
                entry.setModified(entry.getUpdated());
                entry.getIdElement().setValue(FOMHelper.generateUuid());
                entry.addLink("foo/" + entry.getId().toString(), "edit");
                getFeed().getRoot().insertEntry((Entry) entry.clone());
                BaseResponseContext rc = getEntryDocument(entry);
                rc.setStatus(201);
                String elink = entry.getEditLink().getHref().toString();
                rc.setLocation(elink);
                rc.setContentLocation(elink);
                return rc;
              } else {
                throw new AbderaServerException(
                  AbderaServerException.Code.UNSUPPORTEDMEDIATYPE, 
                  "Unsupported Media Type", "");
              }
            } catch (AbderaServerException e) {
              throw e;
            } catch (Exception e) {
              throw new AbderaServerException(e);
            }
          }
      } else if (type == ResourceType.ENTRY_EDIT) {
          Entry entry = getEntryFromFeed(requestContext);
          if (entry == null)
            throw new AbderaServerException(
              AbderaServerException.Code.NOTFOUND, "Not Found", "");
          if (method.equals("GET")) {
            Entry e = (Entry) entry.clone();
            return new BaseResponseContext(e.getDocument());
          } else if (method.equals("PUT")) {
            try {
              Document<Entry> entry_doc = getEntryFromRequestContext(requestContext);
              if (entry_doc == null) 
                throw new AbderaServerException(
                  AbderaServerException.Code.UNSUPPORTEDMEDIATYPE, 
                  "Unsupported Media Type", "");
              Document<Feed> feed_doc = getFeed();
              Entry e = (Entry) entry_doc.getRoot().clone();
              if (!isValidEntry(entry))
                throw new AbderaServerException(
                  AbderaServerException.Code.BADREQUEST, "Invalid Entry", "");
              if (!e.getId().equals(entry.getId()))
                throw new AbderaServerException(
                  AbderaServerException.Code.CONFLICT, "Conflict. Cannot change atom:id", "");
              e.setUpdated(new Date());
              e.setModified(e.getUpdated());
              Link editLink = e.getEditLink();
              if (editLink == null) 
                e.addLink("foo/" + e.getId().toString(), "edit");
              else editLink.setHref("foo/" + e.getId().toString());
              entry.discard();
              feed_doc.getRoot().insertEntry((Entry) e.clone());
              return new EmptyResponseContext(204);
            } catch (Exception e) {
              throw new AbderaServerException(e);
            }
          } else if (method.equals("DELETE")) {
            entry.discard();
            return new EmptyResponseContext(204);
          }
      }
      return null;
    } else {
      throw new AbderaServerException(
        AbderaServerException.Code.NOTFOUND, 
        "Not Found", "");
    }
  }
