Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 276134 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/xpath2/processor/internal/types/ElementType.java (-7 / +26 lines)
Lines 6-20 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
11
 *                                  for attribute/element nodes  
10
 *******************************************************************************/
12
 *******************************************************************************/
11
13
12
package org.eclipse.wst.xml.xpath2.processor.internal.types;
14
package org.eclipse.wst.xml.xpath2.processor.internal.types;
13
15
14
import org.w3c.dom.*;
16
import org.apache.xerces.dom.PSVIElementNSImpl;
17
import org.apache.xerces.xs.XSTypeDefinition;
15
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
16
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
17
import org.eclipse.wst.xml.xpath2.processor.internal.*;
20
import org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary;
21
import org.w3c.dom.Element;
22
import org.w3c.dom.Node;
23
import org.w3c.dom.NodeList;
24
import org.w3c.dom.Text;
18
25
19
/**
26
/**
20
 * A representation of the ElementType datatype
27
 * A representation of the ElementType datatype
Lines 90-99 Link Here
90
	 */
97
	 */
91
	@Override
98
	@Override
92
	public ResultSequence typed_value() {
99
	public ResultSequence typed_value() {
93
		ResultSequence rs = ResultSequenceFactory.create_new();
100
		ResultSequence rs = ResultSequenceFactory.create_new();	
94
101
		
95
		// XXX only if PSVI is not present!! [not our case]
102
		PSVIElementNSImpl psviElem = (PSVIElementNSImpl)_value;
96
		rs.add(new UntypedAtomic(string_value()));
103
		XSTypeDefinition typeDef = psviElem.getTypeDefinition();
104
		
105
		if (typeDef != null && typeDef.getNamespace().equals(XSCtrLibrary.XML_SCHEMA_NS)) {
106
		  Object schemaTypeValue = getTypedValueForPrimitiveType(typeDef);
107
		  if (schemaTypeValue != null) {
108
			rs.add((AnyType)schemaTypeValue);  
109
		  }
110
		  else {
111
			rs.add(new UntypedAtomic(string_value()));  
112
		  }
113
	    } else {
114
		   rs.add(new UntypedAtomic(string_value()));	
115
		}	
97
116
98
		return rs;
117
		return rs;
99
	}
118
	}
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/types/NodeType.java (-5 / +44 lines)
Lines 6-22 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
11
 *                                 for attribute/element nodes 
10
 *******************************************************************************/
12
 *******************************************************************************/
11
13
12
package org.eclipse.wst.xml.xpath2.processor.internal.types;
14
package org.eclipse.wst.xml.xpath2.processor.internal.types;
13
15
14
import org.w3c.dom.*;
16
import java.math.BigInteger;
17
import java.util.ArrayList;
18
import java.util.Hashtable;
19
import java.util.Iterator;
20
21
import org.apache.xerces.xs.XSTypeDefinition;
15
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
22
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
16
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
23
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
17
import org.eclipse.wst.xml.xpath2.processor.internal.*;
24
import org.w3c.dom.Attr;
18
25
import org.w3c.dom.Comment;
19
import java.util.*;
26
import org.w3c.dom.Document;
27
import org.w3c.dom.Element;
28
import org.w3c.dom.Node;
29
import org.w3c.dom.ProcessingInstruction;
30
import org.w3c.dom.Text;
20
31
21
/**
32
/**
22
 * A representation of a Node datatype
33
 * A representation of a Node datatype
Lines 175-178 Link Here
175
186
176
		return !before(a, b);
187
		return !before(a, b);
177
	}
188
	}
189
	
190
	protected Object getTypedValueForPrimitiveType(XSTypeDefinition typeDef) {		
191
		Object schemaTypeValue = null;
192
		
193
		if (typeDef.getName().equals("date")) {		
194
		   schemaTypeValue = XSDate.parse_date(string_value());
195
		}
196
		else if (typeDef.getName().equals("int")) {		
197
		   schemaTypeValue = new XSInt(new BigInteger(string_value()));
198
		}
199
		else if (typeDef.getName().equals("long")) {		
200
		  schemaTypeValue = new XSLong(new BigInteger(string_value()));
201
	    }
202
		else if (typeDef.getName().equals("integer")) {		
203
		  schemaTypeValue = new XSInteger(new BigInteger(string_value()));
204
		}
205
		else if (typeDef.getName().equals("double")) {		
206
		  schemaTypeValue = new XSDouble(Double.parseDouble(string_value()));
207
		}
208
		else if (typeDef.getName().equals("float")) {		
209
		  schemaTypeValue = new XSFloat(Float.parseFloat(string_value()));
210
	    }
211
		else if (typeDef.getName().equals("decimal")) {		
212
		  schemaTypeValue = new XSDecimal(Double.parseDouble(string_value()));
213
		}
214
		
215
		return schemaTypeValue;
216
	}
178
}
217
}
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/types/AttrType.java (-7 / +23 lines)
Lines 6-20 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
11
 *                                 for attribute/element nodes 
10
 *******************************************************************************/
12
 *******************************************************************************/
11
13
12
package org.eclipse.wst.xml.xpath2.processor.internal.types;
14
package org.eclipse.wst.xml.xpath2.processor.internal.types;
13
15
14
import org.w3c.dom.*;
16
import org.apache.xerces.dom.PSVIAttrNSImpl;
17
import org.apache.xerces.xs.XSTypeDefinition;
15
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
16
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
17
import org.eclipse.wst.xml.xpath2.processor.internal.*;
20
import org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary;
21
import org.w3c.dom.Attr;
18
22
19
/**
23
/**
20
 * A representation of the AttributeType datatype
24
 * A representation of the AttributeType datatype
Lines 72-81 Link Here
72
	@Override
76
	@Override
73
	public ResultSequence typed_value() {
77
	public ResultSequence typed_value() {
74
		ResultSequence rs = ResultSequenceFactory.create_new();
78
		ResultSequence rs = ResultSequenceFactory.create_new();
75
79
		
76
		// XXX with no PSVI
80
		PSVIAttrNSImpl psviAttr = (PSVIAttrNSImpl)_value;
77
		rs.add(new UntypedAtomic(string_value()));
81
		XSTypeDefinition typeDef = psviAttr.getTypeDefinition();
78
82
		
83
		if (typeDef != null && typeDef.getNamespace().equals(XSCtrLibrary.XML_SCHEMA_NS)) {
84
		  Object schemaTypeValue = getTypedValueForPrimitiveType(typeDef);
85
		  if (schemaTypeValue != null) {
86
			rs.add((AnyType)schemaTypeValue);  
87
		  }
88
		  else {
89
			rs.add(new UntypedAtomic(string_value()));  
90
		  }
91
	    } else {
92
		   rs.add(new UntypedAtomic(string_value()));	
93
		}
94
		
79
		return rs;
95
		return rs;
80
	}
96
	}
81
97
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/function/FsEq.java (-2 / +5 lines)
Lines 6-12 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
11
 *                                 for attribute/element nodes 
10
 *******************************************************************************/
12
 *******************************************************************************/
