[New] added StrolchQuery.getSelection() and cleaned up some constants

This commit is contained in:
Robert von Burg 2014-08-04 14:50:36 +02:00
parent d36267f640
commit c21f96a5ae
5 changed files with 56 additions and 19 deletions

View File

@ -0,0 +1,23 @@
package li.strolch.model;
import li.strolch.model.parameter.Parameter;
public class StrolchModelConstants {
/**
* The type to set on {@link StrolchRootElement StrolchRootElements} when defining a template for a type of element
*/
public static final String TEMPLATE = "Template"; //$NON-NLS-1$
/**
* This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference
* to a {@link Resource}
*/
public static final String INTERPRETATION_RESOURCE_REF = "Resource-Ref"; //$NON-NLS-1$
/**
* This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference
* to an {@link Order}
*/
public static final String INTERPRETATION_ORDER_REF = "Order-Ref"; //$NON-NLS-1$
}

View File

@ -40,5 +40,4 @@ public class Tags {
public static final String INCLUDE_FILE = "IncludeFile"; public static final String INCLUDE_FILE = "IncludeFile";
public static final String FILE = "file"; public static final String FILE = "file";
public static final String TEMPLATE = "Template";
} }

View File

@ -17,6 +17,7 @@ package li.strolch.model.parameter;
import li.strolch.model.ParameterizedElement; import li.strolch.model.ParameterizedElement;
import li.strolch.model.StrolchElement; import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchModelConstants;
import li.strolch.model.visitor.ParameterVisitor; import li.strolch.model.visitor.ParameterVisitor;
/** /**
@ -104,6 +105,7 @@ public interface Parameter<T> extends StrolchElement {
* *
* @return * @return
*/ */
@Override
public ParameterizedElement getParent(); public ParameterizedElement getParent();
/** /**
@ -116,8 +118,8 @@ public interface Parameter<T> extends StrolchElement {
* this {@link Parameter} means. Currently there are three definitions, but any String value can be used: * this {@link Parameter} means. Currently there are three definitions, but any String value can be used:
* <ul> * <ul>
* <li>{@link Parameter#INTERPRETATION_NONE}</li> * <li>{@link Parameter#INTERPRETATION_NONE}</li>
* <li>{@link Parameter#INTERPRETATION_ORDER_REF}</li> * <li>{@link StrolchModelConstants#INTERPRETATION_ORDER_REF}</li>
* <li>{@link Parameter#INTERPRETATION_RESOURCE_REF}</li> * <li>{@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}</li>
* </ul> * </ul>
* *
* @return string value * @return string value
@ -129,8 +131,8 @@ public interface Parameter<T> extends StrolchElement {
* {@link Parameter} means. Currently there are three definitions, but any String value can be used: * {@link Parameter} means. Currently there are three definitions, but any String value can be used:
* <ul> * <ul>
* <li>{@link Parameter#INTERPRETATION_NONE}</li> * <li>{@link Parameter#INTERPRETATION_NONE}</li>
* <li>{@link Parameter#INTERPRETATION_ORDER_REF}</li> * <li>{@link StrolchModelConstants#INTERPRETATION_ORDER_REF}</li>
* <li>{@link Parameter#INTERPRETATION_RESOURCE_REF}</li> * <li>{@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}</li>
* </ul> * </ul>
* *
* @param interpretation * @param interpretation

View File

@ -57,6 +57,7 @@ public abstract class ParameterSelection implements Selection {
accept((ParameterSelectionVisitor) visitor); accept((ParameterSelectionVisitor) visitor);
} }
@SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -243,7 +244,7 @@ public abstract class ParameterSelection implements Selection {
public DateRangeParameterSelection(String bagKey, String paramKey, Date from, Date to) { public DateRangeParameterSelection(String bagKey, String paramKey, Date from, Date to) {
super(bagKey, paramKey); super(bagKey, paramKey);
DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); DBC.PRE.assertFalse("Either 'to' or 'from' must be set! Both can not be null!", from == null && to == null); //$NON-NLS-1$
this.from = from; this.from = from;
this.to = to; this.to = to;
} }

View File

@ -28,43 +28,55 @@ public abstract class StrolchQuery<T extends QueryVisitor> {
public StrolchQuery(Navigation navigation) { public StrolchQuery(Navigation navigation) {
this.navigation = navigation; this.navigation = navigation;
} }
public boolean hasNavigation() { public boolean hasNavigation() {
return navigation != null; return this.navigation != null;
}
public boolean hasSelection() {
return selection != null && selection.hasSelection();
} }
public void select(Selection selection) { public boolean hasSelection() {
DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", return this.selection != null && this.selection.hasSelection();
}
public Selection getSelection() {
return this.selection;
}
public void with(Selection selection) {
DBC.PRE.assertNull("A selection is already set! Use a boolean operator to perform multiple selections", //$NON-NLS-1$
this.selection); this.selection);
this.selection = selection; this.selection = selection;
} }
/**
* @deprecated use {@link #with(Selection)} instead
*/
@Deprecated
public void select(Selection selection) {
with(selection);
}
public AndSelection and() { public AndSelection and() {
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
AndSelection and = new AndSelection(); AndSelection and = new AndSelection();
this.selection = and; this.selection = and;
return and; return and;
} }
public OrSelection or() { public OrSelection or() {
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
OrSelection or = new OrSelection(); OrSelection or = new OrSelection();
this.selection = or; this.selection = or;
return or; return or;
} }
public void not(Selection selection) { public void not(Selection selection) {
DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); DBC.PRE.assertNull("A selection is already set! Create hierarchical boolean selections", this.selection); //$NON-NLS-1$
this.selection = new NotSelection(selection); this.selection = new NotSelection(selection);
} }
public void accept(T visitor) { public void accept(T visitor) {
DBC.PRE.assertNotNull("No navigation set!", this.navigation); DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$
DBC.PRE.assertNotNull("No selection defined!", this.selection); DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$
this.navigation.accept(visitor); this.navigation.accept(visitor);
this.selection.accept(visitor); this.selection.accept(visitor);
} }