1 22 23 package org.xquark.xpath.schema; 24 25 26 import java.util.Iterator ; 27 28 import org.xquark.schema.ComplexType; 29 import org.xquark.schema.Declaration; 30 import org.xquark.schema.Schema; 31 import org.xquark.xpath.*; 32 33 37 public class SchemaTreeBuilder extends TypedXTreeBuilder 38 { 39 private static final String RCSRevision = "$Revision: 1.1 $"; 40 private static final String RCSName = "$Name: $"; 41 public XTreeNode allocateNode(XTreeNode parent, String namespace, String localName, byte type) 42 { 43 return new SchemaNode(tree, (SchemaNode)parent, namespace, localName, type); 44 } 45 public XTreeNode allocateNode(XTreeNode parent, Declaration decl) 46 { 47 return new SchemaNode(tree, (SchemaNode)parent, decl); 48 } 49 50 public XTree allocateTree() 51 { 52 return new XTree(); 53 } 54 55 private void expand(TypedXTreeNode node) 56 { 57 if (node.getDeclaration().getType() instanceof ComplexType) 58 { 59 ComplexType type = (ComplexType)node.getDeclaration().getType(); 60 Declaration decl = null; 61 62 Iterator it = type.getAttributeDeclarations().iterator(); 64 while(it.hasNext()) 65 { 66 decl = (Declaration) it.next(); 67 createNamedNode(node, decl.getNamespace(), decl.getName(), NodeKind.ATTRIBUTE); 68 } 69 70 it = type.getElementDeclarations().iterator(); 72 while(it.hasNext()) 73 { 74 decl = (Declaration) it.next(); 75 expand((SchemaNode)createNamedNode(node, decl.getNamespace(), decl.getName(), NodeKind.ELEMENT)); 76 } 77 } 78 } 79 public void expandSchemaTree(Schema schema) 80 { 81 Iterator it = schema.getElementDeclarations().iterator(); 82 83 while(it.hasNext()) 84 { expand(createTypedNode(tree.getRoot(), (Declaration)it.next())); 86 } 87 } 88 } 89 | Popular Tags |