Merge branch 'master' of ../model

This commit is contained in:
Robert von Burg 2014-09-16 09:03:11 +02:00
commit 6d815c7667
133 changed files with 11630 additions and 0 deletions

16
li.strolch.model/.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
/.settings
/.classpath
/.project
/target
/target
/target
/target
/target
/target
/target
/target
/target
/target
/target
/target
/target

202
li.strolch.model/LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,6 @@
li.strolch.model
================
[![Build Status](http://jenkins.eitchnet.ch/buildStatus/icon?job=li.strolch.model)](http://jenkins.eitchnet.ch/view/strolch/job/li.strolch.model/)
Strolch is a generic framework for building parameterized models for modification at runtime written in Java

78
li.strolch.model/pom.xml Normal file
View File

@ -0,0 +1,78 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>li.strolch</groupId>
<artifactId>li.strolch.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../li.strolch.parent/pom.xml</relativePath>
</parent>
<artifactId>li.strolch.model</artifactId>
<packaging>jar</packaging>
<name>li.strolch.model</name>
<url>https://github.com/eitchnet/li.strolch.model</url>
<inceptionYear>2012</inceptionYear>
<issueManagement>
<system>Github Issues</system>
<url>https://github.com/eitchnet/li.strolch.model/issues</url>
</issueManagement>
<scm>
<connection>scm:git:https://github.com/eitchnet/li.strolch.model.git</connection>
<developerConnection>scm:git:git@github.com:eitch/li.strolch.model.git</developerConnection>
<url>https://github.com/eitchnet/li.strolch.model</url>
</scm>
<dependencies>
<dependency>
<groupId>ch.eitchnet</groupId>
<artifactId>ch.eitchnet.utils</artifactId>
</dependency>
<dependency>
<groupId>ch.eitchnet</groupId>
<artifactId>ch.eitchnet.privilege</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/componentVersion.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,40 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.exception;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class StrolchException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
* @param message
* @param cause
*/
public StrolchException(String message, Throwable cause) {
super(message, cause);
}
/**
* @param message
*/
public StrolchException(String message) {
super(message);
}
}

View File

@ -0,0 +1,179 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.Locator.LocatorBuilder;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AbstractStrolchElement implements StrolchElement {
private static final long serialVersionUID = 0L;
protected long dbid = Long.MAX_VALUE;
protected String id;
protected String name;
/**
* Empty constructor
*/
public AbstractStrolchElement() {
//
}
/**
* Default constructor
*
* @param id
* id of this {@link StrolchElement}
* @param name
* name of this {@link StrolchElement}
*/
public AbstractStrolchElement(String id, String name) {
setId(id);
setName(name);
}
@Override
public long getDbid() {
return this.dbid;
}
@Override
public void setDbid(long dbid) {
this.dbid = dbid;
}
@Override
public String getId() {
return this.id;
}
@Override
public void setId(String id) {
if (StringHelper.isEmpty(id)) {
String msg = "The id may never be empty for {0}";
msg = MessageFormat.format(msg, getClass().getSimpleName());
throw new StrolchException(msg);
}
this.id = id;
}
@Override
public String getName() {
return this.name;
}
@Override
public void setName(String name) {
if (StringHelper.isEmpty(name)) {
String msg = "The name may never be empty for {0} {1}";
msg = MessageFormat.format(msg, getClass().getSimpleName(), getLocator());
throw new StrolchException(msg);
}
this.name = name;
}
/**
* Used to build a {@link Locator} for this {@link StrolchElement}. It must be implemented by the concrete
* implemented as parents must first add their {@link Locator} information
*
* @param locatorBuilder
* the {@link LocatorBuilder} to which the {@link StrolchElement} must add its locator information
*/
protected abstract void fillLocator(LocatorBuilder locatorBuilder);
/**
* fills the {@link StrolchElement} clone with the id, name and type
*
* @param clone
*/
protected void fillClone(StrolchElement clone) {
clone.setId(getId());
clone.setName(getName());
}
protected void fillElement(Element element) {
element.setAttribute(Tags.ID, getId());
element.setAttribute(Tags.NAME, getName());
element.setAttribute(Tags.TYPE, getType());
}
/**
* Builds the fields of this {@link StrolchElement} from a {@link Element}
*
* @param element
*/
protected void fromDom(Element element) {
String id = element.getAttribute(Tags.ID);
String name = element.getAttribute(Tags.NAME);
if (id != null && name != null) {
setId(id);
setName(name);
} else {
String msg = "Check the values of the element: {0} either id or name attribute is null!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, element.getNodeName());
throw new StrolchException(msg);
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AbstractStrolchElement other = (AbstractStrolchElement) obj;
if (this.id == null) {
if (other.id != null) {
return false;
}
} else if (!this.id.equals(other.id)) {
return false;
}
return true;
}
@Override
public int compareTo(StrolchElement o) {
return getId().compareTo(o.getId());
}
@Override
public abstract String toString();
}

View File

@ -0,0 +1,300 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import li.strolch.exception.StrolchException;
import li.strolch.model.parameter.Parameter;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class GroupedParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
protected Map<String, ParameterBag> parameterBagMap;
protected String type;
/**
* Empty constructor
*/
protected GroupedParameterizedElement() {
//
}
/**
* Default Constructor
*
* @param id
* @param name
* @param type
*/
protected GroupedParameterizedElement(String id, String name, String type) {
super(id, name);
setType(type);
}
@Override
public String getType() {
return this.type;
}
/**
* Sets the type of this {@link GroupedParameterizedElement}
*
* @param type
* the type to set
*/
public void setType(String type) {
if (StringHelper.isEmpty(type)) {
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator());
throw new StrolchException(msg);
}
this.type = type;
}
/**
* Returns the {@link Parameter} with the given key from the {@link ParameterBag} with the given bagKey, or null if
* the {@link Parameter} or the {@link ParameterBag} does not exist
*
* @param bagKey
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be returned
* @param paramKey
* the key of the {@link Parameter} which is to be returned
*
* @return the found {@link Parameter} or null if it was not found
*/
public <T> T getParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null) {
return null;
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) {
return null;
}
return bag.getParameter(paramKey);
}
/**
* Adds a new {@link Parameter} to the {@link ParameterBag} with the given key
*
* @param bagKey
* the key of the {@link ParameterBag} to which the {@link Parameter} should be added
* @param parameter
* the {@link Parameter} to be added to the {@link ParameterBag}
*
* @throws StrolchException
* if the {@link ParameterBag} does not exist
*/
public void addParameter(String bagKey, Parameter<?> parameter) throws StrolchException {
if (this.parameterBagMap == null) {
this.parameterBagMap = new HashMap<String, ParameterBag>();
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) {
String msg = "No parameter bag exists with key {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, bagKey);
throw new StrolchException(msg);
}
bag.addParameter(parameter);
}
/**
* Removes the {@link Parameter} with the given paramKey from the {@link ParameterBag} with the given bagKey
*
* @param bagKey
* the key of the {@link ParameterBag} from which the {@link Parameter} is to be removed
* @param paramKey
* the key of the {@link Parameter} which is to be removed
*
* @return the removed {@link Parameter} or null if it did not exist
*/
public <T> Parameter<T> removeParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null) {
return null;
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) {
return null;
}
return bag.removeParameter(paramKey);
}
/**
* Returns the {@link ParameterBag} with the given key, or null if it does not exist
*
* @param key
* the key of the {@link ParameterBag} to return
*
* @return the {@link ParameterBag} with the given key, or null if it does not exist
*/
public ParameterBag getParameterBag(String key) {
if (this.parameterBagMap == null) {
return null;
}
return this.parameterBagMap.get(key);
}
/**
* Adds the given {@link ParameterBag} to this {@link GroupedParameterizedElement}
*
* @param bag
* the {@link ParameterBag} to add
*/
public void addParameterBag(ParameterBag bag) {
if (this.parameterBagMap == null) {
this.parameterBagMap = new HashMap<String, ParameterBag>();
}
if (this.parameterBagMap.containsKey(bag.getId())) {
String msg = "A ParameterBag already exists with id {0} on {1}";
throw new StrolchException(MessageFormat.format(msg, bag.getId(), getLocator()));
}
this.parameterBagMap.put(bag.getId(), bag);
bag.setParent(this);
}
/**
* Removes the {@link ParameterBag} with the given key
*
* @param key
* the key of the {@link ParameterBag} to remove
*
* @return the removed {@link ParameterBag}, or null if it does not exist
*/
public ParameterBag removeParameterBag(String key) {
if (this.parameterBagMap == null) {
return null;
}
return this.parameterBagMap.remove(key);
}
/**
* Returns true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
*
* @return true if this {@link GroupedParameterizedElement} has any {@link ParameterBag ParameterBag}
*/
public boolean hasParameterBags() {
return this.parameterBagMap != null && !this.parameterBagMap.isEmpty();
}
/**
* 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
*
* @param bagKey
* the key of the {@link ParameterBag} on which to find the {@link Parameter}
* @param paramKey
* the key of the {@link Parameter} to be found
*
* @return true if the {@link Parameter} with the given paramKey exists on the {@link ParameterBag} with the given
* bagKey. False is returned if the {@link ParameterBag} does not exist, or the {@link Parameter} does not
* exist on the {@link ParameterBag}
*/
public boolean hasParameter(String bagKey, String paramKey) {
if (this.parameterBagMap == null) {
return false;
}
ParameterBag bag = this.parameterBagMap.get(bagKey);
if (bag == null) {
return false;
}
return bag.hasParameter(paramKey);
}
/**
* Returns the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
*
* @return the {@link Set} of keys for the {@link ParameterBag}s on this {@link GroupedParameterizedElement}
*/
public Set<String> getParameterBagKeySet() {
if (this.parameterBagMap == null) {
return Collections.emptySet();
}
return new HashSet<String>(this.parameterBagMap.keySet());
}
@Override
public void fromDom(Element element) {
super.fromDom(element);
String type = element.getAttribute(Tags.TYPE);
setType(type);
NodeList bags = element.getElementsByTagName(Tags.PARAMETER_BAG);
for (int i = 0; i < bags.getLength(); i++) {
Element bagElement = (Element) bags.item(i);
ParameterBag bag = new ParameterBag(bagElement);
addParameterBag(bag);
}
}
@Override
protected void fillElement(Element element) {
super.fillElement(element);
if (this.parameterBagMap != null) {
for (ParameterBag bag : this.parameterBagMap.values()) {
element.appendChild(bag.toDom(element.getOwnerDocument()));
}
}
}
/**
* Fills {@link GroupedParameterizedElement} properties of this clone
*
* @param clone
*/
protected void fillClone(GroupedParameterizedElement clone) {
super.fillClone(clone);
clone.setType(getType());
if (this.parameterBagMap != null) {
for (ParameterBag bag : this.parameterBagMap.values()) {
clone.addParameterBag(bag.getClone());
}
}
}
}

View File

@ -0,0 +1,368 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import li.strolch.exception.StrolchException;
import ch.eitchnet.utils.helper.StringHelper;
/**
* <p>
* The {@link Locator} is an immutable object and is used to fully qualify the location of an object in the model. It
* consists of a {@link List} of Strings which starting from the first value, defining the root, with the last item
* defining the objects id.
* </p>
*
* <p>
* When the {@link Locator} is formatted to a String, it resembles the same format as is used in Unix based files
* systems, with slashes (/), separating the different list values
* </p>
*
* <p>
* A {@link Locator} is always immutable, modifications return a new instance
* </p>
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class Locator {
/**
* The separator used when formatting a {@link Locator} object ot a string
*/
public static final String PATH_SEPARATOR = "/"; //$NON-NLS-1$
/**
* {@link List} of path elements, with the first being the top level or root element
*/
private final List<String> pathElements;
/**
* Constructs a new {@link Locator} with the given list of path elements
*
* @param pathElements
* the elements making up the {@link Locator}
*
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*/
public Locator(List<String> pathElements) throws StrolchException {
if (pathElements == null || pathElements.isEmpty()) {
throw new StrolchException("The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$
}
this.pathElements = Collections.unmodifiableList(new ArrayList<String>(pathElements));
}
/**
* Constructs a new {@link Locator} using the given path parts
*
* @param path
* the path to parse for instantiate this {@link Locator} with elements
*
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*/
public Locator(String... path) throws StrolchException {
this.pathElements = Collections.unmodifiableList(Arrays.asList(path));
}
/**
* Constructs a new {@link Locator} by parsing the given string path.
*
* @param path
* the path to parse for instantiate this {@link Locator} with elements
*
* @throws StrolchException
* if the path is invalid, meaning has less than two elements in it
*/
public Locator(String path) throws StrolchException {
this.pathElements = Collections.unmodifiableList(parsePath(path));
}
/**
* Internal constructor to append a sub path to a constructor
*
* @param path
* the base path of the locator
* @param subPath
* the additional path
*/
private Locator(List<String> path, List<String> subPath) {
List<String> fullPath = new ArrayList<String>();
fullPath.addAll(path);
fullPath.addAll(subPath);
this.pathElements = Collections.unmodifiableList(fullPath);
}
/**
* Internal constructor to append a element to a constructor
*
* @param path
* the base path of the locator
* @param element
* the additional element
*/
private Locator(List<String> path, String element) {
List<String> fullPath = new ArrayList<String>();
fullPath.addAll(path);
fullPath.add(element);
this.pathElements = Collections.unmodifiableList(fullPath);
}
/**
* Returns the immutable list of path elements making up this locator
*
* @return the pathElements
*/
public List<String> getPathElements() {
return this.pathElements;
}
/**
* Returns the number of elements which this {@link Locator} contains
*
* @return the number of elements which this {@link Locator} contains
*/
public int getSize() {
return this.pathElements.size();
}
/**
* Returns a new {@link Locator} where the given sub path is appended to the locator
*
* @param subPathElements
* the sub path to append
*
* @return the new locator
*/
public Locator append(List<String> subPathElements) {
return new Locator(this.pathElements, subPathElements);
}
/**
* Returns a new {@link Locator} where the given element is appended to the locator
*
* @param element
* the element to append
*
* @return the new locator
*/
public Locator append(String element) {
return new Locator(this.pathElements, element);
}
/**
* Returns the string representation of this {@link Locator} by using the {@link #PATH_SEPARATOR} to separate the
* values
*/
@Override
public String toString() {
return formatPath(this.pathElements);
}
/**
* Parses the given path to a {@link List} of path elements by splitting the string with the {@link #PATH_SEPARATOR}
*
* @param path
* the path to parse
*
* @return the list of path elements for the list
*
* @throws StrolchException
* if the path is empty, or does not contain at least 2 elements separated by {@link #PATH_SEPARATOR}
*/
private List<String> parsePath(String path) throws StrolchException {
if (StringHelper.isEmpty(path)) {
throw new StrolchException("A path may not be empty!"); //$NON-NLS-1$
}
String[] elements = path.split(Locator.PATH_SEPARATOR);
return Arrays.asList(elements);
}
/**
* Formats the given list of path elements to a String representation of the {@link Locator}
*
* @param pathElements
* the locator elements
*
* @return a string representation of the path elements
*
* @throws StrolchException
* if the path elements does not contain at least two items
*/
private String formatPath(List<String> pathElements) throws StrolchException {
StringBuilder sb = new StringBuilder();
Iterator<String> iter = pathElements.iterator();
while (iter.hasNext()) {
String element = iter.next();
sb.append(element);
if (iter.hasNext()) {
sb.append(Locator.PATH_SEPARATOR);
}
}
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.pathElements == null) ? 0 : this.pathElements.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Locator other = (Locator) obj;
if (this.pathElements == null) {
if (other.pathElements != null) {
return false;
}
} else if (!this.pathElements.equals(other.pathElements)) {
return false;
}
return true;
}
/**
* Instantiates a new immutable {@link Locator} instance from the given string
*
* @param locatorPath
* the path from which to instantiate the locator
* @return the immutable {@link Locator} instance
*/
public static Locator valueOf(String locatorPath) {
return new Locator(locatorPath);
}
/**
* Instantiates a new immutable {@link Locator} instance from the given path parts
*
* @param path
* the path from which to instantiate the locator
* @return the immutable {@link Locator} instance
*/
public static Locator valueOf(String... path) {
return new Locator(path);
}
/**
* Creates a new {@link LocatorBuilder} instance and appends the given elements to it
*
* @param path
* the first element on the {@link Locator}
*
* @return a new {@link LocatorBuilder} instance with the given root element tag as the first element
*/
public static LocatorBuilder newBuilder(String... path) {
return new LocatorBuilder().append(path);
}
/**
* Creates a new {@link LocatorBuilder} instance and appends the given root element tag to it
*
* @param rootElement
* the first element on the {@link Locator}
*
* @return a new {@link LocatorBuilder} instance with the given root element tag as the first element
*/
public static LocatorBuilder newBuilder(String rootElement) {
return new LocatorBuilder().append(rootElement);
}
/**
* {@link LocatorBuilder} is used to build {@link Locator}s where a deep hierarchy is to be created. The
* {@link #append(String)} method returns itself for chain building
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public static class LocatorBuilder {
private final List<String> pathElements;
/**
* Default constructor
*/
public LocatorBuilder() {
this.pathElements = new ArrayList<String>();
}
/**
* Append the given elements to the path
*
* @param path
* the path elements to add
*
* @return this instance for chaining
*/
public LocatorBuilder append(String... path) {
for (String element : path) {
this.pathElements.add(element);
}
return this;
}
/**
* Append an element to the path
*
* @param element
* the element to add
*
* @return this instance for chaining
*/
public LocatorBuilder append(String element) {
this.pathElements.add(element);
return this;
}
/**
* Remove the last element from the path
*
* @return this instance for chaining
*/
public LocatorBuilder removeLast() {
this.pathElements.remove(this.pathElements.size() - 1);
return this;
}
/**
* Creates an immutable {@link Locator} instance with the current elements
*
* @return a new {@link Locator} instance
*/
public Locator build() {
if (this.pathElements.isEmpty()) {
throw new StrolchException("The path elements must contain at least 1 item"); //$NON-NLS-1$
}
return new Locator(this.pathElements);
}
}
}

