[New] finally implemented a query model

In li.strolch.model we keep the API so that the visitors are available
in all Strolch projects
This commit is contained in:
Robert von Burg 2013-12-11 23:50:20 +01:00
parent d3353062b9
commit 2ab55605b9
33 changed files with 1214 additions and 100 deletions

View File

@ -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

View File

@ -19,15 +19,11 @@
* along with li.strolch.model. If not, see
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
* 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 <eitch@eitchnet.ch>
*/
@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)}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AndSelection<T extends Selection> extends BooleanSelection<T> {
/**
* @param selections
*/
public AndSelection(List<T> selections) {
super(selections);
}
public void accept(QueryVisitor visitor) {
visitor.visitAnd(this);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public abstract class BooleanSelection<T extends Selection> implements Selection {
protected List<T> selections;
public BooleanSelection(List<T> selections) {
this.selections = selections;
}
public List<T> getSelections() {
return this.selections;
}
public abstract void accept(QueryVisitor visitor);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import java.util.Date;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
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);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
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);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
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);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface Navigation {
// marker interface
public void accept(QueryVisitor visitor);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class OrSelection<T extends Selection> extends BooleanSelection<T> {
public OrSelection(List<T> selections) {
super(selections);
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitOr(this);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderQuery extends StrolchQuery<OrderQueryVisitor> {
public OrderQuery(Navigation navigation) {
super(navigation);
}
public void add(OrderSelection selection) {
this.selections.add(selection);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor {
// marker interface
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public abstract class OrderSelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((OrderSelectionVisitor) visitor);
}
public abstract void accept(OrderSelectionVisitor visitor);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface OrderSelectionVisitor extends StrolchElementSelectionVisitor {
public void visit(DateSelection selection);
public void visit(StateSelection selection);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import java.util.Date;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
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<String> 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<String> value;
public StringListParameterSelection(String bagKey, String paramKey, List<String> value) {
super(bagKey, paramKey);
this.value = value;
}
public List<String> getValue() {
return this.value;
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
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);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface Query<T extends QueryVisitor> {
public void visit(T queryVisitor);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface QueryVisitor {
public <T extends Selection> void visitAnd(AndSelection<T> andSelection);
public <T extends Selection> void visitOr(OrSelection<T> orSelection);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceQuery extends StrolchQuery<ResourceQueryVisitor> {
public ResourceQuery(Navigation navigation) {
super(navigation);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface ResourceQueryVisitor extends StrolchElementSelectionVisitor, ParameterSelectionVisitor {
// marker interface
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Selection {
// marker interface
public void accept(QueryVisitor visitor);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import li.strolch.model.State;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class StateSelection {
private State state;
public StateSelection(State state) {
this.state = state;
}
/**
* @return the state
*/
public State getState() {
return this.state;
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchElementSelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((StrolchElementSelectionVisitor) visitor);
}
public abstract void accept(StrolchElementSelectionVisitor visitor);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchElementSelectionVisitor extends QueryVisitor{
public void visit(StrolchTypeNavigation navigation);
public void visit(IdSelection selection);
public void visit(NameSelection selection);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
import java.util.ArrayList;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public abstract class StrolchQuery<T extends QueryVisitor> {
private Navigation navigation;
protected List<Selection> selections;
public StrolchQuery(Navigation navigation) {
this.navigation = navigation;
this.selections = new ArrayList<>();
}
public void addSelection(BooleanSelection<Selection> 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);
}
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
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);
}
}

View File

@ -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<String> stringList = new ArrayList<String>();
stringList.add("Hello");
stringList.add("World");
assertEquals(stringList, stringListP.getValue());
}
}

View File

@ -19,7 +19,7 @@
* along with XXX. If not, see
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.model.test;
package li.strolch.model;
import static org.junit.Assert.assertEquals;

View File

@ -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<String> stringList = new ArrayList<String>();
stringList.add("Hello");
stringList.add("World");
assertEquals(stringList, stringListP.getValue());
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,4 +1,4 @@
package li.strolch.model.test.timevalue;
package li.strolch.model.timevalue;
import static org.junit.Assert.assertEquals;