1 16 19 package com.sun.org.apache.xpath.internal.objects; 20 21 import com.sun.org.apache.xml.internal.dtm.Axis; 22 import com.sun.org.apache.xml.internal.dtm.DTM; 23 import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; 24 import com.sun.org.apache.xml.internal.dtm.DTMIterator; 25 import com.sun.org.apache.xpath.internal.XPathContext; 26 import com.sun.org.apache.xpath.internal.axes.OneStepIterator; 27 28 29 public class XObjectFactory 30 { 31 32 41 static public XObject create(Object val) 42 { 43 44 XObject result; 45 46 if (val instanceof XObject) 47 { 48 result = (XObject) val; 49 } 50 else if (val instanceof String ) 51 { 52 result = new XString((String ) val); 53 } 54 else if (val instanceof Boolean ) 55 { 56 result = new XBoolean((Boolean )val); 57 } 58 else if (val instanceof Double ) 59 { 60 result = new XNumber(((Double ) val)); 61 } 62 else 63 { 64 result = new XObject(val); 65 } 66 67 return result; 68 } 69 70 80 static public XObject create(Object val, XPathContext xctxt) 81 { 82 83 XObject result; 84 85 if (val instanceof XObject) 86 { 87 result = (XObject) val; 88 } 89 else if (val instanceof String ) 90 { 91 result = new XString((String ) val); 92 } 93 else if (val instanceof Boolean ) 94 { 95 result = new XBoolean((Boolean )val); 96 } 97 else if (val instanceof Number ) 98 { 99 result = new XNumber(((Number ) val)); 100 } 101 else if (val instanceof DTM) 102 { 103 DTM dtm = (DTM)val; 104 try 105 { 106 int dtmRoot = dtm.getDocument(); 107 DTMAxisIterator iter = dtm.getAxisIterator(Axis.SELF); 108 iter.setStartNode(dtmRoot); 109 DTMIterator iterator = new OneStepIterator(iter, Axis.SELF); 110 iterator.setRoot(dtmRoot, xctxt); 111 result = new XNodeSet(iterator); 112 } 113 catch(Exception ex) 114 { 115 throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(ex); 116 } 117 } 118 else if (val instanceof DTMAxisIterator) 119 { 120 DTMAxisIterator iter = (DTMAxisIterator)val; 121 try 122 { 123 DTMIterator iterator = new OneStepIterator(iter, Axis.SELF); 124 iterator.setRoot(iter.getStartNode(), xctxt); 125 result = new XNodeSet(iterator); 126 } 127 catch(Exception ex) 128 { 129 throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(ex); 130 } 131 } 132 else if (val instanceof DTMIterator) 133 { 134 result = new XNodeSet((DTMIterator) val); 135 } 136 else if (val instanceof org.w3c.dom.Node ) 139 { 140 result = new XNodeSetForDOM((org.w3c.dom.Node )val, xctxt); 141 } 142 else if (val instanceof org.w3c.dom.NodeList ) 145 { 146 result = new XNodeSetForDOM((org.w3c.dom.NodeList )val, xctxt); 147 } 148 else if (val instanceof org.w3c.dom.traversal.NodeIterator) 149 { 150 result = new XNodeSetForDOM((org.w3c.dom.traversal.NodeIterator)val, xctxt); 151 } 152 else 153 { 154 result = new XObject(val); 155 } 156 157 return result; 158 } 159 } 160 | Popular Tags |