Revision: 10503
http://datanucleus.svn.sourceforge.net/datanucleus/?rev=10503&view=rev
Author: seelmann
Date: 2010-08-07 21:14:55 +0000 (Sat, 07 Aug 2010)
Log Message:
-----------
o bump version
o [NUCLDAP-43] remove dependency to shared-ldap
o [NUCLDAP-43] added LDAP filter classes
o [NUCLDAP-43] added GeneralizedTime class
Modified Paths:
--------------
platform/store.ldap/trunk/META-INF/MANIFEST.MF
platform/store.ldap/trunk/pom.xml
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/CalendarToGeneralizedTimeStringConverter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/DateToGeneralizedTimeStringConverter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/QueryToLDAPFilterMapper.java
Added Paths:
-----------
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/GeneralizedTime.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractBranchFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractLeafFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractValueFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AndFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/EqualityFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/Filter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/GreaterEqFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/LessEqFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/NotFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/OrFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/PresenceFilter.java
platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/SubstringFilter.java
Modified: platform/store.ldap/trunk/META-INF/MANIFEST.MF
===================================================================
--- platform/store.ldap/trunk/META-INF/MANIFEST.MF 2010-08-07 20:54:51 UTC (rev 10502)
+++ platform/store.ldap/trunk/META-INF/MANIFEST.MF 2010-08-07 21:14:55 UTC (rev 10503)
@@ -2,64 +2,13 @@
Bundle-ManifestVersion: 2
Bundle-Name: DataNucleus LDAP
Bundle-SymbolicName: org.datanucleus.store.ldap;singleton:=true
-Bundle-Version: 2.1.0.release
+Bundle-Version: 2.2.0.m1
Bundle-Vendor: DataNucleus
-Require-Bundle: org.datanucleus;bundle-version="2.1.0.release"
+Require-Bundle: org.datanucleus;bundle-version="2.2.0.m1"
Import-Package: javax.jdo,
javax.jdo.annotations,
javax.jdo.datastore,
javax.jdo.identity,
javax.jdo.listener,
- org.apache.directory.shared.asn1;resolution:=optional,
- org.apache.directory.shared.asn1.ber;resolution:=optional,
- org.apache.directory.shared.asn1.ber.grammar;resolution:=optional,
- org.apache.directory.shared.asn1.ber.tlv;resolution:=optional,
- org.apache.directory.shared.asn1.codec;resolution:=optional,
- org.apache.directory.shared.asn1.codec.binary;resolution:=optional,
- org.apache.directory.shared.asn1.codec.stateful;resolution:=optional,
- org.apache.directory.shared.asn1.codec.stateful.examples;resolution:=optional,
- org.apache.directory.shared.asn1.der;resolution:=optional,
- org.apache.directory.shared.asn1.primitives;resolution:=optional,
- org.apache.directory.shared.asn1.util;resolution:=optional,
- org.apache.directory.shared.ldap;resolution:=optional,
- org.apache.directory.shared.ldap.aci;resolution:=optional,
- org.apache.directory.shared.ldap.codec;resolution:=optional,
- org.apache.directory.shared.ldap.codec.abandon;resolution:=optional,
- org.apache.directory.shared.ldap.codec.actions;resolution:=optional,
- org.apache.directory.shared.ldap.codec.add;resolution:=optional,
- org.apache.directory.shared.ldap.codec.bind;resolution:=optional,
- org.apache.directory.shared.ldap.codec.compare;resolution:=optional,
- org.apache.directory.shared.ldap.codec.controls;resolution:=optional,
- org.apache.directory.shared.ldap.codec.del;resolution:=optional,
- org.apache.directory.shared.ldap.codec.extended;resolution:=optional,
- org.apache.directory.shared.ldap.codec.extended.operations;resolution:=optional,
- org.apache.directory.shared.ldap.codec.modify;resolution:=optional,
- org.apache.directory.shared.ldap.codec.modifyDn;resolution:=optional,
- org.apache.directory.shared.ldap.codec.search;resolution:=optional,
- org.apache.directory.shared.ldap.codec.search.controls;resolution:=optional,
- org.apache.directory.shared.ldap.codec.unbind;resolution:=optional,
- org.apache.directory.shared.ldap.codec.util;resolution:=optional,
- org.apache.directory.shared.ldap.constants;resolution:=optional,
- org.apache.directory.shared.ldap.entry;resolution:=optional,
- org.apache.directory.shared.ldap.entry.client;resolution:=optional,
- org.apache.directory.shared.ldap.exception;resolution:=optional,
- org.apache.directory.shared.ldap.filter;resolution:=optional,
- org.apache.directory.shared.ldap.ldif;resolution:=optional,
- org.apache.directory.shared.ldap.message;resolution:=optional,
- org.apache.directory.shared.ldap.message.control;resolution:=optional,
- org.apache.directory.shared.ldap.message.extended;resolution:=optional,
- org.apache.directory.shared.ldap.message.spi;resolution:=optional,
- org.apache.directory.shared.ldap.name;resolution:=optional,
- org.apache.directory.shared.ldap.schema;resolution:=optional,
- org.apache.directory.shared.ldap.schema.comparator;resolution:=optional,
- org.apache.directory.shared.ldap.schema.parser;resolution:=optional,
- org.apache.directory.shared.ldap.schema.syntax;resolution:=optional,
- org.apache.directory.shared.ldap.schema.syntax.parser;resolution:=optional,
- org.apache.directory.shared.ldap.sp;resolution:=optional,
- org.apache.directory.shared.ldap.subtree;resolution:=optional,
- org.apache.directory.shared.ldap.trigger;resolution:=optional,
- org.apache.directory.shared.ldap.util;resolution:=optional,
- org.apache.directory.shared.ldap.util.tree;resolution:=optional,
- org.apache.directory.shared.ldap.util.unicode;resolution:=optional,
javax.transaction;resolution:=optional,
javax.transaction.xa;resolution:=optional
Modified: platform/store.ldap/trunk/pom.xml
===================================================================
--- platform/store.ldap/trunk/pom.xml 2010-08-07 20:54:51 UTC (rev 10502)
+++ platform/store.ldap/trunk/pom.xml 2010-08-07 21:14:55 UTC (rev 10503)
@@ -2,7 +2,7 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.datanucleus</groupId>
- <version>2.1.0-release</version>
+ <version>2.2.0-m1-SNAPSHOT</version>
<artifactId>datanucleus-ldap</artifactId>
<name>DataNucleus LDAP plugin</name>
<description>
@@ -34,29 +34,9 @@
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
- <version>[2.0.99, )</version>
+ <version>[2.1.99, )</version>
<scope>provided</scope>
</dependency>
-
- <!-- Compile dependencies -->
- <dependency>
- <groupId>org.apache.directory.shared</groupId>
- <artifactId>shared-ldap</artifactId>
- <version>0.9.14</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.shared</groupId>
- <artifactId>shared-asn1</artifactId>
- <version>0.9.14</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.apache.directory.shared</groupId>
- <artifactId>shared-ldap-constants</artifactId>
- <version>0.9.14</version>
- <optional>true</optional>
- </dependency>
</dependencies>
<build>
Modified: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/CalendarToGeneralizedTimeStringConverter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/CalendarToGeneralizedTimeStringConverter.java 2010-08-07 20:54:51 UTC (rev 10502)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/CalendarToGeneralizedTimeStringConverter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -19,13 +19,11 @@
package org.datanucleus.store.ldap.fieldmanager;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
+import java.text.ParseException;
import java.util.Calendar;
import org.datanucleus.exceptions.NucleusException;
import org.datanucleus.store.types.ObjectStringConverter;
-import org.datanucleus.util.ClassUtils;
/**
* Class to handle the conversion between java.util.Calendar and the generalized time syntax as described in RFC 4517.
@@ -42,27 +40,18 @@
try
{
- // this class cannot be linked at compile time since its dependencies are considered as optional
- Class cls = Class.forName("org.apache.directory.shared.ldap.util.GeneralizedTime");
+ GeneralizedTime gt = new GeneralizedTime(str);
+ Calendar calendar = gt.getCalendar();
- Constructor constr = ClassUtils.getConstructorWithArguments(cls, new Class[]{String.class});
- Object instance = constr.newInstance(new Object[]{str});
-
- Method method = ClassUtils.getMethodForClass(cls, "getCalendar", null);
- Calendar calendar = (Calendar) method.invoke(instance, (Object[]) null);
-
- // workaround: the GeneralizedTime sets the calendar to non-lenient, we reset it here to its default value
- calendar.setLenient(true);
-
// most LDAP servers only store "century year month day hour minute second"
// TODO: add extension to store millis as fraction
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
}
- catch (Throwable e)
+ catch (ParseException e)
{
- throw new NucleusException("Type java.util.Calendar is not supported without Apache Directory shared-ldap library.");
+ throw new NucleusException("Error parsing string to calendar.", e);
}
}
@@ -77,21 +66,8 @@
// TODO: add extension to store millis as fraction
calendar.set(Calendar.MILLISECOND, 0);
- try
- {
- // this class cannot be linked at compile time since its dependencies are considered as optional
- Class cls = Class.forName("org.apache.directory.shared.ldap.util.GeneralizedTime");
-
- Constructor constr = ClassUtils.getConstructorWithArguments(cls, new Class[]{Calendar.class});
- Object instance = constr.newInstance(new Object[]{obj});
-
- Method method = ClassUtils.getMethodForClass(cls, "toGeneralizedTime", null);
- str = (String) method.invoke(instance, (Object[]) null);
- }
- catch (Throwable e)
- {
- throw new NucleusException("Type java.util.Calendar is not supported without Apache Directory shared-ldap library.");
- }
+ GeneralizedTime gt = new GeneralizedTime(calendar);
+ str = gt.toGeneralizedTime();
}
else
{
Modified: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/DateToGeneralizedTimeStringConverter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/DateToGeneralizedTimeStringConverter.java 2010-08-07 20:54:51 UTC (rev 10502)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/DateToGeneralizedTimeStringConverter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -21,6 +21,7 @@
import java.util.Calendar;
import java.util.Date;
+import java.util.TimeZone;
/**
* Class to handle the conversion between java.util.Date and the generalized time syntax as described in RFC 4517.
@@ -34,6 +35,7 @@
if (object instanceof Calendar)
{
Calendar calendar = (Calendar) object;
+ calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = calendar.getTime();
return date;
}
@@ -49,6 +51,7 @@
{
Date date = (Date) obj;
Calendar calendar = Calendar.getInstance();
+ calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
calendar.setTime(date);
obj = calendar;
}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/GeneralizedTime.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/GeneralizedTime.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/fieldmanager/GeneralizedTime.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,644 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.fieldmanager;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+/**
+ * Converts between {@link Calendar} and LDAP generalized time syntax as defined in
+ * RFC 4517 section 3.3.13.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class GeneralizedTime implements Comparable<GeneralizedTime>
+{
+
+ public enum Format {
+ YEAR_MONTH_DAY_HOUR_MIN_SEC, YEAR_MONTH_DAY_HOUR_MIN_SEC_FRACTION,
+
+ YEAR_MONTH_DAY_HOUR_MIN, YEAR_MONTH_DAY_HOUR_MIN_FRACTION,
+
+ YEAR_MONTH_DAY_HOUR, YEAR_MONTH_DAY_HOUR_FRACTION, ;
+ }
+
+ public enum FractionDelimiter {
+ DOT, COMMA
+ }
+
+ public enum TimeZoneFormat {
+ Z, DIFF_HOUR, DIFF_HOUR_MINUTE;
+ }
+
+ private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
+ /** The user provided value */
+ private String upGeneralizedTime;
+
+ /** The user provided format */
+ private Format upFormat;
+
+ /** The user provided time zone format */
+ private TimeZoneFormat upTimeZoneFormat;
+
+ /** The user provided fraction delimiter */
+ private FractionDelimiter upFractionDelimiter;
+
+ /** the user provided fraction length */
+ private int upFractionLength;
+
+ /** The calendar */
+ private Calendar calendar;
+
+ /**
+ * Creates a new instance of GeneralizedTime, based on the given Calendar object. Uses
+ *
+ * <pre>
+ * Format.YEAR_MONTH_DAY_HOUR_MIN_SEC
+ * </pre>
+ *
+ * as default format and
+ *
+ * <pre>
+ * TimeZoneFormat.Z
+ * </pre>
+ *
+ * as default time zone format.
+ * @param calendar the calendar containing the date, time and timezone information
+ */
+ public GeneralizedTime(Calendar calendar)
+ {
+ if (calendar == null)
+ {
+ throw new IllegalArgumentException("Calendar must not be null.");
+ }
+
+ this.calendar = calendar;
+ upGeneralizedTime = null;
+ upFormat = Format.YEAR_MONTH_DAY_HOUR_MIN_SEC;
+ upTimeZoneFormat = TimeZoneFormat.Z;
+ upFractionDelimiter = FractionDelimiter.DOT;
+ upFractionLength = 3;
+ }
+
+ /**
+ * Creates a new instance of GeneralizedTime, based on the given generalized time string.
+ * @param generalizedTime the generalized time
+ * @throws ParseException if the given generalized time can't be parsed.
+ */
+ public GeneralizedTime(String generalizedTime) throws ParseException
+ {
+ if (generalizedTime == null)
+ {
+ throw new ParseException("generalizedTime is null", 0);
+ }
+
+ this.upGeneralizedTime = generalizedTime;
+
+ calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(0);
+ calendar.setLenient(false);
+
+ parseYear();
+ parseMonth();
+ parseDay();
+ parseHour();
+
+ if (upGeneralizedTime.length() < 11)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'minute' or 'fraction of hour' or 'timezone'.", 10);
+ }
+
+ // pos 10:
+ // if digit => minute field
+ // if . or , => fraction of hour field
+ // if Z or + or - => timezone field
+ // else error
+ int pos = 10;
+ char c = upGeneralizedTime.charAt(pos);
+ if ('0' <= c && c <= '9')
+ {
+ parseMinute();
+
+ if (upGeneralizedTime.length() < 13)
+ {
+ throw new ParseException(
+ "Generalized Time too short, doesn't contain field 'second' or 'fraction of minute' or 'timezone'.", 12);
+ }
+
+ // pos 12:
+ // if digit => second field
+ // if . or , => fraction of minute field
+ // if Z or + or - => timezone field
+ // else error
+ pos = 12;
+ c = upGeneralizedTime.charAt(pos);
+ if ('0' <= c && c <= '9')
+ {
+ parseSecond();
+
+ if (upGeneralizedTime.length() < 15)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'fraction of second' or 'timezone'.", 14);
+ }
+
+ // pos 14:
+ // if . or , => fraction of second field
+ // if Z or + or - => timezone field
+ // else error
+ pos = 14;
+ c = upGeneralizedTime.charAt(pos);
+ if (c == '.' || c == ',')
+ {
+ // read fraction of second
+ parseFractionOfSecond();
+ pos += 1 + upFractionLength;
+
+ parseTimezone(pos);
+ upFormat = Format.YEAR_MONTH_DAY_HOUR_MIN_SEC_FRACTION;
+ }
+ else if (c == 'Z' || c == '+' || c == '-')
+ {
+ // read timezone
+ parseTimezone(pos);
+ upFormat = Format.YEAR_MONTH_DAY_HOUR_MIN_SEC;
+ }
+ else
+ {
+ throw new ParseException("Invalid Time too short, expected field 'fraction of second' or 'timezone'.", 14);
+ }
+ }
+ else if (c == '.' || c == ',')
+ {
+ // read fraction of minute
+ parseFractionOfMinute();
+ pos += 1 + upFractionLength;
+
+ parseTimezone(pos);
+ upFormat = Format.YEAR_MONTH_DAY_HOUR_MIN_FRACTION;
+ }
+ else if (c == 'Z' || c == '+' || c == '-')
+ {
+ // read timezone
+ parseTimezone(pos);
+ upFormat = Format.YEAR_MONTH_DAY_HOUR_MIN;
+ }
+ else
+ {
+ throw new ParseException("Invalid Time too short, expected field 'second' or 'fraction of minute' or 'timezone'.", 12);
+ }
+ }
+ else if (c == '.' || c == ',')
+ {
+ // read fraction of hour
+ parseFractionOfHour();
+ pos += 1 + upFractionLength;
+
+ parseTimezone(pos);
+ upFormat = Format.YEAR_MONTH_DAY_HOUR_FRACTION;
+ }
+ else if (c == 'Z' || c == '+' || c == '-')
+ {
+ // read timezone
+ parseTimezone(pos);
+ upFormat = Format.YEAR_MONTH_DAY_HOUR;
+ }
+ else
+ {
+ throw new ParseException("Invalid Generalized Time, expected field 'minute' or 'fraction of hour' or 'timezone'.", 10);
+ }
+
+ // this calculates and verifies the calendar
+ try
+ {
+ calendar.getTimeInMillis();
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new ParseException("Invalid date/time values.", 0);
+ }
+
+ calendar.setLenient(true);
+ }
+
+ private void parseTimezone(int pos) throws ParseException
+ {
+ if (upGeneralizedTime.length() < pos + 1)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'timezone'.", pos);
+ }
+
+ char c = upGeneralizedTime.charAt(pos);
+ if (c == 'Z')
+ {
+ calendar.setTimeZone(GMT);
+ upTimeZoneFormat = TimeZoneFormat.Z;
+
+ if (upGeneralizedTime.length() > pos + 1)
+ {
+ throw new ParseException("Invalid Generalized Time, expected 'timezone' as the last field.", pos + 1);
+ }
+ }
+ else if (c == '+' || c == '-')
+ {
+ StringBuilder sb = new StringBuilder("GMT");
+ sb.append(c);
+
+ String digits = getAllDigits(pos + 1);
+ sb.append(digits);
+
+ if (digits.length() == 2 && digits.matches("^([01]\\d|2[0-3])$"))
+ {
+ TimeZone timeZone = TimeZone.getTimeZone(sb.toString());
+ calendar.setTimeZone(timeZone);
+ upTimeZoneFormat = TimeZoneFormat.DIFF_HOUR;
+ }
+ else if (digits.length() == 4 && digits.matches("^([01]\\d|2[0-3])([0-5]\\d)$"))
+ {
+ TimeZone timeZone = TimeZone.getTimeZone(sb.toString());
+ calendar.setTimeZone(timeZone);
+ upTimeZoneFormat = TimeZoneFormat.DIFF_HOUR_MINUTE;
+ }
+ else
+ {
+ throw new ParseException("Invalid Generalized Time, expected field 'timezone' must contain 2 or 4 digits.", pos);
+ }
+
+ if (upGeneralizedTime.length() > pos + 1 + digits.length())
+ {
+ throw new ParseException("Invalid Generalized Time, expected 'timezone' as the last field.", pos + 1 + digits.length());
+ }
+ }
+ }
+
+ private void parseFractionOfSecond() throws ParseException
+ {
+ parseFractionDelmiter(14);
+ String fraction = getFraction(14 + 1);
+ upFractionLength = fraction.length();
+
+ double fract = Double.parseDouble("0." + fraction);
+ int millisecond = (int) Math.round(fract * 1000);
+
+ calendar.set(Calendar.MILLISECOND, millisecond);
+ }
+
+ private void parseFractionOfMinute() throws ParseException
+ {
+ parseFractionDelmiter(12);
+ String fraction = getFraction(12 + 1);
+ upFractionLength = fraction.length();
+
+ double fract = Double.parseDouble("0." + fraction);
+ int milliseconds = (int) Math.round(fract * 1000 * 60);
+ int second = milliseconds / 1000;
+ int millisecond = milliseconds - (second * 1000);
+
+ calendar.set(Calendar.SECOND, second);
+ calendar.set(Calendar.MILLISECOND, millisecond);
+ }
+
+ private void parseFractionOfHour() throws ParseException
+ {
+ parseFractionDelmiter(10);
+ String fraction = getFraction(10 + 1);
+ upFractionLength = fraction.length();
+
+ double fract = Double.parseDouble("0." + fraction);
+ int milliseconds = (int) Math.round(fract * 1000 * 60 * 60);
+ int minute = milliseconds / (1000 * 60);
+ int second = (milliseconds - (minute * 60 * 1000)) / 1000;
+ int millisecond = milliseconds - (minute * 60 * 1000) - (second * 1000);
+
+ calendar.set(Calendar.MINUTE, minute);
+ calendar.set(Calendar.SECOND, second);
+ calendar.set(Calendar.MILLISECOND, millisecond);
+ }
+
+ private void parseFractionDelmiter(int fractionDelimiterPos)
+ {
+ char c = upGeneralizedTime.charAt(fractionDelimiterPos);
+ upFractionDelimiter = c == '.' ? FractionDelimiter.DOT : FractionDelimiter.COMMA;
+ }
+
+ private String getFraction(int startIndex) throws ParseException
+ {
+ String fraction = getAllDigits(startIndex);
+
+ // minimum one digit
+ if (fraction.length() == 0)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain number for 'fraction'.", startIndex);
+ }
+
+ return fraction;
+ }
+
+ private String getAllDigits(int startIndex)
+ {
+ StringBuilder sb = new StringBuilder();
+ while (upGeneralizedTime.length() > startIndex)
+ {
+ char c = upGeneralizedTime.charAt(startIndex);
+ if ('0' <= c && c <= '9')
+ {
+ sb.append(c);
+ startIndex++;
+ }
+ else
+ {
+ break;
+ }
+ }
+ return sb.toString();
+ }
+
+ private void parseSecond() throws ParseException
+ {
+ // read minute
+ if (upGeneralizedTime.length() < 14)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'second'.", 12);
+ }
+ try
+ {
+ int second = Integer.parseInt(upGeneralizedTime.substring(12, 14));
+ calendar.set(Calendar.SECOND, second);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ParseException("Invalid Generalized Time, field 'second' is not numeric.", 12);
+ }
+ }
+
+ private void parseMinute() throws ParseException
+ {
+ // read minute
+ if (upGeneralizedTime.length() < 12)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'minute'.", 10);
+ }
+ try
+ {
+ int minute = Integer.parseInt(upGeneralizedTime.substring(10, 12));
+ calendar.set(Calendar.MINUTE, minute);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ParseException("Invalid Generalized Time, field 'minute' is not numeric.", 10);
+ }
+ }
+
+ private void parseHour() throws ParseException
+ {
+ if (upGeneralizedTime.length() < 10)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'hour'.", 8);
+ }
+ try
+ {
+ int hour = Integer.parseInt(upGeneralizedTime.substring(8, 10));
+ calendar.set(Calendar.HOUR_OF_DAY, hour);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ParseException("Invalid Generalized Time, field 'hour' is not numeric.", 8);
+ }
+ }
+
+ private void parseDay() throws ParseException
+ {
+ if (upGeneralizedTime.length() < 8)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'day'.", 6);
+ }
+ try
+ {
+ int day = Integer.parseInt(upGeneralizedTime.substring(6, 8));
+ calendar.set(Calendar.DAY_OF_MONTH, day);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ParseException("Invalid Generalized Time, field 'day' is not numeric.", 6);
+ }
+ }
+
+ private void parseMonth() throws ParseException
+ {
+ if (upGeneralizedTime.length() < 6)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'month'.", 4);
+ }
+ try
+ {
+ int month = Integer.parseInt(upGeneralizedTime.substring(4, 6));
+ calendar.set(Calendar.MONTH, month - 1);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ParseException("Invalid Generalized Time, field 'month' is not numeric.", 4);
+ }
+ }
+
+ private void parseYear() throws ParseException
+ {
+ if (upGeneralizedTime.length() < 4)
+ {
+ throw new ParseException("Generalized Time too short, doesn't contain field 'century/year'.", 0);
+ }
+ try
+ {
+ int year = Integer.parseInt(upGeneralizedTime.substring(0, 4));
+ calendar.set(Calendar.YEAR, year);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ParseException("Invalid Generalized Time, field 'century/year' is not numeric.", 0);
+ }
+ }
+
+ /**
+ * Returns the string representation of this generalized time. This method uses the same format as the user provided
+ * format.
+ * @return the string representation of this generalized time
+ */
+ public String toGeneralizedTime()
+ {
+ return toGeneralizedTime(upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat);
+ }
+
+ /**
+ * Returns the string representation of this generalized time.
+ * @param format the target format
+ * @param fractionDelimiter the target fraction delimiter, may be null
+ * @param fractionLength the fraction length
+ * @param timeZoneFormat the target time zone format
+ * @return the string
+ */
+ public String toGeneralizedTime(Format format, FractionDelimiter fractionDelimiter, int fractionLength, TimeZoneFormat timeZoneFormat)
+ {
+ Calendar calendar = (Calendar) this.calendar.clone();
+ if (timeZoneFormat == TimeZoneFormat.Z)
+ {
+ calendar.setTimeZone(GMT);
+ }
+
+ NumberFormat twoDigits = new DecimalFormat("00");
+ NumberFormat fourDigits = new DecimalFormat("00");
+ StringBuffer fractionFormat = new StringBuffer("");
+ for (int i = 0; i < fractionLength && i < 3; i++)
+ {
+ fractionFormat.append("0");
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(fourDigits.format(calendar.get(Calendar.YEAR)));
+ sb.append(twoDigits.format(calendar.get(Calendar.MONTH) + 1));
+ sb.append(twoDigits.format(calendar.get(Calendar.DAY_OF_MONTH)));
+ sb.append(twoDigits.format(calendar.get(Calendar.HOUR_OF_DAY)));
+
+ switch (format)
+ {
+ case YEAR_MONTH_DAY_HOUR_MIN_SEC :
+ sb.append(twoDigits.format(calendar.get(Calendar.MINUTE)));
+ sb.append(twoDigits.format(calendar.get(Calendar.SECOND)));
+ break;
+
+ case YEAR_MONTH_DAY_HOUR_MIN_SEC_FRACTION :
+ sb.append(twoDigits.format(calendar.get(Calendar.MINUTE)));
+ sb.append(twoDigits.format(calendar.get(Calendar.SECOND)));
+
+ NumberFormat fractionDigits = new DecimalFormat(fractionFormat.toString());
+ sb.append(fractionDelimiter == FractionDelimiter.COMMA ? ',' : '.');
+ sb.append(fractionDigits.format(calendar.get(Calendar.MILLISECOND)));
+ break;
+
+ case YEAR_MONTH_DAY_HOUR_MIN :
+ sb.append(twoDigits.format(calendar.get(Calendar.MINUTE)));
+ break;
+
+ case YEAR_MONTH_DAY_HOUR_MIN_FRACTION :
+ sb.append(twoDigits.format(calendar.get(Calendar.MINUTE)));
+
+ // sec + millis => fraction of minute
+ double millisec = 1000 * calendar.get(Calendar.SECOND) + calendar.get(Calendar.MILLISECOND);
+ double fraction = millisec / (1000 * 60);
+ fractionDigits = new DecimalFormat("0." + fractionFormat);
+ sb.append(fractionDelimiter == FractionDelimiter.COMMA ? ',' : '.');
+ sb.append(fractionDigits.format(fraction).substring(2));
+ break;
+
+ case YEAR_MONTH_DAY_HOUR_FRACTION :
+ // min + sec + millis => fraction of minute
+ millisec = 1000 * 60 * calendar.get(Calendar.MINUTE) + 1000 * calendar.get(Calendar.SECOND) + calendar
+ .get(Calendar.MILLISECOND);
+ fraction = millisec / (1000 * 60 * 60);
+ fractionDigits = new DecimalFormat("0." + fractionFormat);
+ sb.append(fractionDelimiter == FractionDelimiter.COMMA ? ',' : '.');
+ sb.append(fractionDigits.format(fraction).substring(2));
+
+ break;
+ }
+
+ if (timeZoneFormat == TimeZoneFormat.Z && calendar.getTimeZone().hasSameRules(GMT))
+ {
+ sb.append('Z');
+ }
+ else
+ {
+ TimeZone timeZone = calendar.getTimeZone();
+ int rawOffset = timeZone.getRawOffset();
+ sb.append(rawOffset < 0 ? '-' : '+');
+
+ rawOffset = Math.abs(rawOffset);
+ int hour = rawOffset / (60 * 60 * 1000);
+ int minute = (rawOffset - (hour * 60 * 60 * 1000)) / (1000 * 60);
+
+ if (hour < 10)
+ {
+ sb.append('0');
+ }
+ sb.append(hour);
+
+ if (timeZoneFormat == TimeZoneFormat.DIFF_HOUR_MINUTE || timeZoneFormat == TimeZoneFormat.Z)
+ {
+ if (minute < 10)
+ {
+ sb.append('0');
+ }
+ sb.append(minute);
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Gets the calendar. It could be used to manipulate this {@link GeneralizedTime} settings.
+ * @return the calendar
+ */
+ public Calendar getCalendar()
+ {
+ return calendar;
+ }
+
+ @Override
+ public String toString()
+ {
+ return toGeneralizedTime();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + calendar.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof GeneralizedTime)
+ {
+ GeneralizedTime other = (GeneralizedTime) obj;
+ return calendar.equals(other.calendar);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Compares this GeneralizedTime object with the specified GeneralizedTime object.
+ * @param other the other GeneralizedTime object
+ * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the
+ * specified object.
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(GeneralizedTime other)
+ {
+ return calendar.compareTo(other.calendar);
+ }
+
+}
\ No newline at end of file
Modified: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/QueryToLDAPFilterMapper.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/QueryToLDAPFilterMapper.java 2010-08-07 20:54:51 UTC (rev 10502)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/QueryToLDAPFilterMapper.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -22,17 +22,6 @@
import java.util.Map;
import java.util.Stack;
-import org.apache.directory.shared.ldap.entry.Value;
-import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
-import org.apache.directory.shared.ldap.filter.AndNode;
-import org.apache.directory.shared.ldap.filter.EqualityNode;
-import org.apache.directory.shared.ldap.filter.ExprNode;
-import org.apache.directory.shared.ldap.filter.GreaterEqNode;
-import org.apache.directory.shared.ldap.filter.LessEqNode;
-import org.apache.directory.shared.ldap.filter.NotNode;
-import org.apache.directory.shared.ldap.filter.OrNode;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
-import org.apache.directory.shared.ldap.filter.SubstringNode;
import org.datanucleus.exceptions.NucleusException;
import org.datanucleus.metadata.AbstractClassMetaData;
import org.datanucleus.metadata.AbstractMemberMetaData;
@@ -47,6 +36,15 @@
import org.datanucleus.query.expression.Expression.Operator;
import org.datanucleus.query.symbol.SymbolTable;
import org.datanucleus.store.ldap.LDAPUtils;
+import org.datanucleus.store.ldap.query.filter.AndFilter;
+import org.datanucleus.store.ldap.query.filter.EqualityFilter;
+import org.datanucleus.store.ldap.query.filter.Filter;
+import org.datanucleus.store.ldap.query.filter.GreaterEqFilter;
+import org.datanucleus.store.ldap.query.filter.LessEqFilter;
+import org.datanucleus.store.ldap.query.filter.NotFilter;
+import org.datanucleus.store.ldap.query.filter.OrFilter;
+import org.datanucleus.store.ldap.query.filter.PresenceFilter;
+import org.datanucleus.store.ldap.query.filter.SubstringFilter;
/**
* Class which maps a compiled query to an LDAP filter. Utilizes the filter of the java query and adds them to the
@@ -103,9 +101,9 @@
if (!stack.empty())
{
Object object = stack.pop();
- if (object instanceof ExprNode)
+ if (object instanceof Filter)
{
- ExprNode additionalFilter = (ExprNode) object;
+ Filter additionalFilter = (Filter) object;
return additionalFilter.toString();
}
else
@@ -126,12 +124,10 @@
{
Object right = stack.pop();
Object left = stack.pop();
- OrNode filter;
- if (left instanceof ExprNode && right instanceof ExprNode)
+ OrFilter filter;
+ if (left instanceof Filter && right instanceof Filter)
{
- filter = new OrNode();
- filter.addNode((ExprNode) left);
- filter.addNode((ExprNode) right);
+ filter = new OrFilter((Filter) left,(Filter) right);
stack.push(filter);
}
else
@@ -147,12 +143,10 @@
{
Object right = stack.pop();
Object left = stack.pop();
- AndNode filter;
- if (left instanceof ExprNode && right instanceof ExprNode)
+ AndFilter filter;
+ if (left instanceof Filter && right instanceof Filter)
{
- filter = new AndNode();
- filter.addNode((ExprNode) left);
- filter.addNode((ExprNode) right);
+ filter = new AndFilter((Filter) left, (Filter) right);
stack.push(filter);
}
else
@@ -198,7 +192,7 @@
{
Object right = stack.pop();
Object left = stack.pop();
- ExprNode filter;
+ Filter filter;
if (left instanceof PrimaryExpression && right instanceof Literal)
{
String param = QueryUtils.getStringValueForExpression((Literal) right, parameters);
@@ -258,7 +252,7 @@
{
Expression invokedExpr = expr.getLeft();
String method = expr.getOperation();
- SubstringNode filter;
+ SubstringFilter filter;
if (invokedExpr instanceof PrimaryExpression)
{
PrimaryExpression primaryExpression = (PrimaryExpression) invokedExpr;
@@ -268,8 +262,8 @@
// TODO Check if the field we invoke on is String-based
Expression param = (Expression) expr.getArguments().get(0);
String value = QueryUtils.getStringValueForExpression(param, parameters);
- filter = new SubstringNode(attribute);
- filter.setInitial(getEscapedValue(value));
+ filter = new SubstringFilter(attribute);
+ filter.setInitialPattern(getEscapedValue(value));
stack.push(filter);
}
else if (method.equals("endsWith"))
@@ -277,8 +271,8 @@
// TODO Check if the field we invoke on is String-based
Expression param = (Expression) expr.getArguments().get(0);
String value = QueryUtils.getStringValueForExpression(param, parameters);
- filter = new SubstringNode(attribute);
- filter.setFinal(getEscapedValue(value));
+ filter = new SubstringFilter(attribute);
+ filter.setFinalPattern(getEscapedValue(value));
stack.push(filter);
}
else
@@ -315,38 +309,34 @@
return value;
}
- private ExprNode getFilterForPrimaryLiteralValue(Operator operator, PrimaryExpression expr, String param)
+ private Filter getFilterForPrimaryLiteralValue(Operator operator, PrimaryExpression expr, String param)
{
String attribute = getLdapAttributeType(expr);
- Value value = new ClientStringValue(getEscapedValue(param));
+ String value = getEscapedValue(param);
- ExprNode filter = null;
+ Filter filter = null;
if (operator == Expression.OP_EQ)
{
- if (!value.isNull())
+ if (value != null)
{
- filter = new EqualityNode(attribute, value);
+ filter = new EqualityFilter(attribute, value);
}
else
{
// (attribute == null) -> attribute must be absent
- NotNode notNode = new NotNode();
- notNode.addNode(new PresenceNode(attribute));
- filter = notNode;
+ filter = new NotFilter(new PresenceFilter(attribute));
}
}
else if (operator == Expression.OP_NOTEQ)
{
- if (!value.isNull())
+ if (value != null)
{
- NotNode notNode = new NotNode();
- notNode.addNode(new EqualityNode(attribute, value));
- filter = notNode;
+ filter = new NotFilter(new EqualityFilter(attribute, value));
}
else
{
// (attribute != null) -> attribute must be present
- filter = new PresenceNode(attribute);
+ filter = new PresenceFilter(attribute);
}
}
else if (operator == Expression.OP_LT)
@@ -355,17 +345,13 @@
// "lesser than or equal. So we have two possibilities to handle this:
// 1st: use "lesser than or equal" and let the in-memory evaluator filter the equal ones
// 2nd: use an AND filter to exclude the equal (&(att<=5)(!(att=5)))
- LessEqNode lessEqualNode = new LessEqNode(attribute, value);
- NotNode notEqualNode = new NotNode();
- notEqualNode.addNode(new EqualityNode(attribute, value));
- AndNode andNode = new AndNode();
- andNode.addNode(lessEqualNode);
- andNode.addNode(notEqualNode);
- filter = andNode;
+ LessEqFilter lessEqualFilter = new LessEqFilter(attribute, value);
+ NotFilter notEqualFilter = new NotFilter(new EqualityFilter(attribute, value));
+ filter = new AndFilter(lessEqualFilter, notEqualFilter);
}
else if (operator == Expression.OP_LTEQ)
{
- filter = new LessEqNode(attribute, value);
+ filter = new LessEqFilter(attribute, value);
}
else if (operator == Expression.OP_GT)
{
@@ -373,17 +359,13 @@
// "greater than or equal. So we have two possibilities to handle this:
// 1st: use "greater than or equal" and let the in-memory evaluator filter the equal ones
// 2nd: use an AND filter to exclude the equal (&(att>=5)(!(att=5)))
- GreaterEqNode greaterEqualNode = new GreaterEqNode(attribute, value);
- NotNode notEqualNode = new NotNode();
- notEqualNode.addNode(new EqualityNode(attribute, value));
- AndNode andNode = new AndNode();
- andNode.addNode(greaterEqualNode);
- andNode.addNode(notEqualNode);
- filter = andNode;
+ GreaterEqFilter greaterEqualFilter = new GreaterEqFilter(attribute, value);
+ NotFilter notEqualFilter = new NotFilter(new EqualityFilter(attribute, value));
+ filter = new AndFilter(greaterEqualFilter, notEqualFilter);
}
else if (operator == Expression.OP_GTEQ)
{
- filter = new GreaterEqNode(attribute, value);
+ filter = new GreaterEqFilter(attribute, value);
}
else
{
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractBranchFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractBranchFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractBranchFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,63 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Base implementation for all branch filter types.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public abstract class AbstractBranchFilter implements Filter
+{
+ /** The child list of this branch filter */
+ protected final List<Filter> children;
+
+ /**
+ * Instantiates a new branch filter.
+ * @param children the child filters
+ */
+ protected AbstractBranchFilter(Filter... children)
+ {
+ this.children = new ArrayList<Filter>(children.length);
+ for (Filter child : children)
+ {
+ this.children.add(child);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final boolean isLeaf()
+ {
+ return false;
+ }
+
+ /**
+ * Gets the children below this BranchNode.
+ * @return the list of child filters under this branch filter.
+ */
+ public List<Filter> getChildren()
+ {
+ return children;
+ }
+
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractLeafFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractLeafFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractLeafFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,57 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * Base implementation for all leaf filter types.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public abstract class AbstractLeafFilter implements Filter
+{
+
+ /** The attribute of this leaf filter */
+ protected String attribute;
+
+ /**
+ * Instantiates a new leaf filter.
+ * @param attribute the attribute of this leaf filter
+ */
+ protected AbstractLeafFilter(String attribute)
+ {
+ this.attribute = attribute;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final boolean isLeaf()
+ {
+ return true;
+ }
+
+ /**
+ * Gets the attribute of this leaf filter.
+ * @return the attribute asserted
+ */
+ public final String getAttribute()
+ {
+ return attribute;
+ }
+
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractValueFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractValueFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AbstractValueFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,50 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * Base implementation for all leaf filter types with an assertion value.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public abstract class AbstractValueFilter extends AbstractLeafFilter
+{
+ /** The value of this value filter */
+ protected String value;
+
+ /**
+ * Instantiates a new value filter.
+ * @param attribute the attribute of this value filter
+ * @param value the value of this value filter
+ */
+ protected AbstractValueFilter(String attribute, String value)
+ {
+ super(attribute);
+ this.value = value;
+ }
+
+ /**
+ * Gets the value.
+ * @return the value
+ */
+ public final String getValue()
+ {
+ return value;
+ }
+
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AndFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AndFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/AndFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,53 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * An AND filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class AndFilter extends AbstractBranchFilter
+{
+
+ /**
+ * Instantiates a new AND filter.
+ * @param children the child filters
+ */
+ public AndFilter(Filter... children)
+ {
+ super(children);
+ }
+
+ /**
+ * Gets the recursive prefix string representation of this AND filter.
+ * @return the string representation of this AND filter
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append("(&");
+ for (Filter child : getChildren())
+ {
+ buf.append(child);
+ }
+ buf.append(')');
+ return buf.toString();
+ }
+
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/EqualityFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/EqualityFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/EqualityFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,47 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * An equality filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class EqualityFilter extends AbstractValueFilter
+{
+ /**
+ * Instantiates a new equality filter.
+ * @param attribute the attribute
+ * @param value the value
+ */
+ public EqualityFilter(String attribute, String value)
+ {
+ super(attribute, value);
+ }
+
+ /**
+ * Gets the string representation of this equality filter.
+ * @return the string representation of this equality filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append('(').append(getAttribute()).append('=').append(getValue()).append(')');
+ return buf.toString();
+ }
+}
\ No newline at end of file
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/Filter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/Filter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/Filter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,34 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * Base interface for LDAP filters.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public interface Filter
+{
+
+ /**
+ * Tests to see if this filter is a leaf or branch node.
+ * @return true if the filter is a leaf node, false otherwise
+ */
+ boolean isLeaf();
+
+}
\ No newline at end of file
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/GreaterEqFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/GreaterEqFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/GreaterEqFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,47 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * A greater or equals filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class GreaterEqFilter extends AbstractValueFilter
+{
+ /**
+ * Instantiates a new greater or equals filter.
+ * @param attribute the attribute
+ * @param value the value
+ */
+ public GreaterEqFilter(String attribute, String value)
+ {
+ super(attribute, value);
+ }
+
+ /**
+ * Gets the string representation of this greater or equals filter.
+ * @return the string representation of this greater or equals filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append('(').append(getAttribute()).append(">=").append(getValue()).append(')');
+ return buf.toString();
+ }
+}
\ No newline at end of file
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/LessEqFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/LessEqFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/LessEqFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,47 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * A less or equals filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class LessEqFilter extends AbstractValueFilter
+{
+ /**
+ * Instantiates a new less or equals filter.
+ * @param attribute the attribute
+ * @param value the value
+ */
+ public LessEqFilter(String attribute, String value)
+ {
+ super(attribute, value);
+ }
+
+ /**
+ * Gets the string representation of this less or equals filter.
+ * @return the string representation of this less or equals filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append('(').append(getAttribute()).append("<=").append(getValue()).append(')');
+ return buf.toString();
+ }
+}
\ No newline at end of file
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/NotFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/NotFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/NotFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,48 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * A NOT filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class NotFilter extends AbstractBranchFilter
+{
+ /**
+ * Instantiates a new NOT filter.
+ * @param child the child filter
+ */
+ public NotFilter(Filter child)
+ {
+ super(child);
+ }
+
+ /**
+ * Gets the recursive prefix string representation of this NOT filter.
+ * @return the string representation of this NOT filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append("(!");
+ buf.append(getChildren().get(0));
+ buf.append(')');
+ return buf.toString();
+ }
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/OrFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/OrFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/OrFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,53 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * An OR filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class OrFilter extends AbstractBranchFilter
+{
+
+ /**
+ * Instantiates a new OR filter.
+ * @param children the child filters
+ */
+ public OrFilter(Filter... children)
+ {
+ super(children);
+ }
+
+ /**
+ * Gets the recursive prefix string representation of this OR filter.
+ * @return the string representation of this OR filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append("(|");
+ for (Filter child : getChildren())
+ {
+ buf.append(child);
+ }
+ buf.append(')');
+ return buf.toString();
+ }
+
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/PresenceFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/PresenceFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/PresenceFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,46 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+/**
+ * An presence filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public final class PresenceFilter extends AbstractLeafFilter
+{
+ /**
+ * Instantiates a new presence filter.
+ * @param attribute the attribute
+ */
+ public PresenceFilter(String attribute)
+ {
+ super(attribute);
+ }
+
+ /**
+ * Gets the string representation of this presence filter.
+ * @return the string representation of this presence filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+ buf.append('(').append(getAttribute()).append("=*").append(')');
+ return buf.toString();
+ }
+}
Added: platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/SubstringFilter.java
===================================================================
--- platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/SubstringFilter.java (rev 0)
+++ platform/store.ldap/trunk/src/java/org/datanucleus/store/ldap/query/filter/SubstringFilter.java 2010-08-07 21:14:55 UTC (rev 10503)
@@ -0,0 +1,139 @@
+/**********************************************************************
+Copyright (c) 2010 Stefan Seelmann and others. All rights reserved.
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Contributors:
+ ...
+ **********************************************************************/
+package org.datanucleus.store.ldap.query.filter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An substring filter.
+ *
+ * Copied and adapted from Apache Directory shared-ldap.
+ */
+public class SubstringFilter extends AbstractLeafFilter
+{
+ /** The initial pattern */
+ private String initialPattern;
+
+ /** The final pattern */
+ private String finalPattern;
+
+ /** List of patterns */
+ private List<String> anyPatterns;
+
+ /**
+ * Instantiates a new substring filter.
+ * @param attribute the attribute
+ */
+ public SubstringFilter(String attribute)
+ {
+ super(attribute);
+ this.initialPattern = null;
+ this.finalPattern = null;
+ this.anyPatterns = new ArrayList<String>(2);
+ }
+
+ /**
+ * Gets the initial pattern.
+ * @return the initial pattern
+ */
+ public final String getInitialPattern()
+ {
+ return initialPattern;
+ }
+
+ /**
+ * Sets the initial pattern.
+ * @param initialPattern the initial pattern
+ */
+ public void setInitialPattern(String initialPattern)
+ {
+ this.initialPattern = initialPattern;
+ }
+
+ /**
+ * Gets the final pattern.
+ * @return the final pattern
+ */
+ public final String getFinalPattern()
+ {
+ return finalPattern;
+ }
+
+ /**
+ * Sets the final pattern.
+ * @param finalPattern the final pattern
+ */
+ public void setFinalPattern(String finalPattern)
+ {
+ this.finalPattern = finalPattern;
+ }
+
+ /**
+ * Gets the list of any patterns.
+ * @return the any patterns
+ */
+ public final List<String> getAnyPatterns()
+ {
+ return anyPatterns;
+ }
+
+ /**
+ * Add an any pattern.
+ * @param anyPattern the any pattern
+ */
+ public void addAnyPattern(String anyPattern)
+ {
+ this.anyPatterns.add(anyPattern);
+ }
+
+ /**
+ * Gets the string representation of this substring filter.
+ * @return the string representation of this substring filter
+ */
+ public String toString()
+ {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append('(').append(getAttribute()).append('=');
+
+ if (null != initialPattern)
+ {
+ buf.append(initialPattern);
+ }
+ buf.append('*');
+
+ if (null != anyPatterns)
+ {
+ for (String any : anyPatterns)
+ {
+ buf.append(any);
+ buf.append('*');
+ }
+ }
+
+ if (null != finalPattern)
+ {
+ buf.append(finalPattern);
+ }
+
+ buf.append(')');
+
+ return buf.toString();
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|