1 22 23 package org.xquark.schema.loader; 24 25 import org.xml.sax.Attributes ; 26 import org.xml.sax.SAXException ; 27 import org.xquark.schema.*; 28 import org.xquark.util.DefaultElementHandler; 29 import org.xquark.util.ElementHandler; 30 31 class ElementTypeHandler extends DefaultElementHandler implements SchemaConstants 32 { 33 private static final String RCSRevision = "$Revision: 1.1 $"; 34 private static final String RCSName = "$Name: $"; 35 private Loader loader = null; 36 private ElementDeclaration decl; 37 38 ElementTypeHandler(Loader loader, ElementDeclaration decl) { 39 this.loader = loader; 40 this.decl = decl; 41 } 42 43 public ElementHandler startElement(String namespaceURI, String localName, Attributes atts) 44 throws SAXException 45 { 46 if ( namespaceURI.equals(XMLSCHEMA_URI) ) { 47 if ( !localName.equals(ANNOTATION_TAG) ) { 48 if ( decl instanceof ElementDeclarationRef ) { 49 String errCode = "src-element.2.2"; 50 String errMsg = "Error while processing localName -> " + localName; 51 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 52 } 53 } 54 55 if (localName.equals(COMPLEX_TYPE_TAG)) { 56 if (decl.getType() != null) { 57 String errCode = "src-element.3"; 58 String errMsg = "Error while processing localName -> " + localName; 59 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 60 } 61 ComplexType type = null; 62 try { 63 type = loader.buildComplexType(atts); 64 } 65 catch ( SchemaException se ) { 66 String errMsg = "Error while processing localName -> " + localName; 67 loader.reportLoadingError(errMsg, se); 68 } 69 decl.setType(type); 70 return new ComplexTypeHandler(loader, type, false, false); 71 } 72 73 else if (localName.equals(SIMPLE_TYPE_TAG)) { 74 if (decl.getType() != null) { 75 String errCode = "src-element.3"; 76 String errMsg = "Error while processing localName -> " + localName; 77 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 78 } 79 SimpleType type = null; 80 try { 81 type = loader.buildSimpleType(atts); 82 } 83 catch ( SchemaException se ) { 84 String errMsg = "Error while processing localName -> " + localName; 85 loader.reportLoadingError(errMsg, se); 86 } 87 decl.setType(type); 88 return new SimpleTypeHandler(loader, type, false, false); 89 } 90 91 else if ( localName.equals(KEY_TAG) || 92 localName.equals(KEYREF_TAG) || 93 localName.equals(UNIQUE_TAG) ) 94 { 95 IdentityConstraint identityConstraint = null; 96 try { 97 identityConstraint = loader.buildIdentityConstraint(atts, localName, decl); 98 decl.register(identityConstraint); 99 decl.getSchema().register(identityConstraint); 100 } 101 catch ( SchemaException se ) { 102 String errMsg = "Error while processing localName -> " + localName; 103 loader.reportLoadingError(errMsg, se); 104 } 105 return new IdentityConstraintHandler(loader, identityConstraint); 106 } 107 108 else if (localName.equals(ANNOTATION_TAG)) { 109 return new AnnotationHandler(); 110 } 111 } 112 113 loader.notifyUnknownElement(namespaceURI, localName); 114 return this; 115 } 116 } 117 118 | Popular Tags |