1 22 23 package org.xquark.mapper.mapping; 24 25 import org.xquark.mapper.RepositoryException; 26 import org.xquark.mapper.metadata.StoragePathMetadata; 27 import org.xquark.mapper.storage.PathIterator; 28 import org.xquark.xpath.NodeKind; 29 import org.xquark.xpath.PathExpr; 30 import org.xquark.xpath.XNode; 31 32 36 public class MappingIterator implements PathIterator 37 { 38 private static final String RCSRevision = "$Revision: 1.1 $"; 39 private static final String RCSName = "$Name: $"; 40 41 45 47 private RepositoryMapping mapping; 48 private MappingNode wNode; 49 private XNode pattern = new XNode(); 50 private int extraPop; 51 52 56 public MappingIterator(RepositoryMapping mapping) 57 { 58 this.mapping = mapping; 59 reset(); 60 } 61 62 public void reset() 63 { 64 wNode = (MappingNode)mapping.getRoot(); 65 extraPop = 0; 66 } 67 68 69 public StoragePathMetadata createNode(String namespace, String localName, byte type) throws RepositoryException 70 { 71 return getChild(namespace, localName, type); 72 } 73 74 75 public StoragePathMetadata push(String namespace, String localName) throws RepositoryException 76 { 77 MappingNode node = null; 78 if ((extraPop > 0) || ((node = getChild(namespace, localName, NodeKind.ELEMENT)) == null)) 79 extraPop++; 80 else 81 wNode = node; 82 return node; 83 } 84 85 87 private MappingNode getChild(String namespace, String localName, byte type) 88 { 89 pattern.set(namespace, localName, type); 90 return (MappingNode)wNode.getChild(pattern); 91 } 92 93 94 public StoragePathMetadata pop() 95 { 96 MappingNode leftNode = wNode; 97 if (extraPop == 0) 98 wNode = (MappingNode)wNode.getParent(); 99 else 100 { 101 extraPop--; 102 leftNode = null; 103 } 104 return leftNode; 105 } 106 107 110 public PathExpr getLocation() 111 { 112 return wNode.getLocation(); 113 } 114 115 public StoragePathMetadata getStoragePathMetadata() 116 { 117 if (extraPop == 0) 118 return wNode; 119 else 120 return null; 121 } 122 } 123 | Popular Tags |