1 22 23 package org.xquark.mapper.mapping; 24 25 import org.xml.sax.SAXException ; 26 import org.xquark.schema.*; 27 import org.xquark.xpath.NodeKind; 28 import org.xquark.xpath.XNode; 29 30 35 public class BuilderMappingContext extends SchemaContext 36 { 37 private static final String RCSRevision = "$Revision: 1.1 $"; 38 private static final String RCSName = "$Name: $"; 39 protected MappingFactory factory; 43 protected RepositoryMapping mapping; 44 protected MappingNode wNode; 45 protected XNode pattern = new XNode(); 46 47 51 public BuilderMappingContext(MappingFactory factory) 52 { 53 super(factory.getSchemaManager(), factory.getSchemaLocator()); 54 this.factory = factory; 55 mapping = (RepositoryMapping)factory.getTree(); 56 wNode = (MappingNode)mapping.getRoot(); 57 } 58 59 63 67 public void createElementMapping(ElementDeclaration decl, boolean typeMapping) 68 { 69 factory.createElementNode(wNode, decl, typeMapping); 70 push(decl); } 73 74 75 public org.xquark.schema.Type createTypeMapping(String namespace, String localName) throws SAXException 76 { 77 org.xquark.schema.Type type = factory.findType(namespace, localName); 78 wNode = factory.createTypeNode(type); 79 return type; 80 } 81 82 83 public void popType() 84 { 85 wNode = (MappingNode)mapping.getRoot(); 86 } 87 88 89 public void register(Mapping mapping) 90 { 91 SchemaComponent comp = mapping.getSchemaComponent(); 92 if (comp instanceof AttributeDeclaration) 93 this.mapping.register((MappingNode)factory.createNamedNodeIfNotExist(wNode, 94 comp.getNamespace(), 95 comp.getName(), 96 NodeKind.ATTRIBUTE), mapping); 97 else this.mapping.register(wNode, mapping); 99 } 100 101 105 public final void push(ElementDeclaration decl) 106 { 107 super.push(decl); 108 pattern.set(decl.getNamespace(), decl.getName(), NodeKind.ELEMENT); 109 wNode = (MappingNode)wNode.getChild(pattern); 110 } 111 112 public final ElementDeclaration pop() 113 { 114 ElementDeclaration decl = super.pop(); 115 wNode = (MappingNode)wNode.getParent(); 116 return decl; 117 } 118 119 122 MappingNode getCurrentNode() { 123 return wNode; 124 } 125 126 } 127 | Popular Tags |