} else if (obj instanceof Object[]) { boolean createNodeSequence = true; Object[] array = (Object[])obj; for(int i = 0; i < array.length; i++) { if (!(array[i] instanceof NodeProxy)) createNodeSequence = false; } Sequence seq = null; if (createNodeSequence) seq = new AVLTreeNodeSet(); else seq = new ValueSequence(); for (int i = 0; i < array.length; i++) { seq.add((Item) javaObjectToXPath(array[i])); } return seq; } else return new JavaObjectValue(obj); }
Sequence seq = null; if (createNodeSequence) seq = new AVLTreeNodeSet(); else seq = new ValueSequence(); for (int i = 0; i < array.length; i++) { seq.add((Item) javaObjectToXPath(array[i])); } return seq; } else return new JavaObjectValue(obj); }
	public final static Sequence javaObjectToXPath(Object obj) throws XPathException {		if (obj == null)			return Sequence.EMPTY_SEQUENCE;		if (obj instanceof Sequence)			return (Sequence) obj;		else if (obj instanceof String)			return new StringValue((String) obj);		else if (obj instanceof Boolean)			return BooleanValue.valueOf(((Boolean) obj).booleanValue());		else if (obj instanceof Float)			return new FloatValue(((Float) obj).floatValue());		else if (obj instanceof Double)			return new DoubleValue(((Double) obj).doubleValue());		else if (obj instanceof Short)			return new IntegerValue(((Short) obj).shortValue(), Type.SHORT);		else if (obj instanceof Integer)			return new IntegerValue(((Integer) obj).intValue(), Type.INT);		else if (obj instanceof Long)			return new IntegerValue(((Long) obj).longValue(), Type.LONG);		else if (obj instanceof List) {			boolean createNodeSequence = true;			Object next;			for (Iterator i = ((List) obj).iterator(); i.hasNext();) {				next = i.next();				if (!(next instanceof NodeProxy))					createNodeSequence = false;			}			Sequence seq = null;			if (createNodeSequence)				seq = new AVLTreeNodeSet();			else				seq = new ValueSequence();			for (Iterator i = ((List) obj).iterator(); i.hasNext();) {				seq.add((Item) javaObjectToXPath(i.next()));			}			return seq;		} else if (obj instanceof NodeList) {		    DOMStreamer streamer = DOMStreamerPool.getInstance().borrowDOMStreamer();		    try {		        MemTreeBuilder builder = new MemTreeBuilder();				builder.startDocument();                DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);                streamer.setContentHandler(receiver);                ValueSequence seq = new ValueSequence();                NodeList nl = (NodeList)obj;                int last = builder.getDocument().getLastNode();                for(int i = 0; i < nl.getLength(); i++) {                    Node n = nl.item(i);                    streamer.serialize(n, false);                    NodeImpl created = builder.getDocument().getNode(last + 1);                    seq.add(created);                    last = builder.getDocument().getLastNode();                }                return seq;            } catch (SAXException e) {                throw new XPathException("Failed to transform node into internal model: " + e.getMessage());            } finally {                DOMStreamerPool.getInstance().returnDOMStreamer(streamer);            }		} else if (obj instanceof Node) {		    DOMStreamer streamer = DOMStreamerPool.getInstance().borrowDOMStreamer();		    try {		        MemTreeBuilder builder = new MemTreeBuilder();				builder.startDocument();                DocumentBuilderReceiver receiver = new DocumentBuilderReceiver(builder);                streamer.setContentHandler(receiver);                streamer.serialize((Node)obj, false);                return builder.getDocument().getNode(1);            } catch (SAXException e) {                throw new XPathException("Failed to transform node into internal model: " + e.getMessage());            } finally {                DOMStreamerPool.getInstance().returnDOMStreamer(streamer);            }		} else if (obj instanceof Object[]) {			boolean createNodeSequence = true;			Object[] array = (Object[])obj;			for(int i = 0; i < array.length; i++) {				if (!(array[i] instanceof NodeProxy))					createNodeSequence = false;			}			Sequence seq = null;			if (createNodeSequence)				seq = new AVLTreeNodeSet();			else				seq = new ValueSequence();			for (int i = 0; i < array.length; i++) {				seq.add((Item) javaObjectToXPath(array[i]));			}			return seq;		} else			return new JavaObjectValue(obj);	}