You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/09/07 22:50:12 UTC
svn commit: r441221 - in /incubator/abdera/java/trunk:
core/src/main/java/org/apache/abdera/util/AbstractXPath.java
core/src/main/java/org/apache/abdera/xpath/XPath.java
parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
Author: jmsnell
Date: Thu Sep 7 13:50:12 2006
New Revision: 441221
URL: http://svn.apache.org/viewvc?view=rev&rev=441221
Log:
Enhancements to the XPath api
* Use generics to reduce the need to cast explicitly in Java1.5
* Make the default namespaces immutable, but allow subclasses of AbstractXPath
to pass in their on default namespaces maps
Modified:
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractXPath.java
incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/xpath/XPath.java
incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractXPath.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractXPath.java?view=diff&rev=441221&r1=441220&r2=441221
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractXPath.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractXPath.java Thu Sep 7 13:50:12 2006
@@ -28,30 +28,41 @@
public abstract class AbstractXPath
implements XPath {
- private Map<String,String> namespaces = null;
+ private final Map<String,String> namespaces;
- public Map<String, String> getDefaultNamespaces() {
+ protected AbstractXPath() {
+ this(null);
+ }
+
+ protected AbstractXPath(Map<String,String> defaultNamespaces) {
+ namespaces = (defaultNamespaces != null) ?
+ defaultNamespaces :
+ initDefaultNamespaces();
+ }
+
+ private Map<String, String> initDefaultNamespaces() {
+ Map<String,String> namespaces = new HashMap<String,String>();
if (namespaces == null) {
namespaces = new HashMap<String,String>();
namespaces.put("a", Constants.ATOM_NS);
namespaces.put("app", Constants.APP_NS);
}
- return new HashMap<String,String>(namespaces);
+ return namespaces;
}
- public void setDefaultNamespaces(Map<String, String> namespaces) {
- this.namespaces = namespaces;
+ public Map<String,String> getDefaultNamespaces() {
+ return new HashMap<String,String>(namespaces);
}
-
+
public List selectNodes(String path, Base base) throws XPathException {
return selectNodes(path, base, getDefaultNamespaces());
}
- public Object selectSingleNode(String path, Base base) throws XPathException {
+ public <T>T selectSingleNode(String path, Base base) throws XPathException {
return selectSingleNode(path, base, getDefaultNamespaces());
}
- public Object evaluate(String path, Base base) throws XPathException {
+ public <T>T evaluate(String path, Base base) throws XPathException {
return evaluate(path, base, getDefaultNamespaces());
}
@@ -63,7 +74,7 @@
return isTrue(path, base, getDefaultNamespaces());
}
- public Number numericValueOf(String path, Base base) throws XPathException {
+ public <T extends Number>T numericValueOf(String path, Base base) throws XPathException {
return numericValueOf(path, base, getDefaultNamespaces());
}
Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/xpath/XPath.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/xpath/XPath.java?view=diff&rev=441221&r1=441220&r2=441221
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/xpath/XPath.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/xpath/XPath.java Thu Sep 7 13:50:12 2006
@@ -29,17 +29,15 @@
Map<String,String> getDefaultNamespaces();
- void setDefaultNamespaces(Map<String,String> namespaces);
-
List selectNodes(
String path,
Base base) throws XPathException;
- Object selectSingleNode(
+ <T>T selectSingleNode(
String path,
Base base) throws XPathException;
- Object evaluate(
+ <T>T evaluate(
String path,
Base base) throws XPathException;
@@ -51,7 +49,7 @@
String path,
Base base) throws XPathException;
- Number numericValueOf(
+ <T extends Number>T numericValueOf(
String path,
Base base)
throws XPathException;
@@ -61,12 +59,12 @@
Base base,
Map<String,String> namespaces) throws XPathException;
- Object selectSingleNode(
+ <T>T selectSingleNode(
String path,
Base base,
Map<String,String> namespaces) throws XPathException;
- Object evaluate(
+ <T>T evaluate(
String path,
Base base,
Map<String,String> namespaces) throws XPathException;
@@ -81,7 +79,7 @@
Base base,
Map<String,String> namespaces) throws XPathException;
- Number numericValueOf(
+ <T extends Number>T numericValueOf(
String path,
Base base,
Map<String, String> namespaces)
Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java?view=diff&rev=441221&r1=441220&r2=441221
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java (original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java Thu Sep 7 13:50:12 2006
@@ -61,25 +61,27 @@
}
}
- public Object selectSingleNode(
+ @SuppressWarnings("unchecked")
+ public <T>T selectSingleNode(
String path,
Base base,
Map<String,String> namespaces) throws XPathException {
try {
XPath xpath = getXPath(path, namespaces);
- return xpath.selectSingleNode(base);
+ return (T)xpath.selectSingleNode(base);
} catch (JaxenException e) {
throw new XPathException(e);
}
}
- public Object evaluate(
+ @SuppressWarnings("unchecked")
+ public <T>T evaluate(
String path,
Base base,
Map<String,String> namespaces) throws XPathException {
try {
XPath xpath = getXPath(path, namespaces);
- return xpath.evaluate(base);
+ return (T)xpath.evaluate(base);
} catch (JaxenException e) {
throw new XPathException(e);
}
@@ -111,14 +113,15 @@
}
}
- public Number numericValueOf(
+ @SuppressWarnings("unchecked")
+ public <T extends Number>T numericValueOf(
String path,
Base base,
Map<String,String>namespaces)
throws XPathException {
try {
XPath xpath = getXPath(path, namespaces);
- return xpath.numberValueOf(base);
+ return (T)xpath.numberValueOf(base);
} catch (JaxenException e) {
throw new XPathException(e);
}