11
13
12
package org.eclipse.wst.xml.xpath2.processor.internal.function;
14
package org.eclipse.wst.xml.xpath2.processor.internal.function;
Lines 64-70 Link Here
64
		for (Iterator i = args.iterator(); i.hasNext();) {
66
		for (Iterator i = args.iterator(); i.hasNext();) {
65
			ResultSequence rs = (ResultSequence) i.next();
67
			ResultSequence rs = (ResultSequence) i.next();
66
68
67
			FnData.fast_atomize(rs);
69
			//FnData.fast_atomize(rs);
70
			rs = FnData.atomize(rs);
68
71
69
			if (rs.empty())
72
			if (rs.empty())
70
				return new ArrayList();
73
				return new ArrayList();
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnData.java (-8 / +15 lines)
Lines 6-22 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
11
 *                                 for attribute/element nodes 
10
 *******************************************************************************/
12
 *******************************************************************************/
11
13
12
package org.eclipse.wst.xml.xpath2.processor.internal.function;
14
package org.eclipse.wst.xml.xpath2.processor.internal.function;
13
15
16
import java.util.Collection;
17
import java.util.Iterator;
18
import java.util.ListIterator;
19
14
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
20
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
15
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
21
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
16
import org.eclipse.wst.xml.xpath2.processor.internal.*;
22
import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType;
17
import org.eclipse.wst.xml.xpath2.processor.internal.types.*;
23
import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
18
24
import org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType;
19
import java.util.*;
25
import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
20
26
21
/**
27
/**
22
 * fn:data takes a sequence of items and returns a sequence of atomic values.
28
 * fn:data takes a sequence of items and returns a sequence of atomic values.
Lines 65-78 Link Here
65
		for (Iterator i = arg.iterator(); i.hasNext();) {
71
		for (Iterator i = arg.iterator(); i.hasNext();) {
66
			AnyType at = (AnyType) i.next();
72
			AnyType at = (AnyType) i.next();
67
73
68
			if (at instanceof AnyAtomicType)
74
			if (at instanceof AnyAtomicType) {
69
				rs.add(at);
75
				rs.add(at);
76
			}
70
			else if (at instanceof NodeType) {
77
			else if (at instanceof NodeType) {
71
				NodeType nt = (NodeType) at;
78
				NodeType nt = (NodeType) at;
72
73
				rs.concat(nt.typed_value());
79
				rs.concat(nt.typed_value());
74
			} else
80
			} else {
75
				assert false;
81
				assert false;
82
			}
76
		}
83
		}
77
84
78
		return rs;
85
		return rs;
(-)src/org/eclipse/wst/xml/xpath2/processor/XercesLoader.java (-4 / +23 lines)
Lines 6-12 Link Here
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - bug 276134 - improvements to schema aware primitive type support
11
 *                                 for attribute/element nodes  
10
 *******************************************************************************/
12
 *******************************************************************************/
11
13
12
package org.eclipse.wst.xml.xpath2.processor;
14
package org.eclipse.wst.xml.xpath2.processor;
Lines 15-20 Link Here
15
17
16
import org.w3c.dom.*;
18
import org.w3c.dom.*;
17
import javax.xml.parsers.*;
19
import javax.xml.parsers.*;
20
import javax.xml.validation.Schema;
21
18
import org.xml.sax.*;
22
import org.xml.sax.*;
19
23
20
/**
24
/**
Lines 41-46 Link Here
41
	public static final String DOCUMENT_PSVI_IMPLEMENTATION = "org.apache.xerces.dom.PSVIDocumentImpl";
45
	public static final String DOCUMENT_PSVI_IMPLEMENTATION = "org.apache.xerces.dom.PSVIDocumentImpl";
42
46
43
	boolean _validating;
47
	boolean _validating;
48
	
49
	Schema _schema = null;;
44
50
45
	/**
51
	/**
46
	 * Constructor for Xerxes loader.
52
	 * Constructor for Xerxes loader.
Lines 48-53 Link Here
48
	public XercesLoader() {
54
	public XercesLoader() {
49
		_validating = false;
55
		_validating = false;
50
	}
56
	}
57
	
58
	public XercesLoader(Schema schema) {
59
		_validating = false;
60
		_schema = schema;
61
	}
51
62
52
	/**
63
	/**
53
	 * The Xerces loader loads the XML docuemnt
64
	 * The Xerces loader loads the XML docuemnt
Lines 64-75 Link Here
64
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
75
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
65
76
66
		factory.setNamespaceAware(true);
77
		factory.setNamespaceAware(true);
67
		factory.setValidating(_validating);
68
		factory.setAttribute(SCHEMA_VALIDATION_FEATURE,
78
		factory.setAttribute(SCHEMA_VALIDATION_FEATURE,
69
				new Boolean(_validating));
79
				new Boolean(_validating));
70
		factory.setAttribute(DOCUMENT_IMPLEMENTATION_PROPERTY,
80
		factory.setAttribute(DOCUMENT_IMPLEMENTATION_PROPERTY,
71
				DOCUMENT_PSVI_IMPLEMENTATION);
81
				DOCUMENT_PSVI_IMPLEMENTATION);
72
		// factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
82
		
83
		if (_schema != null) {
84
		  factory.setSchema(_schema);
85
		}
86
		else {
87
		  factory.setValidating(_validating);	
88
		}
73
89
74
		try {
90
		try {
75
			DocumentBuilder builder = factory.newDocumentBuilder();
91
			DocumentBuilder builder = factory.newDocumentBuilder();
Lines 94-106 Link Here
94
			}
110
			}
95
			return builder.parse(in);
111
			return builder.parse(in);
96
		} catch (SAXException e) {
112
		} catch (SAXException e) {
97
			throw new DOMLoaderException("SAX exception: " + e.getMessage());
113
			//throw new DOMLoaderException("SAX exception: " + e.getMessage());
114
			e.printStackTrace();
98
		} catch (ParserConfigurationException e) {
115
		} catch (ParserConfigurationException e) {
99
			throw new DOMLoaderException("Parser configuration exception: "
116
			throw new DOMLoaderException("Parser configuration exception: "
100
					+ e.getMessage());
117
					+ e.getMessage());
101
		} catch (IOException e) {
118
		} catch (IOException e) {
102
			throw new DOMLoaderException("IO exception: " + e.getMessage());
119
			throw new DOMLoaderException("IO exception: " + e.getMessage());
103
		}
120
		}
121
		
122
		return null;
104
123
105
	}
124
	}
106
125

Return to bug 276134