/*
 * 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 net.sf.saxon.s9api.XdmNode;
import org.trancecode.annotation.Immutable;
import org.trancecode.xml.Location;

/**
 * @author Herve Quiroz
 */
@Immutable
public class SaxonLocation implements Location
{
    private static final long serialVersionUID = 7136827002407040675L;

    public final XdmNode node;

    private String toString;

    public SaxonLocation(final XdmNode node)
    {
        this.node = node;
    }

    public String getSystemId()
    {
        return node.getUnderlyingNode().getSystemId();
    }

    public int getColumnNumber()
    {
        return node.getUnderlyingNode().getColumnNumber();
    }

    public int getLineNumber()
    {
        return node.getUnderlyingNode().getLineNumber();
    }

    public String getPublicId()
    {
        return null;
    }

    @Override
    public String toString()
    {
        if (toString == null)
        {
            toString = String.format("line %s, column %s in %s", getLineNumber(), getColumnNumber(), getSystemId());
        }

        return toString;
    }
}

@@ -1112,21 +1112,22 @@
 ;%0A%0A    p
-ublic
+rivate
  final X
@@ -1149,103 +1149,242 @@
    p
-rivate String toString;%0A%0A    public SaxonLocation(final XdmNode node)%0A    %7B%0A        this.node =
+ublic static SaxonLocation of(final XdmNode node)%0A    %7B%0A        return new SaxonLocation(node);%0A    %7D%0A%0A    private SaxonLocation(final XdmNode node)%0A    %7B%0A        this.node = node;%0A    %7D%0A%0A    public XdmNode node()%0A    %7B%0A        return
  nod
@@ -1826,62 +1826,14 @@
     
-if (toString == null)%0A        %7B%0A            toString =
+return
  Str
@@ -1927,44 +1927,8 @@
 ));%0A
-        %7D%0A%0A        return toString;%0A
     

Refactor SaxonLocation to allow a single static factory method and remove toString() caching