diff --git a/src/main/java/li/strolch/model/GroupedParameterizedElement.java b/src/main/java/li/strolch/model/GroupedParameterizedElement.java index 2428e8444..3510e4851 100644 --- a/src/main/java/li/strolch/model/GroupedParameterizedElement.java +++ b/src/main/java/li/strolch/model/GroupedParameterizedElement.java @@ -193,6 +193,17 @@ public abstract class GroupedParameterizedElement extends AbstractStrolchElement return this.parameterBagMap.remove(key); } + /** + * Returns true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. + * + * @param bagKey + * the key of the {@link ParameterBag} which is to be checked for existence + * @return true if the {@link ParameterBag} with the given key exists on this {@link GroupedParameterizedElement}. + */ + public boolean hasParameterBag(String bagKey) { + return this.parameterBagMap != null && this.parameterBagMap.containsKey(bagKey); + } + /** * Returns true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given * bagKey diff --git a/src/test/java/li/strolch/model/test/ModelTestHelper.java b/src/main/java/li/strolch/model/ModelGenerator.java similarity index 88% rename from src/test/java/li/strolch/model/test/ModelTestHelper.java rename to src/main/java/li/strolch/model/ModelGenerator.java index 280c37bee..18c9ca1d7 100644 --- a/src/test/java/li/strolch/model/test/ModelTestHelper.java +++ b/src/main/java/li/strolch/model/ModelGenerator.java @@ -19,15 +19,11 @@ * along with li.strolch.model. If not, see * . */ -package li.strolch.model.test; +package li.strolch.model; import java.util.ArrayList; import java.util.Date; -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; import li.strolch.model.parameter.BooleanParameter; import li.strolch.model.parameter.DateParameter; import li.strolch.model.parameter.FloatParameter; @@ -38,11 +34,13 @@ import li.strolch.model.parameter.StringListParameter; import li.strolch.model.parameter.StringParameter; /** - * @author Robert von Burg + * Class which can be used to generate objects which implement {@link StrolchElement}. These generated classes can then + * be used in test classes etc. * + * @author Robert von Burg */ @SuppressWarnings("nls") -public class ModelTestHelper { +public class ModelGenerator { public static final String PARAM_BOOLEAN_ID = "@param1"; public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; @@ -90,6 +88,23 @@ public class ModelTestHelper { return resource; } + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id + * the id of the {@link Order} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type) { + return createOrder(id, name, type, new Date(), State.CREATED); + } + /** * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling * {@link #createParameterBag(String, String, String)} diff --git a/src/main/java/li/strolch/model/query/AndSelection.java b/src/main/java/li/strolch/model/query/AndSelection.java new file mode 100644 index 000000000..754e7c7ae --- /dev/null +++ b/src/main/java/li/strolch/model/query/AndSelection.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.List; + +/** + * @author Robert von Burg + */ +public class AndSelection extends BooleanSelection { + + /** + * @param selections + */ + public AndSelection(List selections) { + super(selections); + } + + public void accept(QueryVisitor visitor) { + visitor.visitAnd(this); + } +} diff --git a/src/main/java/li/strolch/model/query/BooleanSelection.java b/src/main/java/li/strolch/model/query/BooleanSelection.java new file mode 100644 index 000000000..8ecd98d23 --- /dev/null +++ b/src/main/java/li/strolch/model/query/BooleanSelection.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.List; + +/** + * @author Robert von Burg + * + */ +public abstract class BooleanSelection implements Selection { + + protected List selections; + + public BooleanSelection(List selections) { + this.selections = selections; + } + + public List getSelections() { + return this.selections; + } + + public abstract void accept(QueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/DateSelection.java b/src/main/java/li/strolch/model/query/DateSelection.java new file mode 100644 index 000000000..5e21e6e40 --- /dev/null +++ b/src/main/java/li/strolch/model/query/DateSelection.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.Date; + +/** + * @author Robert von Burg + */ +public class DateSelection extends OrderSelection { + + private Date date; + + public DateSelection(Date date) { + this.date = date; + } + + public Date getDate() { + return this.date; + } + + @Override + public void accept(OrderSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/query/IdSelection.java b/src/main/java/li/strolch/model/query/IdSelection.java new file mode 100644 index 000000000..c4aeb5cce --- /dev/null +++ b/src/main/java/li/strolch/model/query/IdSelection.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class IdSelection extends StrolchElementSelection { + + private String id; + + /** + * @param id + */ + public IdSelection(String id) { + this.id = id; + } + + /** + * @return the id + */ + public String getId() { + return this.id; + } + + @Override + public void accept(StrolchElementSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/query/NameSelection.java b/src/main/java/li/strolch/model/query/NameSelection.java new file mode 100644 index 000000000..acb5e244c --- /dev/null +++ b/src/main/java/li/strolch/model/query/NameSelection.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class NameSelection extends StrolchElementSelection { + + private String name; + + /** + * @param name + */ + public NameSelection(String name) { + this.name = name; + } + + /** + * @return the name + */ + public String getName() { + return this.name; + } + + @Override + public void accept(StrolchElementSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/main/java/li/strolch/model/query/Navigation.java b/src/main/java/li/strolch/model/query/Navigation.java new file mode 100644 index 000000000..3e7bbf65d --- /dev/null +++ b/src/main/java/li/strolch/model/query/Navigation.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + + +/** + * @author Robert von Burg + * + */ +public interface Navigation { + + // marker interface + + public void accept(QueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/OrSelection.java b/src/main/java/li/strolch/model/query/OrSelection.java new file mode 100644 index 000000000..67c5b59cf --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrSelection.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.List; + +/** + * @author Robert von Burg + * + */ +public class OrSelection extends BooleanSelection { + + public OrSelection(List selections) { + super(selections); + } + + @Override + public void accept(QueryVisitor visitor) { + visitor.visitOr(this); + } +} diff --git a/src/main/java/li/strolch/model/query/OrderQuery.java b/src/main/java/li/strolch/model/query/OrderQuery.java new file mode 100644 index 000000000..764439a98 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderQuery.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class OrderQuery extends StrolchQuery { + + public OrderQuery(Navigation navigation) { + super(navigation); + } + + public void add(OrderSelection selection) { + this.selections.add(selection); + } +} diff --git a/src/main/java/li/strolch/model/query/OrderQueryVisitor.java b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java new file mode 100644 index 000000000..c637b4fc0 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderQueryVisitor.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor { + + // marker interface +} diff --git a/src/main/java/li/strolch/model/query/OrderSelection.java b/src/main/java/li/strolch/model/query/OrderSelection.java new file mode 100644 index 000000000..0289afe75 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderSelection.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public abstract class OrderSelection implements Selection { + + @Override + public void accept(QueryVisitor visitor) { + accept((OrderSelectionVisitor) visitor); + } + + public abstract void accept(OrderSelectionVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java new file mode 100644 index 000000000..642cbd0e6 --- /dev/null +++ b/src/main/java/li/strolch/model/query/OrderSelectionVisitor.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface OrderSelectionVisitor extends StrolchElementSelectionVisitor { + + public void visit(DateSelection selection); + + public void visit(StateSelection selection); +} diff --git a/src/main/java/li/strolch/model/query/ParameterSelection.java b/src/main/java/li/strolch/model/query/ParameterSelection.java new file mode 100644 index 000000000..5f5ae57d5 --- /dev/null +++ b/src/main/java/li/strolch/model/query/ParameterSelection.java @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.Date; +import java.util.List; + +/** + * @author Robert von Burg + */ +public abstract class ParameterSelection implements Selection { + + private String bagKey; + private String paramKey; + + public ParameterSelection(String bagKey, String paramKey) { + this.bagKey = bagKey; + this.paramKey = paramKey; + } + + /** + * @return the bagKey + */ + public String getBagKey() { + return this.bagKey; + } + + /** + * @return the paramKey + */ + public String getParamKey() { + return this.paramKey; + } + + @Override + public void accept(QueryVisitor visitor) { + accept((ParameterSelectionVisitor) visitor); + } + + public abstract void accept(ParameterSelectionVisitor visitor); + + public static ParameterSelection stringSelection(String bagKey, String paramKey, String value) { + return new StringParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection integerSelection(String bagKey, String paramKey, int value) { + return new IntegerParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) { + return new BooleanParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection floatSelection(String bagKey, String paramKey, double value) { + return new FloatParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection longSelection(String bagKey, String paramKey, long value) { + return new LongParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection dateSelection(String bagKey, String paramKey, Date value) { + return new DateParameterSelection(bagKey, paramKey, value); + } + + public static ParameterSelection stringListSelection(String bagKey, String paramKey, List value) { + return new StringListParameterSelection(bagKey, paramKey, value); + } + + public static class StringParameterSelection extends ParameterSelection { + + private String value; + + public StringParameterSelection(String bagKey, String paramKey, String value) { + super(bagKey, paramKey); + this.value = value; + } + + public String getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class IntegerParameterSelection extends ParameterSelection { + + private Integer value; + + public IntegerParameterSelection(String bagKey, String paramKey, Integer value) { + super(bagKey, paramKey); + this.value = value; + } + + public Integer getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class BooleanParameterSelection extends ParameterSelection { + private Boolean value; + + public BooleanParameterSelection(String bagKey, String paramKey, Boolean value) { + super(bagKey, paramKey); + this.value = value; + } + + public Boolean getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class LongParameterSelection extends ParameterSelection { + private Long value; + + public LongParameterSelection(String bagKey, String paramKey, Long value) { + super(bagKey, paramKey); + this.value = value; + } + + public Long getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class FloatParameterSelection extends ParameterSelection { + private Double value; + + public FloatParameterSelection(String bagKey, String paramKey, Double value) { + super(bagKey, paramKey); + this.value = value; + } + + public Double getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class DateParameterSelection extends ParameterSelection { + private Date value; + + public DateParameterSelection(String bagKey, String paramKey, Date value) { + super(bagKey, paramKey); + this.value = value; + } + + public Date getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } + + public static class StringListParameterSelection extends ParameterSelection { + private List value; + + public StringListParameterSelection(String bagKey, String paramKey, List value) { + super(bagKey, paramKey); + this.value = value; + } + + public List getValue() { + return this.value; + } + + @Override + public void accept(ParameterSelectionVisitor visitor) { + visitor.visit(this); + } + } +} diff --git a/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java new file mode 100644 index 000000000..784a10c7d --- /dev/null +++ b/src/main/java/li/strolch/model/query/ParameterSelectionVisitor.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import li.strolch.model.query.ParameterSelection.BooleanParameterSelection; +import li.strolch.model.query.ParameterSelection.DateParameterSelection; +import li.strolch.model.query.ParameterSelection.FloatParameterSelection; +import li.strolch.model.query.ParameterSelection.IntegerParameterSelection; +import li.strolch.model.query.ParameterSelection.LongParameterSelection; +import li.strolch.model.query.ParameterSelection.StringListParameterSelection; +import li.strolch.model.query.ParameterSelection.StringParameterSelection; + +/** + * @author Robert von Burg + * + */ +public interface ParameterSelectionVisitor extends QueryVisitor { + + public void visit(StringParameterSelection selection); + + public void visit(IntegerParameterSelection selection); + + public void visit(BooleanParameterSelection selection); + + public void visit(LongParameterSelection selection); + + public void visit(FloatParameterSelection selection); + + public void visit(DateParameterSelection selection); + + public void visit(StringListParameterSelection selection); +} diff --git a/src/main/java/li/strolch/model/query/Query.java b/src/main/java/li/strolch/model/query/Query.java new file mode 100644 index 000000000..88bfe65d7 --- /dev/null +++ b/src/main/java/li/strolch/model/query/Query.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + + +/** + * @author Robert von Burg + * + */ +public interface Query { + + public void visit(T queryVisitor); +} diff --git a/src/main/java/li/strolch/model/query/QueryVisitor.java b/src/main/java/li/strolch/model/query/QueryVisitor.java new file mode 100644 index 000000000..d2147c9c0 --- /dev/null +++ b/src/main/java/li/strolch/model/query/QueryVisitor.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface QueryVisitor { + + public void visitAnd(AndSelection andSelection); + + public void visitOr(OrSelection orSelection); +} diff --git a/src/main/java/li/strolch/model/query/ResourceQuery.java b/src/main/java/li/strolch/model/query/ResourceQuery.java new file mode 100644 index 000000000..5ef97c77b --- /dev/null +++ b/src/main/java/li/strolch/model/query/ResourceQuery.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public class ResourceQuery extends StrolchQuery { + + public ResourceQuery(Navigation navigation) { + super(navigation); + } +} diff --git a/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java new file mode 100644 index 000000000..df4008278 --- /dev/null +++ b/src/main/java/li/strolch/model/query/ResourceQueryVisitor.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public interface ResourceQueryVisitor extends StrolchElementSelectionVisitor, ParameterSelectionVisitor { + + // marker interface +} diff --git a/src/main/java/li/strolch/model/query/Selection.java b/src/main/java/li/strolch/model/query/Selection.java new file mode 100644 index 000000000..e7186abb2 --- /dev/null +++ b/src/main/java/li/strolch/model/query/Selection.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public interface Selection { + + // marker interface + + public void accept(QueryVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/StateSelection.java b/src/main/java/li/strolch/model/query/StateSelection.java new file mode 100644 index 000000000..636968a0e --- /dev/null +++ b/src/main/java/li/strolch/model/query/StateSelection.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import li.strolch.model.State; + +/** + * @author Robert von Burg + * + */ +public class StateSelection { + + private State state; + + public StateSelection(State state) { + this.state = state; + } + + /** + * @return the state + */ + public State getState() { + return this.state; + } +} diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelection.java b/src/main/java/li/strolch/model/query/StrolchElementSelection.java new file mode 100644 index 000000000..d9df67b00 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchElementSelection.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public abstract class StrolchElementSelection implements Selection { + + @Override + public void accept(QueryVisitor visitor) { + accept((StrolchElementSelectionVisitor) visitor); + } + + public abstract void accept(StrolchElementSelectionVisitor visitor); +} diff --git a/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java new file mode 100644 index 000000000..47e59e30b --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchElementSelectionVisitor.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + */ +public interface StrolchElementSelectionVisitor extends QueryVisitor{ + + public void visit(StrolchTypeNavigation navigation); + + public void visit(IdSelection selection); + + public void visit(NameSelection selection); +} diff --git a/src/main/java/li/strolch/model/query/StrolchQuery.java b/src/main/java/li/strolch/model/query/StrolchQuery.java new file mode 100644 index 000000000..df2010e53 --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchQuery.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Robert von Burg + * + */ +public abstract class StrolchQuery { + + private Navigation navigation; + protected List selections; + + public StrolchQuery(Navigation navigation) { + this.navigation = navigation; + this.selections = new ArrayList<>(); + } + + public void addSelection(BooleanSelection selection) { + this.selections.add(selection); + } + + public void addSelection(StrolchElementSelection selection) { + this.selections.add(selection); + } + + public void addSelection(ParameterSelection selection) { + this.selections.add(selection); + } + + public void accept(T visitor) { + this.navigation.accept(visitor); + for (Selection selection : this.selections) { + selection.accept(visitor); + } + } +} diff --git a/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java new file mode 100644 index 000000000..ae8cb204a --- /dev/null +++ b/src/main/java/li/strolch/model/query/StrolchTypeNavigation.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the XXX. + * + * XXX is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * XXX is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XXX. If not, see + * . + */ +package li.strolch.model.query; + +/** + * @author Robert von Burg + * + */ +public class StrolchTypeNavigation implements Navigation { + + private String type; + + public StrolchTypeNavigation(String type) { + this.type = type; + } + + /** + * @return the type + */ + public String getType() { + return this.type; + } + + @Override + public void accept(QueryVisitor visitor) { + accept((StrolchElementSelectionVisitor) visitor); + } + + public void accept(StrolchElementSelectionVisitor visitor) { + visitor.visit(this); + } +} diff --git a/src/test/java/li/strolch/model/ModelTest.java b/src/test/java/li/strolch/model/ModelTest.java new file mode 100644 index 000000000..077d42895 --- /dev/null +++ b/src/test/java/li/strolch/model/ModelTest.java @@ -0,0 +1,88 @@ +package li.strolch.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.Date; + +import li.strolch.model.ModelGenerator; +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +import org.junit.Test; + +@SuppressWarnings("nls") +public class ModelTest { + + @Test + public void shouldCreateResource() { + + Resource resource = ModelGenerator.createResource("@res01", "Test resource", "MyType"); + ParameterBag bag = resource.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } + + @Test + public void shouldCreateOrder() { + + Order order = ModelGenerator.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); + ParameterBag bag = order.getParameterBag(ModelGenerator.BAG_ID); + validateBag(bag); + } + + public static void validateBag(ParameterBag bag) { + + assertNotNull(bag); + + assertEquals(ModelGenerator.BAG_ID, bag.getId()); + assertEquals(ModelGenerator.BAG_NAME, bag.getName()); + assertEquals(ModelGenerator.BAG_TYPE, bag.getType()); + + validateParams(bag); + } + + public static void validateParams(ParameterBag bag) { + + BooleanParameter boolParam = bag.getParameter(ModelGenerator.PARAM_BOOLEAN_ID); + assertNotNull("Boolean Param missing with id " + ModelGenerator.PARAM_BOOLEAN_ID, boolParam); + assertEquals(true, boolParam.getValue().booleanValue()); + + FloatParameter floatParam = bag.getParameter(ModelGenerator.PARAM_FLOAT_ID); + assertNotNull("Float Param missing with id " + ModelGenerator.PARAM_FLOAT_ID, floatParam); + assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); + + IntegerParameter integerParam = bag.getParameter(ModelGenerator.PARAM_INTEGER_ID); + assertNotNull("Integer Param missing with id " + ModelGenerator.PARAM_INTEGER_ID, integerParam); + assertEquals(77, integerParam.getValue().intValue()); + + LongParameter longParam = bag.getParameter(ModelGenerator.PARAM_LONG_ID); + assertNotNull("Long Param missing with id " + ModelGenerator.PARAM_LONG_ID, longParam); + assertEquals(4453234566L, longParam.getValue().longValue()); + + StringParameter stringParam = bag.getParameter(ModelGenerator.PARAM_STRING_ID); + assertNotNull("String Param missing with id " + ModelGenerator.PARAM_STRING_ID, stringParam); + assertEquals("Strolch", stringParam.getValue()); + + DateParameter dateParam = bag.getParameter(ModelGenerator.PARAM_DATE_ID); + assertNotNull("Date Param missing with id " + ModelGenerator.PARAM_DATE_ID, dateParam); + assertEquals(1354295525628L, dateParam.getValue().getTime()); + + StringListParameter stringListP = bag.getParameter(ModelGenerator.PARAM_LIST_STRING_ID); + assertNotNull("StringList Param missing with id " + ModelGenerator.PARAM_LIST_STRING_ID, stringListP); + + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + assertEquals(stringList, stringListP.getValue()); + } +} diff --git a/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java rename to src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java index cbd26a62e..8183b0dfc 100644 --- a/src/test/java/li/strolch/model/test/XmlModelDefaultHandlerTest.java +++ b/src/test/java/li/strolch/model/XmlModelDefaultHandlerTest.java @@ -19,7 +19,7 @@ * along with XXX. If not, see * . */ -package li.strolch.model.test; +package li.strolch.model; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/li/strolch/model/test/ModelTest.java b/src/test/java/li/strolch/model/test/ModelTest.java deleted file mode 100644 index f5de4dee3..000000000 --- a/src/test/java/li/strolch/model/test/ModelTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package li.strolch.model.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.Date; - -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; -import li.strolch.model.parameter.BooleanParameter; -import li.strolch.model.parameter.DateParameter; -import li.strolch.model.parameter.FloatParameter; -import li.strolch.model.parameter.IntegerParameter; -import li.strolch.model.parameter.LongParameter; -import li.strolch.model.parameter.StringListParameter; -import li.strolch.model.parameter.StringParameter; - -import org.junit.Test; - -@SuppressWarnings("nls") -public class ModelTest { - - @Test - public void shouldCreateResource() { - - Resource resource = ModelTestHelper.createResource("@res01", "Test resource", "MyType"); - ParameterBag bag = resource.getParameterBag(ModelTestHelper.BAG_ID); - validateBag(bag); - } - - @Test - public void shouldCreateOrder() { - - Order order = ModelTestHelper.createOrder("@ord01", "Test Order", "MyType", new Date(), State.OPEN); - ParameterBag bag = order.getParameterBag(ModelTestHelper.BAG_ID); - validateBag(bag); - } - - public static void validateBag(ParameterBag bag) { - - assertNotNull(bag); - - assertEquals(ModelTestHelper.BAG_ID, bag.getId()); - assertEquals(ModelTestHelper.BAG_NAME, bag.getName()); - assertEquals(ModelTestHelper.BAG_TYPE, bag.getType()); - - validateParams(bag); - } - - public static void validateParams(ParameterBag bag) { - - BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID); - assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam); - assertEquals(true, boolParam.getValue().booleanValue()); - - FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID); - assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam); - assertEquals(44.3, floatParam.getValue().doubleValue(), 0.0001); - - IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID); - assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam); - assertEquals(77, integerParam.getValue().intValue()); - - LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID); - assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam); - assertEquals(4453234566L, longParam.getValue().longValue()); - - StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID); - assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam); - assertEquals("Strolch", stringParam.getValue()); - - DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID); - assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam); - assertEquals(1354295525628L, dateParam.getValue().getTime()); - - StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID); - assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP); - - ArrayList stringList = new ArrayList(); - stringList.add("Hello"); - stringList.add("World"); - assertEquals(stringList, stringListP.getValue()); - } -} diff --git a/src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java rename to src/test/java/li/strolch/model/timedstate/TimeStateTest.java index e2182fba8..d4757d81b 100644 --- a/src/test/java/li/strolch/model/test/timedstate/TimeStateTest.java +++ b/src/test/java/li/strolch/model/timedstate/TimeStateTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timedstate; +package li.strolch.model.timedstate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java similarity index 99% rename from src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java rename to src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java index fd09d465a..45aabeabd 100644 --- a/src/test/java/li/strolch/model/test/timevalue/FloatTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/FloatTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java rename to src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java index d11460032..062530711 100644 --- a/src/test/java/li/strolch/model/test/timevalue/IntegerTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/IntegerTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java similarity index 98% rename from src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java rename to src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java index 18f801549..d8e54d96a 100644 --- a/src/test/java/li/strolch/model/test/timevalue/StringTimeVariableTest.java +++ b/src/test/java/li/strolch/model/timevalue/StringTimeVariableTest.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/src/test/java/li/strolch/model/test/timevalue/ValueTests.java b/src/test/java/li/strolch/model/timevalue/ValueTests.java similarity index 98% rename from src/test/java/li/strolch/model/test/timevalue/ValueTests.java rename to src/test/java/li/strolch/model/timevalue/ValueTests.java index a6489fac8..af901fbea 100644 --- a/src/test/java/li/strolch/model/test/timevalue/ValueTests.java +++ b/src/test/java/li/strolch/model/timevalue/ValueTests.java @@ -1,4 +1,4 @@ -package li.strolch.model.test.timevalue; +package li.strolch.model.timevalue; import static org.junit.Assert.assertEquals;