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 RedefineHandler 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 37 RedefineHandler(Loader loader) { 38 this.loader = loader; 39 } 40 41 public ElementHandler startElement(String namespaceURI, String localName, Attributes atts) 42 throws SAXException 43 { 44 if ( namespaceURI.equals(XMLSCHEMA_URI) ) { 45 String redefinedName = atts.getValue("", NAME_ATTR); 46 48 if ( localName.equals(SIMPLE_TYPE_TAG) || localName.equals(COMPLEX_TYPE_TAG) ) { 50 Type oldType = loader.getSchema().getType(redefinedName); 52 if ( oldType == null ) { 53 String errCode = "src-redefine.4.2"; 54 String errMsg = "Error while processing localName -> " + localName; 55 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 56 } 57 oldType.setName(redefinedName + ".redefine"); 58 59 if ( localName.equals(SIMPLE_TYPE_TAG) ) { 61 SimpleType newType = null; 62 try { 63 newType = loader.buildSimpleType(atts); 64 newType.setBaseType(oldType); 65 loader.getSchema().removeRegisteredComponent(newType); 66 loader.getSchema().register(newType); 67 } 68 catch ( SchemaException se ) { 69 String errMsg = "Error while processing localName -> " + localName; 70 loader.reportLoadingError(errMsg, se); 71 } 72 return new SimpleTypeHandler(loader, newType, false, true); 73 } 74 else { 75 ComplexType newType = null; 76 try { 77 newType = loader.buildComplexType(atts); 78 newType.setBaseType(oldType); 79 loader.getSchema().removeRegisteredComponent(newType); 80 loader.getSchema().register(newType); 81 } 82 catch ( SchemaException se ) { 83 String errMsg = "Error while processing localName -> " + localName; 84 loader.reportLoadingError(errMsg, se); 85 } 86 return new ComplexTypeHandler(loader, newType, false, true); 87 } 88 } 89 90 else if ( localName.equals(ATTRIBUTE_GROUP_TAG) ) { 92 AttributeGroupDefinition oldAttGroup = loader.getSchema().getAttributeGroupDefinition(redefinedName); 94 if ( oldAttGroup == null ) { 95 String errCode = "src-redefine.4.2"; 96 String errMsg = "Error while processing localName -> " + localName; 97 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 98 } 99 oldAttGroup.setName(redefinedName + ".redefine"); 100 101 AttributeGroupDefinition def = loader.buildAttributeGroupDefinition(atts, loader.getSchema()); 103 loader.getSchema().removeRegisteredComponent(def); 104 try { 105 loader.getSchema().register(def); 106 } catch ( SchemaException se ) { 107 } 109 return new AttributeGroupHandler(loader, def, oldAttGroup); 110 } 111 112 else if ( localName.equals(GROUP_TAG) ) { 114 ModelGroupDefinition oldGroup = loader.getSchema().getModelGroupDefinition(redefinedName); 115 if ( oldGroup == null ) { 116 String errCode = "src-redefine.4.2"; 117 String errMsg = "Error while processing localName -> " + localName; 118 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 119 } 120 oldGroup.setName(redefinedName + ".redefine"); 121 try { 122 loader.getSchema().register(oldGroup); 123 } catch ( SchemaException se ) { 124 } 126 127 ModelGroupDefinition def = loader.buildModelGroupDefinition(atts, loader.getSchema()); 128 loader.getSchema().removeRegisteredComponent(def); 129 try { 130 loader.getSchema().register(def); 131 } catch ( SchemaException se ) { 132 } 134 return new ContentModelHandler(loader, def, true); 135 } 136 137 else if (localName.equals(ANNOTATION_TAG)) { 138 return new AnnotationHandler(); 139 } 140 } 141 loader.notifyUnknownElement(namespaceURI, localName); 142 return this; 143 } 144 } 145 146 | Popular Tags |