From 9831d711897f890321af8a9349201b3b86871b09 Mon Sep 17 00:00:00 2001 From: micycle1 Date: Tue, 8 Jun 2021 16:53:34 +0100 Subject: [PATCH] init --- .github/workflows/maven.yml | 31 ++++ .gitignore | 5 + README.md | 5 + pom.xml | 116 ++++++++++++ .../fr/ign/cogit/geoxygene/filter/And.java | 52 ++++++ .../filter/BinaryComparisonOpsType.java | 50 ++++++ .../geoxygene/filter/BinaryLogicOpsType.java | 86 +++++++++ .../geoxygene/filter/ComparisonOpsType.java | 87 +++++++++ .../cogit/geoxygene/filter/ElseFilter.java | 38 ++++ .../geoxygene/filter/ElseFilterImpl.java | 41 +++++ .../fr/ign/cogit/geoxygene/filter/Filter.java | 34 ++++ .../cogit/geoxygene/filter/LogicOpsType.java | 32 ++++ .../fr/ign/cogit/geoxygene/filter/Not.java | 32 ++++ .../fr/ign/cogit/geoxygene/filter/Or.java | 37 ++++ .../geoxygene/filter/PropertyIsEqualTo.java | 76 ++++++++ .../filter/PropertyIsGreaterThan.java | 56 ++++++ .../PropertyIsGreaterThanOrEqualTo.java | 57 ++++++ .../geoxygene/filter/PropertyIsLessThan.java | 56 ++++++ .../filter/PropertyIsLessThanOrEqualTo.java | 56 ++++++ .../geoxygene/filter/PropertyIsLike.java | 88 +++++++++ .../filter/PropertyIsNotEqualTo.java | 58 ++++++ .../geoxygene/filter/PropertyIsNull.java | 40 +++++ .../geoxygene/filter/SpatialOpsType.java | 26 +++ .../geoxygene/filter/UnaryLogicOpsType.java | 73 ++++++++ .../geoxygene/filter/expression/Add.java | 45 +++++ .../filter/expression/BinaryExpression.java | 99 +++++++++++ .../geoxygene/filter/expression/Divide.java | 45 +++++ .../filter/expression/Expression.java | 35 ++++ .../filter/expression/ExpressionFactory.java | 81 +++++++++ .../geoxygene/filter/expression/Function.java | 60 +++++++ .../geoxygene/filter/expression/Literal.java | 121 +++++++++++++ .../geoxygene/filter/expression/Multiply.java | 45 +++++ .../filter/expression/PropertyName.java | 168 ++++++++++++++++++ .../geoxygene/filter/expression/Subtract.java | 45 +++++ .../cogit/geoxygene/filter/function/Abs.java | 39 ++++ .../geoxygene/filter/function/EndAngle.java | 54 ++++++ .../filter/function/FunctionImpl.java | 157 ++++++++++++++++ .../cogit/geoxygene/filter/function/Max.java | 40 +++++ .../cogit/geoxygene/filter/function/Min.java | 50 ++++++ .../cogit/geoxygene/filter/function/Pow.java | 41 +++++ .../cogit/geoxygene/filter/package-info.java | 29 +++ .../filter/spatial/BinarySpatialOpsType.java | 28 +++ .../filter/expression/SimpleTest.java | 90 ++++++++++ 43 files changed, 2504 insertions(+) create mode 100644 .github/workflows/maven.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/And.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/BinaryComparisonOpsType.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/BinaryLogicOpsType.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/ComparisonOpsType.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilter.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilterImpl.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/Filter.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/LogicOpsType.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/Not.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/Or.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsEqualTo.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThan.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThanOrEqualTo.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThan.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThanOrEqualTo.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLike.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNotEqualTo.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNull.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/SpatialOpsType.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/UnaryLogicOpsType.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Add.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/BinaryExpression.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Divide.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Expression.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/ExpressionFactory.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Function.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Literal.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Multiply.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/PropertyName.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/expression/Subtract.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/function/Abs.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/function/EndAngle.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/function/FunctionImpl.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/function/Max.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/function/Min.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/function/Pow.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/package-info.java create mode 100644 src/main/java/fr/ign/cogit/geoxygene/filter/spatial/BinarySpatialOpsType.java create mode 100644 src/test/java/fr/ign/cogit/geoxygene/filter/expression/SimpleTest.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..68e72cd --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,31 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + - name: Build with Maven + run: mvn -B package --file pom.xml + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..909f0f5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/target/ +/.settings +.classpath +.project +/bin/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ae71d9 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +[![](https://jitpack.io/v/GeOxygene/geoxygene-filter.svg)](https://jitpack.io/#GeOxygene/geoxygene-filter) + +# geoxygene-filter + +_geoxygene-filter_, a module from [Geoxygene](https://github.com/IGNF/geoxygene), hosted as a standalone artifact/repository. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..70cb158 --- /dev/null +++ b/pom.xml @@ -0,0 +1,116 @@ + + 4.0.0 + + geoxygene-filter + jar + geoxygene-filter + fr.ign.cogit + 1.9 + + + 2.4.0-b180830.0359 + 2.4.0-b180830.0438 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 8 + 8 + UTF-8 + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + deploy + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.0 + + + attach-javadocs + deploy + + jar + + + + + + + + + + org.apache.logging.log4j + log4j-core + 2.13.3 + + + + com.github.GeOxygene + geoxygene-api + 1.9 + + + com.github.GeOxygene + geoxygene-spatial + 1.9 + + + junit + junit + 4.13.1 + + + javax.xml.bind + jaxb-api + ${jaxb.version} + + + org.glassfish.jaxb + jaxb-runtime + ${jaxb.runtime.version} + runtime + + + + + + + + + + + + + javax.activation + activation + 1.1.1 + + + + + + jitpack.io + https://jitpack.io + + + diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/And.java b/src/main/java/fr/ign/cogit/geoxygene/filter/And.java new file mode 100644 index 0000000..c5b0ccd --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/And.java @@ -0,0 +1,52 @@ +/* + * This file is part of the GeOxygene project source files. + * + * GeOxygene aims at providing an open framework which implements OGC/ISO + * specifications for the development and deployment of geographic (GIS) + * applications. It is a open source contribution of the COGIT laboratory at the + * Institut Géographique National (the French National Mapping Agency). + * + * See: http://oxygene-project.sourceforge.net + * + * Copyright (C) 2005 Institut Géographique National + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library (see file LICENSE if present); if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "And") +public class And extends BinaryLogicOpsType { + + @Override + public boolean evaluate(Object object) { + for (Filter filter : this.getOps()) { + if (!filter.evaluate(object)) { + return false; + } + } + return true; + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/BinaryComparisonOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/BinaryComparisonOpsType.java new file mode 100644 index 0000000..cd5a7c7 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/BinaryComparisonOpsType.java @@ -0,0 +1,50 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +public abstract class BinaryComparisonOpsType extends ComparisonOpsType { + + @XmlAttribute(required = false) + private boolean matchCase = true; + + /** + * Affecte la valeur de l'attribut matchCase. + * @param matchCase l'attribut matchCase à affecter + */ + public void setMatchCase(boolean matchCase) { + this.matchCase = matchCase; + } + + /** + * Renvoie la valeur de l'attribut matchCase. + * @return la valeur de l'attribut matchCase + */ + public boolean isMatchCase() { + return this.matchCase; + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/BinaryLogicOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/BinaryLogicOpsType.java new file mode 100644 index 0000000..22dc8a3 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/BinaryLogicOpsType.java @@ -0,0 +1,86 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * @author Julien Perret + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlSeeAlso({ PropertyIsEqualTo.class, PropertyIsGreaterThan.class, + PropertyIsGreaterThanOrEqualTo.class, PropertyIsLessThan.class, + PropertyIsLessThanOrEqualTo.class, PropertyIsNotEqualTo.class, And.class, + Or.class, Not.class }) +@XmlRootElement +public abstract class BinaryLogicOpsType extends LogicOpsType { + + @XmlElements({ + @XmlElement(name = "PropertyIsEqualTo", type = PropertyIsEqualTo.class), + @XmlElement(name = "PropertyIsGreaterThan", type = PropertyIsGreaterThan.class), + @XmlElement(name = "PropertyIsGreaterThanOrEqualTo", type = PropertyIsGreaterThanOrEqualTo.class), + @XmlElement(name = "PropertyIsLessThan", type = PropertyIsLessThan.class), + @XmlElement(name = "PropertyIsLessThanOrEqualTo", type = PropertyIsLessThanOrEqualTo.class), + @XmlElement(name = "PropertyIsNotEqualTo", type = PropertyIsNotEqualTo.class), + @XmlElement(name = "And", type = And.class), + @XmlElement(name = "Or", type = Or.class), + @XmlElement(name = "Not", type = Not.class) }) + List ops = new ArrayList(); + + /** + * Renvoie la valeur de l'attribut ops. + * @return la valeur de l'attribut ops + */ + public List getOps() { + return this.ops; + } + + /** + * Affecte la valeur de l'attribut ops. + * @param ops l'attribut ops à affecter + */ + public void setOps(List ops) { + this.ops = ops; + } + + @Override + public String toString() { + return this.ops.get(0).toString() + this.getClass().getSimpleName() + + this.ops.get(1).toString(); + } + @Override + public boolean equals(Object o) { + if (! BinaryLogicOpsType.class.isAssignableFrom(o.getClass())) { + return false; + } + BinaryLogicOpsType f = (BinaryLogicOpsType) o; + return f.getClass().equals(this.getClass()) + && f.getOps().equals(this.getOps()); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/ComparisonOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/ComparisonOpsType.java new file mode 100644 index 0000000..6e6cfb8 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/ComparisonOpsType.java @@ -0,0 +1,87 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +import fr.ign.cogit.geoxygene.filter.expression.Literal; +import fr.ign.cogit.geoxygene.filter.expression.PropertyName; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +public abstract class ComparisonOpsType extends Filter { + @XmlElement(name = "PropertyName") + PropertyName propertyName; + + /** + * Renvoie la valeur de l'attribut propertyName. + * @return la valeur de l'attribut propertyName + */ + public PropertyName getPropertyName() { + return this.propertyName; + } + + /** + * Affecte la valeur de l'attribut propertyName. + * @param propertyName l'attribut propertyName à affecter + */ + public void setPropertyName(PropertyName propertyName) { + this.propertyName = propertyName; + } + + @XmlElement(name = "Literal") + Literal literal; + + /** + * Renvoie la valeur de l'attribut literal. + * @return la valeur de l'attribut literal + */ + public Literal getLiteral() { + return this.literal; + } + + /** + * Affecte la valeur de l'attribut literal. + * @param literal l'attribut literal à affecter + */ + public void setLiteral(Literal literal) { + this.literal = literal; + } + + @Override + public String toString() { + return this.getClass().getSimpleName() + " " + this.getPropertyName() //$NON-NLS-1$ + + " " + this.getLiteral().toString(); //$NON-NLS-1$ + } + @Override + public boolean equals(Object o) { + if (! ComparisonOpsType.class.isAssignableFrom(o.getClass())) { + return false; + } + ComparisonOpsType f = (ComparisonOpsType) o; + return f.getClass().equals(this.getClass()) + && f.getLiteral().equals(this.getLiteral()) + && f.getPropertyName().equals(this.propertyName); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilter.java b/src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilter.java new file mode 100644 index 0000000..5201b05 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilter.java @@ -0,0 +1,38 @@ +/* + * This file is part of the GeOxygene project source files. + * + * GeOxygene aims at providing an open framework which implements OGC/ISO + * specifications for the development and deployment of geographic (GIS) + * applications. It is a open source contribution of the COGIT laboratory at the + * Institut Géographique National (the French National Mapping Agency). + * + * See: http://oxygene-project.sourceforge.net + * + * Copyright (C) 2005 Institut Géographique National + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library (see file LICENSE if present); if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +/** + * @author Julien Perret + * + */ +public interface ElseFilter { + + public boolean evaluate(Object object); + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilterImpl.java b/src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilterImpl.java new file mode 100644 index 0000000..d88e5b8 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/ElseFilterImpl.java @@ -0,0 +1,41 @@ +/* + * This file is part of the GeOxygene project source files. + * + * GeOxygene aims at providing an open framework which implements OGC/ISO + * specifications for the development and deployment of geographic (GIS) + * applications. It is a open source contribution of the COGIT laboratory at the + * Institut Géographique National (the French National Mapping Agency). + * + * See: http://oxygene-project.sourceforge.net + * + * Copyright (C) 2005 Institut Géographique National + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library (see file LICENSE if present); if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +/** + * @author Julien Perret + * + */ +public class ElseFilterImpl implements ElseFilter { + + @Override + public boolean evaluate(Object object) { + return true; + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/Filter.java b/src/main/java/fr/ign/cogit/geoxygene/filter/Filter.java new file mode 100644 index 0000000..77b6ad9 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/Filter.java @@ -0,0 +1,34 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * @author Julien Perret + */ +@XmlSeeAlso({ LogicOpsType.class, ComparisonOpsType.class }) +@XmlRootElement +public abstract class Filter { + + public abstract boolean evaluate(Object object); + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/LogicOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/LogicOpsType.java new file mode 100644 index 0000000..9f92cf3 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/LogicOpsType.java @@ -0,0 +1,32 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * @author Julien Perret + */ +@XmlSeeAlso({ BinaryLogicOpsType.class, UnaryLogicOpsType.class }) +@XmlRootElement +public abstract class LogicOpsType extends Filter { + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/Not.java b/src/main/java/fr/ign/cogit/geoxygene/filter/Not.java new file mode 100644 index 0000000..466420f --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/Not.java @@ -0,0 +1,32 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +/** + * @author Julien Perret + */ +public class Not extends UnaryLogicOpsType { + + @Override + public boolean evaluate(Object object) { + return !this.getOp().evaluate(object); + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/Or.java b/src/main/java/fr/ign/cogit/geoxygene/filter/Or.java new file mode 100644 index 0000000..40d93b5 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/Or.java @@ -0,0 +1,37 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +/** + * @author Julien Perret + */ +public class Or extends BinaryLogicOpsType { + + @Override + public boolean evaluate(Object object) { + for (Filter filter : this.getOps()) { + if (filter.evaluate(object)) { + return true; + } + } + return false; + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsEqualTo.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsEqualTo.java new file mode 100644 index 0000000..ffc36d9 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsEqualTo.java @@ -0,0 +1,76 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import fr.ign.cogit.geoxygene.filter.expression.Literal; +import fr.ign.cogit.geoxygene.filter.expression.PropertyName; + +/** + * @author Julien Perret + */ +public class PropertyIsEqualTo extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsEqualTo.class.getName()); + + public PropertyIsEqualTo() { + } + + /** + * @param propertyName + * @param literal + */ + public PropertyIsEqualTo(PropertyName propertyName, Literal literal) { + this.setPropertyName(propertyName); + this.setLiteral(literal); + } + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + return false; + } + if (property instanceof String) { + if (!this.isMatchCase()) { + return (String.CASE_INSENSITIVE_ORDER.compare(((String) property), this + .getLiteral().getValue()) == 0); + } + return (((String) property).compareTo(this.getLiteral().getValue()) == 0); + // FIXME voir cas sensitif à la case + } + if (property instanceof Number) { + return (((Number) property).doubleValue() == Double.parseDouble(this + .getLiteral().getValue())); + } + if (property instanceof Boolean) { + return ((Boolean) property).equals(Boolean.valueOf(this.getLiteral() + .getValue())); + } + return property.equals(this.getLiteral()); + } + + @Override + public String toString() { + return this.getPropertyName() + "==" //$NON-NLS-1$ + + this.getLiteral(); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThan.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThan.java new file mode 100644 index 0000000..4560bdb --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThan.java @@ -0,0 +1,56 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + */ +public class PropertyIsGreaterThan extends BinaryComparisonOpsType { + static Logger logger = LogManager + .getLogger(PropertyIsGreaterThan.class.getName()); + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + return false; + } + if (property instanceof String) { + if (!this.isMatchCase()) { + return (String.CASE_INSENSITIVE_ORDER.compare(((String) property), this + .getLiteral().getValue()) > 0); + // FIXME voir cas sensitif à la case + } + } + if (property instanceof Number) { + return (((Number) property).doubleValue() > Double.parseDouble(this + .getLiteral().getValue())); + } + return property.equals(this.getLiteral()); + } + + @Override + public String toString() { + return this.getPropertyName() + " > " + this.getLiteral().toString(); //$NON-NLS-1$ + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThanOrEqualTo.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThanOrEqualTo.java new file mode 100644 index 0000000..441daf9 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsGreaterThanOrEqualTo.java @@ -0,0 +1,57 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + * + */ +public class PropertyIsGreaterThanOrEqualTo extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsGreaterThanOrEqualTo.class + .getName()); + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + return false; + } + if (property instanceof String) { + if (!this.isMatchCase()) { + return (String.CASE_INSENSITIVE_ORDER.compare(((String) property), this + .getLiteral().getValue()) >= 0); + // FIXME voir cas sensitif à la case + } + } + if (property instanceof Number) { + return (((Number) property).doubleValue() >= Double.parseDouble(this + .getLiteral().getValue())); + } + return property.equals(this.getLiteral()); + } + + @Override + public String toString() { + return this.getPropertyName() + " >= " + this.getLiteral().toString(); //$NON-NLS-1$ + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThan.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThan.java new file mode 100644 index 0000000..397d69a --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThan.java @@ -0,0 +1,56 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + * + */ +public class PropertyIsLessThan extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsLessThan.class.getName()); + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + return false; + } + if (property instanceof String) { + if (!this.isMatchCase()) { + return (String.CASE_INSENSITIVE_ORDER.compare(((String) property), this + .getLiteral().getValue()) < 0); + // FIXME voir cas sensitif à la case + } + } + if (property instanceof Number) { + return (((Number) property).doubleValue() < Double.parseDouble(this + .getLiteral().getValue())); + } + return property.equals(this.getLiteral()); + } + + @Override + public String toString() { + return this.getPropertyName() + " < " + this.getLiteral().toString(); //$NON-NLS-1$ + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThanOrEqualTo.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThanOrEqualTo.java new file mode 100644 index 0000000..be6045e --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLessThanOrEqualTo.java @@ -0,0 +1,56 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + */ +public class PropertyIsLessThanOrEqualTo extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsLessThanOrEqualTo.class + .getName()); + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + return false; + } + if (property instanceof String) { + if (!this.isMatchCase()) { + return (String.CASE_INSENSITIVE_ORDER.compare(((String) property), this + .getLiteral().getValue()) <= 0); + // FIXME voir cas sensitif à la case + } + } + if (property instanceof Number) { + return (((Number) property).doubleValue() <= Double.parseDouble(this + .getLiteral().getValue())); + } + return property.equals(this.getLiteral()); + } + + @Override + public String toString() { + return this.getPropertyName() + " <= " + this.getLiteral().toString(); //$NON-NLS-1$ + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLike.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLike.java new file mode 100644 index 0000000..cadd557 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsLike.java @@ -0,0 +1,88 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlAttribute; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + * + */ +public class PropertyIsLike extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsLike.class.getName()); + @XmlAttribute(required = true) + private String wildCard; + @XmlAttribute(required = true) + private String singleChar; + @XmlAttribute(name = "escape", required = true) + private String escapeChar; + + public String getWildCard() { + return this.wildCard; + } + + public void setWildCard(String wildCard) { + this.wildCard = wildCard; + } + + public String getSingleChar() { + return this.singleChar; + } + + public void setSingleChar(String singleChar) { + this.singleChar = singleChar; + } + + public String getEscapeChar() { + return this.escapeChar; + } + + public void setEscapeChar(String escapeChar) { + this.escapeChar = escapeChar; + } + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + return false; + } + String regex = this.getLiteral().getValue(); + regex.replace(this.getSingleChar(), "."); //$NON-NLS-1$ + regex.replace(this.getWildCard(), ".*"); //$NON-NLS-1$ + regex.replace(this.getEscapeChar(), "\\"); //$NON-NLS-1$ + if (property instanceof String) { + // FIXME voir influence sensibilité à la casse + return ((String) property).matches(regex); + } + if (property instanceof Number) { + return ((Number) property).toString().matches(regex); + } + return false; + } + + @Override + public String toString() { + return this.getPropertyName() + " is like " + this.getLiteral().toString(); //$NON-NLS-1$ + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNotEqualTo.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNotEqualTo.java new file mode 100644 index 0000000..5294dc6 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNotEqualTo.java @@ -0,0 +1,58 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + */ +public class PropertyIsNotEqualTo extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsNotEqualTo.class.getName()); + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) { + // modif gtouya: return true to be the logical contrary of + // PropertyIsEqualTo that returns false when there is no property. + // this modification is not obvious and can be discussed! + return true; + } + if (property instanceof String) { + if (!this.isMatchCase()) { + return (String.CASE_INSENSITIVE_ORDER.compare(((String) property), this + .getLiteral().getValue()) != 0); + // FIXME voir cas sensitif à la case + } + } + if (property instanceof Number) { + return (((Number) property).doubleValue() != Double.parseDouble(this + .getLiteral().getValue())); + } + return property.equals(this.getLiteral()); + } + + @Override + public String toString() { + return this.getPropertyName() + " <> " + this.getLiteral().toString(); //$NON-NLS-1$ + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNull.java b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNull.java new file mode 100644 index 0000000..ce4e269 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/PropertyIsNull.java @@ -0,0 +1,40 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author GTouya + */ +public class PropertyIsNull extends BinaryComparisonOpsType { + static Logger logger = LogManager.getLogger(PropertyIsNull.class.getName()); + + @Override + public boolean evaluate(Object object) { + Object property = this.getPropertyName().evaluate(object); + if (property == null) + return true; + // FIXME ne fait pas la différence entre un attribut absent et une valeur + // nulle + return false; + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/SpatialOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/SpatialOpsType.java new file mode 100644 index 0000000..c1e1191 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/SpatialOpsType.java @@ -0,0 +1,26 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +/** + * @author Julien Perret + */ +public abstract class SpatialOpsType extends Filter { +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/UnaryLogicOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/UnaryLogicOpsType.java new file mode 100644 index 0000000..634bfe9 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/UnaryLogicOpsType.java @@ -0,0 +1,73 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElements; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +public abstract class UnaryLogicOpsType extends LogicOpsType { + + @XmlElements({ + @XmlElement(name = "PropertyIsEqualTo", type = PropertyIsEqualTo.class), + @XmlElement(name = "PropertyIsGreaterThan", type = PropertyIsGreaterThan.class), + @XmlElement(name = "PropertyIsGreaterThanOrEqualTo", type = PropertyIsGreaterThanOrEqualTo.class), + @XmlElement(name = "PropertyIsLessThan", type = PropertyIsLessThan.class), + @XmlElement(name = "PropertyIsLessThanOrEqualTo", type = PropertyIsLessThanOrEqualTo.class), + @XmlElement(name = "PropertyIsNotEqualTo", type = PropertyIsNotEqualTo.class), + @XmlElement(name = "And", type = And.class), + @XmlElement(name = "Or", type = Or.class), + @XmlElement(name = "Not", type = Not.class) }) + Filter op = null; + + /** + * Renvoie la valeur de l'attribut op. + * @return la valeur de l'attribut op + */ + public Filter getOp() { + return this.op; + } + + /** + * Affecte la valeur de l'attribut op. + * @param op l'attribut op à affecter + */ + public void setOp(Filter op) { + this.op = op; + } + @Override + public String toString() { + return this.getClass().getSimpleName() + " " + this.op.toString(); //$NON-NLS-1$ + } + @Override + public boolean equals(Object o) { + if (! UnaryLogicOpsType.class.isAssignableFrom(o.getClass())) { + return false; + } + UnaryLogicOpsType f = (UnaryLogicOpsType) o; + return f.getClass().equals(this.getClass()) + && f.getOp().equals(this.getOp()); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Add.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Add.java new file mode 100644 index 0000000..5195319 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Add.java @@ -0,0 +1,45 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "Add") +public class Add extends BinaryExpression { + + @Override + public Object evaluate(Object object) { + BigDecimal value1 = (this.getExpression1().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression1().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression1().evaluate(object)).booleanValue() ? 1 : 0); + BigDecimal value2 = (this.getExpression2().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression2().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression2().evaluate(object)).booleanValue() ? 1 : 0); + return value1.add(value2, BinaryExpression.mc); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/BinaryExpression.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/BinaryExpression.java new file mode 100644 index 0000000..8cf703f --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/BinaryExpression.java @@ -0,0 +1,99 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.MathContext; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlSeeAlso({ Add.class, Divide.class, Multiply.class, Subtract.class }) +public abstract class BinaryExpression extends Expression { + static MathContext mc = new MathContext((int) Math.min( + 9 + (long) Math.ceil(30.0), Integer.MAX_VALUE), + RoundingMode.HALF_EVEN); + + @XmlElementRefs(@XmlElementRef) + private final List parameters = new ArrayList(); + + public List getParameters() { + return this.parameters; + } + + public Expression getExpression1() { + return this.parameters.get(0); + } + + public Expression getExpression2() { + return this.parameters.get(1); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((this.parameters == null) ? 0 : this.parameters.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + BinaryExpression other = (BinaryExpression) obj; + if (this.parameters == null) { + if (other.parameters != null) { + return false; + } + } else if (!this.parameters.equals(other.parameters)) { + return false; + } + return true; + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Divide.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Divide.java new file mode 100644 index 0000000..bb2354a --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Divide.java @@ -0,0 +1,45 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "Div") +public class Divide extends BinaryExpression { + + @Override + public Object evaluate(Object object) { + BigDecimal value1 = (this.getExpression1().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression1().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression1().evaluate(object)).booleanValue() ? 1 : 0); + BigDecimal value2 = (this.getExpression2().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression2().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression2().evaluate(object)).booleanValue() ? 1 : 0); + return value1.divide(value2, BinaryExpression.mc); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Expression.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Expression.java new file mode 100644 index 0000000..1400e8c --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Expression.java @@ -0,0 +1,35 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlSeeAlso({ PropertyName.class, BinaryExpression.class, Function.class }) +@XmlRootElement +public abstract class Expression { + public abstract Object evaluate(Object object); +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/ExpressionFactory.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/ExpressionFactory.java new file mode 100644 index 0000000..08724e8 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/ExpressionFactory.java @@ -0,0 +1,81 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * @author Julien Perret + */ +public class ExpressionFactory { + private static Logger logger = LogManager.getLogger(ExpressionFactory.class + .getName()); + + /** + * FIXME voir comment créer des fonctions + * @param type + * @return a new Expression corresponding to the given type + */ + public static Expression createExpression(String type) { + if (type.equalsIgnoreCase("add")) { + return new Add(); + } + if (type.equalsIgnoreCase("sub")) { + return new Subtract(); + } + if (type.equalsIgnoreCase("mul")) { + return new Multiply(); + } + if (type.equalsIgnoreCase("div")) { + return new Divide(); + } + if (type.equalsIgnoreCase("literal")) { + return new Literal(); + } + if (type.equalsIgnoreCase("propertyName")) { + return new PropertyName(); + } + return null; + } + + /** + * @param name + * @return a new function corresponding to the given name + */ + public static Function createFunction(String name) { + String nomClasse = "fr.ign.cogit.geoxygene.filter.function." //$NON-NLS-1$ + + name.substring(0, 1).toUpperCase() + name.substring(1); + try { + Class classe = Class.forName(nomClasse); + return (Function) classe.newInstance(); + } catch (ClassNotFoundException e) { + ExpressionFactory.logger + .error("La classe " + nomClasse + " n'existe pas"); + } catch (InstantiationException e) { + ExpressionFactory.logger + .error("Impossible d'instancier un objet de la classe " + nomClasse); + } catch (IllegalAccessException e) { + ExpressionFactory.logger.error("Constructeur de la classe " + nomClasse + + " inaccessible"); + } + return null; + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Function.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Function.java new file mode 100644 index 0000000..1611bc4 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Function.java @@ -0,0 +1,60 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +import fr.ign.cogit.geoxygene.filter.function.FunctionImpl; + +/** + * @author Julien Perret + */ +@XmlRootElement(name = "Function") +@XmlSeeAlso({ FunctionImpl.class }) +public abstract class Function extends Expression { + /** + * @return the name of the function + */ + public abstract String getName(); + + /** + * @return the fallback (default) value returned by the function, especially + * used if the function could not be evaluated. + */ + public abstract String getFallbackValue(); + + /** + * @param fallbackValue + */ + public abstract void setFallbackValue(String fallbackValue); + + /** + * @return the list of the function's parameters + */ + public abstract List getParameters(); + + /** + * @param parameters + */ + public abstract void setParameters(List parameters); +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Literal.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Literal.java new file mode 100644 index 0000000..fe579af --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Literal.java @@ -0,0 +1,121 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.BigDecimal; +import java.util.Arrays; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "Literal") +public class Literal extends Expression { + + /** + * + */ + public Literal() { + } + + /** + * @param value + */ + public Literal(String value) { + this.setValue(value); + } + + @XmlMixed + private final String[] value = new String[1]; + + /** + * @return the value of the Literal + */ + public String getValue() { + return this.value[0]; + } + + /** + * @param value + */ + public void setValue(String value) { + this.value[0] = value; + } + + @Override + public Object evaluate(Object object) { + return new BigDecimal(this.getValue()); + } + + @Override + public String toString() { + return this.getValue(); + } + + // @Override + // public boolean equals(Object o) { + // if (!Literal.class.isAssignableFrom(o.getClass())) { + // return false; + // } + // Literal l = (Literal) o; + // return l.getValue().equals(this.getValue()); + // } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(this.value); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + Literal other = (Literal) obj; + if (!this.getValue().equals(other.getValue())) { + return false; + } + return true; + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Multiply.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Multiply.java new file mode 100644 index 0000000..1c541a7 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Multiply.java @@ -0,0 +1,45 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "Mul") +public class Multiply extends BinaryExpression { + + @Override + public Object evaluate(Object object) { + BigDecimal value1 = (this.getExpression1().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression1().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression1().evaluate(object)).booleanValue() ? 1 : 0); + BigDecimal value2 = (this.getExpression2().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression2().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression2().evaluate(object)).booleanValue() ? 1 : 0); + return value1.multiply(value2, BinaryExpression.mc); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/PropertyName.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/PropertyName.java new file mode 100644 index 0000000..c373bc8 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/PropertyName.java @@ -0,0 +1,168 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.util.Arrays; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlMixed; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import fr.ign.cogit.geoxygene.api.feature.IFeature; + +/** + * @author Julien Perret + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "PropertyName") +public class PropertyName extends Expression { + static Logger logger = LogManager.getLogger(PropertyName.class.getName()); + + /** + * + */ + public PropertyName() { + } + + /** + * @param name + */ + public PropertyName(String name) { + this.setPropertyName(name); + } + + @XmlMixed + private final String[] propertyName = new String[1]; + + /** + * @return the name of the PropertyName + */ + public String getPropertyName() { + return this.propertyName[0]; + } + + /** + * @param propertyName + */ + public void setPropertyName(String propertyName) { + this.propertyName[0] = propertyName; + } + + @Override + public Object evaluate(Object object) { + String getterName = "get" //$NON-NLS-1$ + + this.getPropertyName().substring(0, 1).toUpperCase() + + this.getPropertyName().substring(1); + if (object instanceof IFeature) { + IFeature feature = (IFeature) object; + Object resultat = feature.getAttribute(this.getPropertyName()); + if (resultat instanceof Number) { + return new BigDecimal(((Number) resultat).doubleValue()); + } + // if (resultat instanceof Boolean) return new + // BigDecimal(((Boolean)resultat).booleanValue()?0:1); + return resultat; + } + Class classe = object.getClass(); + while (!classe.equals(Object.class)) { + try { + Method getter = classe.getMethod(getterName, new Class[0]); + Object resultat = getter.invoke(object, new Object[0]); + if (resultat instanceof Number) { + return new BigDecimal(((Number) resultat).doubleValue()); + } + return resultat; + } catch (SecurityException e) { + PropertyName.logger.error( + "La méthode " + getterName + " n'est pas autorisée sur la classe " + + object.getClass() + " / " + classe); + } catch (NoSuchMethodException e) { + PropertyName.logger + .error("La méthode " + getterName + " n'existe pas dans la classe " + + object.getClass() + " / " + classe); + } catch (IllegalArgumentException e) { + PropertyName.logger + .error("Arguments illégaux pour la méthode " + getterName + + " de la classe " + object.getClass() + " / " + classe); + } catch (IllegalAccessException e) { + PropertyName.logger.error("accès illégal à la méthode " + getterName + + " de la classe " + object.getClass() + " / " + classe); + } catch (InvocationTargetException e) { + PropertyName.logger + .error("problème pendant l'invocation de la méthode " + getterName + + " sur la classe " + object.getClass() + " / " + classe); + } + classe = classe.getSuperclass(); + } + PropertyName.logger.error( + "On a échoué sur l'objet " + object + " avec le getter " + getterName); + return null; + } + + @Override + public String toString() { + return this.getPropertyName(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(this.propertyName); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + PropertyName other = (PropertyName) obj; + if (!Arrays.equals(this.propertyName, other.propertyName)) { + return false; + } + return true; + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Subtract.java b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Subtract.java new file mode 100644 index 0000000..4bec6f5 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/expression/Subtract.java @@ -0,0 +1,45 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "Sub") +public class Subtract extends BinaryExpression { + + @Override + public Object evaluate(Object object) { + BigDecimal value1 = (this.getExpression1().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression1().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression1().evaluate(object)).booleanValue() ? 1 : 0); + BigDecimal value2 = (this.getExpression2().evaluate(object) instanceof BigDecimal) ? (BigDecimal) this + .getExpression2().evaluate(object) : new BigDecimal(((Boolean) this + .getExpression2().evaluate(object)).booleanValue() ? 1 : 0); + return value1.subtract(value2, BinaryExpression.mc); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/function/Abs.java b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Abs.java new file mode 100644 index 0000000..d71bc84 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Abs.java @@ -0,0 +1,39 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.function; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlRootElement(name = "Function") +public class Abs extends FunctionImpl { + + public Abs() { + this.name = "Abs";} //$NON-NLS-1$ + + @Override + public Object evaluate(Object object) { + return ((BigDecimal) this.getParameters().get(0).evaluate(object)).abs(); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/function/EndAngle.java b/src/main/java/fr/ign/cogit/geoxygene/filter/function/EndAngle.java new file mode 100644 index 0000000..67cb945 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/function/EndAngle.java @@ -0,0 +1,54 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.function; + +import javax.xml.bind.annotation.XmlRootElement; + +import fr.ign.cogit.geoxygene.api.feature.IFeature; +import fr.ign.cogit.geoxygene.api.spatial.coordgeom.IDirectPosition; +import fr.ign.cogit.geoxygene.api.spatial.coordgeom.IDirectPositionList; +import fr.ign.cogit.geoxygene.api.spatial.geomroot.IGeometry; +import fr.ign.cogit.geoxygene.contrib.geometrie.Angle; + +/** + * @author Julien Perret + */ +@XmlRootElement(name = "Function", namespace = "") +public class EndAngle extends FunctionImpl { + + public EndAngle() { + this.name = "EndAngle";} //$NON-NLS-1$ + + @Override + public Object evaluate(Object object) { + double angle = 0; + IGeometry g = ((IFeature) object).getGeom(); + if (g.numPoints() < 2) { + return angle; + } + IDirectPositionList l = g.coord(); + IDirectPosition p1 = l.get(g.numPoints() - 2); + IDirectPosition p2 = l.get(g.numPoints() - 1); + Angle a = new Angle(p1, p2); + // convert to degrees + angle = a.getValeur() * 180 / Math.PI; + return angle; + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/function/FunctionImpl.java b/src/main/java/fr/ign/cogit/geoxygene/filter/function/FunctionImpl.java new file mode 100644 index 0000000..5b1cb67 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/function/FunctionImpl.java @@ -0,0 +1,157 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.function; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlRootElement; + +import fr.ign.cogit.geoxygene.filter.expression.Expression; +import fr.ign.cogit.geoxygene.filter.expression.ExpressionFactory; +import fr.ign.cogit.geoxygene.filter.expression.Function; + +/** + * @author Julien Perret + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlRootElement(name = "Function") +public class FunctionImpl extends Function { + String fallbackValue; + + @Override + public String getFallbackValue() { + return this.fallbackValue; + } + + @Override + public void setFallbackValue(String fallbackValue) { + this.fallbackValue = fallbackValue; + } + + @XmlAttribute + String name = "Function default implementation"; //$NON-NLS-1$ + + @Override + public String getName() { + return this.name; + } + + @XmlElementRefs(@XmlElementRef) + List parameters = new ArrayList(); + + @Override + public List getParameters() { + return this.parameters; + } + + /** + * Affecte la valeur de l'attribut parameters. + * + * @param parameters + * l'attribut parameters à affecter + */ + @Override + public void setParameters(List parameters) { + this.parameters = parameters; + } + + @Override + public Object evaluate(Object object) { + Function function = ExpressionFactory.createFunction(this.name); + if (function != null) { + function.getParameters().addAll(this.parameters); + return function.evaluate(object); + } + return this.getFallbackValue(); + } + + @Override + public String toString() { + return this.getName(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime + * result + + ((this.fallbackValue == null) ? 0 : this.fallbackValue + .hashCode()); + result = prime * result + + ((this.name == null) ? 0 : this.name.hashCode()); + result = prime * result + + ((this.parameters == null) ? 0 : this.parameters.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + FunctionImpl other = (FunctionImpl) obj; + if (this.fallbackValue == null) { + if (other.fallbackValue != null) { + return false; + } + } else if (!this.fallbackValue.equals(other.fallbackValue)) { + return false; + } + if (this.name == null) { + if (other.name != null) { + return false; + } + } else if (!this.name.equals(other.name)) { + return false; + } + if (this.parameters == null) { + if (other.parameters != null) { + return false; + } + } else if (!this.parameters.equals(other.parameters)) { + return false; + } + return true; + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/function/Max.java b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Max.java new file mode 100644 index 0000000..48e4e16 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Max.java @@ -0,0 +1,40 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.function; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlRootElement(name = "Function") +public class Max extends FunctionImpl { + + public Max() { + this.name = "Max";} //$NON-NLS-1$ + + @Override + public Object evaluate(Object object) { + return ((BigDecimal) this.getParameters().get(0).evaluate(object)) + .max((BigDecimal) this.getParameters().get(1).evaluate(object)); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/function/Min.java b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Min.java new file mode 100644 index 0000000..17a2135 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Min.java @@ -0,0 +1,50 @@ +/* + * This file is part of the GeOxygene project source files. + * + * GeOxygene aims at providing an open framework which implements OGC/ISO + * specifications for the development and deployment of geographic (GIS) + * applications. It is a open source contribution of the COGIT laboratory at the + * Institut Géographique National (the French National Mapping Agency). + * + * See: http://oxygene-project.sourceforge.net + * + * Copyright (C) 2005 Institut Géographique National + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library (see file LICENSE if present); if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.function; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + * + */ +@XmlRootElement(name = "Function") +public class Min extends FunctionImpl { + + public Min() { + this.name = "Min";} //$NON-NLS-1$ + + @Override + public Object evaluate(Object object) { + return ((BigDecimal) this.getParameters().get(0).evaluate(object)) + .min((BigDecimal) this.getParameters().get(1).evaluate(object)); + } + +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/function/Pow.java b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Pow.java new file mode 100644 index 0000000..d2745f5 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/function/Pow.java @@ -0,0 +1,41 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.function; + +import java.math.BigDecimal; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Julien Perret + */ +@XmlRootElement(name = "Function") +public class Pow extends FunctionImpl { + + public Pow() { + this.name = "Pow";} //$NON-NLS-1$ + + @Override + public Object evaluate(Object object) { + return ((BigDecimal) this.getParameters().get(0).evaluate(object)) + .pow(((BigDecimal) this.getParameters().get(1).evaluate(object)) + .intValue()); + } +} diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/package-info.java b/src/main/java/fr/ign/cogit/geoxygene/filter/package-info.java new file mode 100644 index 0000000..ca27848 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/package-info.java @@ -0,0 +1,29 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * GeOxygene Filter package. + *

+ * It contains GeOxygene OGC Filter Implementation. + */ +@XmlSchema(xmlns = { @javax.xml.bind.annotation.XmlNs(prefix = "ogc", namespaceURI = "http://www.opengis.net/ogc") }, namespace = "http://www.opengis.net/ogc") +package fr.ign.cogit.geoxygene.filter; + +import javax.xml.bind.annotation.XmlSchema; + diff --git a/src/main/java/fr/ign/cogit/geoxygene/filter/spatial/BinarySpatialOpsType.java b/src/main/java/fr/ign/cogit/geoxygene/filter/spatial/BinarySpatialOpsType.java new file mode 100644 index 0000000..4c48349 --- /dev/null +++ b/src/main/java/fr/ign/cogit/geoxygene/filter/spatial/BinarySpatialOpsType.java @@ -0,0 +1,28 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.spatial; + +import fr.ign.cogit.geoxygene.filter.SpatialOpsType; + +/** + * @author Julien Perret + */ +public abstract class BinarySpatialOpsType extends SpatialOpsType { +} diff --git a/src/test/java/fr/ign/cogit/geoxygene/filter/expression/SimpleTest.java b/src/test/java/fr/ign/cogit/geoxygene/filter/expression/SimpleTest.java new file mode 100644 index 0000000..c6b33da --- /dev/null +++ b/src/test/java/fr/ign/cogit/geoxygene/filter/expression/SimpleTest.java @@ -0,0 +1,90 @@ +/* + * This file is part of the GeOxygene project source files. GeOxygene aims at + * providing an open framework which implements OGC/ISO specifications for the + * development and deployment of geographic (GIS) applications. It is a open + * source contribution of the COGIT laboratory at the Institut Géographique + * National (the French National Mapping Agency). See: + * http://oxygene-project.sourceforge.net Copyright (C) 2005 Institut + * Géographique National This library is free software; you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the License, + * or any later version. This library is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. You should have received a copy of + * the GNU Lesser General Public License along with this library (see file + * LICENSE if present); if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package fr.ign.cogit.geoxygene.filter.expression; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import fr.ign.cogit.geoxygene.filter.function.Max; +import junit.framework.Assert; + +/** + * @author Julien Perret + */ +public class SimpleTest { + + @Test + public void testArithmeticExpressions() { + Add add = new Add(); + Literal literal1 = new Literal(); + String stringValue1 = new String("5"); //$NON-NLS-1$ + literal1.setValue(stringValue1); + add.getParameters().add(literal1); + Literal literal2 = new Literal(); + String stringValue2 = new String("2.00"); //$NON-NLS-1$ + literal2.setValue(stringValue2); + add.getParameters().add(literal2); + Object resultAdd = add.evaluate(null); + System.out.println(resultAdd); + Assert.assertTrue(resultAdd.equals(new BigDecimal("7.00"))); //$NON-NLS-1$ + Subtract sub = new Subtract(); + sub.getParameters().add(literal1); + sub.getParameters().add(literal2); + Object resultSub = sub.evaluate(null); + System.out.println(resultSub); + Assert.assertTrue(resultSub.equals(new BigDecimal("3.00"))); //$NON-NLS-1$ + Multiply mul = new Multiply(); + mul.getParameters().add(literal1); + mul.getParameters().add(literal2); + Object resultMul = mul.evaluate(null); + System.out.println(resultMul); + Assert.assertTrue(resultMul.equals(new BigDecimal("10.00"))); //$NON-NLS-1$ + Divide div = new Divide(); + div.getParameters().add(literal1); + div.getParameters().add(literal2); + Object resultDiv = div.evaluate(null); + System.out.println(resultDiv); + Assert.assertTrue(resultDiv.equals(new BigDecimal("2.5"))); //$NON-NLS-1$ + Function function = new Max(); + Subtract subtract = new Subtract(); + subtract.getParameters().add(new Literal("100")); //$NON-NLS-1$ + Multiply multiply = new Multiply(); + Subtract subtract2 = new Subtract(); + subtract2.getParameters().add(new Literal("0")); //$NON-NLS-1$ + subtract2.getParameters().add(new Literal("20")); //$NON-NLS-1$ + System.out.println("subtract2 = " + subtract2.evaluate(null)); //$NON-NLS-1$ + multiply.getParameters().add(subtract2); + multiply.getParameters().add(new Literal("5")); //$NON-NLS-1$ + subtract.getParameters().add(multiply); + System.out.println("subtract = " + subtract.evaluate(null)); //$NON-NLS-1$ + List parameters = new ArrayList(); + parameters.add(subtract); + Multiply multiply2 = new Multiply(); + multiply2.getParameters().add(new Literal("100")); //$NON-NLS-1$ + multiply2.getParameters().add(new Literal("0")); //$NON-NLS-1$ + parameters.add(multiply2); + function.setParameters(parameters); + Object resultFunction = function.evaluate(null); + System.out.println(resultFunction); + } +}