Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 145487 Details for
Bug 280555
[xpath2] fn:compare returns XPST0017
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch which adds collation support for fn:compare
compare-collation-patch.txt (text/plain), 16.41 KB, created by
Jesper Moller
on 2009-08-24 17:24:48 EDT
(
hide
)
Description:
Patch which adds collation support for fn:compare
Filename:
MIME Type:
Creator:
Jesper Moller
Created:
2009-08-24 17:24:48 EDT
Size:
16.41 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.xml.xpath2.processor >Index: src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSString.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSString.java,v >retrieving revision 1.8 >diff -u -r1.8 XSString.java >--- src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSString.java 23 Aug 2009 20:55:54 -0000 1.8 >+++ src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSString.java 24 Aug 2009 21:20:32 -0000 >@@ -9,6 +9,7 @@ > * Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 > * Mukul Gandhi - improved comparison of xs:string with other XDM types > * Jesper S Moller - bug 286061 correct handling of quoted string >+ * Jesper S Moller - bug 280555 - Add pluggable collation support > *******************************************************************************/ > > package org.eclipse.wst.xml.xpath2.processor.internal.types; >@@ -16,9 +17,9 @@ > import org.eclipse.wst.xml.xpath2.processor.DynamicError; > import org.eclipse.wst.xml.xpath2.processor.ResultSequence; > import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; >-import org.eclipse.wst.xml.xpath2.processor.internal.function.*; >- >-import java.util.*; >+import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpEq; >+import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpGt; >+import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpLt; > > /** > * A representation of the String datatype >@@ -113,20 +114,16 @@ > > // 666 indicates death [compare returned empty seq] > private int do_compare(AnyType arg) throws DynamicError { >- Collection args = new ArrayList(); >- >- ResultSequence rs = ResultSequenceFactory.create_new(this); >- args.add(rs); >- args.add(ResultSequenceFactory.create_new(new >- XSString(arg.string_value()))); >- rs = FnCompare.compare(args); > >- if (rs.empty()) >- return 666; >+ ResultSequence rs = ResultSequenceFactory.create_new(); >+ // XXX: This can't happen, I guess >+ if (arg == null) return 666; > >- XSInteger i = (XSInteger) rs.first(); >+ // XXX: This must be addressed >+ // fn:compare need the dynamic context, and we don't have that here (yet!) >+// rs = FnCompare.compare_string(collationUri, this, arg, dynamicContext); > >- return i.int_value().intValue(); >+ return _value.compareTo(arg.string_value()); > } > > /** >Index: src/org/eclipse/wst/xml/xpath2/processor/DynamicError.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/DynamicError.java,v >retrieving revision 1.22 >diff -u -r1.22 DynamicError.java >--- src/org/eclipse/wst/xml/xpath2/processor/DynamicError.java 14 Aug 2009 04:44:10 -0000 1.22 >+++ src/org/eclipse/wst/xml/xpath2/processor/DynamicError.java 24 Aug 2009 21:20:32 -0000 >@@ -12,6 +12,7 @@ > * Jesper Steen Moeller - bug 28149 - add more fn:error info > * Jesper Steen Moller - bug 281159 - fix document loading and resolving URIs > * Jesper Steen Moller - Bug 286062 - Add FOAR0002 >+ * Jesper Steen Moller - bug 280555 - Add pluggable collation support > *******************************************************************************/ > > package org.eclipse.wst.xml.xpath2.processor; >@@ -199,7 +200,25 @@ > > return new DynamicError("FOCH0001", error); > } >- >+ >+ /** >+ * Returns the dynamic error for an unsupported normalization form >+ * >+ * @param collationName >+ * is the error >+ * @return the DynamicError. >+ * @since 1.1 >+ * >+ */ >+ public static DynamicError unsupported_collation(String collationName) { >+ String error = "Unsupported collation URI. "; >+ >+ if (collationName != null) >+ error += " " + collationName; >+ >+ return new DynamicError("FOCH0002", error); >+ } >+ > /** > * Returns the dynamic error for an unsupported normalization form > * >Index: src/org/eclipse/wst/xml/xpath2/processor/DefaultDynamicContext.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/DefaultDynamicContext.java,v >retrieving revision 1.13 >diff -u -r1.13 DefaultDynamicContext.java >--- src/org/eclipse/wst/xml/xpath2/processor/DefaultDynamicContext.java 20 Aug 2009 21:48:28 -0000 1.13 >+++ src/org/eclipse/wst/xml/xpath2/processor/DefaultDynamicContext.java 24 Aug 2009 21:20:32 -0000 >@@ -13,6 +13,7 @@ > * Jesper Moller- bug 281159 - fix document loading and resolving URIs > * Jesper Moller- bug 286452 - always return the stable date/time from dynamic context > * Jesper Moller- bug 275610 - Avoid big time and memory overhead for externals >+ * Jesper Moller- bug 280555 - Add pluggable collation support > *******************************************************************************/ > > package org.eclipse.wst.xml.xpath2.processor; >@@ -23,6 +24,7 @@ > import org.eclipse.wst.xml.xpath2.processor.internal.function.*; > import org.eclipse.wst.xml.xpath2.processor.internal.types.*; > >+import java.text.Collator; > import java.util.*; > > import org.w3c.dom.*; >@@ -44,6 +46,8 @@ > private XSDuration _tz; > private Map _loaded_documents; > private GregorianCalendar _current_date_time; >+ private String _default_collation_name = CODEPOINT_COLLATION; >+ private CollationProvider _collation_provider; > > /** > * Constructor. >@@ -242,4 +246,30 @@ > super.set_variable(var, val); > } > >+ public void set_default_collation(String _default_collation) { >+ this._default_collation_name = _default_collation; >+ } >+ >+ public String default_collation_name() { >+ return _default_collation_name; >+ } >+ >+ // We are explicitly NOT using generics here, in anticipation of JDK1.4 compatibility >+ private static Comparator CODEPOINT_COMPARATOR = new Comparator() { >+ >+ public int compare(Object o1, Object o2) { >+ return ((String)o1).compareTo((String)o2); >+ } >+ }; >+ >+ public Comparator<Object> get_collation(String uri) { >+ if (CODEPOINT_COLLATION.equals(uri)) return CODEPOINT_COMPARATOR; >+ >+ return _collation_provider != null ? _collation_provider.get_collation(uri) : null; >+ } >+ >+ void set_collation_provider(CollationProvider provider) { >+ this._collation_provider = provider; >+ } >+ > } >Index: src/org/eclipse/wst/xml/xpath2/processor/DynamicContext.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/DynamicContext.java,v >retrieving revision 1.11 >diff -u -r1.11 DynamicContext.java >--- src/org/eclipse/wst/xml/xpath2/processor/DynamicContext.java 20 Aug 2009 21:48:28 -0000 1.11 >+++ src/org/eclipse/wst/xml/xpath2/processor/DynamicContext.java 24 Aug 2009 21:20:32 -0000 >@@ -12,16 +12,20 @@ > * Jesper Moller- bug 281159 - fix document loading and resolving URIs > * Jesper Moller- bug 286452 - always return the stable date/time from dynamic context > * Jesper Moller- bug 275610 - Avoid big time and memory overhead for externals >+ * Jesper Moller- bug 280555 - Add pluggable collation support > *******************************************************************************/ > > package org.eclipse.wst.xml.xpath2.processor; > >-import org.eclipse.wst.xml.xpath2.processor.internal.Focus; >-import org.eclipse.wst.xml.xpath2.processor.internal.types.*; >- > import java.net.URI; >-import java.util.*; >-import org.w3c.dom.*; >+import java.util.Collection; >+import java.util.Comparator; >+import java.util.GregorianCalendar; >+ >+import org.eclipse.wst.xml.xpath2.processor.internal.Focus; >+import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType; >+import org.eclipse.wst.xml.xpath2.processor.internal.types.QName; >+import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration; > > /** > * Interface for dynamic context. >@@ -29,6 +33,11 @@ > public interface DynamicContext extends StaticContext { > > /** >+ * The default collation which is guaranteed to always be implemented >+ */ >+ public static final String CODEPOINT_COLLATION = "http://www.w3.org/2005/xpath-functions/collation/codepoint"; >+ >+ /** > * Get context item. > * > * @return the context item. >@@ -138,6 +147,20 @@ > * @return Focus > */ > public Focus focus(); >- >+ >+ /** >+ * Return a useful collator for the specified URI >+ * >+ * @param uri >+ * @return A Jaa collator, or null, if no such Collator exists >+ */ >+ public Comparator<Object> get_collation(String uri); >+ >+ /** >+ * Returns the current default collator >+ * >+ * @return The default name to use as the collator >+ */ >+ public String default_collation_name(); > > } >Index: src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnCompare.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnCompare.java,v >retrieving revision 1.3 >diff -u -r1.3 FnCompare.java >--- src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnCompare.java 30 Jul 2009 23:09:22 -0000 1.3 >+++ src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnCompare.java 24 Aug 2009 21:20:32 -0000 >@@ -8,10 +8,12 @@ > * Contributors: > * Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 > * Jesper Steen Moeller - bug 285145 - implement full arity checking >+ * Jesper Steen Moeller - bug 280555 - Add pluggable collation support > *******************************************************************************/ > > package org.eclipse.wst.xml.xpath2.processor.internal.function; > >+import org.eclipse.wst.xml.xpath2.processor.DynamicContext; > import org.eclipse.wst.xml.xpath2.processor.DynamicError; > import org.eclipse.wst.xml.xpath2.processor.ResultSequence; > import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; >@@ -58,8 +60,7 @@ > * Constructor of FnCompare. > */ > public FnCompare() { >- // XXX: This should be 2-3 when compare learns how to deal with collations >- super(new QName("compare"), 2); >+ super(new QName("compare"), 2, 3); > } > > /** >@@ -73,45 +74,59 @@ > */ > @Override > public ResultSequence evaluate(Collection args) throws DynamicError { >- return compare(args); >+ return compare(args, dynamic_context()); > } > > /** > * Compare the arguments. > * > * @param args >- * are compared. >+ * are compared (optional 3rd argument is the collation) >+ * @param dynamicContext >+ * Current dynamic context > * @throws DynamicError > * Dynamic error. > * @return The result of the comparison of the arguments. > */ >- public static ResultSequence compare(Collection args) throws DynamicError { >+ public static ResultSequence compare(Collection args, DynamicContext dynamicContext) throws DynamicError { > Collection cargs = Function.convert_arguments(args, expected_args()); > >- ResultSequence rs = ResultSequenceFactory.create_new(); >- > Iterator argiter = cargs.iterator(); > ResultSequence arg1 = (ResultSequence) argiter.next(); >- if (arg1.empty()) >- return rs; > ResultSequence arg2 = (ResultSequence) argiter.next(); >- if (arg2.empty()) >- return rs; > >- XSString xstr1 = (XSString) arg1.first(); >- XSString xstr2 = (XSString) arg2.first(); >+ String collationUri = dynamicContext.default_collation_name(); >+ if (argiter.hasNext()) { >+ ResultSequence collArg = (ResultSequence) argiter.next(); >+ collationUri = collArg.first().string_value(); >+ } > >- // XXX collations!!! >- int ret = xstr1.value().compareTo(xstr2.value()); >+ XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first(); >+ XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first(); >+ >+ BigInteger result = compare_string(collationUri, xstr1, xstr2, dynamicContext); >+ if (result != null) { >+ return ResultSequenceFactory.create_new(new XSInteger(result)); >+ } else { >+ return ResultSequenceFactory.create_new(); >+ } >+ } >+ >+ public static BigInteger compare_string(String collationUri, XSString xstr1, >+ XSString xstr2, DynamicContext dynamicContext) throws DynamicError { >+ Comparator collator = dynamicContext.get_collation(collationUri); >+ if (collator == null) throw DynamicError.unsupported_collation(collationUri); >+ >+ if (xstr1 == null || xstr2 == null) return null; >+ >+ int ret = collator.compare(xstr1.value(), xstr2.value()); > > if (ret == 0) >- rs.add(new XSInteger(BigInteger.valueOf(0))); >+ return BigInteger.ZERO; > else if (ret < 0) >- rs.add(new XSInteger(BigInteger.valueOf(-1))); >+ return BigInteger.valueOf(-1); > else >- rs.add(new XSInteger(BigInteger.valueOf(1))); >- >- return rs; >+ return BigInteger.ONE; > } > > /** >@@ -125,6 +140,7 @@ > SeqType arg = new SeqType(new XSString(), SeqType.OCC_QMARK); > _expected_args.add(arg); > _expected_args.add(arg); >+ _expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE)); > } > > return _expected_args; >Index: src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnDefaultCollation.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath2.processor/src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnDefaultCollation.java,v >retrieving revision 1.2 >diff -u -r1.2 FnDefaultCollation.java >--- src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnDefaultCollation.java 30 Jul 2009 23:09:23 -0000 1.2 >+++ src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnDefaultCollation.java 24 Aug 2009 21:20:32 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * David Carver (STAR) - initial API and implementation > * Jesper Steen Moeller - bug 285145 - implement full arity checking >+ * Jesper Steen Moeller - bug 280555 - Add pluggable collation support > *******************************************************************************/ > package org.eclipse.wst.xml.xpath2.processor.internal.function; > >@@ -17,7 +18,6 @@ > import org.eclipse.wst.xml.xpath2.processor.ResultSequence; > import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory; > import org.eclipse.wst.xml.xpath2.processor.internal.types.QName; >-import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean; > import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString; > > /** >@@ -43,8 +43,6 @@ > */ > public class FnDefaultCollation extends Function { > >- private static final String DEFAULT_COLLATION = "http://www.w3.org/2005/xpath-functions/collation/codepoint"; >- > public FnDefaultCollation() { > super(new QName("default-collation"), 0); > } >@@ -53,7 +51,7 @@ > public ResultSequence evaluate(Collection args) throws DynamicError { > assert args.size() >= min_arity() && args.size() <= max_arity(); > ResultSequence rs = ResultSequenceFactory.create_new(); >- rs.add(new XSString(DEFAULT_COLLATION)); >+ rs.add(new XSString(dynamic_context().default_collation_name())); > return rs; > } > >Index: src/org/eclipse/wst/xml/xpath2/processor/CollationProvider.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/xpath2/processor/CollationProvider.java >diff -N src/org/eclipse/wst/xml/xpath2/processor/CollationProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xml/xpath2/processor/CollationProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Jesper Moller, and others >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Jesper Moller - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.wst.xml.xpath2.processor; >+ >+import java.util.Comparator; >+ >+/** >+ * Service provider interface for looking up collations from within the dynamic context. >+ */ >+public interface CollationProvider { >+ /** >+ * Gets the named collator. W3C does not define collation names (yet?) so we are constrained to using an >+ * implementation-defined naming scheme. >+ * >+ * @param name A URI designating the collation to use >+ * @return The collation to use, or null if no such collation exists by this provider >+ */ >+ Comparator get_collation(String name); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 280555
:
145487
|
146320