1 22 23 package org.xquark.extractor.algebra; 24 25 import java.io.DataOutputStream ; 26 import java.util.List ; 27 28 import org.xquark.extractor.metadata.ExtractorMappingInfo; 29 import org.xquark.jdbc.typing.TypeMap; 30 import org.xquark.schema.SimpleType; 31 import org.xquark.xquery.parser.QName; 32 import org.xquark.xquery.parser.XQueryException; 33 import org.xquark.xquery.parser.XQueryExpression; 34 35 public final class MapItem implements Cloneable { 36 37 private static final String RCSRevision = "$Revision: 1.20 $"; 38 private static final String RCSName = "$Name: $"; 39 40 41 private String _path = null; 42 private QName _qName = null; 43 private String _itemName = null; 44 45 46 private Expression _relatedExpression = null; 47 48 private ExtractorMappingInfo _mappingInfo = null; 49 50 51 private List _children = null; 52 53 57 private List _childChildItems = null; 58 59 63 private long _partOf = 0; 64 65 66 public MapItem() 67 {} 68 69 public Object clone () throws CloneNotSupportedException 70 { 71 MapItem retVal = (MapItem)super.clone(); 72 retVal.setPath((getPath() == null) ? null : new String (getPath()) ); 73 try { 76 retVal.setQName((getQName() == null) ? null : new QName(getQName().getNameSpace(),getQName().getPrefixName(),getQName().getLocalName(),null, null)); 77 } catch (XQueryException xqe) { 78 throw new CloneNotSupportedException ("could not clone : " + retVal.getQName()); 79 } 80 retVal.setItemName((getItemName() == null) ? null : new String (getItemName()) ); 81 retVal.setRelatedExpression((getRelatedExpression() == null) ? null : (Expression)getRelatedExpression().clone()); 82 retVal.setChildren(AlgebraTools.clone(getChildren())); 83 return retVal; 84 } 85 86 public boolean equals(Object o) { 87 if (o == this) 88 return true; 89 if (!(o instanceof MapItem)) 90 return false; 91 92 MapItem p = (MapItem) o; 93 if ( ! getPath().equals(p.getPath())) 94 return false; 95 return true; 96 } 97 98 public MapItem (String path, QName qName,String itemName,List children) 99 { 100 _path = path; 101 _qName = qName; 102 _itemName = itemName; 103 _children = children; 104 105 } 106 107 public String getPath() 108 { 109 return _path; 110 } 111 112 public void setPath (String path) 113 { 114 _path = path; 115 } 116 117 public void setQName (QName qName) 118 { 119 _qName = qName; 120 } 121 122 public QName getQName() { 123 return _qName; 124 } 125 126 public String getElementName() { 127 if (null!=_qName) { 128 return _qName.getLocalName(); 129 } 130 else { 131 return null; 132 } 133 } 134 135 public String getNamespace() { 136 if (null!=_qName) { 137 return _qName.getNameSpace(); 138 } 139 else { 140 return null; 141 } 142 } 143 144 145 public String getItemName() 146 { 147 return _itemName; 148 } 149 150 public void setItemName (String itemName) 151 { 152 _itemName = itemName; 153 } 154 155 public Expression getRelatedExpression() 156 { 157 return _relatedExpression; 158 } 159 160 public void setRelatedExpression (Expression relatedExpression) 161 { 162 _relatedExpression = relatedExpression; 163 } 164 165 public boolean isLeafPath() 166 { 167 return null == _children; 168 } 169 170 public List getChildren() 171 { 172 return _children; 173 } 174 175 public void setChildren(List children) 176 { 177 _children = children; 178 } 179 180 public List getChildItemList() 181 { 182 return _childChildItems; 183 } 184 185 public void setChildItemLis(List childChildItemLis) 186 { 187 _childChildItems = childChildItemLis; 188 } 189 190 public String pprint () 191 { 192 char[] spaces = 193 (new String (" ")).toCharArray(); 194 StringBuffer retVal = new StringBuffer (); 195 196 retVal.append( _path); 197 if (_path.length()< 40) { 198 retVal.append(spaces, 0, 40 - _path.length()); 199 } 200 retVal.append("\t") ; 201 202 if (null != _qName) { 203 String qname = _qName.toString(); 204 retVal.append( qname); 205 if (qname.length()< 40) { 206 retVal.append(spaces, 0,40- qname.length()); 207 } 208 } 209 else { 210 retVal.append( spaces,0,40); 211 } 212 retVal.append("\t") ; 213 214 if (null != _itemName) { 215 retVal.append( _itemName); 216 if (_itemName.length()< 40) { 217 retVal.append(spaces, 0, 40 - _itemName.length()); 218 } 219 } 220 else { 221 retVal.append( spaces,0,40); 222 } 223 retVal.append("\t") ; 224 225 retVal.append(Long.toBinaryString(_partOf)); 226 retVal.append("\t") ; 227 228 if (null!=_children) { 229 retVal.append ("["); 230 for (int i = 0; i < _children.size(); i++) { 231 retVal.append(_children.get(i)); 232 retVal.append(",\t"); 233 } 234 retVal.append ("]"); 235 } 236 else { 237 retVal.append("[null]"); 238 } 239 240 return retVal.toString(); 241 }; 242 243 public void write(DataOutputStream dos) throws java.io.IOException 244 { 245 247 String newLine = System.getProperty("line.separator"); 248 249 dos.writeBytes("<MapItem>"); 250 dos.writeBytes(newLine); 251 if (null != _path) { 252 dos.writeBytes("<Path>"); 253 dos.writeBytes(_path); 254 dos.writeBytes("</Path>"); 255 dos.writeBytes(newLine); 256 } 257 258 if (null != _qName) { 259 dos.writeBytes("<ElementName>"); 260 dos.writeBytes(_qName.toString()); 261 dos.writeBytes("</ElementName>"); 262 dos.writeBytes(newLine); 263 } 264 265 if (null != _itemName) { 266 dos.writeBytes("<ItemName>"); 267 dos.writeBytes(_itemName); 268 dos.writeBytes("</ItemName>"); 269 dos.writeBytes(newLine); 270 } 271 272 if (null != _children) { 273 dos.writeBytes("<Children>"); 274 dos.writeBytes(newLine); 275 for (int i = 0; i < _children.size(); i++) { 276 dos.writeBytes("<Child>"); 277 dos.writeBytes((String )_children.get(i)); 278 dos.writeBytes("</Child>"); 279 dos.writeBytes(newLine); 280 } 281 dos.writeBytes("</Children>"); 282 dos.writeBytes(newLine); 283 } 284 285 dos.writeBytes("</MapItem>"); 286 dos.writeBytes(newLine); 287 288 } 290 291 292 293 private String fillUp (String str, int length) 294 { 295 return null; 296 } 297 298 public boolean isPartOf(long parts) 299 { 300 return (_partOf & parts) > 0 ; 301 } 302 public void participate (long parts) 303 { 304 _partOf = _partOf | parts; 305 } 306 public long getPart() 307 { 308 return _partOf; 309 } 310 public void setPart(long parts) 311 { 312 _partOf = parts; 313 } 314 315 319 public ExtractorMappingInfo getMappingInfo() { 320 return _mappingInfo; 321 } 322 public ExtractorMappingInfo getMappingInfo(TypeMap typeMap) throws XQueryException { 323 if (_mappingInfo == null) { 324 Expression algebraExpr = _relatedExpression; 325 if (algebraExpr instanceof RenameItem) 328 algebraExpr = ((RenameItem)algebraExpr).getOperand(); 329 330 if (algebraExpr instanceof AttributeExpression) 331 algebraExpr = ((AttributeExpression)algebraExpr).getUnderlyinExpr(); 332 333 if (algebraExpr instanceof Attribute) { 334 _mappingInfo = ((Attribute)algebraExpr).getAttribute().getMappingInfo(); 335 } 336 else { XQueryExpression xqExpr = _relatedExpression.getOrginalXExpr(); 338 if (xqExpr != null) { SimpleType sType = xqExpr.getQType().getSimpleType(); 340 if (sType != null) 341 _mappingInfo = new ExtractorMappingInfo(sType, typeMap); 342 } 343 } 344 } 345 if (_mappingInfo != null) 346 _mappingInfo.checkForExtraction(); 347 return _mappingInfo; 348 } 349 350 } 351 352 | Popular Tags |