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 ComplexTypeHandler 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 ComplexType type = null; 37 private boolean complexContent; 38 private boolean redefine; 39 40 ComplexTypeHandler(Loader loader, ComplexType type, boolean complexContent, boolean redefine) 41 throws SAXException 42 { 43 this.loader = loader; 44 this.type = type; 45 this.complexContent = complexContent; 46 this.redefine = redefine; 47 } 48 49 public ElementHandler startElement(String namespaceURI, String localName, Attributes atts) 50 throws SAXException 51 { 52 if ( namespaceURI.equals(XMLSCHEMA_URI) ) { 53 if ( complexContent ) { 55 if ( localName.equals(RESTRICTION_TAG) || localName.equals(EXTENSION_TAG) ) { 56 Type baseType = null; 57 try { 58 baseType = loader.getType(atts.getValue("", BASE_ATTR)); 59 } 60 catch ( SchemaException se ) { 61 String errMsg = "Error while processing localName -> " + localName; 62 loader.reportLoadingError(errMsg, se); 63 } 64 if ( redefine ) { 65 redefine = false; 66 if ( type.getName() == null || baseType == null || 67 !type.getName().equals(baseType.getName()) ) { 68 String errCode = "src-redefine.5"; 69 String errMsg = "Error while processing localName -> " + localName; 70 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 71 } 72 } 73 else 74 type.setBaseType(baseType); 75 76 if ( localName.equals(RESTRICTION_TAG) ) type.setExtension(false); 78 else type.setExtension(true); 79 80 return this; 81 } 82 } 83 else { 84 if ( localName.equals(SIMPLECONTENT_TAG) ) { 86 if ( !redefine ) { 87 type.setContentModel(new ContentModel(TEXT_ONLY)); 88 } 89 return new SimpleTypeHandler(loader, type, true, redefine); 90 } 91 92 if ( localName.equals(COMPLEXCONTENT_TAG) ) { 94 String mixed = atts.getValue("", MIXED_VALUE); 95 if ( TRUE_VALUE.equals(mixed)) { 96 type.setContentModel(new ContentModel(MIXED)); 97 } 98 return new ComplexTypeHandler(loader, type, true, redefine); 99 } 100 } 101 102 if ( redefine ) { 104 String errCode = "src-redefine.5"; 105 String errMsg = "Error while processing localName -> " + localName; 106 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 107 } 108 109 if (localName.equals(GROUP_TAG) || localName.equals(SEQUENCE_TAG) 111 || localName.equals(CHOICE_TAG) || localName.equals(ALL_TAG)) { 112 if ( !complexContent ) type.setExtension(false); 113 Particle particle = null; 114 try { 115 particle = loader.buildParticle(localName, type, atts); 116 } 117 catch ( SchemaException se ) { 118 String errMsg = "Error while processing localName -> " + localName; 119 loader.reportLoadingError(errMsg, se); 120 } 121 if (type.getContentModel() == null) { 122 type.setContentModel(new ContentModel(particle)); 123 } 124 else if (type.getContentModel().getModel() == null) { 125 type.getContentModel().setModel(particle); 126 } 127 Object term = particle.getTerm(); 128 if (term instanceof ModelGroup) { 129 return new ContentModelHandler(loader, (ModelGroup)term, type); 130 } 131 else return this; 132 } 133 134 if ( localName.equals(ATTRIBUTE_TAG) ) { 136 if ( !complexContent ) type.setExtension(false); 137 AttributeDeclaration decl = null; 138 try { 139 decl = loader.buildAttributeDeclaration(atts, type); 140 type.register(decl); 141 } catch ( SchemaException e ) { 142 String errMsg = "Error while processing localName -> " + localName; 143 loader.reportLoadingError(errMsg, e); 144 } 145 return new AttributeTypeHandler(loader, decl); 146 } 147 148 if ( localName.equals(ATTRIBUTE_GROUP_TAG) ) { 150 if ( !complexContent ) type.setExtension(false); 151 String refName = atts.getValue("", REF_ATTR); SchemaComponent ref = null; 153 try { 154 ref = loader.getRef(refName, Schema.ATTRIBUTE_GROUP_DEFINITION); 155 type.register(ref); 156 } catch ( SchemaException e ) { 157 String errMsg = "Error while processing localName -> " + localName; 158 loader.reportLoadingError(errMsg, e); 159 } 160 return this; 161 } 162 163 if (localName.equals(ANY_ATTRIBUTE_TAG)) { 165 if ( !complexContent ) type.setExtension(false); 166 Wildcard wildcard = null; 167 try { 168 wildcard = loader.buildWildcard(atts); 169 } catch ( SchemaException e ) { 170 String errMsg = "Error while processing localName -> " + localName; 171 loader.reportLoadingError(errMsg, e); 172 } 173 type.setAttributeWildcard(wildcard); 174 return this; 175 } 176 177 if ( localName.equals(ANNOTATION_TAG) ) return new AnnotationHandler(); 179 } 180 loader.notifyUnknownElement(namespaceURI, localName); 181 return this; 182 } 183 } 184 | Popular Tags |