class StateB implements State { private int count=0; public void writeName(StateContext stateContext, String name) { System.out.println(name.toUpperCase()); if(++count>1) { stateContext.setState(new StateA()); } } }
@Override public void handle(StateContext state, RootCollectionLoadEntityContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); state.setState(new RecordTerminalState(record)); }
@Override public void handle(StateContext state, RootCollectionSubCollectionContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); state.setState(new RecordState(record)); }
@Override public void handle(StateContext state, RootCollectionLoadEntityContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); state.setState(new RecordTerminalState(record)); }
@Override public void handle(StateContext state, RootCollectionSubCollectionContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); state.setState(new RecordState(record)); }
@Override public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) { String entityName = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty())); }
@Override public void handle(StateContext state, RootCollectionLoadEntitiesContext ctx) { String entityName = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass = dictionary.getEntityClass(entityName); if (entityClass == null || !dictionary.isRoot(entityClass)) { throw new InvalidCollectionException(entityName); } state.setState(new CollectionTerminalState(entityClass, Optional.empty(), Optional.empty())); }
@Override public void handle(StateContext state, RootCollectionRelationshipContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(record, relationName); record.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(record, relationName)); }
@Override public void handle(StateContext state, RootCollectionRelationshipContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(record, relationName); record.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(record, relationName)); }
@Override public void handle(StateContext state, SubCollectionSubCollectionContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); try { state.setState(new RecordState(resource.getRelation(subCollection, id))); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } }
@Override public void handle(StateContext state, SubCollectionReadEntityContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); try { PersistentResource nextRecord = resource.getRelation(subCollection, id); state.setState(new RecordTerminalState(nextRecord)); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } }
@Override public void handle(StateContext state, SubCollectionSubCollectionContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); try { state.setState(new RecordState(resource.getRelation(subCollection, id))); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } }
@Override public void handle(StateContext state, SubCollectionReadEntityContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); try { PersistentResource nextRecord = resource.getRelation(subCollection, id); state.setState(new RecordTerminalState(nextRecord)); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } }
@Override public void handle(StateContext state, SubCollectionRelationshipContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); PersistentResource childRecord; try { childRecord = resource.getRelation(subCollection, id); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); childRecord.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(childRecord, relationName)); } }
nextState = collectionTerminalState; state.setState(nextState); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection);
@Override public void handle(StateContext state, SubCollectionRelationshipContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); PersistentResource childRecord; try { childRecord = resource.getRelation(subCollection, id); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } String relationName = ctx.relationship().term().getText(); try { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); childRecord.getRelationCheckedFiltered(relationName, filterExpression, Optional.empty(), Optional.empty()); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(relationName); } state.setState(new RelationshipTerminalState(childRecord, relationName)); } }
nextState = collectionTerminalState; state.setState(nextState); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection);