[New] OrderQuery and ResourceQuery now require a visitor
This visitor is used to transform the query result. In cases where transformation is not required, use the NoStrategyOrderVisitor or NoStrategyResourceVisitor. For convenience new static helper methods were: ResourceQuery.resourceQuery(Navigation) ResourceQuery.resourceQuery(String) ResourceQuery.resourceQuery(String, ResourceVisitor) OrderQuery.orderQuery(Navigation) OrderQuery.orderQuery(String) OrderQuery.orderQuery(String, ResourceVisitor)
This commit is contained in:
parent
1ceedfc818
commit
1f986797d4
|
@ -15,12 +15,70 @@
|
|||
*/
|
||||
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
|
||||
* navigate to a type of order on which any further {@link Selection Selections} will be performed. The
|
||||
* {@link OrderVisitor} is used to transform the returned object into a domain specific object (if required). This
|
||||
* mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and
|
||||
* then performing this transformation.
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class OrderQuery extends StrolchQuery<OrderQueryVisitor> {
|
||||
public class OrderQuery<U> extends StrolchQuery<OrderQueryVisitor> {
|
||||
|
||||
public OrderQuery(Navigation navigation) {
|
||||
private OrderVisitor<U> elementVisitor;
|
||||
|
||||
public OrderQuery(Navigation navigation, OrderVisitor<U> elementVisitor) {
|
||||
super(navigation);
|
||||
this.elementVisitor = elementVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the elementVisitor
|
||||
*/
|
||||
public OrderVisitor<U> getElementVisitor() {
|
||||
return this.elementVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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> orderQuery(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> orderQuery(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> orderQuery(String type, OrderVisitor<U> orderVisitor) {
|
||||
return new OrderQuery<U>(new StrolchTypeNavigation(type), orderVisitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,76 @@
|
|||
*/
|
||||
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
|
||||
* to navigate to a type of resource on which any further {@link Selection Selections} will be performed. The
|
||||
* {@link ResourceVisitor} is used to transform the returned object into a domain specific object (if required). This
|
||||
* mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and
|
||||
* then performing this transformation.
|
||||
*
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class ResourceQuery extends StrolchQuery<ResourceQueryVisitor> {
|
||||
public class ResourceQuery<U> extends StrolchQuery<ResourceQueryVisitor> {
|
||||
|
||||
public ResourceQuery(Navigation navigation) {
|
||||
private ResourceVisitor<U> elementVisitor;
|
||||
|
||||
/**
|
||||
* Create a new
|
||||
*
|
||||
* @param navigation
|
||||
* @param elementVisitor
|
||||
*/
|
||||
public ResourceQuery(Navigation navigation, ResourceVisitor<U> elementVisitor) {
|
||||
super(navigation);
|
||||
this.elementVisitor = elementVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the elementVisitor
|
||||
*/
|
||||
public ResourceVisitor<U> getElementVisitor() {
|
||||
return this.elementVisitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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> resourceQuery(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> resourceQuery(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> resourceQuery(String type, ResourceVisitor<U> resourceVisitor) {
|
||||
return new ResourceQuery<U>(new StrolchTypeNavigation(type), resourceVisitor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package li.strolch.model.query;
|
|||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
*/
|
||||
public class StrolchTypeNavigation implements Navigation {
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.OrderVisitor;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyOrderVisitor implements OrderVisitor<Order> {
|
||||
|
||||
@Override
|
||||
public Order visit(Order element) {
|
||||
return element;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.ResourceVisitor;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyResourceVisitor implements ResourceVisitor<Resource> {
|
||||
|
||||
@Override
|
||||
public Resource visit(Resource element) {
|
||||
return element;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package li.strolch.model.visitor;
|
||||
|
||||
import li.strolch.model.StrolchElement;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
*/
|
||||
public class NoStrategyVisitor<T extends StrolchElement> implements StrolchElementVisitor<T, T> {
|
||||
|
||||
@Override
|
||||
public T visit(T element) {
|
||||
return element;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue