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 ContentModelHandler 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 ModelGroup group = null; 37 private SchemaScope scope = null; 38 private ModelGroupDefinition groupDef = null; 39 private boolean redefined = false; 40 41 ContentModelHandler(Loader loader, ModelGroupDefinition def, boolean redefined) { 42 this.loader = loader; 43 groupDef = def; 44 this.redefined = redefined; 45 if ( redefined ) { 46 group = new SequenceModelGroup(); 47 def.setModelGroup(group); 48 } 49 } 50 51 ContentModelHandler(Loader loader, ModelGroup group, SchemaScope scope) { 52 this.loader = loader; 53 this.group = group; 54 this.scope = scope; 55 } 56 57 public ElementHandler startElement(String namespaceURI, String localName, Attributes atts) 58 throws SAXException 59 { 60 if ( namespaceURI.equals(XMLSCHEMA_URI) ) { 61 if ( redefined && localName.equals(GROUP_TAG)) { 63 String refName = atts.getValue("", REF_ATTR); 65 if ( refName.equals(groupDef.getName()) ) { 67 String minOccurs = atts.getValue("", MIN_OCCURS_ATTR); 70 String maxOccurs = atts.getValue("", MAX_OCCURS_ATTR); 71 if ( ( minOccurs != null && !"1".equals(minOccurs.trim()) ) || 72 ( maxOccurs != null && !"1".equals(maxOccurs.trim()) ) ) { 73 String errCode = "src-redefine.6.1.2"; 74 String errMsg = "Error while processing localName -> " + localName; 75 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 76 } 77 String redefinedName = refName + ".redefine"; 78 ModelGroupDefinition redefinedGroup = loader.getSchema().getModelGroupDefinition(redefinedName); 79 Particle result = new Particle(redefinedGroup); 80 result.setMinOccurs(1); 81 result.setMaxOccurs(1); 82 group.add(result); 83 return this; 84 } 85 } 86 87 Particle particle = null; 88 try { 89 particle = loader.buildParticle(localName, scope, atts); 90 } 91 catch ( SchemaException se ) { 92 String errMsg = "Error while processing localName -> " + localName; 93 loader.reportLoadingError(errMsg, se); 94 } 95 if (particle != null) { 96 if (group != null) group.add(particle); 97 Object term = particle.getTerm(); 98 if (term instanceof ModelGroup) { 99 if (group == null) { 100 group = (ModelGroup)term; 101 groupDef.setModelGroup(group); 102 } 103 return new ContentModelHandler(loader, (ModelGroup)term, scope); 104 } 105 else if (term instanceof ElementDeclaration) { 106 return new ElementTypeHandler(loader, (ElementDeclaration)term); 107 } 108 else { 109 return this; 110 } 111 } 112 113 else if (localName.equals(ANNOTATION_TAG)) { 114 return new AnnotationHandler(); 115 } 116 else 117 return this; 120 } 121 122 loader.notifyUnknownElement(namespaceURI, localName); 123 return this; 124 } 125 } 126 | Popular Tags |