View File

@ -0,0 +1,404 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;
import li.strolch.model.audit.AccessType;
import li.strolch.model.audit.Audit;
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.Parameter;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
import li.strolch.model.timedstate.BooleanTimedState;
import li.strolch.model.timedstate.FloatTimedState;
import li.strolch.model.timedstate.IntegerTimedState;
import li.strolch.model.timedstate.StringSetTimedState;
import li.strolch.model.timedstate.StrolchTimedState;
import li.strolch.model.timevalue.impl.AString;
import li.strolch.model.timevalue.impl.BooleanValue;
import li.strolch.model.timevalue.impl.FloatValue;
import li.strolch.model.timevalue.impl.IntegerValue;
import li.strolch.model.timevalue.impl.StringSetValue;
import li.strolch.model.timevalue.impl.ValueChange;
import ch.eitchnet.utils.helper.StringHelper;
/**
* 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 ModelGenerator {
public static final String PARAM_BOOLEAN_ID = "@param1";
public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
public static final String PARAM_FLOAT_ID = "@param2";
public static final String PARAM_FLOAT_NAME = "Float Param";
public static final String PARAM_INTEGER_ID = "@param3";
public static final String PARAM_INTEGER_NAME = "Integer Param";
public static final String PARAM_LONG_ID = "@param4";
public static final String PARAM_LONG_NAME = "Long Param";
public static final String PARAM_STRING_ID = "@param5";
public static final String PARAM_STRING_NAME = "String Param";
public static final String PARAM_DATE_ID = "@param6";
public static final String PARAM_DATE_NAME = "Date Param";
public static final String PARAM_LIST_STRING_ID = "@param7";
public static final String PARAM_LIST_STRING_NAME = "StringList Param";
public static final String STATE_FLOAT_ID = "@state1";
public static final String STATE_FLOAT_NAME = "Float State";
public static final String STATE_INTEGER_ID = "@state2";
public static final String STATE_INTEGER_NAME = "Float State";
public static final String STATE_STRING_ID = "@state3";
public static final String STATE_STRING_NAME = "Float State";
public static final String STATE_BOOLEAN_ID = "@state4";
public static final String STATE_BOOLEAN_NAME = "Float State";
public static final long STATE_TIME_0 = 0L;
public static final long STATE_TIME_10 = 10L;
public static final long STATE_TIME_20 = 20L;
public static final long STATE_TIME_30 = 30L;
public static final Double STATE_FLOAT_TIME_0 = 0.0D;
public static final Double STATE_FLOAT_TIME_10 = 10.0D;
public static final Double STATE_FLOAT_TIME_20 = 20.0D;
public static final Double STATE_FLOAT_TIME_30 = 30.0D;
public static final Integer STATE_INTEGER_TIME_0 = 0;
public static final Integer STATE_INTEGER_TIME_10 = 10;
public static final Integer STATE_INTEGER_TIME_20 = 20;
public static final Integer STATE_INTEGER_TIME_30 = 30;
public static final String STATE_STRING_TIME_0 = "empty";
public static final String STATE_STRING_TIME_10 = "a";
public static final String STATE_STRING_TIME_20 = "b";
public static final String STATE_STRING_TIME_30 = "c";
public static final Boolean STATE_BOOLEAN_TIME_0 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_10 = Boolean.TRUE;
public static final Boolean STATE_BOOLEAN_TIME_20 = Boolean.FALSE;
public static final Boolean STATE_BOOLEAN_TIME_30 = Boolean.TRUE;
public static final String BAG_ID = "@bag01";
public static final String BAG_NAME = "Test Bag";
public static final String BAG_TYPE = "TestBag";
/**
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)}
*
* @param id
* the id of the {@link Resource}
* @param name
* the name of the {@link Resource}
* @param type
* the type of the {@link Resource}
*
* @return the newly created {@link Resource}
*/
public static Resource createResource(String id, String name, String type) {
Resource resource = new Resource(id, name, type);
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
resource.addParameterBag(bag);
addTimedStates(resource);
return resource;
}
/**
* Creates {@link StrolchTimedState} instances and adds them to the {@link Resource}
*
* @param resource
* the resource to which to addd the newly created {@link StrolchTimedState}
*/
public static void addTimedStates(Resource resource) {
// float state
FloatTimedState floatTimedState = new FloatTimedState(STATE_FLOAT_ID, STATE_FLOAT_NAME);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new FloatValue(STATE_FLOAT_TIME_0)));
FloatValue floatValueChange = new FloatValue(STATE_FLOAT_TIME_10);
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_10, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_20, floatValueChange));
floatTimedState.applyChange(new ValueChange<>(STATE_TIME_30, floatValueChange));
resource.addTimedState(floatTimedState);
// integer state
IntegerTimedState integerTimedState = new IntegerTimedState(STATE_INTEGER_ID, STATE_INTEGER_NAME);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new IntegerValue(STATE_INTEGER_TIME_0)));
IntegerValue integerValueChange = new IntegerValue(STATE_INTEGER_TIME_10);
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_10, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_20, integerValueChange));
integerTimedState.applyChange(new ValueChange<>(STATE_TIME_30, integerValueChange));
resource.addTimedState(integerTimedState);
// boolean state
BooleanTimedState booleanTimedState = new BooleanTimedState(STATE_BOOLEAN_ID, STATE_BOOLEAN_NAME);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_0, new BooleanValue(STATE_BOOLEAN_TIME_0)));
BooleanValue booleanValueChange = new BooleanValue(STATE_BOOLEAN_TIME_10);
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_10, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_20, booleanValueChange));
booleanValueChange = booleanValueChange.getInverse();
booleanTimedState.applyChange(new ValueChange<>(STATE_TIME_30, booleanValueChange));
resource.addTimedState(booleanTimedState);
// string state
StringSetTimedState stringTimedState = new StringSetTimedState(STATE_STRING_ID, STATE_STRING_NAME);
StringSetValue change = new StringSetValue(asSet(STATE_STRING_TIME_0));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_0, change));
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_10));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_10, change));
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_20));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_20, change));
removeInverted(change.getValue());
change = change.getInverse();
change.add(asSet(STATE_STRING_TIME_30));
stringTimedState.applyChange(new ValueChange<>(STATE_TIME_30, change));
resource.addTimedState(stringTimedState);
}
private static Set<AString> asSet(String value) {
HashSet<AString> hashSet = new HashSet<>();
hashSet.add(new AString(value));
return hashSet;
}
private static void removeInverted(Set<AString> set) {
for (Iterator<AString> iter = set.iterator(); iter.hasNext();) {
AString aString = iter.next();
if (aString.isInverse()) {
iter.remove();
}
}
}
/**
* Creates a list of {@link Resource Resources} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)}
*
* @param idStart
* id range start
* @param count
* the number of elements to create
* @param idPrefix
* the prefix to generate IDs for the {@link Resource Resources}
* @param name
* the name of the {@link Resource}
* @param type
* the type of the {@link Resource}
*
* @return the list of newly created {@link Resource Resources}
*/
public static List<Resource> createResources(int idStart, int count, String idPrefix, String name, String type) {
List<Resource> resources = new ArrayList<>();
for (int i = 0; i < count; i++) {
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
resources.add(createResource(idPrefix + id, name + " " + i, type));
}
return resources;
}
/**
* 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)}
*
* @param id
* the id of the {@link Order}
* @param name
* the name of the {@link Order}
* @param type
* the type of the {@link Order}
* @param date
* the date of the {@link Order}
* @param state
* the {@link State} of the {@link Order}
*
* @return the newly created {@link Order}
*/
public static Order createOrder(String id, String name, String type, Date date, State state) {
Order order = new Order(id, name, type, date, state);
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
order.addParameterBag(bag);
return order;
}
/**
* Creates a list of {@link Order Orders} with the given values and adds a {@link ParameterBag} by calling
* {@link #createParameterBag(String, String, String)}
*
* @param idStart
* id range start
* @param count
* the number of elements to create
* @param idPrefix
* the prefix to generate IDs for the {@link Order Orders}
* @param name
* the name of the {@link Order}
* @param type
* the type of the {@link Order}
*
* @return the list of newly created {@link Order Orders}
*/
public static List<Order> createOrders(int idStart, int count, String idPrefix, String name, String type) {
List<Order> orders = new ArrayList<>();
for (int i = 0; i < count; i++) {
String id = StringHelper.normalizeLength(String.valueOf((i + idStart)), 8, true, '0');
orders.add(createOrder(idPrefix + id, name + " " + i, type));
}
return orders;
}
/**
* Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add
* {@link Parameter}s
*
* @param id
* the id of the {@link ParameterBag}
* @param name
* the name of the {@link ParameterBag}
* @param type
* the type of the {@link ParameterBag}
*
* @return the newly created {@link ParameterBag}
*/
public static ParameterBag createParameterBag(String id, String name, String type) {
ParameterBag bag = new ParameterBag(id, name, type);
addAllParameters(bag);
return bag;
}
/**
* Adds the following {@link Parameter}s to the given {@link ParameterBag}:
* <ul>
* <li>BooleanParameter - true</li>
* <li>FloatParameter - 44.3</li>
* <li>IntegerParameter - 77</li>
* <li>LongParameter - 4453234566L</li>
* <li>StringParameter - "Strolch"</li>
* <li>DateParameter - 1354295525628L</li>
* <li>StringListParameter - Hello, World</li>
* </ul>
*
* @param bag
*/
public static void addAllParameters(ParameterBag bag) {
BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true);
boolParam.setIndex(1);
bag.addParameter(boolParam);
FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3);
floatParam.setIndex(2);
bag.addParameter(floatParam);
IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77);
integerParam.setIndex(3);
bag.addParameter(integerParam);
LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L);
longParam.setIndex(4);
bag.addParameter(longParam);
StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch");
stringParam.setIndex(5);
bag.addParameter(stringParam);
DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L));
dateParam.setIndex(6);
bag.addParameter(dateParam);
ArrayList<String> stringList = new ArrayList<String>();
stringList.add("Hello");
stringList.add("World");
StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME,
stringList);
stringListP.setIndex(7);
bag.addParameter(stringListP);
}
private static String randomValue(Random rand, String[] values) {
return values[rand.nextInt(values.length)];
}
public static Audit randomAudit() {
Random rand = new Random(234234L);
String[] usernames = new String[] { "bob", "alice", "jenny" };
String[] firstnames = new String[] { "Bob", "Alice", "Jenny" };
String[] lastnames = new String[] { "Richards", "Kennedy", "Davids" };
String[] types = new String[] { Tags.RESOURCE, Tags.ORDER, Tags.AUDIT };
String[] actions = new String[] { "AddResourceService", "UpdateResourceService", "RemoveResourceService",
"AddOrderService", "UpdateOrderService", "RemoveOrderService" };
Audit audit = new Audit();
audit.setId(StringHelper.getUniqueIdLong());
audit.setUsername(randomValue(rand, usernames));
audit.setFirstname(randomValue(rand, firstnames));
audit.setLastname(randomValue(rand, lastnames));
audit.setDate(new Date(rand.nextInt(5000)));
audit.setElementType(randomValue(rand, types));
audit.setElementAccessed(StringHelper.getUniqueId());
audit.setNewVersion(new Date(rand.nextInt(5000)));
audit.setAction(randomValue(rand, actions));
audit.setAccessType(AccessType.values()[rand.nextInt(AccessType.values().length)]);
return audit;
}
}

View File

