[New] Moved *Visitor transformations in query into query method

This is better than keeping the Visitor in the instance of the query,
where it might be to early to instantiate it.
This commit is contained in:
Robert von Burg 2014-08-06 18:42:44 +02:00
parent e1dbb00ab7
commit 41f0e72cc5
2 changed files with 12 additions and 94 deletions

View File

@ -18,7 +18,6 @@ package li.strolch.model.query;
import li.strolch.model.Order;
import li.strolch.model.OrderVisitor;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.visitor.NoStrategyOrderVisitor;
/**
* {@link OrderQuery} is the user API to query {@link Order Orders} in Strolch. The {@link Navigation} is used to
@ -29,56 +28,17 @@ import li.strolch.model.visitor.NoStrategyOrderVisitor;
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderQuery<U> extends StrolchQuery<OrderQueryVisitor> {
public class OrderQuery extends StrolchQuery<OrderQueryVisitor> {
private OrderVisitor<U> elementVisitor;
public OrderQuery(Navigation navigation, OrderVisitor<U> elementVisitor) {
public OrderQuery(Navigation navigation) {
super(navigation);
this.elementVisitor = elementVisitor;
}
/**
* @return the elementVisitor
*/
public OrderVisitor<U> getElementVisitor() {
return this.elementVisitor;
public static OrderQuery query(Navigation navigation) {
return new OrderQuery(navigation);
}
/**
* Returns an instance of {@link OrderQuery} where the visitor used is the {@link NoStrategyOrderVisitor} thus
* returning the actual Order, i.e. no transformation is performed
*
* @param navigation
* @return
*/
public static OrderQuery<Order> query(Navigation navigation) {
return new OrderQuery<Order>(navigation, new NoStrategyOrderVisitor());
}
/**
* Returns an instance of {@link OrderQuery} where the visitor used is the {@link NoStrategyOrderVisitor} thus
* returning the actual Order, i.e. no transformation is performed
*
* @param type
* the type of Order to navigate to
* @return
*/
public static OrderQuery<Order> query(String type) {
return new OrderQuery<Order>(new StrolchTypeNavigation(type), new NoStrategyOrderVisitor());
}
/**
* Returns an instance of {@link OrderQuery} using the given {@link OrderVisitor} thus performing the given
* transformation
*
* @param type
* the type of Order to navigate to
* @param orderVisitor
* the visitor to use for transformation
* @return
*/
public static <U> OrderQuery<U> query(String type, OrderVisitor<U> orderVisitor) {
return new OrderQuery<U>(new StrolchTypeNavigation(type), orderVisitor);
public static OrderQuery query(String type) {
return new OrderQuery(new StrolchTypeNavigation(type));
}
}

View File

@ -18,7 +18,6 @@ package li.strolch.model.query;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.visitor.NoStrategyResourceVisitor;
/**
* {@link ResourceQuery} is the user API to query {@link Resource Resources} in Strolch. The {@link Navigation} is used
@ -29,62 +28,21 @@ import li.strolch.model.visitor.NoStrategyResourceVisitor;
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceQuery<U> extends StrolchQuery<ResourceQueryVisitor> {
private ResourceVisitor<U> elementVisitor;
public class ResourceQuery extends StrolchQuery<ResourceQueryVisitor> {
/**
* Create a new
*
* @param navigation
* @param elementVisitor
*/
public ResourceQuery(Navigation navigation, ResourceVisitor<U> elementVisitor) {
public ResourceQuery(Navigation navigation) {
super(navigation);
this.elementVisitor = elementVisitor;
}
/**
* @return the elementVisitor
*/
public ResourceVisitor<U> getElementVisitor() {
return this.elementVisitor;
public static ResourceQuery query(Navigation navigation) {
return new ResourceQuery(navigation);
}
/**
* Returns an instance of {@link ResourceQuery} where the visitor used is the {@link NoStrategyResourceVisitor} thus
* returning the actual Resource, i.e. no transformation is performed
*
* @param navigation
* @return
*/
public static ResourceQuery<Resource> query(Navigation navigation) {
return new ResourceQuery<Resource>(navigation, new NoStrategyResourceVisitor());
}
/**
* Returns an instance of {@link ResourceQuery} where the visitor used is the {@link NoStrategyResourceVisitor} thus
* returning the actual Resource, i.e. no transformation is performed
*
* @param type
* the type of {@link Resource} to navigate to
* @return
*/
public static ResourceQuery<Resource> query(String type) {
return new ResourceQuery<Resource>(new StrolchTypeNavigation(type), new NoStrategyResourceVisitor());
}
/**
* Returns an instance of {@link ResourceQuery} using the given {@link ResourceVisitor} thus performing the given
* transformation
*
* @param type
* the type of Order to navigate to
* @param resourceVisitor
* the visitor to use for transformation
* @return
*/
public static <U> ResourceQuery<U> query(String type, ResourceVisitor<U> resourceVisitor) {
return new ResourceQuery<U>(new StrolchTypeNavigation(type), resourceVisitor);
public static ResourceQuery query(String type) {
return new ResourceQuery(new StrolchTypeNavigation(type));
}
}