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 AttributeGroupHandler extends DefaultElementHandler implements SchemaConstants 32 { 33 private static final String RCSRevision = "$Revision: 1.1 $"; 34 private static final String RCSName = "$Name: $"; 35 36 private Loader loader = null; 37 private AttributeGroupDefinition def; 38 private boolean redefined; 39 private AttributeGroupDefinition oldGroup; 40 41 AttributeGroupHandler(Loader loader, AttributeGroupDefinition def) { 42 this.loader = loader; 43 this.def = def; 44 this.redefined = false; 45 } 46 47 AttributeGroupHandler(Loader loader, AttributeGroupDefinition def, AttributeGroupDefinition oldGroup) { 48 this(loader, def); 49 this.redefined = true; 50 this.oldGroup = oldGroup; 51 } 52 53 public ElementHandler startElement(String namespaceURI, String localName, Attributes atts) 54 throws SAXException 55 { 56 if ( namespaceURI.equals(XMLSCHEMA_URI) ) { 57 if (localName.equals(ATTRIBUTE_GROUP_TAG)) { 58 String refName = atts.getValue("", REF_ATTR); 60 if ( redefined && refName.equals(def.getName()) ) { 62 def.add(oldGroup); 64 redefined = false; 65 } 66 else { 67 SchemaComponent ref = null; 68 try { 69 ref = loader.getRef(refName, Schema.ATTRIBUTE_GROUP_DEFINITION); 70 } 71 catch ( SchemaException se ) { 72 String errMsg = "Error while processing localName -> " + localName; 73 loader.reportLoadingError(errMsg, se); 74 } 75 def.add(ref); 76 } 77 return this; 78 } 79 80 else if (localName.equals(ATTRIBUTE_TAG)) { 81 AttributeDeclaration decl = null; 82 try { 83 decl = loader.buildAttributeDeclaration(atts, null); 84 } 85 catch ( SchemaException se ) { 86 String errMsg = "Error while processing localName -> " + localName; 87 loader.reportLoadingError(errMsg, se); 88 } 89 if ( redefined ) { 90 try { 91 checkAttributeValidRestriction(decl); 92 } 93 catch ( SchemaException e) { 94 String errMsg = "Error while processing localName -> " + localName; 95 loader.reportLoadingError(errMsg, e); 96 } 97 } 98 if ( def.attributeFind(decl) ) { 99 String errCode = "ag-props-correct.2"; 100 String errMsg = "Error while processing localName -> " + localName; 101 loader.reportLoadingError(errMsg, new SchemaException(errCode)); 102 } 103 def.add(decl); 104 return new AttributeTypeHandler(loader, decl); 105 } 106 107 else if (localName.equals(ANY_ATTRIBUTE_TAG)) { 108 Wildcard wildcard = null; 109 try { 110 wildcard = loader.buildWildcard(atts); 111 } 112 catch ( SchemaException se ) { 113 String errMsg = "Error while processing localName -> " + localName; 114 loader.reportLoadingError(errMsg, se); 115 } 116 if ( redefined ) { 117 try { 118 checkAttributeValidRestriction(wildcard); 119 } 120 catch ( SchemaException e) { 121 String errMsg = "Error while processing localName -> " + localName; 122 loader.reportLoadingError(errMsg, e); 123 } 124 } 125 def.setAttributeWildcard(wildcard); 126 return this; 127 } 128 129 else if (localName.equals(ANNOTATION_TAG)) { 130 return new AnnotationHandler(); 131 } 132 } 133 134 loader.notifyUnknownElement(namespaceURI, localName); 135 return this; 136 } 137 138 private void checkAttributeValidRestriction(AttributeDeclaration decl) 139 throws SchemaException { 140 java.util.Iterator it = this.oldGroup.getAttributeDeclarations().iterator(); 141 AttributeDeclaration baseDecl = null; 142 while ( it.hasNext() ) { 143 AttributeDeclaration attr = (AttributeDeclaration)it.next(); 144 if ( decl.getName().equals(attr.getName()) && 145 ( ( decl.getNamespace() == null && attr.getNamespace() == null ) || 146 ( decl.getNamespace().equals(attr.getNamespace()) ) ) ) { 147 baseDecl = attr; 148 break; 149 } 150 } 151 152 if ( baseDecl != null ) { 153 if ( !(baseDecl.getUse() != REQUIRED || decl.getUse() == REQUIRED) ) { 154 throw new SchemaException("derivation-ok-restriction.2.1.1", decl); 156 } 157 String errCode02 = decl.getType().checkTypeDerivationOK(baseDecl.getType(), baseDecl.getType().getFinal(), false); 158 if ( errCode02 != null ) { 159 throw new SchemaException("derivation-ok-restriction.2.1.2", decl, new SchemaException(errCode02, decl)); 161 } 162 if ( !( baseDecl.getFixedValue() == null || baseDecl.getFixedValue().equals(decl.getFixedValue()) ) ) { 163 throw new SchemaException("derivation-ok-restriction.2.1.3", decl); 165 } 166 } 167 else if ( this.oldGroup.getAttributeWildcard() == null || 168 this.oldGroup.getAttributeWildcard().isAllowed(decl.getNamespace()) == false ) 169 { 170 throw new SchemaException("derivation-ok-restriction.2.2", decl); 172 } 173 } 174 175 private void checkAttributeValidRestriction(Wildcard wild) 176 throws SchemaException { 177 Wildcard baseW = this.oldGroup.getAttributeWildcard(); 178 if ( baseW == null ) { 179 throw new SchemaException("derivation-ok-restriction.4.1", this); 181 } 182 else { 183 String errCode02 = wild.validWildcardSubset(baseW); 184 if ( errCode02 != null ) { 185 throw new SchemaException("derivation-ok-restriction.4.2", this, new SchemaException(errCode02, wild)); 187 } 188 } 189 } 190 } 191 192 | Popular Tags |