@ -0,0 +1,49 @@
package li.strolch.model;
import static ch.eitchnet.utils.helper.StringHelper.NULL;
import java.util.Date;
import ch.eitchnet.utils.helper.StringHelper;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
public class ModelStatistics {
public Date startTime;
public long durationNanos;
public long nrOfResources;
public long nrOfOrders;
/**
* @return the nrOfOrders
*/
public long getNrOfOrders() {
return this.nrOfOrders;
}
/**
* @return the nrOfResources
*/
public long getNrOfResources() {
return this.nrOfResources;
}
public long getNrOfElements() {
return this.nrOfOrders + this.nrOfResources;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + " [startTime=");
builder.append(this.startTime == null ? NULL : ISO8601FormatFactory.getInstance().formatDate(this.startTime));
builder.append(", durationNanos=");
builder.append(StringHelper.formatNanoDuration(this.durationNanos));
builder.append(", nrOfResources=");
builder.append(this.nrOfResources);
builder.append(", nrOfOrders=");
builder.append(this.nrOfOrders);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,208 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.util.Date;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.visitor.StrolchRootElementVisitor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* The Order is an object used in the EDF to transfer data from one range to another. Orders are not to be thought of as
* Resources. Resources are supposed to be thought of as things i.e. a table, a machine and so forth, where a order is
* to be thought of as an object for doing something.
*
* In this sense, orders do not need to be verified, so all verifier chracteristics are disabled and the
* getVerifier()-method will return the null reference
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class Order extends GroupedParameterizedElement implements StrolchRootElement {
private static final long serialVersionUID = 0L;
private Date date;
private State state;
/**
* Empty constructor
*/
public Order() {
//
}
/**
* Default Constructor
*
* @param id
* @param name
* @param type
*/
public Order(String id, String name, String type) {
super(id, name, type);
setState(State.CREATED);
setDate(new Date());
}
/**
* Extended Constructor for date and {@link State}
*
* @param id
* @param name
* @param type
* @param date
* @param state
*/
public Order(String id, String name, String type, Date date, State state) {
super(id, name, type);
setState(state);
setDate(date);
}
/**
* DOM Constructor
*
* @param element
*/
public Order(Element element) {
super.fromDom(element);
String date = element.getAttribute(Tags.DATE);
String state = element.getAttribute(Tags.STATE);
if (StringHelper.isEmpty(date)) {
setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse("-")); //$NON-NLS-1$
} else {
setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date));
}
if (state == null || state.isEmpty()) {
setState(State.CREATED);
} else {
setState(State.valueOf(state));
}
}
/**
* @return the date
*/
public Date getDate() {
return this.date;
}
/**
* @param date
* the date to set
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @return the state
*/
public State getState() {
return this.state;
}
/**
* @param state
* the state to set
*/
public void setState(State state) {
this.state = state;
}
@Override
public Element toDom(Document doc) {
Element orderElement = doc.createElement(Tags.ORDER);
fillElement(orderElement);
orderElement.setAttribute(Tags.DATE, ISO8601FormatFactory.getInstance().formatDate(this.date));
orderElement.setAttribute(Tags.STATE, this.state.toString());
return orderElement;
}
@Override
public Order getClone() {
Order clone = new Order();
super.fillClone(clone);
clone.setDate(this.date);
clone.setState(this.state);
return clone;
}
@Override
protected void fillLocator(LocatorBuilder lb) {
lb.append(Tags.ORDER).append(getType()).append(getId());
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb);
return lb.build();
}
@Override
public StrolchElement getParent() {
return null;
}
@Override
public Order getRootElement() {
return this;
}
@Override
public <T> T accept(StrolchRootElementVisitor<T> visitor) {
return visitor.visitOrder(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Order [id=");
builder.append(this.id);
builder.append(", name=");
builder.append(this.name);
builder.append(", type=");
builder.append(this.type);
builder.append(", state=");
builder.append(this.state);
builder.append(", date=");
builder.append(ISO8601FormatFactory.getInstance().formatDate(this.date));
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import li.strolch.model.visitor.StrolchElementVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface OrderVisitor<U> extends StrolchElementVisitor<Order, U> {
@Override
public U visit(Order element);
}

View File

@ -0,0 +1,80 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import li.strolch.model.Locator.LocatorBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ParameterBag extends ParameterizedElement {
private static final long serialVersionUID = 1L;
/**
* Empty Constructor
*/
public ParameterBag() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param type
*/
public ParameterBag(String id, String name, String type) {
super(id, name, type);
}
/**
* DOM Constructor
*
* @param bagElement
*/
public ParameterBag(Element bagElement) {
super.fromDom(bagElement);
}
@Override
public ParameterBag getClone() {
ParameterBag clone = new ParameterBag();
super.fillClone(clone);
return clone;
}
@Override
public void fillLocator(LocatorBuilder lb) {
this.parent.fillLocator(lb);
lb.append(Tags.BAG);
lb.append(this.id);
}
@Override
public Element toDom(Document doc) {
Element element = doc.createElement(Tags.PARAMETER_BAG);
fillElement(element);
return element;
}
}

View File

@ -0,0 +1,308 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import li.strolch.exception.StrolchException;
import li.strolch.model.Locator.LocatorBuilder;
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.Parameter;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class ParameterizedElement extends AbstractStrolchElement {
private static final long serialVersionUID = 0L;
protected GroupedParameterizedElement parent;
protected Map<String, Parameter<?>> parameterMap;
protected String type;
/**
* Empty Constructor
*/
protected ParameterizedElement() {
//
}
/**
* Default Constructor
*
* @param id
* @param name
* @param type
*/
public ParameterizedElement(String id, String name, String type) {
setId(id);
setName(name);
setType(type);
}
@Override
public String getType() {
return this.type;
}
/**
* Sets the type of this {@link ParameterizedElement}
*
* @param type
* the type to set
*/
public void setType(String type) {
if (StringHelper.isEmpty(type)) {
String msg = "Type may not be empty on element {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getLocator());
throw new StrolchException(msg);
}
this.type = type;
}
/**
* Returns the {@link Parameter} with the given id, or null if it does not exist
*
* @param key
* the id of the parameter to return
*
* @return the {@link Parameter} with the given id, or null if it does not exist
*/
@SuppressWarnings("unchecked")
public <T> T getParameter(String key) {
if (this.parameterMap == null) {
return null;
}
return (T) this.parameterMap.get(key);
}
/**
* Adds the given {@link Parameter} to the {@link ParameterizedElement}
*
* @param parameter
* the {@link Parameter} to add
*/
public void addParameter(Parameter<?> parameter) {
if (this.parameterMap == null) {
this.parameterMap = new HashMap<String, Parameter<?>>();
}
if (this.parameterMap.containsKey(parameter.getId())) {
String msg = "A Parameter already exists with id {0} on {1}";
throw new StrolchException(MessageFormat.format(msg, parameter.getId(), getLocator()));
}
this.parameterMap.put(parameter.getId(), parameter);
parameter.setParent(this);
}
/**
* Removes the {@link Parameter} with the given key
*
* @param key
* the key of the {@link Parameter} to remove
*
* @return the removed {@link Parameter}, or null if it does not exist
*/
@SuppressWarnings("unchecked")
public <T> Parameter<T> removeParameter(String key) {
if (this.parameterMap == null) {
return null;
}
return (Parameter<T>) this.parameterMap.remove(key);
}
/**
* Returns a list of all the {@link Parameter}s in this {@link ParameterizedElement}
*
* @return a list of all the {@link Parameter}s in this {@link ParameterizedElement}
*/
public List<Parameter<?>> getParameters() {
if (this.parameterMap == null) {
return Collections.emptyList();
}
return new ArrayList<Parameter<?>>(this.parameterMap.values());
}
/**
* Returns true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
*
* @return true, if the this {@link ParameterizedElement} has any {@link Parameter Parameters}, false otherwise
*/
public boolean hasParameters() {
return this.parameterMap != null && !this.parameterMap.isEmpty();
}
/**
* Returns true, if the {@link Parameter} exists with the given key, false otherwise
*
* @param key
* the key of the {@link Parameter} to check for
*
* @return true, if the {@link Parameter} exists with the given key, false otherwise
*/
public boolean hasParameter(String key) {
if (this.parameterMap == null) {
return false;
}
return this.parameterMap.containsKey(key);
}
/**
* Returns a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
*
* @return a {@link Set} of all the {@link Parameter} keys in this {@link ParameterizedElement}
*/
public Set<String> getParameterKeySet() {
if (this.parameterMap == null) {
return Collections.emptySet();
}
return new HashSet<String>(this.parameterMap.keySet());
}
@Override
public abstract void fillLocator(LocatorBuilder lb);
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb);
return lb.build();
}
@Override
protected void fromDom(Element element) {
super.fromDom(element);
String type = element.getAttribute(Tags.TYPE);
setType(type);
// add all the parameters
NodeList parameterElements = element.getElementsByTagName(Tags.PARAMETER);
for (int i = 0; i < parameterElements.getLength(); i++) {
Element paramElement = (Element) parameterElements.item(i);
String paramtype = paramElement.getAttribute(Tags.TYPE);
DBC.PRE.assertNotEmpty("Type must be set on Parameter for bag with id " + this.id, paramtype);
if (paramtype.equals(StringParameter.TYPE)) {
StringParameter param = new StringParameter(paramElement);
addParameter(param);
} else if (paramtype.equals(IntegerParameter.TYPE)) {
IntegerParameter param = new IntegerParameter(paramElement);
addParameter(param);
} else if (paramtype.equals(FloatParameter.TYPE)) {
FloatParameter param = new FloatParameter(paramElement);
addParameter(param);
} else if (paramtype.equals(LongParameter.TYPE)) {
LongParameter param = new LongParameter(paramElement);
addParameter(param);
} else if (paramtype.equals(DateParameter.TYPE)) {
DateParameter param = new DateParameter(paramElement);
addParameter(param);
} else if (paramtype.equals(BooleanParameter.TYPE)) {
BooleanParameter param = new BooleanParameter(paramElement);
addParameter(param);
} else if (paramtype.equals(StringListParameter.TYPE)) {
StringListParameter param = new StringListParameter(paramElement);
addParameter(param);
} else {
String msg = "What kind of parameter is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, paramtype);
throw new StrolchException(msg);
}
}
}
@Override
protected void fillElement(Element element) {
super.fillElement(element);
if (this.parameterMap != null) {
for (Parameter<?> parameter : this.parameterMap.values()) {
element.appendChild(parameter.toDom(element.getOwnerDocument()));
}
}
}
@Override
protected void fillClone(StrolchElement clone) {
super.fillClone(clone);
ParameterizedElement peClone = (ParameterizedElement) clone;
peClone.setType(this.type);
if (this.parameterMap != null) {
for (Parameter<?> param : this.parameterMap.values()) {
peClone.addParameter(param.getClone());
}
}
}
@Override
public GroupedParameterizedElement getParent() {
return this.parent;
}
/**
* Set the parent for this {@link ParameterizedElement}
*
* @param parent
* the parent to set
*/
public void setParent(GroupedParameterizedElement parent) {
this.parent = parent;
}
@Override
public StrolchRootElement getRootElement() {
return this.parent.getRootElement();
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ParameterizedElement [id=");
builder.append(this.id);
builder.append(", name=");
builder.append(this.name);
builder.append(", type=");
builder.append(this.type);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,221 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import li.strolch.exception.StrolchException;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.timedstate.BooleanTimedState;
import li.strolch.model.timedstate.FloatTimedState;
import li.strolch.model.timedstate.IntegerTimedState;
import li.strolch.model.timedstate.StringSetTimedState;
import li.strolch.model.timedstate.StrolchTimedState;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.visitor.StrolchRootElementVisitor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class Resource extends GroupedParameterizedElement implements StrolchRootElement {
private static final long serialVersionUID = 0L;
private Map<String, StrolchTimedState<IValue<?>>> timedStateMap;
/**
* Empty constructor
*/
public Resource() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param type
*/
public Resource(String id, String name, String type) {
super(id, name, type);
}
/**
* DOM Constructor
*
* @param element
*/
public Resource(Element element) {
super.fromDom(element);
NodeList timedStateElems = element.getElementsByTagName(Tags.TIMED_STATE);
for (int i = 0; i < timedStateElems.getLength(); i++) {
Element timedStateElem = (Element) timedStateElems.item(i);
String typeS = timedStateElem.getAttribute(Tags.TYPE);
DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + this.id, typeS);
if (typeS.equals(FloatTimedState.TYPE)) {
FloatTimedState timedState = new FloatTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(IntegerTimedState.TYPE)) {
IntegerTimedState timedState = new IntegerTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(BooleanTimedState.TYPE)) {
BooleanTimedState timedState = new BooleanTimedState(timedStateElem);
addTimedState(timedState);
} else if (typeS.equals(StringSetTimedState.TYPE)) {
StringSetTimedState timedState = new StringSetTimedState(timedStateElem);
addTimedState(timedState);
} else {
String msg = "What kind of TimedState is this: {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, typeS);
throw new StrolchException(msg);
}
}
}
@SuppressWarnings("unchecked")
public void addTimedState(StrolchTimedState<?> strolchTimedState) {
if (this.timedStateMap == null) {
this.timedStateMap = new HashMap<>();
}
this.timedStateMap.put(strolchTimedState.getId(), (StrolchTimedState<IValue<?>>) strolchTimedState);
strolchTimedState.setParent(this);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T extends StrolchTimedState> T getTimedState(String id) {
if (this.timedStateMap == null) {
return null;
}
return (T) this.timedStateMap.get(id);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T extends StrolchTimedState> T removeTimedState(String id) {
if (this.timedStateMap == null) {
return null;
}
return (T) this.timedStateMap.remove(id);
}
public Set<String> getTimedStateKeySet() {
if (this.timedStateMap == null) {
return Collections.emptySet();
}
return new HashSet<>(this.timedStateMap.keySet());
}
public List<StrolchTimedState<IValue<?>>> getTimedStates() {
if (this.timedStateMap == null) {
return Collections.emptyList();
}
return new ArrayList<>(this.timedStateMap.values());
}
public boolean hasTimedStates() {
return this.timedStateMap != null && !this.timedStateMap.isEmpty();
}
public boolean hasTimedState(String id) {
return this.timedStateMap != null && this.timedStateMap.containsKey(id);
}
@Override
public Element toDom(Document doc) {
Element element = doc.createElement(Tags.RESOURCE);
fillElement(element);
if (this.timedStateMap != null) {
for (StrolchTimedState<?> state : this.timedStateMap.values()) {
Element timedStateElem = state.toDom(element.getOwnerDocument());
element.appendChild(timedStateElem);
}
}
return element;
}
@Override
public Resource getClone() {
Resource clone = new Resource();
super.fillClone(clone);
return clone;
}
@Override
public void fillLocator(LocatorBuilder lb) {
lb.append(Tags.RESOURCE).append(getType()).append(getId());
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
fillLocator(lb);
return lb.build();
}
@Override
public StrolchElement getParent() {
return null;
}
@Override
public Resource getRootElement() {
return this;
}
@Override
public <T> T accept(StrolchRootElementVisitor<T> visitor) {
return visitor.visitResource(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Resource [id=");
builder.append(this.id);
builder.append(", name=");
builder.append(this.name);
builder.append(", type=");
builder.append(this.type);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import li.strolch.model.visitor.StrolchElementVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
* @param <U>
*/
public interface ResourceVisitor<U> extends StrolchElementVisitor<Resource, U> {
@Override
public U visit(Resource element);
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public enum State {
CREATED("Created"), //$NON-NLS-1$
OPEN("Open"), //$NON-NLS-1$
EXECUTION("Execution"), //$NON-NLS-1$
CLOSED("Closed"); //$NON-NLS-1$
private String state;
/**
* @param state
*/
private State(String state) {
this.state = state;
}
/**
* @return
*/
public String getStateName() {
return this.state;
}
}

View File

@ -0,0 +1,116 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import java.io.Serializable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchElement extends Serializable, Comparable<StrolchElement> {
/**
* Return the {@link Locator} for this element
*
* @return the {@link Locator} for this element
*/
public Locator getLocator();
/**
* Set the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
* implementations of this interface
*
* @param id
*/
public void setId(String id);
/**
* Returns the semi unique id of this {@link StrolchElement}. This value should be unique under all concrete
* implementations of this interface
*
* @return
*/
public String getId();
/**
* Set the name of this {@link StrolchElement}
*
* @param name
*/
public void setName(String name);
/**
* Returns the name of this {@link StrolchElement}
*
* @return
*/
public String getName();
/**
* Set the currently set long value which defines the primary key for use in RDBM-Systems
*
* @param dbid
*/
public void setDbid(long dbid);
/**
* Returns the currently set long value which defines the primary key for use in RDBM-Systems
*
* @return
*/
public long getDbid();
/**
* Returns an {@link Element} object which is an XML representation of this object
*
* @param doc
* the document to which this element is being written. The client must not append to the document, the
* caller will perform this as needed
*
* @return
*/
public Element toDom(Document doc);
/**
* Returns the type of this {@link StrolchElement}
*
* @return
*/
public String getType();
public StrolchElement getParent();
public StrolchRootElement getRootElement();
/**
* Return a clone of this {@link StrolchElement}
*
* @return
*/
public StrolchElement getClone();
@Override
public int hashCode();
@Override
public boolean equals(Object obj);
@Override
public int compareTo(StrolchElement o);
}

View File

@ -0,0 +1,33 @@
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$
/**
* This interpretation value indicates that the {@link Parameter} has no defined interpretation
*/
public static final String INTERPRETATION_NONE = "None"; //$NON-NLS-1$
/**
* This uom value indicates that the {@link Parameter} has no defined uom
*/
public static final String UOM_NONE = "None"; //$NON-NLS-1$
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
import li.strolch.model.visitor.StrolchRootElementVisitor;
/**
* Root element for all top level {@link StrolchElement}. These are elements which have no parent, e.g. {@link Resource
* Resources} and {@link Order Orders}
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchRootElement extends StrolchElement {
public <T> T accept(StrolchRootElementVisitor<T> visitor);
}

View File

@ -0,0 +1,60 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model;
@SuppressWarnings("nls")
public class Tags {
public static final String CDATA = "CDATA";
public static final String ID = "Id";
public static final String NAME = "Name";
public static final String TYPE = "Type";
public static final String DATE = "Date";
public static final String STATE = "State";
public static final String VALUE = "Value";
public static final String TIME = "Time";
public static final String INTERPRETATION = "Interpretation";
public static final String UOM = "Uom";
public static final String HIDDEN = "Hidden";
public static final String INDEX = "Index";
public static final String PARAMETER = "Parameter";
public static final String TIMED_STATE = "TimedState";
public static final String PARAMETERIZED_ELEMENT = "ParameterizedElement";
public static final String RESOURCE = "Resource";
public static final String ORDER = "Order";
public static final String PARAMETER_BAG = "ParameterBag";
public static final String STROLCH_MODEL = "StrolchModel";
public static final String INCLUDE_FILE = "IncludeFile";
public static final String FILE = "file";
public static final String BAG = "Bag";
public static final String AUDIT = "Audit";
public class Audit {
public static final String ID = Tags.ID;
public static final String USERNAME = "Username";
public static final String FIRSTNAME = "Firstname";
public static final String LASTNAME = "Lastname";
public static final String DATE = "Date";
public static final String ELEMENT_TYPE = "ElementType";
public static final String ELEMENT_ACCESSED = "ElementAccessed";
public static final String NEW_VERSION = "NewVersion";
public static final String ACTION = "Action";
public static final String ACCESS_TYPE = "AccessType";
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import li.strolch.model.StrolchRootElement;
/**
* Defines the type of access performed on a {@link StrolchRootElement}
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public enum AccessType {
READ, CREATE, UPDATE, DELETE;
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import li.strolch.model.query.StringSelection;
import ch.eitchnet.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ActionSelection extends AuditSelection {
private StringSelection actionSelection;
private AccessType[] accessTypes;
public ActionSelection(AuditQuery query) {
super(query);
}
public ActionSelection actions(StringMatchMode matchMode, String... actions) {
this.actionSelection = new StringSelection(matchMode, actions);
return this;
}
public ActionSelection accessTypes(AccessType... accessTypes) {
this.accessTypes = accessTypes;
return this;
}
public AccessType[] getAccessTypes() {
return this.accessTypes;
}
public StringSelection getActionSelection() {
return this.actionSelection;
}
public boolean isWildcardActionType() {
return this.accessTypes == null || this.accessTypes.length == 0;
}
public boolean isWildcardAction() {
return this.actionSelection == null || this.actionSelection.isWildCard();
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,233 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import java.io.Serializable;
import java.util.Date;
import li.strolch.model.StrolchRootElement;
/**
* Used to log/audit access to {@link StrolchRootElement}
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class Audit implements Comparable<Audit>, Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String username;
private String firstname;
private String lastname;
private Date date;
private String elementType;
private String elementAccessed;
private Date newVersion;
private String action;
private AccessType accessType;
/**
* @return the id
*/
public Long getId() {
return this.id;
}
/**
* @param id
* the id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* @return the username
*/
public String getUsername() {
return this.username;
}
/**
* @param username
* the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the firstname
*/
public String getFirstname() {
return this.firstname;
}
/**
* @param firstname
* the firstname to set
*/
public void setFirstname(String firstname) {
this.firstname = firstname;
}
/**
* @return the lastname
*/
public String getLastname() {
return this.lastname;
}
/**
* @param lastname
* the lastname to set
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}
/**
* @return the date
*/
public Date getDate() {
return this.date;
}
/**
* @param date
* the date to set
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @return the elementType
*/
public String getElementType() {
return this.elementType;
}
/**
* @param elementType
* the elementType to set
*/
public void setElementType(String elementType) {
this.elementType = elementType;
}
/**
* @return the elementAccessed
*/
public String getElementAccessed() {
return this.elementAccessed;
}
/**
* @param elementAccessed
* the elementAccessed to set
*/
public void setElementAccessed(String elementAccessed) {
this.elementAccessed = elementAccessed;
}
/**
* @return the newVersion
*/
public Date getNewVersion() {
return this.newVersion;
}
/**
* @param newVersion
* the newVersion to set
*/
public void setNewVersion(Date newVersion) {
this.newVersion = newVersion;
}
/**
* @return the action
*/
public String getAction() {
return this.action;
}
/**
* @param action
* the action to set
*/
public void setAction(String action) {
this.action = action;
}
/**
* @return the accessType
*/
public AccessType getAccessType() {
return this.accessType;
}
/**
* @param accessType
* the accessType to set
*/
public void setAccessType(AccessType accessType) {
this.accessType = accessType;
}
public <U> U accept(AuditVisitor<U> visitor) {
return visitor.visitAudit(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Audit other = (Audit) obj;
if (this.id == null) {
if (other.id != null) {
return false;
}
} else if (!this.id.equals(other.id)) {
return false;
}
return true;
}
@Override
public int compareTo(Audit o) {
return getId().compareTo(o.getId());
}
}

View File

@ -0,0 +1,100 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import java.text.MessageFormat;
import li.strolch.model.Tags;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditFromDomReader {
public Audit from(Element rootElement) {
Audit audit = new Audit();
String idS = rootElement.getAttribute(Tags.Audit.ID);
DBC.INTERIM.assertNotEmpty("Id must be set!", idS);
audit.setId(Long.valueOf(idS));
NodeList childNodes = rootElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
if (!(item instanceof Element))
continue;
Element element = (Element) item;
String nodeName = element.getNodeName();
String txtContent = element.getTextContent();
switch (nodeName) {
case Tags.Audit.USERNAME:
audit.setUsername(txtContent);
break;
case Tags.Audit.FIRSTNAME:
audit.setFirstname(txtContent);
break;
case Tags.Audit.LASTNAME:
audit.setLastname(txtContent);
break;
case Tags.Audit.DATE:
audit.setDate(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent));
break;
case Tags.Audit.ELEMENT_TYPE:
audit.setElementType(txtContent);
break;
case Tags.Audit.ELEMENT_ACCESSED:
audit.setElementAccessed(txtContent);
break;
case Tags.Audit.NEW_VERSION:
audit.setNewVersion(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent));
break;
case Tags.Audit.ACTION:
audit.setAction(txtContent);
break;
case Tags.Audit.ACCESS_TYPE:
audit.setAccessType(AccessType.valueOf(txtContent));
break;
default:
throw new IllegalArgumentException(MessageFormat.format("Unhandled/Invalid tag {0} for Audit {1}",
nodeName, idS));
}
}
String msg = " missing for element with id " + audit.getId();
DBC.INTERIM.assertNotEmpty("Username" + msg, audit.getUsername());
DBC.INTERIM.assertNotEmpty("Firstname" + msg, audit.getFirstname());
DBC.INTERIM.assertNotEmpty("Lastname" + msg, audit.getLastname());
DBC.INTERIM.assertNotNull("Date" + msg, audit.getDate());
DBC.INTERIM.assertNotEmpty("ElementType" + msg, audit.getElementType());
DBC.INTERIM.assertNotEmpty("ElementAccessed" + msg, audit.getElementAccessed());
//DBC.INTERIM.assertNotNull("NewVersion" + msg, audit.getNewVersion());
DBC.INTERIM.assertNotEmpty("Action" + msg, audit.getAction());
DBC.INTERIM.assertNotNull("AccessType" + msg, audit.getAccessType());
return audit;
}
}

View File

@ -0,0 +1,91 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import java.util.ArrayList;
import java.util.List;
import li.strolch.model.query.StrolchQuery;
import ch.eitchnet.utils.collections.DateRange;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditQuery implements StrolchQuery {
private String elementTypeSelection;
private List<AuditSelection> selections;
private DateRange dateRange;
public AuditQuery(String elementTypeSelection, DateRange dateRange) {
DBC.PRE.assertFalse("dateRange may not be unbounded!", dateRange.isUnbounded());
this.elementTypeSelection = elementTypeSelection;
this.dateRange = dateRange;
this.selections = new ArrayList<>();
}
public String getElementTypeSelection() {
return this.elementTypeSelection;
}
public DateRange getDateRange() {
return this.dateRange;
}
public ActionSelection action() {
ActionSelection selection = new ActionSelection(this);
this.selections.add(selection);
return selection;
}
public ElementSelection element() {
ElementSelection selection = new ElementSelection(this);
this.selections.add(selection);
return selection;
}
public IdentitySelection identity() {
IdentitySelection selection = new IdentitySelection(this);
this.selections.add(selection);
return selection;
}
public void accept(AuditQueryVisitor visitor) {
DBC.PRE.assertNotNull("No elementTypeSelection (navigation) set!", this.elementTypeSelection); //$NON-NLS-1$
DBC.PRE.assertNotNull("No dateRange set!", this.dateRange); //$NON-NLS-1$
visitor.visit(this);
for (AuditSelection selection : this.selections) {
selection.accept(visitor);
}
}
/**
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
*/
@Override
public String getPrivilegeName() {
return StrolchQuery.class.getName();
}
/**
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue()
*/
@Override
public Object getPrivilegeValue() {
return getClass().getName();
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface AuditQueryVisitor {
public void visit(ElementSelection selection);
public void visit(IdentitySelection selection);
public void visit(ActionSelection selection);
public void visit(AuditQuery auditQuery);
}

View File

@ -0,0 +1,25 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import org.xml.sax.helpers.DefaultHandler;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditSaxReader extends DefaultHandler {
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class AuditSelection {
private AuditQuery query;
public AuditSelection(AuditQuery query) {
super();
this.query = query;
}
public AuditQuery query() {
return this.query;
}
public abstract void accept(AuditQueryVisitor visitor);
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import javax.xml.parsers.DocumentBuilder;
import li.strolch.model.Tags;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.DomUtil;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AuditToDomVisitor implements AuditVisitor<Document> {
@Override
public Document visitAudit(Audit audit) {
DocumentBuilder documentBuilder = DomUtil.createDocumentBuilder();
Document doc = documentBuilder.getDOMImplementation().createDocument(null, null, null);
Element auditE = doc.createElement(Tags.AUDIT);
auditE.setAttribute(Tags.Audit.ID, audit.getId().toString());
auditE.appendChild(elem(doc, Tags.Audit.USERNAME, audit.getUsername()));
auditE.appendChild(elem(doc, Tags.Audit.FIRSTNAME, audit.getUsername()));
auditE.appendChild(elem(doc, Tags.Audit.LASTNAME, audit.getUsername()));
auditE.appendChild(elem(doc, Tags.Audit.DATE, ISO8601FormatFactory.getInstance().formatDate(audit.getDate())));
auditE.appendChild(elem(doc, Tags.Audit.ELEMENT_TYPE, audit.getElementType()));
auditE.appendChild(elem(doc, Tags.Audit.ELEMENT_ACCESSED, audit.getElementAccessed()));
if (audit.getNewVersion() != null)
auditE.appendChild(elem(doc, Tags.Audit.NEW_VERSION,
ISO8601FormatFactory.getInstance().formatDate(audit.getNewVersion())));
auditE.appendChild(elem(doc, Tags.Audit.ACTION, audit.getAction()));
auditE.appendChild(elem(doc, Tags.Audit.ACCESS_TYPE, audit.getAccessType().name()));
doc.appendChild(auditE);
return doc;
}
private Element elem(Document doc, String tag, String txtValue) {
Element element = doc.createElement(tag);
element.setTextContent(txtValue);
return element;
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface AuditVisitor<U> {
public U visitAudit(Audit audit);
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import li.strolch.model.query.StringSelection;
import ch.eitchnet.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ElementSelection extends AuditSelection {
private StringSelection elementAccessedSelection;
public ElementSelection(AuditQuery query) {
super(query);
}
public ElementSelection elementsAccessed(StringMatchMode matchMode, String... elementsAccessed) {
this.elementAccessedSelection = new StringSelection(matchMode, elementsAccessed);
return this;
}
public StringSelection getElementAccessedSelection() {
return this.elementAccessedSelection;
}
public boolean isElementsAccessedWildcard() {
return this.elementAccessedSelection == null || this.elementAccessedSelection.isWildCard();
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
import li.strolch.model.query.StringSelection;
import ch.eitchnet.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class IdentitySelection extends AuditSelection {
private StringSelection usernameSelection;
private StringSelection firstnameSelection;
private StringSelection lastnameSelection;
public IdentitySelection(AuditQuery query) {
super(query);
}
public IdentitySelection usernames(StringMatchMode matchMode, String... usernames) {
this.usernameSelection = new StringSelection(matchMode, usernames);
return this;
}
public IdentitySelection firstnames(StringMatchMode matchMode, String... firstnames) {
this.firstnameSelection = new StringSelection(matchMode, firstnames);
return this;
}
public IdentitySelection lastnames(StringMatchMode matchMode, String... lastnames) {
this.lastnameSelection = new StringSelection(matchMode, lastnames);
return this;
}
/**
* @return the firstnameSelection
*/
public StringSelection getFirstnameSelection() {
return this.firstnameSelection;
}
/**
* @return the lastnameSelection
*/
public StringSelection getLastnameSelection() {
return this.lastnameSelection;
}
/**
* @return the usernameSelection
*/
public StringSelection getUsernameSelection() {
return this.usernameSelection;
}
public boolean isFirstnameWildcard() {
return this.firstnameSelection == null || this.firstnameSelection.isWildCard();
}
public boolean isLastnameWildcard() {
return this.lastnameSelection == null || this.lastnameSelection.isWildCard();
}
public boolean isUsernameWildcard() {
return this.usernameSelection == null || this.usernameSelection.isWildCard();
}
public boolean isWildcard() {
return isFirstnameWildcard() && isLastnameWildcard() && isUsernameWildcard();
}
@Override
public void accept(AuditQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.audit;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NoStrategyAuditVisitor implements AuditVisitor<Audit> {
@Override
public Audit visitAudit(Audit audit) {
return audit;
}
}

View File

@ -0,0 +1,267 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE;
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.AbstractStrolchElement;
import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
* @param <T>
*/
public abstract class AbstractParameter<T> extends AbstractStrolchElement implements Parameter<T> {
private static final long serialVersionUID = 0L;
protected boolean hidden = false;
protected int index;
protected String interpretation = INTERPRETATION_NONE;
protected String uom = UOM_NONE;
protected ParameterizedElement parent;
/**
* Empty constructor
*/
protected AbstractParameter() {
//
}
/**
* Default constructor
*
* @param id
* @param name
*/
public AbstractParameter(String id, String name) {
super(id, name);
}
@Override
public boolean isHidden() {
return this.hidden;
}
@Override
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
@Override
public String getInterpretation() {
return this.interpretation;
}
@Override
public void setInterpretation(String interpretation) {
if (StringHelper.isEmpty(interpretation)) {
this.interpretation = INTERPRETATION_NONE;
} else {
this.interpretation = interpretation;
}
}
@Override
public String getUom() {
return this.uom;
}
@Override
public void setUom(String uom) {
if (StringHelper.isEmpty(uom)) {
this.uom = UOM_NONE;
} else {
this.uom = uom;
}
}
@Override
public void setIndex(int index) {
this.index = index;
}
@Override
public int getIndex() {
return this.index;
}
@Override
public ParameterizedElement getParent() {
return this.parent;
}
@Override
public void setParent(ParameterizedElement parent) {
this.parent = parent;
}
@Override
public StrolchRootElement getRootElement() {
return this.parent.getRootElement();
}
@Override
public Element toDom(Document doc) {
Element element = doc.createElement(Tags.PARAMETER);
fillElement(element);
element.setAttribute(Tags.VALUE, getValueAsString());
if (!this.interpretation.equals(INTERPRETATION_NONE)) {
element.setAttribute(Tags.INTERPRETATION, this.interpretation);
}
if (!this.uom.equals(UOM_NONE)) {
element.setAttribute(Tags.UOM, this.uom);
}
if (this.hidden) {
element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden));
}
if (this.index != 0) {
element.setAttribute(Tags.INDEX, Integer.toString(this.index));
}
return element;
}
@Override
public void fromDom(Element element) {
super.fromDom(element);
String typeS = element.getAttribute(Tags.TYPE);
if (StringHelper.isEmpty(typeS)) {
String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, this.id);
throw new StrolchException(msg);
} else if (!typeS.equals(getType())) {
String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS);
throw new StrolchException(msg);
}
String interpretation = element.getAttribute(Tags.INTERPRETATION);
String hidden = element.getAttribute(Tags.HIDDEN);
String uom = element.getAttribute(Tags.UOM);
String index = element.getAttribute(Tags.INDEX);
setInterpretation(interpretation);
setUom(uom);
if (StringHelper.isEmpty(index)) {
this.index = 0;
} else {
this.index = Integer.valueOf(index);
}
if (StringHelper.isEmpty(hidden)) {
setHidden(false);
} else {
if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) {
setHidden(true);
} else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
setHidden(false);
} else {
String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
throw new StrolchException(msg);
}
}
}
@Override
protected void fillLocator(LocatorBuilder lb) {
lb.append(this.id);
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
this.parent.fillLocator(lb);
fillLocator(lb);
return lb.build();
}
/**
* Validates that the value is legal. This is the case when it is not null in this implementation
*
* @param value
* the value to check for this parameter instance
*
* @throws StrolchException
* if the value is null
*/
protected void validateValue(T value) throws StrolchException {
if (value == null) {
String msg = "{0} Parameter {1} may not have a null value!"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getType(), getId());
throw new StrolchException(msg);
}
}
/**
* Fills the {@link Parameter} clone with the id, name, hidden, interpretation and uom
*
* @param clone
*/
protected void fillClone(Parameter<?> clone) {
super.fillClone(clone);
clone.setHidden(this.hidden);
clone.setInterpretation(this.interpretation);
clone.setUom(this.uom);
clone.setIndex(this.index);
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitParam(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName());
builder.append(" [id=");
builder.append(this.id);
builder.append(", name=");
builder.append(this.name);
builder.append(", value=");
builder.append(getValueAsString());
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class BooleanParameter extends AbstractParameter<Boolean> {
public static final String TYPE = "Boolean"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
private Boolean value = Boolean.FALSE;
/**
* Empty constructor
*/
public BooleanParameter() {
//
}
/**
* Default constructors
*
* @param id
* @param name
* @param value
*/
public BooleanParameter(String id, String name, Boolean value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public BooleanParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(parseFromString(valueS));
}
@Override
public String getValueAsString() {
return this.value.toString();
}
@Override
public Boolean getValue() {
return this.value;
}
@Override
public void setValue(Boolean value) {
validateValue(value);
this.value = value;
}
@Override
public String getType() {
return BooleanParameter.TYPE;
}
@Override
public BooleanParameter getClone() {
BooleanParameter clone = new BooleanParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitBooleanParam(this);
}
public static Boolean parseFromString(String valueS) {
return StringHelper.parseBoolean(valueS);
}
}

View File

@ -0,0 +1,116 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import java.util.Date;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class DateParameter extends AbstractParameter<Date> {
public static final String TYPE = "Date"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
private Date value;
/**
* Empty constructor
*/
public DateParameter() {
//
}
/**
* Default Constructor
*
* @param id
* @param name
* @param value
*/
public DateParameter(String id, String name, Date value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public DateParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(parseFromString(valueS));
}
@Override
public String getValueAsString() {
return ISO8601FormatFactory.getInstance().formatDate(this.value);
}
@Override
public Date getValue() {
return this.value;
}
@Override
public void setValue(Date value) {
validateValue(value);
this.value = value;
}
@Override
public String getType() {
return DateParameter.TYPE;
}
@Override
public DateParameter getClone() {
DateParameter clone = new DateParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitDateParam(this);
}
public static Date parseFromString(String valueS) {
return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS);
}
}

View File

@ -0,0 +1,116 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class FloatParameter extends AbstractParameter<Double> {
public static final String TYPE = "Float"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
private Double value = Double.MAX_VALUE;
/**
* Empty constructor
*/
public FloatParameter() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param value
*/
public FloatParameter(String id, String name, Double value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public FloatParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(parseFromString(valueS));
}
@Override
public String getValueAsString() {
return Double.toString(this.value);
}
@Override
public Double getValue() {
return this.value;
}
@Override
public void setValue(Double value) {
validateValue(value);
this.value = value;
}
@Override
public String getType() {
return FloatParameter.TYPE;
}
@Override
public FloatParameter getClone() {
FloatParameter clone = new FloatParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitFloatParam(this);
}
public static Double parseFromString(String valueS) {
return Double.valueOf(valueS);
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class IntegerParameter extends AbstractParameter<Integer> {
public static final String TYPE = "Integer"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
private Integer value = Integer.MAX_VALUE;
/**
* Empty constructor
*/
public IntegerParameter() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param value
*/
public IntegerParameter(String id, String name, Integer value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public IntegerParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(parseFromString(valueS));
}
@Override
public String getType() {
return IntegerParameter.TYPE;
}
@Override
public String getValueAsString() {
return Integer.toString(this.value);
}
@Override
public Integer getValue() {
return this.value;
}
@Override
public void setValue(Integer value) {
validateValue(value);
this.value = value;
}
@Override
public IntegerParameter getClone() {
IntegerParameter clone = new IntegerParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitIntegerParam(this);
}
public static Integer parseFromString(String valueS) {
return Integer.valueOf(valueS);
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface ListParameter<E> extends Parameter<List<E>> {
public static final String VALUE_SEPARATOR = ";"; //$NON-NLS-1$
/**
* Adds a single value to the {@link List} of values
*
* @param value
* the value to add
*/
public void addValue(E value);
/**
* Removes a single value from the {@link List} of values
*
* @param value
* the value to remove
*
* @return true if the value was removed, false if it did not exist
*/
public boolean removeValue(E value);
}

View File

@ -0,0 +1,115 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class LongParameter extends AbstractParameter<Long> {
public static final String TYPE = "Long"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
protected Long value;
/**
* Empty constructor
*/
public LongParameter() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param value
*/
public LongParameter(String id, String name, Long value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public LongParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(parseFromString(valueS));
}
@Override
public String getValueAsString() {
return this.value.toString();
}
@Override
public Long getValue() {
return this.value;
}
@Override
public void setValue(Long value) {
validateValue(value);
this.value = value;
}
@Override
public String getType() {
return LongParameter.TYPE;
}
@Override
public LongParameter getClone() {
LongParameter clone = new LongParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitLongParam(this);
}
public static Long parseFromString(String valueS) {
return Long.valueOf(valueS);
}
}

View File

@ -0,0 +1,141 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchModelConstants;
import li.strolch.model.visitor.ParameterVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Parameter<T> extends StrolchElement {
/**
* the value of the parameter as string
*
* @return String
*/
public String getValueAsString();
/**
* the value of the parameter
*
* @return
*/
public T getValue();
/**
* the value of the parameter
*
* @param value
*/
public void setValue(T value);
/**
* get the hidden attribute
*
* @return
*/
public boolean isHidden();
/**
* set the hidden attribute
*
* @param hidden
*/
public void setHidden(boolean hidden);
/**
* Get the UOM of this {@link Parameter}
*
* @return
*/
public String getUom();
/**
* Set the UOM of this {@link Parameter}
*
* @param uom
*/
public void setUom(String uom);
/**
* Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*
* @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*/
public int getIndex();
/**
* Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*
* @param index
* the index to set
*/
public void setIndex(int index);
/**
* Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of
* this {@link Parameter} means. Currently there are three definitions, but any String value can be used:
* <ul>
* <li>{@link StrolchModelConstants#INTERPRETATION_NONE}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_ORDER_REF}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}</li>
* </ul>
*
* @return string value
*/
public String getInterpretation();
/**
* Set the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of this
* {@link Parameter} means. Currently there are three definitions, but any String value can be used:
* <ul>
* <li>{@link StrolchModelConstants#INTERPRETATION_NONE}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_ORDER_REF}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}</li>
* </ul>
*
* @param interpretation
*/
public void setInterpretation(String interpretation);
/**
* The {@link ParameterizedElement} parent to which this {@link Parameter} belongs
*
* @return
*/
@Override
public ParameterizedElement getParent();
/**
* Sets the parent for this {@link Parameter}
*/
public void setParent(ParameterizedElement parent);
@Override
public int hashCode();
@Override
public boolean equals(Object obj);
@Override
public Parameter<T> getClone();
public <U> U accept(ParameterVisitor visitor);
}

View File

@ -0,0 +1,154 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StringListParameter extends AbstractParameter<List<String>> implements ListParameter<String> {
public static final String TYPE = "StringList"; //$NON-NLS-1$
private static final long serialVersionUID = 1L;
protected List<String> value;
/**
* Empty constructor
*/
public StringListParameter() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param value
*/
public StringListParameter(String id, String name, List<String> value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public StringListParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(parseFromString(valueS));
}
@Override
public String getValueAsString() {
if (this.value.isEmpty()) {
return StringHelper.EMPTY;
}
StringBuilder sb = new StringBuilder();
Iterator<String> iter = this.value.iterator();
while (iter.hasNext()) {
sb.append(iter.next());
if (iter.hasNext()) {
sb.append(VALUE_SEPARATOR);
}
}
return sb.toString();
}
@Override
public List<String> getValue() {
return new ArrayList<String>(this.value);
}
@Override
public void setValue(List<String> value) {
validateValue(value);
if (this.value == null) {
this.value = new ArrayList<String>(value.size());
}
this.value.clear();
this.value.addAll(value);
}
@Override
public void addValue(String value) {
this.value.add(value);
}
@Override
public boolean removeValue(String value) {
return this.value.remove(value);
}
@Override
public String getType() {
return TYPE;
}
@Override
public StringListParameter getClone() {
StringListParameter clone = new StringListParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitStringListParam(this);
}
public static List<String> parseFromString(String value) {
if (value.isEmpty()) {
return Collections.emptyList();
}
String[] valueArr = value.split(VALUE_SEPARATOR);
return Arrays.asList(valueArr);
}
}

View File

@ -0,0 +1,113 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.Tags;
import li.strolch.model.visitor.ParameterVisitor;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class StringParameter extends AbstractParameter<String> {
public static final String UNDEFINED_VALUE = "-"; //$NON-NLS-1$
public static final String TYPE = "String"; //$NON-NLS-1$
private static final long serialVersionUID = 0L;
private String value = UNDEFINED_VALUE;
/**
* Empty constructor
*
*/
public StringParameter() {
//
}
/**
* Default constructor
*
* @param id
* @param name
* @param value
*/
public StringParameter(String id, String name, String value) {
super(id, name);
setValue(value);
}
/**
* DOM Constructor
*
* @param element
*/
public StringParameter(Element element) {
super.fromDom(element);
String valueS = element.getAttribute(Tags.VALUE);
if (StringHelper.isEmpty(valueS)) {
String msg = MessageFormat.format("No value defined for {0}", this.id); //$NON-NLS-1$
throw new StrolchException(msg);
}
setValue(valueS);
}
@Override
public String getType() {
return StringParameter.TYPE;
}
@Override
public String getValue() {
return this.value;
}
@Override
public String getValueAsString() {
return this.value;
}
@Override
public void setValue(String value) {
validateValue(value);
this.value = value;
}
@Override
public StringParameter getClone() {
StringParameter clone = new StringParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitStringParam(this);
}
}

View File

@ -0,0 +1,63 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AndSelection extends BooleanSelection {
public AndSelection() {
super();
}
@SafeVarargs
public AndSelection(Selection... selections) {
super(selections);
}
/**
* @param selections
*/
public AndSelection(List<Selection> selections) {
super(selections);
}
@Override
public AndSelection with(Selection selection) {
super.with(selection);
return this;
}
@Override
public AndSelection with(List<Selection> selections) {
super.with(selections);
return this;
}
@Override
public AndSelection with(Selection... selections) {
super.with(selections);
return this;
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitAnd(this);
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class AnySelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
visitor.visitAny();
}
@Override
public boolean hasSelection() {
return true;
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class BooleanSelection implements Selection {
protected List<Selection> selections;
public BooleanSelection() {
this.selections = new ArrayList<>(1);
}
public BooleanSelection(List<Selection> selections) {
this.selections = selections;
}
public BooleanSelection(Selection leftHandSide, Selection rightHandSide) {
this.selections = new ArrayList<>(2);
this.selections.add(leftHandSide);
this.selections.add(rightHandSide);
}
public BooleanSelection(Selection... selections) {
this.selections = Arrays.asList(selections);
}
@Override
public boolean hasSelection() {
if (this.selections == null || this.selections.isEmpty())
return false;
for (Selection selection : this.selections) {
if (selection.hasSelection()) {
return true;
}
}
return false;
}
public List<Selection> getSelections() {
return Collections.unmodifiableList(this.selections);
}
public BooleanSelection with(Selection selection) {
this.selections.add(selection);
return this;
}
public BooleanSelection with(Selection... selections) {
for (Selection selection : selections) {
this.selections.add(selection);
}
return this;
}
public BooleanSelection with(List<Selection> selections) {
this.selections.addAll(selections);
return this;
}
@Override
public abstract void accept(QueryVisitor visitor);
}

View File

@ -0,0 +1,79 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import java.util.Date;
import ch.eitchnet.utils.collections.DateRange;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class DateSelection extends OrderSelection {
private DateRange dateRange;
public DateSelection() {
this.dateRange = new DateRange();
}
public DateSelection from(Date from, boolean inclusive) {
this.dateRange.from(from, inclusive);
return this;
}
public DateSelection to(Date to, boolean inclusive) {
this.dateRange.to(to, inclusive);
return this;
}
public Date getFromDate() {
return this.dateRange.getFromDate();
}
public Date getToDate() {
return this.dateRange.getToDate();
}
public boolean isFromBounded() {
return this.dateRange.isFromBounded();
}
public boolean isToBounded() {
return this.dateRange.isToBounded();
}
public boolean isUnbounded() {
return this.dateRange.isUnbounded();
}
public boolean isBounded() {
return this.dateRange.isBounded();
}
public boolean contains(Date date) {
return this.dateRange.contains(date);
}
public DateRange getDateRange() {
return this.dateRange;
}
@Override
public void accept(OrderSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,75 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class IdSelection extends StrolchElementSelection {
private List<String> ids;
public IdSelection() {
this.ids = new ArrayList<>(1);
}
/**
* @param id
*/
public IdSelection(String id) {
this.ids = new ArrayList<>(1);
this.ids.add(id);
}
/**
* @param ids
*/
public IdSelection(String... ids) {
this.ids = Arrays.asList(ids);
}
/**
* @param ids
*/
public IdSelection(List<String> ids) {
this.ids = ids;
}
/**
* @return the ids
*/
public List<String> getIds() {
return this.ids;
}
/**
* @param id
* @return
*/
public IdSelection with(String id) {
this.ids.add(id);
return this;
}
@Override
public void accept(StrolchElementSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import ch.eitchnet.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NameSelection extends StrolchElementSelection {
private StringMatchMode matchMode;
private String name;
/**
* @param name
* @param matchMode
*/
public NameSelection(String name, StringMatchMode matchMode) {
this.name = name;
this.matchMode = matchMode;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
@Override
public void accept(StrolchElementSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Navigation {
public void accept(QueryVisitor visitor);
}

View File

@ -0,0 +1,47 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NotSelection extends BooleanSelection {
/**
* @param selection
*/
public NotSelection(Selection selection) {
super(selection);
}
/**
* @throws UnsupportedOperationException
* because a {@link NotSelection} can only work on a single {@link Selection}
*/
@Override
public NotSelection with(Selection selection) {
throw new UnsupportedOperationException("NotSelection can only have a single selection"); //$NON-NLS-1$
}
public Selection getSelection() {
return this.selections.get(0);
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitNot(this);
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import java.util.List;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrSelection extends BooleanSelection {
public OrSelection() {
super();
}
public OrSelection(List<Selection> selections) {
super(selections);
}
@SafeVarargs
public OrSelection(Selection... selections) {
super(selections);
}
@Override
public OrSelection with(Selection selection) {
super.with(selection);
return this;
}
@Override
public OrSelection with(List<Selection> selections) {
super.with(selections);
return this;
}
@Override
public OrSelection with(Selection... selections) {
super.with(selections);
return this;
}
@Override
public void accept(QueryVisitor visitor) {
visitor.visitOr(this);
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import li.strolch.model.Order;
import li.strolch.model.OrderVisitor;
import li.strolch.model.parameter.Parameter;
/**
* {@link OrderQuery} is the user API to query {@link Order Orders} in Strolch. The {@link Navigation} is used to
* navigate to a type of order on which any further {@link Selection Selections} will be performed. The
* {@link OrderVisitor} is used to transform the returned object into a domain specific object (if required). This
* mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and
* then performing this transformation.
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderQuery extends StrolchElementQuery<OrderQueryVisitor> {
public OrderQuery(Navigation navigation) {
super(navigation);
}
@Override
public OrderQuery with(Selection selection) {
super.with(selection);
return this;
}
@Override
public OrderQuery not(Selection selection) {
super.not(selection);
return this;
}
@Override
public OrderQuery withAny() {
super.withAny();
return this;
}
public static OrderQuery query(Navigation navigation) {
return new OrderQuery(navigation);
}
public static OrderQuery query(String type) {
return new OrderQuery(new StrolchTypeNavigation(type));
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface OrderQueryVisitor extends OrderSelectionVisitor, ParameterSelectionVisitor {
// marker interface
}

View File

@ -0,0 +1,35 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public abstract class OrderSelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((OrderSelectionVisitor) visitor);
}
@Override
public boolean hasSelection() {
return true;
}
public abstract void accept(OrderSelectionVisitor visitor);
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface OrderSelectionVisitor extends StrolchRootElementSelectionVisitor {
public void visit(DateSelection selection);
public void visit(StateSelection selection);
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ParameterBagSelection implements Selection {
private String bagKey;
public ParameterBagSelection(String bagKey) {
this.bagKey = bagKey;
}
/**
* @return the bagKey
*/
public String getBagKey() {
return this.bagKey;
}
@Override
public boolean hasSelection() {
return true;
}
@Override
public void accept(QueryVisitor visitor) {
accept((StrolchRootElementSelectionVisitor) visitor);
}
public void accept(StrolchRootElementSelectionVisitor visitor) {
visitor.visit(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + " [bagKey=");
builder.append(this.bagKey);
builder.append("]");
return builder.toString();
}
public static class NullParameterBagSelection extends ParameterBagSelection {
public NullParameterBagSelection(String bagKey) {
super(bagKey);
}
@Override
public void accept(StrolchRootElementSelectionVisitor visitor) {
visitor.visit(this);
}
}
}

View File

@ -0,0 +1,288 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import java.util.Date;
import java.util.List;
import ch.eitchnet.utils.StringMatchMode;
import ch.eitchnet.utils.dbc.DBC;
/**
* @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 boolean hasSelection() {
return true;
}
@Override
public void accept(QueryVisitor visitor) {
accept((ParameterSelectionVisitor) visitor);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + " [bagKey=");
builder.append(this.bagKey);
builder.append(", paramKey=");
builder.append(this.paramKey);
builder.append("]");
return builder.toString();
}
public abstract void accept(ParameterSelectionVisitor visitor);
public static StringParameterSelection stringSelection(String bagKey, String paramKey, String value,
StringMatchMode matchMode) {
return new StringParameterSelection(bagKey, paramKey, value, matchMode);
}
public static IntegerParameterSelection integerSelection(String bagKey, String paramKey, int value) {
return new IntegerParameterSelection(bagKey, paramKey, value);
}
public static BooleanParameterSelection booleanSelection(String bagKey, String paramKey, boolean value) {
return new BooleanParameterSelection(bagKey, paramKey, value);
}
public static FloatParameterSelection floatSelection(String bagKey, String paramKey, double value) {
return new FloatParameterSelection(bagKey, paramKey, value);
}
public static LongParameterSelection longSelection(String bagKey, String paramKey, long value) {
return new LongParameterSelection(bagKey, paramKey, value);
}
public static DateParameterSelection dateSelection(String bagKey, String paramKey, Date value) {
return new DateParameterSelection(bagKey, paramKey, value);
}
public static DateRangeParameterSelection dateRangeSelection(String bagKey, String paramKey, Date from, Date to) {
return new DateRangeParameterSelection(bagKey, paramKey, from, to);
}
public static StringListParameterSelection stringListSelection(String bagKey, String paramKey, List<String> value) {
return new StringListParameterSelection(bagKey, paramKey, value);
}
public static NullParameterSelection nullSelection(String bagKey, String paramKey) {
return new NullParameterSelection(bagKey, paramKey);
}
public static class NullParameterSelection extends ParameterSelection {
public NullParameterSelection(String bagKey, String paramKey) {
super(bagKey, paramKey);
}
@Override
public void accept(ParameterSelectionVisitor visitor) {
visitor.visit(this);
}
}
public static class StringParameterSelection extends ParameterSelection {
private StringMatchMode matchMode;
private String value;
public StringParameterSelection(String bagKey, String paramKey, String value, StringMatchMode matchMode) {
super(bagKey, paramKey);
this.value = value;
this.matchMode = matchMode;
}
public String getValue() {
return this.value;
}
public StringMatchMode getMatchMode() {
return this.matchMode;
}
@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 DateRangeParameterSelection extends ParameterSelection {
private Date from;
private Date to;
public DateRangeParameterSelection(String bagKey, String paramKey, Date from, Date to) {
super(bagKey, paramKey);
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.to = to;
}
public Date getFrom() {
return this.from;
}
public Date getTo() {
return this.to;
}
@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,50 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import li.strolch.model.query.ParameterSelection.BooleanParameterSelection;
import li.strolch.model.query.ParameterSelection.DateParameterSelection;
import li.strolch.model.query.ParameterSelection.DateRangeParameterSelection;
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.NullParameterSelection;
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(DateRangeParameterSelection selection);
public void visit(StringListParameterSelection selection);
public void visit(NullParameterSelection nullParameterSelection);
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface QueryVisitor {
public void visitAny();
public void visitAnd(AndSelection andSelection);
public void visitOr(OrSelection orSelection);
public void visitNot(NotSelection notSelection);
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
import li.strolch.model.parameter.Parameter;
/**
* {@link ResourceQuery} is the user API to query {@link Resource Resources} in Strolch. The {@link Navigation} is used
* to navigate to a type of resource on which any further {@link Selection Selections} will be performed. The
* {@link ResourceVisitor} is used to transform the returned object into a domain specific object (if required). This
* mechanism allows you to query only the values of a {@link Parameter} instead of having to return all the elements and
* then performing this transformation.
*
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceQuery extends StrolchElementQuery<ResourceQueryVisitor> {
/**
* @param navigation
* @param elementVisitor
*/
public ResourceQuery(Navigation navigation) {
super(navigation);
}
@Override
public ResourceQuery with(Selection selection) {
super.with(selection);
return this;
}
@Override
public ResourceQuery not(Selection selection) {
super.not(selection);
return this;
}
@Override
public ResourceQuery withAny() {
super.withAny();
return this;
}
public static ResourceQuery query(Navigation navigation) {
return new ResourceQuery(navigation);
}
public static ResourceQuery query(String type) {
return new ResourceQuery(new StrolchTypeNavigation(type));
}
}

View File

@ -0,0 +1,24 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ResourceQueryVisitor extends StrolchRootElementSelectionVisitor, ParameterSelectionVisitor {
// marker interface
}

View File

@ -0,0 +1,26 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface Selection {
public void accept(QueryVisitor visitor);
public boolean hasSelection();
}

View File

@ -0,0 +1,39 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import li.strolch.model.State;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StateSelection extends OrderSelection {
private State state;
public StateSelection(State state) {
this.state = state;
}
public State getState() {
return this.state;
}
@Override
public void accept(OrderSelectionVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import ch.eitchnet.utils.StringMatchMode;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StringSelection {
private StringMatchMode matchMode;
private String[] values;
public StringSelection() {
//
}
/**
* @param matchMode
* @param values
*/
public StringSelection(StringMatchMode matchMode, String[] values) {
this.matchMode = matchMode;
this.values = values;
}
/**
* @return the matchMode
*/
public StringMatchMode getMatchMode() {
return this.matchMode;
}
/**
* @param matchMode
* the matchMode to set
*/
public void setMatchMode(StringMatchMode matchMode) {
this.matchMode = matchMode;
}
/**
* @return the values
*/
public String[] getValues() {
return this.values;
}
/**
* @param values
* the values to set
*/
public void setValues(String... values) {
this.values = values;
}
/**
* @return
*/
public boolean isWildCard() {
return this.values == null || this.values.length == 0;
}
public boolean matches(String value) {
for (String sel : this.values) {
if (this.matchMode.matches(value, sel))
return true;
}
return false;
}
}

View File

@ -0,0 +1,103 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import ch.eitchnet.utils.dbc.DBC;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchElementQuery<T extends QueryVisitor> implements StrolchQuery {
private Navigation navigation;
private Selection selection;
public StrolchElementQuery(Navigation navigation) {
this.navigation = navigation;
}
public boolean hasNavigation() {
return this.navigation != null;
}
public boolean hasSelection() {
return this.selection != null && this.selection.hasSelection();
}
public Selection getSelection() {
return this.selection;
}
public StrolchElementQuery<T> with(Selection selection) {
assertNoSelectionYetSet();
this.selection = selection;
return this;
}
private void assertNoSelectionYetSet() {
String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$
DBC.PRE.assertNull(msg, this.selection);
}
public StrolchElementQuery<T> withAny() {
assertNoSelectionYetSet();
this.selection = new AnySelection();
return this;
}
public AndSelection and() {
assertNoSelectionYetSet();
AndSelection and = new AndSelection();
this.selection = and;
return and;
}
public OrSelection or() {
assertNoSelectionYetSet();
OrSelection or = new OrSelection();
this.selection = or;
return or;
}
public StrolchElementQuery<T> not(Selection selection) {
assertNoSelectionYetSet();
this.selection = new NotSelection(selection);
return this;
}
public void accept(T visitor) {
DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$
DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$
this.navigation.accept(visitor);
this.selection.accept(visitor);
}
/**
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
*/
@Override
public String getPrivilegeName() {
return StrolchQuery.class.getName();
}
/**
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue()
*/
@Override
public Object getPrivilegeValue() {
return getClass().getName();
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public abstract class StrolchElementSelection implements Selection {
@Override
public void accept(QueryVisitor visitor) {
accept((StrolchElementSelectionVisitor) visitor);
}
@Override
public boolean hasSelection() {
return true;
}
public abstract void accept(StrolchElementSelectionVisitor visitor);
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.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,26 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import ch.eitchnet.privilege.model.Restrictable;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchQuery extends Restrictable {
// marker interface
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.query;
import li.strolch.model.query.ParameterBagSelection.NullParameterBagSelection;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface StrolchRootElementSelectionVisitor extends StrolchElementSelectionVisitor {
public void visit(ParameterBagSelection selection);
public void visit(NullParameterBagSelection selection);
}

View File

@ -0,0 +1,44 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.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,263 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE;
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
import java.text.MessageFormat;
import li.strolch.exception.StrolchException;
import li.strolch.model.AbstractStrolchElement;
import li.strolch.model.Locator;
import li.strolch.model.Locator.LocatorBuilder;
import li.strolch.model.Resource;
import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchRootElement;
import li.strolch.model.Tags;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.ITimeVariable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
import li.strolch.model.visitor.TimedStateVisitor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import ch.eitchnet.utils.helper.StringHelper;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@SuppressWarnings("rawtypes")
public abstract class AbstractStrolchTimedState<T extends IValue> extends AbstractStrolchElement implements
StrolchTimedState<T> {
private static final long serialVersionUID = 1L;
protected boolean hidden = false;
protected int index;
protected String interpretation = INTERPRETATION_NONE;
protected String uom = UOM_NONE;
protected Resource parent;
protected ITimedState<T> state;
public AbstractStrolchTimedState() {
this.state = new TimedState<>();
}
public AbstractStrolchTimedState(String id, String name) {
super(id, name);
this.state = new TimedState<>();
}
@Override
public boolean isHidden() {
return this.hidden;
}
@Override
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
@Override
public String getInterpretation() {
return this.interpretation;
}
@Override
public void setInterpretation(String interpretation) {
if (StringHelper.isEmpty(interpretation)) {
this.interpretation = INTERPRETATION_NONE;
} else {
this.interpretation = interpretation;
}
}
@Override
public String getUom() {
return this.uom;
}
@Override
public void setUom(String uom) {
if (StringHelper.isEmpty(uom)) {
this.uom = UOM_NONE;
} else {
this.uom = uom;
}
}
@Override
public void setIndex(int index) {
this.index = index;
}
@Override
public int getIndex() {
return this.index;
}
@Override
public ITimeValue<T> getNextMatch(Long time, T value) {
return this.state.getNextMatch(time, value);
}
@Override
public ITimeValue<T> getPreviousMatch(Long time, T value) {
return this.state.getPreviousMatch(time, value);
}
@Override
public <U extends IValueChange<T>> void applyChange(U change) {
this.state.applyChange(change);
}
@Override
public ITimeValue<T> getStateAt(Long time) {
return this.state.getStateAt(time);
}
@Override
public ITimeVariable<T> getTimeEvolution() {
return this.state.getTimeEvolution();
}
@Override
public StrolchElement getParent() {
return this.parent;
}
@Override
public void setParent(Resource parent) {
this.parent = parent;
}
@Override
public StrolchRootElement getRootElement() {
return this.parent;
}
@Override
public Element toDom(Document doc) {
Element element = doc.createElement(Tags.PARAMETER);
fillElement(element);
if (!this.interpretation.equals(INTERPRETATION_NONE)) {
element.setAttribute(Tags.INTERPRETATION, this.interpretation);
}
if (!this.uom.equals(UOM_NONE)) {
element.setAttribute(Tags.UOM, this.uom);
}
if (this.hidden) {
element.setAttribute(Tags.HIDDEN, Boolean.toString(this.hidden));
}
if (this.index != 0) {
element.setAttribute(Tags.INDEX, Integer.toString(this.index));
}
return element;
}
@Override
public void fromDom(Element element) {
super.fromDom(element);
String typeS = element.getAttribute(Tags.TYPE);
if (StringHelper.isEmpty(typeS)) {
String msg = "Type must be set on element with id {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, this.id);
throw new StrolchException(msg);
} else if (!typeS.equals(getType())) {
String msg = "{0} must have type {1}, not: {2}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, getClass().getSimpleName(), getType(), typeS);
throw new StrolchException(msg);
}
String interpretation = element.getAttribute(Tags.INTERPRETATION);
String hidden = element.getAttribute(Tags.HIDDEN);
String uom = element.getAttribute(Tags.UOM);
String index = element.getAttribute(Tags.INDEX);
setInterpretation(interpretation);
setUom(uom);
if (StringHelper.isEmpty(index)) {
this.index = 0;
} else {
this.index = Integer.valueOf(index);
}
if (StringHelper.isEmpty(hidden)) {
setHidden(false);
} else {
if (hidden.equalsIgnoreCase(Boolean.TRUE.toString())) {
setHidden(true);
} else if (hidden.equalsIgnoreCase(Boolean.FALSE.toString())) {
setHidden(false);
} else {
String msg = "Boolean string must be either {0} or {1}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, Boolean.TRUE.toString(), Boolean.FALSE.toString());
throw new StrolchException(msg);
}
}
}
@Override
protected void fillLocator(LocatorBuilder lb) {
lb.append(Tags.STATE);
lb.append(this.id);
}
@Override
public Locator getLocator() {
LocatorBuilder lb = new LocatorBuilder();
this.parent.fillLocator(lb);
fillLocator(lb);
return lb.build();
}
protected void fillClone(AbstractStrolchTimedState<T> clone) {
super.fillClone(clone);
clone.state = this.state.getCopy();
}
@Override
public <U> U accept(TimedStateVisitor visitor) {
return visitor.visitTimedState(this);
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName());
builder.append(" [id=");
builder.append(this.id);
builder.append(", name=");
builder.append(this.name);
builder.append(", valueNow=");
builder.append(this.state.getStateAt(System.currentTimeMillis()));
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import java.util.SortedSet;
import li.strolch.model.StrolchElement;
import li.strolch.model.Tags;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.impl.BooleanValue;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class BooleanTimedState extends AbstractStrolchTimedState<BooleanValue> {
private static final long serialVersionUID = 1L;
public static final String TYPE = "BooleanState";
public BooleanTimedState() {
super();
}
public BooleanTimedState(String id, String name) {
super(id, name);
}
public BooleanTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
Boolean value = Boolean.valueOf(timeValueElem.getAttribute(Tags.VALUE));
BooleanValue booleanValue = new BooleanValue(value);
this.state.getTimeEvolution().setValueAt(time, booleanValue);
}
}
@Override
public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement);
SortedSet<ITimeValue<BooleanValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<BooleanValue> timeValue : values) {
Long time = timeValue.getTime();
BooleanValue value = timeValue.getValue();
Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
stateElement.appendChild(valueElem);
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
BooleanTimedState clone = new BooleanTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import java.util.SortedSet;
import li.strolch.model.StrolchElement;
import li.strolch.model.Tags;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.impl.FloatValue;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class FloatTimedState extends AbstractStrolchTimedState<FloatValue> {
private static final long serialVersionUID = 1L;
public static final String TYPE = "FloatState";
public FloatTimedState() {
super();
}
public FloatTimedState(String id, String name) {
super(id, name);
}
public FloatTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
Double value = Double.valueOf(timeValueElem.getAttribute(Tags.VALUE));
FloatValue floatValue = new FloatValue(value);
this.state.getTimeEvolution().setValueAt(time, floatValue);
}
}
@Override
public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement);
SortedSet<ITimeValue<FloatValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<FloatValue> timeValue : values) {
Long time = timeValue.getTime();
FloatValue value = timeValue.getValue();
Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
stateElement.appendChild(valueElem);
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
FloatTimedState clone = new FloatTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.ITimeVariable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
/**
* A time based state characterized by a {@link IValue} object implementation.
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* IValue implementation representing the state at a given time
*/
@SuppressWarnings("rawtypes")
public interface ITimedState<T extends IValue> {
/**
* @return the new {@link ITimeValue} matching the value in the future
*/
ITimeValue<T> getNextMatch(final Long time, T value);
/**
* @return the new {@link ITimeValue} matching the value in the future
*/
ITimeValue<T> getPreviousMatch(final Long time, T value);
/**
* @param change
* the state change to be applied
*/
<U extends IValueChange<T>> void applyChange(final U change);
/**
* @return the state at the given time
*/
ITimeValue<T> getStateAt(final Long time);
/**
* @return get the states evolution in time
*/
ITimeVariable<T> getTimeEvolution();
/**
* @return a copy of this timed state
*/
ITimedState<T> getCopy();
}

View File

@ -0,0 +1,90 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import java.util.SortedSet;
import li.strolch.model.StrolchElement;
import li.strolch.model.Tags;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.impl.IntegerValue;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class IntegerTimedState extends AbstractStrolchTimedState<IntegerValue> {
private static final long serialVersionUID = 1L;
public static final String TYPE = "IntegerState";
public IntegerTimedState() {
super();
}
public IntegerTimedState(String id, String name) {
super(id, name);
}
public IntegerTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
Integer value = Integer.valueOf(timeValueElem.getAttribute(Tags.VALUE));
IntegerValue integerValue = new IntegerValue(value);
this.state.getTimeEvolution().setValueAt(time, integerValue);
}
}
@Override
public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement);
SortedSet<ITimeValue<IntegerValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<IntegerValue> timeValue : values) {
Long time = timeValue.getTime();
IntegerValue value = timeValue.getValue();
Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, value.getValue().toString());
stateElement.appendChild(valueElem);
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
IntegerTimedState clone = new IntegerTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -0,0 +1,113 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.SortedSet;
import li.strolch.model.StrolchElement;
import li.strolch.model.Tags;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.impl.AString;
import li.strolch.model.timevalue.impl.StringSetValue;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class StringSetTimedState extends AbstractStrolchTimedState<StringSetValue> {
private static final long serialVersionUID = 1L;
public static final String TYPE = "StringSetState";
public StringSetTimedState() {
super();
}
public StringSetTimedState(String id, String name) {
super(id, name);
}
public StringSetTimedState(Element element) {
super.fromDom(element);
this.state = new TimedState<>();
NodeList timeValueElems = element.getElementsByTagName(Tags.VALUE);
for (int i = 0; i < timeValueElems.getLength(); i++) {
Element timeValueElem = (Element) timeValueElems.item(i);
Long time = Long.valueOf(timeValueElem.getAttribute(Tags.TIME));
String valueAsString = timeValueElem.getAttribute(Tags.VALUE);
Set<AString> value = new HashSet<>();
String[] values = valueAsString.split(",");
for (String s : values) {
value.add(new AString(s.trim()));
}
StringSetValue integerValue = new StringSetValue(value);
this.state.getTimeEvolution().setValueAt(time, integerValue);
}
}
@Override
public Element toDom(Document doc) {
Element stateElement = doc.createElement(Tags.TIMED_STATE);
super.fillElement(stateElement);
SortedSet<ITimeValue<StringSetValue>> values = this.state.getTimeEvolution().getValues();
for (ITimeValue<StringSetValue> timeValue : values) {
Long time = timeValue.getTime();
StringSetValue stringSetValue = timeValue.getValue();
Set<AString> value = stringSetValue.getValue();
StringBuilder sb = new StringBuilder();
Iterator<AString> iter = value.iterator();
while (iter.hasNext()) {
sb.append(iter.next().getString());
if (iter.hasNext()) {
sb.append(", ");
}
}
String valueAsString = sb.toString();
Element valueElem = doc.createElement(Tags.VALUE);
valueElem.setAttribute(Tags.TIME, time.toString());
valueElem.setAttribute(Tags.VALUE, valueAsString);
stateElement.appendChild(valueElem);
}
return stateElement;
}
@Override
public String getType() {
return TYPE;
}
@Override
public StrolchElement getClone() {
StringSetTimedState clone = new StringSetTimedState();
fillClone(clone);
return clone;
}
}

View File

@ -0,0 +1,116 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import li.strolch.model.Resource;
import li.strolch.model.StrolchElement;
import li.strolch.model.StrolchModelConstants;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.ITimeVariable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
import li.strolch.model.visitor.TimedStateVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@SuppressWarnings("rawtypes")
public interface StrolchTimedState<T extends IValue> extends StrolchElement {
/**
* get the hidden attribute
*
* @return
*/
public boolean isHidden();
/**
* set the hidden attribute
*
* @param hidden
*/
public void setHidden(boolean hidden);
/**
* Get the UOM of this {@link Parameter}
*
* @return
*/
public String getUom();
/**
* Set the UOM of this {@link Parameter}
*
* @param uom
*/
public void setUom(String uom);
/**
* Returns the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*
* @return the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*/
public int getIndex();
/**
* Set the index of this {@link Parameter}. This can be used to sort the parameters in a UI
*
* @param index
* the index to set
*/
public void setIndex(int index);
/**
* Returns the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of
* this {@link Parameter} means. Currently there are three definitions, but any String value can be used:
* <ul>
* <li>{@link StrolchModelConstants#INTERPRETATION_NONE}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_ORDER_REF}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}</li>
* </ul>
*
* @return string value
*/
public String getInterpretation();
/**
* Set the interpretation of this {@link Parameter}. The interpretation semantic describes what the value of this
* {@link Parameter} means. Currently there are three definitions, but any String value can be used:
* <ul>
* <li>{@link StrolchModelConstants#INTERPRETATION_NONE}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_ORDER_REF}</li>
* <li>{@link StrolchModelConstants#INTERPRETATION_RESOURCE_REF}</li>
* </ul>
*
* @param interpretation
*/
public void setInterpretation(String interpretation);
public ITimeValue<T> getNextMatch(Long time, T value);
public ITimeValue<T> getPreviousMatch(Long time, T value);
public <U extends IValueChange<T>> void applyChange(U change);
public ITimeValue<T> getStateAt(Long time);
public ITimeVariable<T> getTimeEvolution();
public void setParent(Resource aThis);
public <U> U accept(TimedStateVisitor visitor);
}

View File

@ -0,0 +1,87 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timedstate;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.ITimeVariable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
import li.strolch.model.timevalue.impl.TimeVariable;
/**
* @author Martin Smock <smock.martin@gmail.com>
*/
@SuppressWarnings("rawtypes")
public class TimedState<T extends IValue> implements ITimedState<T>, Serializable {
private static final long serialVersionUID = 1L;
private ITimeVariable<T> timeVariable = new TimeVariable<T>();
@Override
@SuppressWarnings("unchecked")
public ITimeValue<T> getNextMatch(final Long time, final T value) {
Collection<ITimeValue<T>> futureValues = this.timeVariable.getFutureValues(time);
for (ITimeValue<T> iTimeValue : futureValues) {
if (iTimeValue.getValue().matches(value)) {
return iTimeValue;
}
}
return null;
}
@Override
@SuppressWarnings("unchecked")
public ITimeValue<T> getPreviousMatch(final Long time, final T value) {
Collection<ITimeValue<T>> pastValues = this.timeVariable.getPastValues(time);
List<ITimeValue<T>> asList = new ArrayList<ITimeValue<T>>(pastValues);
Collections.reverse(asList);
for (ITimeValue<T> iTimeValue : asList) {
if (iTimeValue.getValue().matches(value)) {
return iTimeValue;
}
}
return null;
}
@Override
public <U extends IValueChange<T>> void applyChange(U change) {
this.timeVariable.applyChange(change);
}
@Override
public ITimeValue<T> getStateAt(final Long time) {
return this.timeVariable.getValueAt(time);
}
@Override
public ITimeVariable<T> getTimeEvolution() {
return this.timeVariable;
}
@Override
public ITimedState<T> getCopy() {
TimedState<T> copy = new TimedState<>();
copy.timeVariable = this.timeVariable.getCopy();
return copy;
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue;
import li.strolch.model.timevalue.impl.TimeVariable;
/**
* Interface for timed value objects to be used with the {@link TimeVariable}
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* the backing value of the timed value object
*/
@SuppressWarnings("rawtypes")
public interface ITimeValue<T extends IValue> extends Comparable<ITimeValue<T>> {
ITimeValue<T> setValue(final T value);
T getValue();
Long getTime();
ITimeValue<T> add(final T change);
ITimeValue<T> getCopy();
}

View File

@ -0,0 +1,91 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue;
import java.util.Collection;
import java.util.SortedSet;
/**
* A timed variable storing a ordered sequence of {@link ITimeValue} objects modeling a time evolution of a quantity.
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* the backing value of the timed value object
*/
@SuppressWarnings("rawtypes")
public interface ITimeVariable<T extends IValue> {
/**
* set the value at a point in time to a given time value object
*
* @param time
* the time to set the {@link IValue}
* @param value
* the {@link IValue} to set
*/
void setValueAt(final Long time, final T value);
/**
* get the latest {@link ITimeValue} whose time field is less or equal to the time given
*/
ITimeValue<T> getValueAt(final Long time);
/**
* Applies a {@link IValueChange} propagating the change to all future values starting from the time of the change.
*
* @param change
* the {@link IValueChange} to be applied
*/
void applyChange(final IValueChange<T> change);
/**
* Get all {@link ITimeValue} objects whose time field is greater or equal to the given time
*
* @param time
* the time the sequence starts with
* @return the sequence of {@link ITimeValue} objects in the future
*/
Collection<ITimeValue<T>> getFutureValues(final Long time);
/**
* Get all {@link ITimeValue} objects whose time field is strictly smaller than the given time
*
* @param time
* the time the sequence starts with
* @return the sequence of {@link ITimeValue} objects in the future
*/
Collection<ITimeValue<T>> getPastValues(final Long time);
/**
* Get all {@link ITimeValue} objects
*
* @return a defensive copy of the {@link ITimeValue}s
*/
SortedSet<ITimeValue<T>> getValues();
/**
* removes {@link ITimeValue} objects from the sequence, where the successor matches value. I.e considering a pair
* of adjacent {@link ITimeValue} objects in the sequence which have the same {@link IValue}, the later one is
* removed, since it contains no additional information.
*/
void compact();
/**
* @return a copy of this time variable
*/
ITimeVariable<T> getCopy();
}

View File

@ -0,0 +1,58 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue;
/**
* A value object defining some basic algebraic operations. Mathematically speaking {@link IValue} objects define a
* group with a addition operation.
*
* @author Martin Smock <smock.martin@gmail.com>
*
* @param <T>
* any object for which a (generalized) add operation can be defined.
*/
public interface IValue<T> {
/**
* @return the backing value
*/
T getValue();
/**
* @return a value with the backing value added to the argument value
*/
IValue<T> add(T o);
/**
* @return true, if the backing values match.
*/
boolean matches(IValue<T> other);
/**
* @return the inverse value, such that add(value.getInverse()) returns the neutral element of the group
*/
IValue<T> getInverse();
/**
* @return a copy of this
*/
IValue<T> getCopy();
/**
* @return this value in string representation
*/
String getValueAsString();
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue;
/**
* Interface for operators to be used to change the values of {@link ITimeValue} in a {@link ITimeVariable}.
*
* @author Martin Smock <smock.martin@gmail.com>
*/
@SuppressWarnings("rawtypes")
public interface IValueChange<T extends IValue> {
/**
* @return the time this change has to be applied
*/
Long getTime();
/**
* @return the value of the change
*/
T getValue();
/**
* @return the inverse neutralizing a change. Very useful to undo changes applied.
*/
IValueChange<T> getInverse();
}

View File

@ -0,0 +1,106 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import ch.eitchnet.utils.dbc.DBC;
/**
* Wrapper for java.util.String object defining a inverse to support algebraic operations.
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class AString implements Serializable {
private static final long serialVersionUID = 1L;
private final String string;
private final boolean inverse;
public AString(final String string) {
DBC.PRE.assertNotNull("Value may not be null!", string);
DBC.PRE.assertFalse("Comma not allowed in value!", string.contains(","));
this.string = string;
this.inverse = false;
}
public AString(final String string, final boolean inverse) {
DBC.PRE.assertNotNull("Value may not be null!", string);
DBC.PRE.assertFalse("Comma not allowed in value!", string.contains(","));
this.string = string;
this.inverse = inverse;
}
public String getString() {
return this.string;
}
public boolean isInverse() {
return this.inverse;
}
public AString getInverse() {
return new AString(this.string, !this.inverse);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (this.inverse ? 1231 : 1237);
result = prime * result + ((this.string == null) ? 0 : this.string.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AString other = (AString) obj;
if (this.inverse != other.inverse) {
return false;
}
if (this.string == null) {
if (other.string != null) {
return false;
}
} else if (!this.string.equals(other.string)) {
return false;
}
return true;
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("AString [string=");
sb.append(this.string);
sb.append(", inverse=");
sb.append(this.inverse);
sb.append("]");
return sb.toString();
}
}

View File

@ -0,0 +1,118 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
/**
* {@link IValue} implementation to work with Boolean valued {@link ITimeValue} objects
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class BooleanValue implements IValue<Boolean>, Serializable {
private static final long serialVersionUID = 1L;
public static final BooleanValue NEUTRAL = new BooleanValue(false);
private Boolean value;
public BooleanValue(Boolean value) {
this.value = value;
}
public BooleanValue(boolean value) {
this.value = Boolean.valueOf(value);
}
public BooleanValue(String valueAsString) throws NumberFormatException {
this.value = Boolean.parseBoolean(valueAsString);
}
@Override
public BooleanValue add(Boolean o) {
this.value = o;
return this;
}
@Override
public boolean matches(IValue<Boolean> other) {
return this.value.equals(other.getValue());
}
@Override
public Boolean getValue() {
return this.value;
}
@Override
public BooleanValue getInverse() {
return new BooleanValue(!getValue());
}
@Override
public String getValueAsString() {
return this.value.toString();
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("BooleanValue [value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
}
@Override
public BooleanValue getCopy() {
return new BooleanValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BooleanValue other = (BooleanValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,127 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
/**
* {@link IValue} implementation to work with Double valued {@link ITimeValue} objects
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class FloatValue implements IValue<Double>, Serializable {
private static final long serialVersionUID = 1L;
public static final FloatValue NEUTRAL = new FloatValue(0.0d);
private Double value;
public FloatValue(Double value) {
this.value = value;
}
public FloatValue(double value) {
this.value = Double.valueOf(value);
}
public FloatValue(Integer value) {
this.value = this.value.doubleValue();
}
public FloatValue(int value) {
this.value = Integer.valueOf(value).doubleValue();
}
public FloatValue(String valueAsString) throws NumberFormatException {
this.value = Double.parseDouble(valueAsString);
}
@Override
public FloatValue add(Double o) {
this.value += o;
return this;
}
@Override
public Double getValue() {
return this.value;
}
@Override
public String getValueAsString() {
return this.value.toString();
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("DoubleValue [value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
}
@Override
public boolean matches(IValue<Double> other) {
return this.value.equals(other.getValue());
}
@Override
public FloatValue getInverse() {
return new FloatValue(-getValue());
}
@Override
public FloatValue getCopy() {
return new FloatValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
FloatValue other = (FloatValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,119 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
/**
* {@link IValue} implementation to work with Integer valued {@link ITimeValue} objects
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class IntegerValue implements IValue<Integer>, Serializable {
private static final long serialVersionUID = 1L;
public static final IntegerValue NEUTRAL = new IntegerValue(0);
private Integer value;
public IntegerValue(Integer value) {
this.value = value;
}
public IntegerValue(int value) {
this.value = Integer.valueOf(value);
}
public IntegerValue(String valueAsString) throws NumberFormatException {
this.value = Integer.parseInt(valueAsString);
}
@Override
public IntegerValue add(Integer o) {
this.value += o;
return this;
}
@Override
public boolean matches(IValue<Integer> other) {
return this.value.equals(other.getValue());
}
@Override
public Integer getValue() {
return this.value;
}
@Override
public IntegerValue getInverse() {
return new IntegerValue(-getValue());
}
@Override
public String getValueAsString() {
return this.value.toString();
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("IntegerValue [value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
}
@Override
public IntegerValue getCopy() {
return new IntegerValue(this.value);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
IntegerValue other = (IntegerValue) obj;
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,131 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import li.strolch.exception.StrolchException;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
import ch.eitchnet.utils.dbc.DBC;
import ch.eitchnet.utils.helper.StringHelper;
/**
* {@link IValue} implementation to work with String valued {@link ITimeValue} objects. Since a java.util.String object
* does not define a inverse, a algebraic {@link AString} wrapper is used.
*
* @author Martin Smock <smock.martin@gmail.com>
*/
public class StringSetValue implements IValue<Set<AString>>, Serializable {
private static final long serialVersionUID = 1L;
private static Set<AString> neu = Collections.emptySet();
public static final IValue<Set<AString>> NEUTRAL = new StringSetValue(neu);
private Set<AString> aStrings = new HashSet<>();
public StringSetValue() {
}
public StringSetValue(final Set<AString> aStrings) {
DBC.PRE.assertNotNull("Value may not be null!", aStrings);
this.aStrings = aStrings;
}
@Override
public Set<AString> getValue() {
return this.aStrings;
}
@Override
public IValue<Set<AString>> add(Set<AString> o) {
Set<AString> toBeAdded = new HashSet<>(o);
for (Iterator<AString> iter1 = toBeAdded.iterator(); iter1.hasNext();) {
AString toAdd = iter1.next();
if (StringHelper.isEmpty(toAdd.getString())) {
throw new StrolchException("StringSetValue may not contain null values in set!");
}
for (Iterator<AString> iter = this.aStrings.iterator(); iter.hasNext();) {
AString aString = iter.next();
boolean valueMatch = aString.getString().equals(toAdd.getString());
boolean compensate = (toAdd.isInverse() && !aString.isInverse())
|| (!toAdd.isInverse() && aString.isInverse());
if (valueMatch && compensate) {
iter.remove();
iter1.remove();
}
}
}
this.aStrings.addAll(toBeAdded);
return this;
}
@Override
public boolean matches(IValue<Set<AString>> other) {
return getValue().equals(other.getValue());
}
@Override
public StringSetValue getInverse() {
Set<AString> inverseSet = new HashSet<>();
for (AString as : this.aStrings) {
inverseSet.add(as.getInverse());
}
StringSetValue inverse = new StringSetValue();
inverse.aStrings = inverseSet;
return inverse;
}
@Override
public StringSetValue getCopy() {
return new StringSetValue(new HashSet<>(this.aStrings));
}
@Override
public String getValueAsString() {
if (this.aStrings.isEmpty())
return StringHelper.EMPTY;
if (this.aStrings.size() == 1)
return this.aStrings.iterator().next().getString();
StringBuilder sb = new StringBuilder();
Iterator<AString> iter = this.aStrings.iterator();
while (iter.hasNext()) {
sb.append(iter.next());
if (iter.hasNext())
sb.append(", ");
}
return sb.toString();
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("StringSetValue [aStrings=");
sb.append(getValueAsString());
sb.append("]");
return sb.toString();
}
}

View File

@ -0,0 +1,128 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.IValue;
/**
* @author Martin Smock <smock.martin@gmail.com>
*/
@SuppressWarnings("rawtypes")
public class TimeValue<T extends IValue> implements ITimeValue<T>, Serializable {
private static final long serialVersionUID = 1L;
protected final Long time;
protected T value;
/**
* @param time
* @param value
*/
public TimeValue(final Long time, final T value) {
this.time = time;
this.value = value;
}
@Override
@SuppressWarnings("unchecked")
public T getValue() {
return (T) this.value.getCopy();
}
@Override
public Long getTime() {
return this.time;
}
@Override
public ITimeValue<T> setValue(final T value) {
this.value = value;
return this;
}
@SuppressWarnings("unchecked")
@Override
public ITimeValue<T> add(final T change) {
this.value.add(change.getValue());
return this;
}
@Override
public int compareTo(final ITimeValue<T> arg0) {
return this.getTime().compareTo(arg0.getTime());
}
@SuppressWarnings("unchecked")
@Override
public ITimeValue<T> getCopy() {
return new TimeValue<T>(this.time, (T) this.value.getCopy());
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("TimeValue [time=");
sb.append(this.time);
sb.append(", value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
@SuppressWarnings("unchecked")
TimeValue<T> other = (TimeValue<T>) obj;
if (this.time == null) {
if (other.time != null) {
return false;
}
} else if (!this.time.equals(other.time)) {
return false;
}
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,130 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;
import li.strolch.model.timevalue.ITimeValue;
import li.strolch.model.timevalue.ITimeVariable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
/**
* @author Martin Smock <smock.martin@gmail.com>
*/
@SuppressWarnings("rawtypes")
public class TimeVariable<T extends IValue> implements ITimeVariable<T>, Serializable {
private static final long serialVersionUID = 1L;
public SortedSet<ITimeValue<T>> container = new TreeSet<ITimeValue<T>>();
@Override
public ITimeValue<T> getValueAt(final Long time) {
ITimeValue<T> tmp = null;
for (ITimeValue<T> value : this.container) {
if (value.getTime() <= time) {
tmp = value;
} else {
break;
}
}
return tmp;
}
@Override
public void setValueAt(final Long time, final T targetValue) {
ITimeValue<T> current = getValueAt(time);
if (current != null && current.getTime().equals(time)) {
current.setValue(targetValue);
} else {
this.container.add(new TimeValue<T>(time, targetValue));
}
}
@Override
public SortedSet<ITimeValue<T>> getFutureValues(final Long time) {
TimeValue<T> picker = new TimeValue<T>(time, null);
return new TreeSet<ITimeValue<T>>(this.container.tailSet(picker));
}
@Override
public Collection<ITimeValue<T>> getPastValues(final Long time) {
TimeValue<T> picker = new TimeValue<T>(time, null);
return new TreeSet<ITimeValue<T>>(this.container.headSet(picker));
}
@Override
public SortedSet<ITimeValue<T>> getValues() {
return new TreeSet<ITimeValue<T>>(this.container);
}
@Override
public void applyChange(final IValueChange<T> change) {
SortedSet<ITimeValue<T>> futureValues = getFutureValues(change.getTime());
for (ITimeValue<T> value : futureValues) {
value.add(change.getValue());
}
ITimeValue<T> initialValue = getValueAt(change.getTime());
if (initialValue == null) {
ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), change.getValue());
this.container.add(newValue);
} else if (initialValue.getTime().longValue() < change.getTime().longValue()) {
ITimeValue<T> newValue = new TimeValue<T>(change.getTime(), initialValue.getValue());
newValue.add(change.getValue());
this.container.add(newValue);
}
compact();
}
@SuppressWarnings("unchecked")
@Override
public void compact() {
if (this.container.size() < 2) {
return;
}
Iterator<ITimeValue<T>> iterator = this.container.iterator();
ITimeValue<T> predecessor = iterator.next();
while (iterator.hasNext()) {
ITimeValue<T> successor = iterator.next();
if (successor.getValue().matches(predecessor.getValue())) {
iterator.remove();
} else {
predecessor = successor;
}
}
}
@Override
public ITimeVariable<T> getCopy() {
TimeVariable<T> clone = new TimeVariable<>();
for (ITimeValue<T> timeValue : this.container) {
clone.container.add(timeValue.getCopy());
}
return clone;
}
}

View File

@ -0,0 +1,110 @@
/*
* Copyright 2013 Martin Smock <smock.martin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.timevalue.impl;
import java.io.Serializable;
import li.strolch.model.timevalue.IValue;
import li.strolch.model.timevalue.IValueChange;
/**
* @author Martin Smock <smock.martin@gmail.com>
*/
@SuppressWarnings("rawtypes")
public class ValueChange<T extends IValue> implements IValueChange<T>, Serializable {
private static final long serialVersionUID = 1L;
protected final Long time;
protected final T value;
/**
* @param time
* @param value
*/
public ValueChange(final Long time, final T value) {
this.time = time;
this.value = value;
}
@Override
public Long getTime() {
return this.time;
}
@Override
@SuppressWarnings("unchecked")
public T getValue() {
return (T) this.value.getCopy();
}
@Override
@SuppressWarnings("unchecked")
public IValueChange<T> getInverse() {
return new ValueChange(this.time, this.value.getInverse());
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
ValueChange<?> other = (ValueChange<?>) obj;
if (this.time == null) {
if (other.time != null) {
return false;
}
} else if (!this.time.equals(other.time)) {
return false;
}
if (this.value == null) {
if (other.value != null) {
return false;
}
} else if (!this.value.equals(other.value)) {
return false;
}
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@SuppressWarnings("nls")
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("ValueChange [time=");
sb.append(this.time);
sb.append(", value=");
sb.append(this.value);
sb.append("]");
return sb.toString();
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import li.strolch.model.Order;
import li.strolch.model.Resource;
import li.strolch.model.Tags;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ElementTypeVisitor implements StrolchRootElementVisitor<String> {
@Override
public String visitOrder(Order order) {
return Tags.ORDER;
}
@Override
public String visitResource(Resource resource) {
return Tags.RESOURCE;
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import li.strolch.model.Order;
import li.strolch.model.OrderVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NoStrategyOrderVisitor implements OrderVisitor<Order> {
@Override
public Order visit(Order element) {
return element;
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NoStrategyResourceVisitor implements ResourceVisitor<Resource> {
@Override
public Resource visit(Resource element) {
return element;
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class NoStrategyVisitor<T extends StrolchElement> implements StrolchElementVisitor<T, T> {
@Override
public T visit(T element) {
return element;
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import java.util.List;
import li.strolch.model.Locator;
import li.strolch.model.Order;
import li.strolch.model.OrderVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class OrderDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements OrderVisitor<List<Locator>> {
private Order srcOrder;
public OrderDeepEqualsVisitor(Order srcOrder) {
this.srcOrder = srcOrder;
}
@Override
public List<Locator> visit(Order dstOrder) {
deepEquals(this.srcOrder, dstOrder);
return getMismatchedLocators();
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import li.strolch.model.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.ListParameter;
import li.strolch.model.parameter.LongParameter;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public interface ParameterVisitor {
public <T> T visitParam(Parameter<?> param);
public <T> T visitBooleanParam(BooleanParameter param);
public <T> T visitDateParam(DateParameter param);
public <T> T visitFloatParam(FloatParameter param);
public <T> T visitIntegerParam(IntegerParameter param);
public <T> T visitLongParam(LongParameter param);
public <T> T visitStringParam(StringParameter param);
public <T> T visitListParam(ListParameter<?> param);
public <T> T visitStringListParam(StringListParameter param);
}

View File

@ -0,0 +1,41 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import java.util.List;
import li.strolch.model.Locator;
import li.strolch.model.Resource;
import li.strolch.model.ResourceVisitor;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class ResourceDeepEqualsVisitor extends StrolchElementDeepEqualsVisitor implements
ResourceVisitor<List<Locator>> {
private Resource srcRes;
public ResourceDeepEqualsVisitor(Resource sourceRes) {
this.srcRes = sourceRes;
}
@Override
public List<Locator> visit(Resource dstRes) {
deepEquals(this.srcRes, dstRes);
return getMismatchedLocators();
}
}

View File

@ -0,0 +1,96 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.visitor;
import li.strolch.model.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.ListParameter;
import li.strolch.model.parameter.LongParameter;
import li.strolch.model.parameter.Parameter;
import li.strolch.model.parameter.StringListParameter;
import li.strolch.model.parameter.StringParameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class SetParameterValueVisitor implements ParameterVisitor {
private String value;
public void setValue(Parameter<?> parameter, String value) {
this.value = value;
try {
parameter.accept(this);
} finally {
this.value = null;
}
}
@Override
public <T> T visitParam(Parameter<?> param) {
throw new UnsupportedOperationException("Not implemented on " + param.getClass());
}
@Override
public <T> T visitListParam(ListParameter<?> param) {
throw new UnsupportedOperationException("Not implemented on " + param.getClass());
}
@Override
public <T> T visitBooleanParam(BooleanParameter param) {
param.setValue(BooleanParameter.parseFromString(this.value));
return null;
}
@Override
public <T> T visitDateParam(DateParameter param) {
param.setValue(DateParameter.parseFromString(this.value));
return null;
}
@Override
public <T> T visitFloatParam(FloatParameter param) {
param.setValue(FloatParameter.parseFromString(this.value));
return null;
}
@Override
public <T> T visitIntegerParam(IntegerParameter param) {
param.setValue(IntegerParameter.parseFromString(this.value));
return null;
}
@Override
public <T> T visitLongParam(LongParameter param) {
param.setValue(LongParameter.parseFromString(this.value));
return null;
}
@Override
public <T> T visitStringParam(StringParameter param) {
param.setValue(this.value);
return null;
}
@Override
public <T> T visitStringListParam(StringListParameter param) {
param.setValue(StringListParameter.parseFromString(this.value));
return null;
}
}

Some files were not shown because too many files have changed in this diff Show More