donaldp 2002/07/06 23:24:16
Modified: xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath
JaxenProcessorImpl.java XPathProcessorImpl.java
Added: xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath
EmptyNodeList.java SimpleNodeList.java
Log:
Minor refactorings
Revision Changes Path
1.3 +13 -39
jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath/JaxenProcessorImpl.java
Index: JaxenProcessorImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath/JaxenProcessorImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JaxenProcessorImpl.java 27 Jun 2002 19:07:00 -0000 1.2
+++ JaxenProcessorImpl.java 7 Jul 2002 06:24:16 -0000 1.3
@@ -42,18 +42,19 @@
* @param str A valid XPath string.
* @return The first node found that matches the XPath, or null.
*/
- public Node selectSingleNode( Node contextNode, String str )
+ public Node selectSingleNode( final Node contextNode,
+ final String str )
{
try
{
- DOMXPath path = new DOMXPath( str );
+ final DOMXPath path = new DOMXPath( str );
return (Node)path.selectSingleNode( (Object)contextNode );
}
- catch( Exception e )
+ catch( final Exception e )
{
// ignore it
+ return null;
}
- return null;
}
/**
@@ -64,46 +65,19 @@
* @param str A valid XPath string.
* @return A NodeList, should never be null.
*/
- public NodeList selectNodeList( Node contextNode, String str )
+ public NodeList selectNodeList( final Node contextNode,
+ final String str )
{
try
{
- DOMXPath path = new DOMXPath( str );
- List list = path.selectNodes( (Object)contextNode );
- return new NodeListEx( list );
+ final DOMXPath path = new DOMXPath( str );
+ final List list = path.selectNodes( (Object)contextNode );
+ return new SimpleNodeList( list );
}
- catch( Exception e )
+ catch( final Exception e )
{
// ignore it
- }
- return new NodeListEx();
- }
-
- class NodeListEx implements NodeList
- {
- List list = null;
-
- NodeListEx()
- {
- }
-
- NodeListEx( List l )
- {
- list = l;
- }
-
- public Node item( int index )
- {
- if( list == null )
- return null;
- return (Node)list.get( index );
- }
-
- public int getLength()
- {
- if( list == null )
- return 0;
- return list.size();
+ return new EmptyNodeList();
}
}
}
1.2 +16 -24
jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath/XPathProcessorImpl.java
Index: XPathProcessorImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath/XPathProcessorImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XPathProcessorImpl.java 22 Apr 2002 10:06:05 -0000 1.1
+++ XPathProcessorImpl.java 7 Jul 2002 06:24:16 -0000 1.2
@@ -1,10 +1,10 @@
-/*****************************************************************************
- * Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE.txt file. *
- *****************************************************************************/
+/*
+ * Copyright (C) The Apache Software Foundation. All rights reserved.
+ *
+ * This software is published under the terms of the Apache Software License
+ * version 1.1, a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ */
package org.apache.avalon.excalibur.xml.xpath;
import org.apache.avalon.framework.logger.AbstractLoggable;
@@ -12,6 +12,7 @@
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import javax.xml.transform.TransformerException;
/**
* This class defines the implementation of the {@link XPathProcessor}
@@ -41,13 +42,14 @@
* @param str A valid XPath string.
* @return The first node found that matches the XPath, or null.
*/
- public Node selectSingleNode( Node contextNode, String str )
+ public Node selectSingleNode( final Node contextNode,
+ final String str )
{
try
{
return XPathAPI.selectSingleNode( contextNode, str );
}
- catch( javax.xml.transform.TransformerException e )
+ catch( final TransformerException te )
{
return null;
}
@@ -61,26 +63,16 @@
* @param str A valid XPath string.
* @return A NodeList, should never be null.
*/
- public NodeList selectNodeList( Node contextNode, String str )
+ public NodeList selectNodeList( final Node contextNode,
+ final String str )
{
try
{
return XPathAPI.selectNodeList( contextNode, str );
}
- catch( javax.xml.transform.TransformerException e )
+ catch( final TransformerException te )
{
- return new NodeList()
- {
- public Node item( int index )
- {
- return null;
- }
-
- public int getLength()
- {
- return 0;
- }
- };
+ return new EmptyNodeList();
}
}
}
1.1
jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath/EmptyNodeList.java
Index: EmptyNodeList.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.xml.xpath;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
/**
* Noop NodeList.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/07 06:24:16 $ $Author: donaldp $
*/
class EmptyNodeList
implements NodeList
{
public Node item( int index )
{
return null;
}
public int getLength()
{
return 0;
}
}
1.1
jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/avalon/excalibur/xml/xpath/SimpleNodeList.java
Index: SimpleNodeList.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.excalibur.xml.xpath;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import java.util.List;
/**
* Simple node list wrapper around a List object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/07/07 06:24:16 $ $Author: donaldp $
*/
class SimpleNodeList
implements NodeList
{
private final List m_list;
SimpleNodeList( final List list )
{
m_list = list;
}
public Node item( final int index )
{
return (Node)m_list.get( index );
}
public int getLength()
{
return m_list.size();
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>