1 package com.thaiopensource.relaxng.impl; 2 3 import org.xml.sax.Locator ; 4 import org.xml.sax.SAXException ; 5 6 class AttributePattern extends Pattern { 7 private final NameClass nameClass; 8 private final Pattern p; 9 private final Locator loc; 10 11 AttributePattern(NameClass nameClass, Pattern value, Locator loc) { 12 super(false, 13 EMPTY_CONTENT_TYPE, 14 combineHashCode(ATTRIBUTE_HASH_CODE, 15 nameClass.hashCode(), 16 value.hashCode())); 17 this.nameClass = nameClass; 18 this.p = value; 19 this.loc = loc; 20 } 21 22 Pattern expand(SchemaPatternBuilder b) { 23 Pattern ep = p.expand(b); 24 if (ep != p) 25 return b.makeAttribute(nameClass, ep, loc); 26 else 27 return this; 28 } 29 30 void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) 31 throws RestrictionViolationException { 32 switch (context) { 33 case START_CONTEXT: 34 throw new RestrictionViolationException("start_contains_attribute"); 35 case ELEMENT_CONTEXT: 36 if (nameClass.isOpen()) 37 throw new RestrictionViolationException("open_name_class_not_repeated"); 38 break; 39 case ELEMENT_REPEAT_GROUP_CONTEXT: 40 throw new RestrictionViolationException("one_or_more_contains_group_contains_attribute"); 41 case ELEMENT_REPEAT_INTERLEAVE_CONTEXT: 42 throw new RestrictionViolationException("one_or_more_contains_interleave_contains_attribute"); 43 case LIST_CONTEXT: 44 throw new RestrictionViolationException("list_contains_attribute"); 45 case ATTRIBUTE_CONTEXT: 46 throw new RestrictionViolationException("attribute_contains_attribute"); 47 case DATA_EXCEPT_CONTEXT: 48 throw new RestrictionViolationException("data_except_contains_attribute"); 49 } 50 if (!dad.addAttribute(nameClass)) { 51 if (nameClass instanceof SimpleNameClass) 52 throw new RestrictionViolationException("duplicate_attribute_detail", ((SimpleNameClass)nameClass).getName()); 53 else 54 throw new RestrictionViolationException("duplicate_attribute"); 55 } 56 try { 57 p.checkRestrictions(ATTRIBUTE_CONTEXT, null, null); 58 } 59 catch (RestrictionViolationException e) { 60 e.maybeSetLocator(loc); 61 throw e; 62 } 63 } 64 65 boolean samePattern(Pattern other) { 66 if (!(other instanceof AttributePattern)) 67 return false; 68 AttributePattern ap = (AttributePattern)other; 69 return nameClass.equals(ap.nameClass)&& p == ap.p; 70 } 71 72 void checkRecursion(int depth) throws SAXException { 73 p.checkRecursion(depth); 74 } 75 76 void accept(PatternVisitor visitor) { 77 visitor.visitAttribute(nameClass, p); 78 } 79 80 Object apply(PatternFunction f) { 81 return f.caseAttribute(this); 82 } 83 84 Pattern getContent() { 85 return p; 86 } 87 88 NameClass getNameClass() { 89 return nameClass; 90 } 91 92 Locator getLocator() { 93 return loc; 94 } 95 } 96 | Popular Tags |