/*
 * Copyright (C) 2008 TranceCode Software
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 *
 * $Id$
 */
package org.trancecode.xml.saxon;

import com.google.common.base.Function;
import com.google.common.base.Preconditions;

import java.util.Iterator;

import net.sf.saxon.s9api.Axis;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.XdmItem;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmNodeKind;

/**
 * Utility methods related to {@link Function} and Saxon.
 * 
 * @author Herve Quiroz
 */
public final class SaxonFunctions
{
    private SaxonFunctions()
    {
        // No instantiation
    }

    public static Function<XdmNode, XdmNodeKind> getNodeKind()
    {
        return GetNodeKindFunction.INSTANCE;
    }

    private static class GetNodeKindFunction implements Function<XdmNode, XdmNodeKind>
    {
        private static GetNodeKindFunction INSTANCE = new GetNodeKindFunction();

        private GetNodeKindFunction()
        {
            // Singleton
        }

        @Override
        public XdmNodeKind apply(final XdmNode node)
        {
            return node.getNodeKind();
        }
    }

    public static Function<XdmNode, Iterator<XdmItem>> axisIterator(final Axis axis)
    {
        return new AxisIteratorFunction(axis);
    }

    private static class AxisIteratorFunction implements Function<XdmNode, Iterator<XdmItem>>
    {
        private final Axis axis;

        public AxisIteratorFunction(final Axis axis)
        {
            super();
            Preconditions.checkNotNull(axis);
            this.axis = axis;
        }

        @Override
        public Iterator<XdmItem> apply(final XdmNode node)
        {
            return node.axisIterator(axis);
        }
    }

    public static Function<XdmNode, String> getStringValue()
    {
        return GetStringValueFunction.INSTANCE;
    }

    private static class GetStringValueFunction implements Function<XdmNode, String>
    {
        private static GetStringValueFunction INSTANCE = new GetStringValueFunction();

        private GetStringValueFunction()
        {
            // Singleton
        }

        @Override
        public String apply(final XdmNode node)
        {
            return node.getStringValue();
        }
    }

    public static Function<XdmNode, QName> getNodeName()
    {
        return GetNodeNameFunction.INSTANCE;
    }

    private static class GetNodeNameFunction implements Function<XdmNode, QName>
    {
        private static GetNodeNameFunction INSTANCE = new GetNodeNameFunction();

        private GetNodeNameFunction()
        {
            // Singleton
        }

        @Override
        public QName apply(final XdmNode node)
        {
            return node.getNodeName();
        }
    }
}

@@ -1448,32 +1448,38 @@
  private static 
+final 
 class GetNodeKin
@@ -1622,92 +1622,8 @@
 );%0A%0A
-        private GetNodeKindFunction()%0A        %7B%0A            // Singleton%0A        %7D%0A%0A
     
@@ -1915,24 +1915,30 @@
 vate static 
+final 
 class AxisIt
@@ -2119,28 +2119,19 @@
     
-super();%0A           
+this.axis =
  Pre
@@ -2165,38 +2165,8 @@
 s);%0A
-            this.axis = axis;%0A
     
@@ -2453,32 +2453,38 @@
  private static 
+final 
 class GetStringV
@@ -2631,95 +2631,8 @@
 );%0A%0A
-        private GetStringValueFunction()%0A        %7B%0A            // Singleton%0A        %7D%0A%0A
     
@@ -2896,16 +2896,22 @@
  static 
+final 
 class Ge
@@ -3056,92 +3056,8 @@
 );%0A%0A
-        private GetNodeNameFunction()%0A        %7B%0A            // Singleton%0A        %7D%0A%0A
     

Reduce code complexity