use of org.whole.lang.visitors.IBinaryVisitor in project whole by wholeplatform.
the class CommandFactory method create.
public Command create(PartRequest request) {
IPartRequestHandler handler;
// tries to handle operation with custom handlers
List<IPartRequestHandler> handlerList = handlersMap.get(request.getRequestType());
if (handlerList != null && !handlerList.isEmpty()) {
Iterator<IPartRequestHandler> handlerIterator = handlerList.iterator();
while (handlerIterator.hasNext()) {
handler = (IPartRequestHandler) handlerIterator.next();
if (handler.canHandlePartRequest(request))
return handler.handlePartRequest(request);
}
}
// handle basic requests
if (EntityUtils.isComposite(request.getModelEntity()) && request.getRequestType() == PartRequest.MOVE_CHILD)
return moveIndexedFeature.create(request);
if (request.getRequestType() == PartRequest.MOVE_ORPHAN_CHILD) {
if (EntityUtils.isComposite(request.getModelEntity()))
return orphanIndexedFeature.create(request);
else
return orphanFeature.create(request);
}
if (request.getRequestType() == PartRequest.DELETE) {
if (EntityUtils.isComposite(request.getParentModelEntity()))
return removeIndexedFeature.create(request);
else
// was else if (EntityUtils.isSimple(request.getParentModelEntity()))
return removeFeature.create(request);
}
// handle composite and simple requests
if (isDnDRequest(request)) {
boolean isCompositeAddCommand, isReplaceCommand;
isCompositeAddCommand = isReplaceCommand = request.size() > 0;
IEntity targetEntity = request.getModelEntity();
boolean isCloneRequest = request.getRequestType() == PartRequest.CLONE_CHILD;
HashSet<IEntity> targetEntityAncestors = new HashSet<IEntity>();
GenericTraversalFactory tf = GenericTraversalFactory.instance;
IBinaryVisitor ancestorsVisitor = tf.ancestors(tf.collect(tf.identity(), targetEntityAncestors));
ancestorsVisitor.visit(targetEntity);
for (IEntityPart dndPart : request) {
IEntity dndEntity = dndPart.getModelEntity();
if (targetEntityAncestors.contains(dndEntity) && !isCloneRequest)
return UnexecutableCommand.INSTANCE;
EntityDescriptor<?> dndEntityDescriptor = dndEntity.wGetEntityDescriptor();
isCompositeAddCommand &= EntityUtils.isAddable(targetEntity, dndEntityDescriptor) || EntityUtils.isComposite(targetEntity);
isReplaceCommand &= EntityUtils.isReplaceable(targetEntity, dndEntityDescriptor);
}
if (isCompositeAddCommand)
return createCompositeAddCommand(request);
else if (isReplaceCommand)
return createReplaceCommand(request);
else
return UnexecutableCommand.INSTANCE;
}
return null;
}
Aggregations