Exemplo n.º 1
0
 @Override
 public void handle(StateContext state, SubCollectionReadCollectionContext ctx) {
   String subCollection = ctx.term().getText();
   EntityDictionary dictionary = state.getRequestScope().getDictionary();
   try {
     Set<PersistentResource> collection = resource.getRelation(subCollection); // Check if exists.
     String entityName =
         dictionary.getBinding(
             dictionary.getParameterizedType(resource.getObject(), subCollection));
     Class<?> entityClass = dictionary.getBinding(entityName);
     if (entityClass == null) {
       throw new IllegalArgumentException("Unknown type " + entityName);
     }
     final BaseState nextState;
     if (collection instanceof SingleElementSet) {
       PersistentResource record = collection.iterator().next();
       nextState = new RecordTerminalState(subCollection, record);
     } else {
       nextState =
           new CollectionTerminalState(
               entityClass, Optional.of(resource), Optional.of(subCollection));
     }
     state.setState(nextState);
   } catch (InvalidAttributeException e) {
     throw new InvalidCollectionException(subCollection);
   }
 }
Exemplo n.º 2
0
 @Override
 public boolean ok(PersistentResource<Parent> record) {
   Parent parent = record.getObject();
   if (parent.getChildren() != null && parent.getSpouses() != null) {
     return true;
   }
   throw new IllegalStateException("Uninitialized " + parent);
 }