1 22 23 package org.xquark.mapper.metadata; 24 25 import java.util.List ; 26 27 import org.xquark.mapper.RepositoryException; 28 import org.xquark.mapper.storage.PathIterator; 29 import org.xquark.schema.ElementDeclaration; 30 import org.xquark.xpath.*; 31 32 35 public class MetadataIterator implements PathIterator 36 { 37 private static final String RCSRevision = "$Revision: 1.1 $"; 38 private static final String RCSName = "$Name: $"; 39 40 44 46 protected PathSetFactory factory; 47 protected PathSet pathSet; 48 protected PathNode wNode; 49 protected XNode pattern = new XNode(); 50 51 55 public MetadataIterator(PathSetFactory factory) 56 { 57 this(factory, (PathNode)factory.getTree().getRoot()); 58 } 59 public MetadataIterator(PathSetFactory factory, PathNode root) 60 { 61 this.factory = factory; 62 pathSet = (PathSet)factory.getTree(); 63 wNode = root; 64 } 65 66 67 public void reset() 68 { 69 wNode = (PathNode)factory.getTree().getRoot(); 70 } 71 72 74 public List getDefaultMapping() 75 { 76 return pathSet.getCollection().getDefaultMappingList(); 77 } 78 79 81 public List getElementTableMappings(String namespace, String localName) 82 { 83 PathNode node = getChild(namespace, localName, NodeKind.ELEMENT); 84 if (node == null) 85 return null; 86 else 87 return node.getMapping().getTableMappings(); 88 } 89 90 92 public List getElementColumnMappings(String namespace, String localName) 93 { 94 PathNode node = getChild(namespace, localName, NodeKind.ELEMENT); 95 if (node == null) 96 return null; else 98 return node.getMapping().getColumnMappings(); 99 } 100 101 103 public List getAttributeTableMappings(String namespace, String localName) 104 { 105 PathNode node = getChild(namespace, localName, NodeKind.ATTRIBUTE); 106 if (node == null) 107 return null; else 109 return node.getMapping().getTableMappings(); 110 } 111 112 114 public List getAttributeColumnMappings(String namespace, String localName) 115 { 116 PathNode node = getChild(namespace, localName, NodeKind.ATTRIBUTE); 117 if (node == null) 118 return null; else 120 return node.getMapping().getColumnMappings(); 121 } 122 123 125 public PathNode getChild(String namespace, String localName, byte type) 126 { 127 pattern.set(namespace, localName, type); 128 return (PathNode)wNode.getChild(pattern); 129 } 130 131 133 public PathMetadata getPathMetadata(short pid) 134 throws RepositoryException 135 { 136 return (PathNode)pathSet.get(pid); 137 } 138 139 public PathNode getPathNode(short pid) 140 throws RepositoryException 141 { 142 return (PathNode)pathSet.get(pid); 143 } 144 145 public String getNameSpace() 146 { 147 return wNode.getNamespace(); 148 } 149 150 public String getLocalName() 151 { 152 return wNode.getLocalName(); 153 } 154 155 public ElementDeclaration getElementDeclaration() 156 { 157 return (ElementDeclaration)wNode.getDeclaration(); 158 } 159 160 161 public StoragePathMetadata createNode(String namespace, String localName, byte type) 162 throws RepositoryException 163 { 164 PathNode node; 165 try { 166 node = (PathNode)factory.createNamedNodeIfNotExist(wNode, namespace, localName, type); } 168 catch (XTreeRuntimeException e) 169 { 170 if (e.getException() instanceof RepositoryException) 171 throw (RepositoryException)e.getException(); 172 XNode parser = new XNode(namespace, localName, type); 173 throw new RepositoryException(RepositoryException.DATA_LOSS, 174 "Error while creating new path " + wNode.getLocation() + "/" + parser.getAbbreviatedSyntax() 175 + " in metadata.", e.getException()); 176 } 177 178 return node; } 180 181 182 public StoragePathMetadata push(String namespace, String localName) throws RepositoryException 183 { 184 return wNode = (PathNode)createNode(namespace, localName, NodeKind.ELEMENT); 185 } 186 187 188 public PathMetadata push(short pid) 189 throws RepositoryException 190 { 191 return wNode = (PathNode)pathSet.get(pid); 192 } 193 194 195 public PathMetadata push(PathNode node) 196 { 197 return wNode = node; 198 } 199 200 201 public StoragePathMetadata pop() 202 { 203 PathNode leftNode = wNode; 204 wNode = (PathNode)wNode.getParent(); 205 if (wNode == null) 206 wNode = leftNode; 207 return leftNode; 209 } 210 211 214 public PathExpr getLocation() 215 { 216 return wNode.getLocation(); 217 } 218 219 public StoragePathMetadata getStoragePathMetadata() 220 { 221 return wNode; 222 } 223 224 public PathMetadata getPathMetadata() 225 { 226 return wNode; 227 } 228 229 public PathNode getPathNode() 230 { 231 return wNode; 232 } 233 } 234 | Popular Tags |