saxon-dom-9.1.0.8j

16:52:04.717 INFO  jd.cli.Main - Decompiling saxon-dom-9.1.0.8j.jar
package net.sf.saxon.dom;

import java.util.ArrayList;
import java.util.List;
import net.sf.saxon.Configuration;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.pattern.ContentTypeTest;
import net.sf.saxon.type.BuiltInAtomicType;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;

public class AttrOverNodeInfo
  extends NodeOverNodeInfo
  implements Attr
{
  public String getName()
  {
    if (node.getNodeKind() == 13)
    {
      String local = node.getLocalPart();
      if (local.equals("")) {
        return "xmlns";
      }
      return "xmlns:" + local;
    }
    return node.getDisplayName();
  }
  
  public String getValue()
  {
    return node.getStringValue();
  }
  
  public boolean hasChildNodes()
  {
    return true;
  }
  
  public Node getFirstChild()
  {
    return new TextOverAttrInfo(this);
  }
  
  public Node getLastChild()
  {
    return getFirstChild();
  }
  
  public NodeList getChildNodes()
  {
    List list = new ArrayList(1);
    list.add(getFirstChild());
    return new DOMNodeList(list);
  }
  
  public boolean getSpecified()
  {
    return true;
  }
  
  public void setValue(String value)
    throws DOMException
  {}
  
  public boolean isId()
  {
    ContentTypeTest idTest = new ContentTypeTest(2, BuiltInAtomicType.ID, node.getConfiguration());
    
    idTest.setMatchDTDTypes(true);
    return idTest.matches(node);
  }
  
  public Element getOwnerElement()
  {
    if ((node.getNodeKind() == 2) || (node.getNodeKind() == 13)) {
      return (Element)wrap(node.getParent());
    }
    throw new UnsupportedOperationException("This method is defined only on attribute and namespace nodes");
  }
  
  public TypeInfo getSchemaTypeInfo()
  {
    int annotation = node.getTypeAnnotation();
    if ((annotation == -1) || ((annotation & 0x40000000) != 0)) {
      return null;
    }
    return new TypeInfoImpl(node.getConfiguration(), node.getConfiguration().getSchemaType(annotation));
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.AttrOverNodeInfo
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.om.AxisIterator;
import net.sf.saxon.om.NamePool;
import net.sf.saxon.om.NamespaceIterator.NamespaceNodeImpl;
import net.sf.saxon.om.NodeInfo;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

class DOMAttributeMap
  implements NamedNodeMap
{
  private NodeInfo parent;
  private int numberOfNamespaces = -1;
  
  public DOMAttributeMap(NodeInfo parent)
  {
    this.parent = parent;
  }
  
  public Node getNamedItem(String name)
  {
    if (name.equals("xmlns"))
    {
      int[] nsarray = parent.getDeclaredNamespaces(null);
      for (int i = 0; i < nsarray.length; i++)
      {
        if (nsarray[i] == -1) {
          return null;
        }
        if ((nsarray[i] >> 16 & 0xFFFF) == 0)
        {
          NamespaceIterator.NamespaceNodeImpl nn = new NamespaceIterator.NamespaceNodeImpl(parent, nsarray[i], i + 1);
          
          return NodeOverNodeInfo.wrap(nn);
        }
      }
      return null;
    }
    if (name.startsWith("xmlns:"))
    {
      String prefix = name.substring(6);
      if (prefix.equals("xml"))
      {
        NamespaceIterator.NamespaceNodeImpl nn = new NamespaceIterator.NamespaceNodeImpl(parent, 1, 0);
        
        return NodeOverNodeInfo.wrap(nn);
      }
      int[] buffer = new int[8];
      int[] nsarray = parent.getDeclaredNamespaces(buffer);
      for (int i = 0; i < nsarray.length; i++)
      {
        if (nsarray[i] == -1) {
          return null;
        }
        if (prefix.equals(parent.getNamePool().getPrefixFromNamespaceCode(nsarray[i])))
        {
          NamespaceIterator.NamespaceNodeImpl nn = new NamespaceIterator.NamespaceNodeImpl(parent, nsarray[i], i + 1);
          
          return NodeOverNodeInfo.wrap(nn);
        }
      }
      return null;
    }
    AxisIterator atts = parent.iterateAxis((byte)2);
    for (;;)
    {
      NodeInfo att = (NodeInfo)atts.next();
      if (att == null) {
        return null;
      }
      if (name.equals(att.getDisplayName())) {
        return NodeOverNodeInfo.wrap(att);
      }
    }
  }
  
  public Node item(int index)
  {
    if (index < 0) {
      return null;
    }
    if (index == 0)
    {
      NamespaceIterator.NamespaceNodeImpl nn = new NamespaceIterator.NamespaceNodeImpl(parent, 65537, 0);
      
      return NodeOverNodeInfo.wrap(nn);
    }
    int nscount = getNumberOfNamespaces();
    if (index < nscount)
    {
      int[] buffer = new int[8];
      int[] nsList = parent.getDeclaredNamespaces(buffer);
      int nscode = nsList[(index - 1)];
      NamespaceIterator.NamespaceNodeImpl nn = new NamespaceIterator.NamespaceNodeImpl(parent, nscode, index);
      
      return NodeOverNodeInfo.wrap(nn);
    }
    int pos = 0;
    int attNr = index - nscount;
    AxisIterator atts = parent.iterateAxis((byte)2);
    for (;;)
    {
      NodeInfo att = (NodeInfo)atts.next();
      if (att == null) {
        return null;
      }
      if (pos == attNr) {
        return NodeOverNodeInfo.wrap(att);
      }
      pos++;
    }
  }
  
  private int getNumberOfNamespaces()
  {
    if (numberOfNamespaces == -1)
    {
      int[] buffer = new int[8];
      int[] nsList = parent.getDeclaredNamespaces(buffer);
      int count = nsList.length;
      for (int i = 0; i < count; i++) {
        if (nsList[i] == -1)
        {
          count = i;
          break;
        }
      }
      numberOfNamespaces = (count + 1);
    }
    return numberOfNamespaces;
  }
  
  public int getLength()
  {
    int length = 0;
    AxisIterator atts = parent.iterateAxis((byte)2);
    while (atts.next() != null) {
      length++;
    }
    return getNumberOfNamespaces() + length;
  }
  
  public Node getNamedItemNS(String uri, String localName)
  {
    if (uri == null) {
      uri = "";
    }
    if ("http://www.w3.org/2000/xmlns/".equals(uri)) {
      return getNamedItem("xmlns:" + localName);
    }
    if ((uri.equals("")) && (localName.equals("xmlns"))) {
      return getNamedItem("xmlns");
    }
    AxisIterator atts = parent.iterateAxis((byte)2);
    for (;;)
    {
      NodeInfo att = (NodeInfo)atts.next();
      if (att == null) {
        return null;
      }
      if ((uri.equals(att.getURI())) && (localName.equals(att.getLocalPart()))) {
        return NodeOverNodeInfo.wrap(att);
      }
    }
  }
  
  public Node setNamedItem(Node arg)
    throws DOMException
  {
    NodeOverNodeInfo.disallowUpdate();
    return null;
  }
  
  public Node removeNamedItem(String name)
    throws DOMException
  {
    NodeOverNodeInfo.disallowUpdate();
    return null;
  }
  
  public Node setNamedItemNS(Node arg)
    throws DOMException
  {
    NodeOverNodeInfo.disallowUpdate();
    return null;
  }
  
  public Node removeNamedItemNS(String uri, String localName)
    throws DOMException
  {
    NodeOverNodeInfo.disallowUpdate();
    return null;
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMAttributeMap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.trans.XPathException;

class DOMEnvelope$1
  extends PJConverter
{
  private final DOMEnvelope this$0;
  
  DOMEnvelope$1(DOMEnvelope paramDOMEnvelope)
    throws XPathException
  {}
  
  public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
    throws XPathException
  {
    return this$0.convertXPathValueToObject(value, targetClass, context);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMEnvelope.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.trans.XPathException;

class DOMEnvelope$2
  extends PJConverter
{
  private final DOMEnvelope this$0;
  
  DOMEnvelope$2(DOMEnvelope paramDOMEnvelope)
    throws XPathException
  {}
  
  public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
    throws XPathException
  {
    return this$0.convertXPathValueToObject(value, targetClass, context);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMEnvelope.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.JPConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.pattern.AnyNodeTest;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;

class DOMEnvelope$3
  extends JPConverter
{
  private final DOMEnvelope this$0;
  
  DOMEnvelope$3(DOMEnvelope paramDOMEnvelope)
    throws XPathException
  {}
  
  public ValueRepresentation convert(Object object, XPathContext context)
    throws XPathException
  {
    return this$0.convertObjectToXPathValue(object, context.getConfiguration());
  }
  
  public ItemType getItemType()
  {
    return AnyNodeTest.getInstance();
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMEnvelope.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import net.sf.saxon.Configuration;
import net.sf.saxon.event.PipelineConfiguration;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.event.Sender;
import net.sf.saxon.expr.JPConverter;
import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.DocumentInfo;
import net.sf.saxon.om.ExternalObjectModel;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.om.VirtualNode;
import net.sf.saxon.pattern.AnyNodeTest;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import net.sf.saxon.value.SequenceExtent;
import net.sf.saxon.value.Value;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class DOMEnvelope
  implements ExternalObjectModel, Serializable
{
  public String getIdentifyingURI()
  {
    return "http://java.sun.com/jaxp/xpath/dom";
  }
  
  public PJConverter getPJConverter(Class targetClass)
  {
    if (NodeOverNodeInfo.class.isAssignableFrom(targetClass)) {
      new PJConverter()
      {
        public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
          throws XPathException
        {
          return convertXPathValueToObject(value, targetClass, context);
        }
      };
    }
    if (NodeList.class.isAssignableFrom(targetClass)) {
      new PJConverter()
      {
        public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
          throws XPathException
        {
          return convertXPathValueToObject(value, targetClass, context);
        }
      };
    }
    return null;
  }
  
  public JPConverter getJPConverter(Class targetClass)
  {
    if (NodeOverNodeInfo.class.isAssignableFrom(targetClass)) {
      new JPConverter()
      {
        public ValueRepresentation convert(Object object, XPathContext context)
          throws XPathException
        {
          return convertObjectToXPathValue(object, context.getConfiguration());
        }
        
        public ItemType getItemType()
        {
          return AnyNodeTest.getInstance();
        }
      };
    }
    return null;
  }
  
  public PJConverter getNodeListCreator(Object node)
  {
    return null;
  }
  
  public boolean isRecognizedNode(Object object)
  {
    return object instanceof NodeOverNodeInfo;
  }
  
  public boolean isRecognizedNodeClass(Class nodeClass)
  {
    return NodeOverNodeInfo.class.isAssignableFrom(nodeClass);
  }
  
  private boolean isRecognizedNodeListClass(Class nodeClass)
  {
    return NodeList.class.isAssignableFrom(nodeClass);
  }
  
  public Receiver getDocumentBuilder(Result result)
    throws XPathException
  {
    return null;
  }
  
  public boolean sendSource(Source source, Receiver receiver, PipelineConfiguration pipe)
    throws XPathException
  {
    if ((source instanceof DOMSource))
    {
      Node startNode = ((DOMSource)source).getNode();
      if ((startNode instanceof NodeOverNodeInfo))
      {
        NodeInfo base = ((NodeOverNodeInfo)startNode).getUnderlyingNodeInfo();
        Sender driver = new Sender(pipe);
        driver.send(base, receiver);
        return true;
      }
    }
    return false;
  }
  
  public NodeInfo unravel(Source source, Configuration config)
  {
    if ((source instanceof DOMSource))
    {
      Node dsnode = ((DOMSource)source).getNode();
      if ((dsnode instanceof NodeOverNodeInfo)) {
        return ((NodeOverNodeInfo)dsnode).getUnderlyingNodeInfo();
      }
    }
    return null;
  }
  
  public ValueRepresentation convertObjectToXPathValue(Object object, Configuration config)
    throws XPathException
  {
    if ((object instanceof NodeList))
    {
      NodeList list = (NodeList)object;
      int len = list.getLength();
      if (len == 0) {
        return null;
      }
      NodeInfo[] nodes = new NodeInfo[len];
      for (int i = 0; i < len; i++) {
        if ((list.item(i) instanceof NodeOverNodeInfo)) {
          nodes[i] = ((NodeOverNodeInfo)list.item(i)).getUnderlyingNodeInfo();
        } else {
          return null;
        }
      }
      return new SequenceExtent(nodes);
    }
    if ((object instanceof NodeOverNodeInfo)) {
      return ((NodeOverNodeInfo)object).getUnderlyingNodeInfo();
    }
    return null;
  }
  
  public Object convertXPathValueToObject(ValueRepresentation value, Object targetClass, XPathContext context)
    throws XPathException
  {
    Class target = (Class)targetClass;
    boolean requireDOM = (Node.class.isAssignableFrom(target)) || (target == NodeList.class) || ((target.isArray()) && (Node.class.isAssignableFrom(target.getComponentType())));
    
    boolean allowDOM = (target == Object.class) || (target.isAssignableFrom(ArrayList.class)) || (target.isAssignableFrom(HashSet.class)) || ((target.isArray()) && (target.getComponentType() == Object.class));
    if ((!requireDOM) && (!allowDOM)) {
      return null;
    }
    List nodes = new ArrayList(20);
    
    SequenceIterator iter = Value.asIterator(value);
    for (;;)
    {
      Item item = iter.next();
      if (item == null) {
        break;
      }
      if ((item instanceof VirtualNode))
      {
        Object o = ((VirtualNode)item).getUnderlyingNode();
        if ((o instanceof Node))
        {
          nodes.add(o);
        }
        else if (requireDOM)
        {
          XPathException err = new XPathException("Extension function required class " + target.getName() + "; supplied value of class " + item.getClass().getName() + " could not be converted");
          
          throw err;
        }
      }
      else if (requireDOM)
      {
        if ((item instanceof NodeInfo))
        {
          nodes.add(NodeOverNodeInfo.wrap((NodeInfo)item));
        }
        else
        {
          XPathException err = new XPathException("Extension function required class " + target.getName() + "; supplied value of class " + item.getClass().getName() + " could not be converted");
          
          throw err;
        }
      }
      else
      {
        return null;
      }
    }
    if ((nodes.size() == 0) && (!requireDOM)) {
      return null;
    }
    if (Node.class.isAssignableFrom(target))
    {
      if (nodes.size() != 1)
      {
        XPathException err = new XPathException("Extension function requires a single DOM Node; supplied value contains " + nodes.size() + " nodes");
        
        throw err;
      }
      return nodes.get(0);
    }
    if (target == NodeList.class) {
      return new DOMNodeList(nodes);
    }
    if ((target.isArray()) && (target.getComponentType() == Node.class))
    {
      Node[] array = new Node[nodes.size()];
      nodes.toArray(array);
      return array;
    }
    if (target.isAssignableFrom(ArrayList.class)) {
      return nodes;
    }
    if (target.isAssignableFrom(HashSet.class)) {
      return new HashSet(nodes);
    }
    return null;
  }
  
  public DocumentInfo wrapDocument(Object node, String baseURI, Configuration config)
  {
    DocumentInfo doc = null;
    if ((node instanceof DocumentOverNodeInfo)) {
      doc = (DocumentInfo)((DocumentOverNodeInfo)node).getUnderlyingNodeInfo();
    } else if ((node instanceof NodeOverNodeInfo)) {
      doc = ((NodeOverNodeInfo)node).getUnderlyingNodeInfo().getDocumentRoot();
    }
    if (doc == null) {
      throw new IllegalArgumentException("Unknown node class " + node.getClass());
    }
    if (doc.getConfiguration() != config) {
      throw new IllegalArgumentException("Externally-supplied DOM envelope belong to the wrong Configuration");
    }
    return doc;
  }
  
  public NodeInfo wrapNode(DocumentInfo document, Object node)
  {
    if ((node instanceof NodeOverNodeInfo)) {
      return ((NodeOverNodeInfo)node).getUnderlyingNodeInfo();
    }
    throw new IllegalArgumentException("Unknown node class " + node.getClass());
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMEnvelope
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import org.w3c.dom.DOMException;

public class DOMExceptionImpl
  extends DOMException
{
  public short code;
  public static final short INVALID_STATE_ERR = 11;
  public static final short SYNTAX_ERR = 12;
  public static final short INVALID_MODIFICATION_ERR = 13;
  public static final short NAMESPACE_ERR = 14;
  public static final short INVALID_ACCESS_ERR = 15;
  
  public DOMExceptionImpl(short code, String message)
  {
    super(code, message);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMExceptionImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;

class DOMImplementationImpl
  implements DOMImplementation
{
  public boolean hasFeature(String feature, String version)
  {
    return ((feature.equalsIgnoreCase("XML")) || (feature.equalsIgnoreCase("Core"))) && ((version == null) || (version.length() == 0) || (version.equals("3.0")) || (version.equals("2.0")) || (version.equals("1.0")));
  }
  
  public Object getFeature(String feature, String version)
  {
    return null;
  }
  
  public DocumentType createDocumentType(String qualifiedName, String publicId, String systemId)
    throws DOMException
  {
    NodeOverNodeInfo.disallowUpdate();
    return null;
  }
  
  public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype)
    throws DOMException
  {
    NodeOverNodeInfo.disallowUpdate();
    return null;
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMImplementationImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import java.util.ArrayList;
import java.util.List;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.VirtualNode;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceExtent;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public final class DOMNodeList
  implements NodeList
{
  private List sequence;
  
  public DOMNodeList(List extent)
  {
    sequence = extent;
  }
  
  public static DOMNodeList checkAndMake(SequenceExtent extent)
    throws XPathException
  {
    SequenceIterator it = extent.iterate();
    List list = new ArrayList(extent.getLength());
    for (;;)
    {
      Item next = it.next();
      if (next == null) {
        break;
      }
      Object o = next;
      if (!(o instanceof NodeInfo)) {
        throw new XPathException("Supplied sequence contains an item that is not a Saxon NodeInfo");
      }
      if ((o instanceof VirtualNode))
      {
        o = ((VirtualNode)o).getUnderlyingNode();
        if (!(o instanceof Node)) {
          throw new XPathException("Supplied sequence contains an item that is not a wrapper around a DOM Node");
        }
        list.add(o);
      }
    }
    return new DOMNodeList(list);
  }
  
  public int getLength()
  {
    return sequence.size();
  }
  
  public Node item(int index)
  {
    if ((index < 0) || (index >= sequence.size())) {
      return null;
    }
    return (Node)sequence.get(index);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMNodeList
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.Value;

class DOMObjectModel$1
  extends PJConverter
{
  private final DOMObjectModel this$0;
  
  DOMObjectModel$1(DOMObjectModel paramDOMObjectModel)
    throws XPathException
  {}
  
  public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
    throws XPathException
  {
    return DOMObjectModel.access$000(this$0, Value.asValue(value), targetClass, context);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.Value;

class DOMObjectModel$2
  extends PJConverter
{
  private final DOMObjectModel this$0;
  
  DOMObjectModel$2(DOMObjectModel paramDOMObjectModel)
    throws XPathException
  {}
  
  public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
    throws XPathException
  {
    return DOMObjectModel.access$000(this$0, Value.asValue(value), targetClass, context);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.JPConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.pattern.AnyNodeTest;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import org.w3c.dom.Node;

class DOMObjectModel$3
  extends JPConverter
{
  private final DOMObjectModel this$0;
  
  DOMObjectModel$3(DOMObjectModel paramDOMObjectModel)
    throws XPathException
  {}
  
  public ValueRepresentation convert(Object obj, XPathContext context)
    throws XPathException
  {
    return DOMObjectModel.access$100(this$0, (Node)obj, context.getConfiguration());
  }
  
  public ItemType getItemType()
  {
    return AnyNodeTest.getInstance();
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.Configuration;
import net.sf.saxon.expr.JPConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.pattern.AnyNodeTest;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import net.sf.saxon.value.SequenceExtent;
import org.w3c.dom.NodeList;

class DOMObjectModel$4
  extends JPConverter
{
  private final DOMObjectModel this$0;
  
  DOMObjectModel$4(DOMObjectModel paramDOMObjectModel)
    throws XPathException
  {}
  
  public ValueRepresentation convert(Object obj, XPathContext context)
    throws XPathException
  {
    Configuration config = context.getConfiguration();
    NodeList list = (NodeList)obj;
    int len = list.getLength();
    NodeInfo[] nodes = new NodeInfo[len];
    for (int i = 0; i < len; i++) {
      nodes[i] = DOMObjectModel.access$100(this$0, list.item(i), config);
    }
    return new SequenceExtent(nodes);
  }
  
  public ItemType getItemType()
  {
    return AnyNodeTest.getInstance();
  }
  
  public int getCardinality()
  {
    return 57344;
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel.4
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.Value;

class DOMObjectModel$5
  extends PJConverter
{
  private final DOMObjectModel this$0;
  
  DOMObjectModel$5(DOMObjectModel paramDOMObjectModel)
    throws XPathException
  {}
  
  public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
    throws XPathException
  {
    return DOMObjectModel.access$000(this$0, Value.asValue(value), DOMObjectModel.class$org$w3c$dom$NodeList == null ? (DOMObjectModel.class$org$w3c$dom$NodeList = DOMObjectModel.class$("org.w3c.dom.NodeList")) : DOMObjectModel.class$org$w3c$dom$NodeList, context);
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel.5
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import java.util.Iterator;
import javax.xml.namespace.NamespaceContext;

class DOMObjectModel$6
  implements NamespaceContext
{
  public String getNamespaceURI(String prefix)
  {
    return prefix.equals("ext") ? "java:net.sf.saxon.dom.DOMObjectModel" : null;
  }
  
  public String getPrefix(String namespaceURI)
  {
    return null;
  }
  
  public Iterator getPrefixes(String namespaceURI)
  {
    return null;
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel.6
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import java.io.PrintStream;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.xpath.XPathConstants;
import net.sf.saxon.Configuration;
import net.sf.saxon.event.PipelineConfiguration;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.expr.JPConverter;
import net.sf.saxon.expr.PJConverter;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.om.DocumentInfo;
import net.sf.saxon.om.ExternalObjectModel;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.om.ValueRepresentation;
import net.sf.saxon.om.VirtualNode;
import net.sf.saxon.pattern.AnyNodeTest;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import net.sf.saxon.value.SequenceExtent;
import net.sf.saxon.value.Value;
import net.sf.saxon.xpath.XPathEvaluator;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class DOMObjectModel
  implements ExternalObjectModel, Serializable
{
  private static DOMObjectModel THE_INSTANCE = new DOMObjectModel();
  private static Method nextSiblingMethod;
  
  public static DOMObjectModel getInstance()
  {
    return THE_INSTANCE;
  }
  
  private static boolean nextSiblingMethodUnavailable = false;
  
  static
  {
    try
    {
      nextSiblingMethod = DOMResult.class.getMethod("getNextSibling", new Class[0]);
    }
    catch (NoSuchMethodException err)
    {
      nextSiblingMethodUnavailable = true;
    }
  }
  
  public String getIdentifyingURI()
  {
    return "http://java.sun.com/jaxp/xpath/dom";
  }
  
  public PJConverter getPJConverter(Class targetClass)
  {
    if ((Node.class.isAssignableFrom(targetClass)) && (!NodeOverNodeInfo.class.isAssignableFrom(targetClass))) {
      new PJConverter()
      {
        public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
          throws XPathException
        {
          return DOMObjectModel.this.convertXPathValueToObject(Value.asValue(value), targetClass, context);
        }
      };
    }
    if (NodeList.class == targetClass) {
      new PJConverter()
      {
        public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
          throws XPathException
        {
          return DOMObjectModel.this.convertXPathValueToObject(Value.asValue(value), targetClass, context);
        }
      };
    }
    return null;
  }
  
  public JPConverter getJPConverter(Class targetClass)
  {
    if ((Node.class.isAssignableFrom(targetClass)) && (!NodeOverNodeInfo.class.isAssignableFrom(targetClass))) {
      new JPConverter()
      {
        public ValueRepresentation convert(Object obj, XPathContext context)
          throws XPathException
        {
          return DOMObjectModel.this.wrapOrUnwrapNode((Node)obj, context.getConfiguration());
        }
        
        public ItemType getItemType()
        {
          return AnyNodeTest.getInstance();
        }
      };
    }
    if (NodeList.class.isAssignableFrom(targetClass)) {
      new JPConverter()
      {
        public ValueRepresentation convert(Object obj, XPathContext context)
          throws XPathException
        {
          Configuration config = context.getConfiguration();
          NodeList list = (NodeList)obj;
          int len = list.getLength();
          NodeInfo[] nodes = new NodeInfo[len];
          for (int i = 0; i < len; i++) {
            nodes[i] = DOMObjectModel.this.wrapOrUnwrapNode(list.item(i), config);
          }
          return new SequenceExtent(nodes);
        }
        
        public ItemType getItemType()
        {
          return AnyNodeTest.getInstance();
        }
        
        public int getCardinality()
        {
          return 57344;
        }
      };
    }
    return null;
  }
  
  public PJConverter getNodeListCreator(Object node)
  {
    if ((node == null) || ((node instanceof Node)) || ((node instanceof DOMSource)) || (((node instanceof VirtualNode)) && ((((VirtualNode)node).getUnderlyingNode() instanceof Node)))) {
      new PJConverter()
      {
        public Object convert(ValueRepresentation value, Class targetClass, XPathContext context)
          throws XPathException
        {
          return DOMObjectModel.this.convertXPathValueToObject(Value.asValue(value), NodeList.class, context);
        }
      };
    }
    return null;
  }
  
  public Receiver getDocumentBuilder(Result result)
    throws XPathException
  {
    if ((result instanceof DOMResult))
    {
      DOMWriter emitter = new DOMWriter();
      Node root = ((DOMResult)result).getNode();
      
      Node nextSibling = null;
      if (!nextSiblingMethodUnavailable) {
        try
        {
          nextSibling = (Node)nextSiblingMethod.invoke(result, new Object[0]);
        }
        catch (IllegalAccessException err) {}catch (InvocationTargetException err) {}
      }
      if (root == null)
      {
        try
        {
          DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
          Document out = docBuilder.newDocument();
          ((DOMResult)result).setNode(out);
          emitter.setNode(out);
        }
        catch (ParserConfigurationException e)
        {
          throw new XPathException(e);
        }
      }
      else
      {
        emitter.setNode(root);
        emitter.setNextSibling(nextSibling);
      }
      return emitter;
    }
    return null;
  }
  
  public boolean sendSource(Source source, Receiver receiver, PipelineConfiguration pipe)
    throws XPathException
  {
    if ((source instanceof DOMSource))
    {
      Node startNode = ((DOMSource)source).getNode();
      DOMSender driver = new DOMSender();
      driver.setStartNode(startNode);
      driver.setReceiver(receiver);
      driver.setPipelineConfiguration(pipe);
      driver.setSystemId(source.getSystemId());
      driver.send();
      return true;
    }
    return false;
  }
  
  public NodeInfo unravel(Source source, Configuration config)
  {
    if ((source instanceof DOMSource))
    {
      Node dsnode = ((DOMSource)source).getNode();
      if (!(dsnode instanceof NodeOverNodeInfo))
      {
        Document dom;
        Document dom;
        if (dsnode.getNodeType() == 9) {
          dom = (Document)dsnode;
        } else {
          dom = dsnode.getOwnerDocument();
        }
        DocumentWrapper docWrapper = new DocumentWrapper(dom, source.getSystemId(), config);
        return docWrapper.wrap(dsnode);
      }
    }
    return null;
  }
  
  private NodeInfo wrapOrUnwrapNode(Node node, Configuration config)
    throws XPathException
  {
    if ((node instanceof NodeOverNodeInfo)) {
      return ((NodeOverNodeInfo)node).getUnderlyingNodeInfo();
    }
    DocumentInfo doc = wrapDocument(node, "", config);
    return wrapNode(doc, node);
  }
  
  private Object convertXPathValueToObject(Value value, Object targetClass, XPathContext context)
    throws XPathException
  {
    Class target = (Class)targetClass;
    boolean requireDOM = (Node.class.isAssignableFrom(target)) || (target == NodeList.class) || ((target.isArray()) && (Node.class.isAssignableFrom(target.getComponentType())));
    
    boolean allowDOM = (target == Object.class) || (target.isAssignableFrom(ArrayList.class)) || (target.isAssignableFrom(HashSet.class)) || ((target.isArray()) && (target.getComponentType() == Object.class));
    if ((!requireDOM) && (!allowDOM)) {
      return null;
    }
    List nodes = new ArrayList(20);
    
    SequenceIterator iter = value.iterate();
    for (;;)
    {
      Item item = iter.next();
      if (item == null) {
        break;
      }
      if ((item instanceof VirtualNode))
      {
        Object o = ((VirtualNode)item).getUnderlyingNode();
        if ((o instanceof Node))
        {
          nodes.add(o);
        }
        else if (requireDOM)
        {
          XPathException err = new XPathException("Extension function required class " + target.getName() + "; supplied value of class " + item.getClass().getName() + " could not be converted");
          
          err.setXPathContext(context);
          throw err;
        }
      }
      else if (requireDOM)
      {
        if ((item instanceof NodeInfo))
        {
          nodes.add(NodeOverNodeInfo.wrap((NodeInfo)item));
        }
        else
        {
          XPathException err = new XPathException("Extension function required class " + target.getName() + "; supplied value of class " + item.getClass().getName() + " could not be converted");
          
          err.setXPathContext(context);
          throw err;
        }
      }
      else
      {
        return null;
      }
    }
    if ((nodes.isEmpty()) && (!requireDOM)) {
      return null;
    }
    if (Node.class.isAssignableFrom(target))
    {
      if (nodes.size() != 1)
      {
        XPathException err = new XPathException("Extension function requires a single DOM Node; supplied value contains " + nodes.size() + " nodes");
        
        err.setXPathContext(context);
        throw err;
      }
      return nodes.get(0);
    }
    if (target == NodeList.class) {
      return new DOMNodeList(nodes);
    }
    if ((target.isArray()) && (target.getComponentType() == Node.class))
    {
      Node[] array = new Node[nodes.size()];
      nodes.toArray(array);
      return array;
    }
    if (target.isAssignableFrom(ArrayList.class)) {
      return nodes;
    }
    if (target.isAssignableFrom(HashSet.class)) {
      return new HashSet(nodes);
    }
    return null;
  }
  
  private DocumentInfo wrapDocument(Object node, String baseURI, Configuration config)
  {
    if ((node instanceof DocumentOverNodeInfo)) {
      return (DocumentInfo)((DocumentOverNodeInfo)node).getUnderlyingNodeInfo();
    }
    if ((node instanceof NodeOverNodeInfo)) {
      return ((NodeOverNodeInfo)node).getUnderlyingNodeInfo().getDocumentRoot();
    }
    if ((node instanceof Node))
    {
      if (((Node)node).getNodeType() == 9)
      {
        Document doc = (Document)node;
        return new DocumentWrapper(doc, baseURI, config);
      }
      if (((Node)node).getNodeType() == 11)
      {
        DocumentFragment doc = (DocumentFragment)node;
        return new DocumentWrapper(doc, baseURI, config);
      }
      Document doc = ((Node)node).getOwnerDocument();
      return new DocumentWrapper(doc, baseURI, config);
    }
    throw new IllegalArgumentException("Unknown node class " + node.getClass());
  }
  
  private NodeInfo wrapNode(DocumentInfo document, Object node)
  {
    return ((DocumentWrapper)document).wrap((Node)node);
  }
  
  public static void main(String[] args)
    throws Exception
  {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder db = factory.newDocumentBuilder();
    Document doc = db.newDocument();
    XPathEvaluator xpe = new XPathEvaluator();
    String exp = "ext:sortArrayToNodeList(('fred', 'jane', 'anne', 'sue'))";
    xpe.setNamespaceContext(new NamespaceContext()
    {
      public String getNamespaceURI(String prefix)
      {
        return prefix.equals("ext") ? "java:net.sf.saxon.dom.DOMObjectModel" : null;
      }
      
      public String getPrefix(String namespaceURI)
      {
        return null;
      }
      
      public Iterator getPrefixes(String namespaceURI)
      {
        return null;
      }
    });
    NodeList isList = (NodeList)xpe.evaluate(exp, doc, XPathConstants.NODESET);
    System.err.println("length " + isList.getLength());
  }
  
  public static NodeList sortArrayToNodeList(Value source)
    throws Exception
  {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder db = factory.newDocumentBuilder();
    Document doc = db.newDocument();
    String[] items = new String[source.getLength()];
    for (int i = 0; i < source.getLength(); i++) {
      items[i] = source.itemAt(i).getStringValue();
    }
    Arrays.sort(items);
    List list = new ArrayList();
    for (int i = 0; i < items.length; i++) {
      list.add(doc.createTextNode(items[i]));
    }
    DOMNodeList resultSet = new DOMNodeList(list);
    return resultSet;
  }
}

/* Location:
 * Qualified Name:     net.sf.saxon.dom.DOMObjectModel
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package net.sf.saxon.dom;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import net.sf.saxon.Configuration;
import net.sf.saxon.event.PipelineConfiguration;
import net.sf.saxon.event.Receiver;
import net.sf.saxon.event.SaxonLocator;
import net.sf.saxon.event.SourceLocationProvider;
import net.sf.saxon.om.NameChecker;
import net.sf.saxon.om.NamePool;
import net.sf.saxon.trans.XPathException;
import org.w3c.dom.Attr;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Comment;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.No
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd