1 17 package org.apache.ws.jaxme.xs.junit; 18 19 import org.apache.ws.jaxme.xs.XSAttributable; 20 import org.apache.ws.jaxme.xs.XSAttribute; 21 import org.apache.ws.jaxme.xs.XSComplexType; 22 import org.apache.ws.jaxme.xs.XSElement; 23 import org.apache.ws.jaxme.xs.XSElementOrAttrRef; 24 import org.apache.ws.jaxme.xs.XSGroup; 25 import org.apache.ws.jaxme.xs.XSIdentityConstraint; 26 import org.apache.ws.jaxme.xs.XSKeyRef; 27 import org.apache.ws.jaxme.xs.XSParticle; 28 import org.apache.ws.jaxme.xs.XSType; 29 import org.xml.sax.SAXException ; 30 31 32 37 public class DumpUtils { 38 private static void dumpElements( XSElement[] elements, String prefix ) 39 throws SAXException 40 { 41 int numElements = elements.length; 42 43 for ( int i=0; i<numElements; i++ ) { 44 dumpElement( elements[i], prefix ); 45 } 46 } 47 48 private static void dumpElement( XSElement element, String prefix ) 49 throws SAXException 50 { 51 String indented = " " + prefix; 52 System.out.println( 53 prefix + "Element "+System.identityHashCode(element) 54 + ": " + element.getName() 55 ); 56 57 dumpType( element.getType(), indented ); 58 dumpIdentityConstraints( element.getIdentityConstraints(), indented ); 59 dumpKeyRefs( element.getKeyRefs(), indented ); 60 } 61 62 private static void dumpType( XSType type, String prefix ) 63 throws SAXException 64 { 65 String indented = " " + prefix; 66 System.out.print( prefix + "Type: " ); 67 68 if ( type.isSimple() ) { 69 System.out.println( "simple - " + type.getName() ); 70 } else { 71 System.out.println( "complex - " + type.getName() ); 72 73 dumpComplexType( type.getComplexType(), indented ); 74 } 75 } 76 77 private static void dumpComplexType( XSComplexType type, String prefix ) 78 throws SAXException 79 { 80 String indented = prefix; 81 XSAttributable[] attributables = type.getAttributes(); 82 int numAttribables = attributables.length; 83 84 for ( int i=0; i<numAttribables; i++ ) { 85 dumpAttributable( attributables[i], indented ); 86 } 87 88 if ( !type.isEmpty() ) { 89 dumpParticle( type.getParticle(), indented ); 90 } 91 } 92 93 private static void dumpIdentityConstraints( 94 XSIdentityConstraint[] constraints, 95 String prefix 96 ) { 97 int numConstraints = constraints.length; 98 99 for ( int i=0; i<numConstraints; i++ ) { 100 dumpIdentityConstraint( constraints[i], prefix ); 101 } 102 } 103 104 private static void dumpKeyRefs( XSKeyRef[] keyRefs, String prefix ) { 105 int numKeyRefs = keyRefs == null ? 0 : keyRefs.length; 106 107 for ( int i=0; i<numKeyRefs; i++ ) { 108 dumpKeyRef( keyRefs[i], prefix ); 109 } 110 } 111 112 private static void dumpIdentityConstraint( 113 XSIdentityConstraint constraint, 114 String prefix 115 ) { 116 System.out.println( 117 prefix + "constraint: " + constraint.getName() 118 + (constraint.isUnique() ? " (unique)" : "") 119 ); 120 121 dumpMatchCriteria( constraint.getMatchCriteria(), prefix + " " ); 122 } 123 124 private static void dumpKeyRef( XSKeyRef keyRef, String prefix ) { 125 System.out.println( 126 prefix + "keyref: " + keyRef.getName() + ": refers " 127 + keyRef.getIdentityConstraint() 128 ); 129 130 dumpMatchCriteria( keyRef.getMatchCriteria(), prefix + " " ); 131 } 132 133 private static void dumpMatchCriteria( 134 XSElementOrAttrRef[][] criteria, 135 String prefix 136 ) { 137 int numKeyParts = criteria.length; 138 139 for ( int i=0; i<numKeyParts; i++ ) { 140 XSElementOrAttrRef[] keys = criteria[i]; 141 142 int numOptions = keys.length; 143 for ( int j=0; j<numOptions; j++ ) { 144 dumpElementOrAttrRef( keys[j], i + ": " ); 145 } 146 } 147 } 148 149 private static void dumpElementOrAttrRef( 150 XSElementOrAttrRef ref, String prefix 151 ) { 152 if ( ref.isAttributeRef() ) { 153 System.out.println( prefix + ref.getAttribute().getName() + " (attr) " ); 154 } else { 155 System.out.println( prefix + ref.getElement().getName() + " (ele) " ); 156 } 157 } 158 159 private static void dumpAttributable( 160 XSAttributable attributable, 161 String prefix 162 ) throws SAXException { 163 if ( attributable instanceof XSAttribute ) { 164 XSAttribute attr = (XSAttribute) attributable; 165 System.out.println( 166 prefix + "attribute " + System.identityHashCode(attr) + ": " 167 + attr.getName() + " " 168 + (attr.getType().isSimple() ? "simple" : "complex!!!") 169 + (attr.isOptional() ? " optional" : " required") 170 ); 171 } else { 172 System.out.println( prefix + "??? attrributable " + attributable ); 173 } 174 } 175 176 private static void dumpParticle( XSParticle particle, String prefix ) 177 throws SAXException 178 { 179 String indented = " " + prefix; 180 System.out.print( 181 prefix + " particle: min=" + particle.getMinOccurs() 182 + " max=" + particle.getMaxOccurs() + " particle_type=" 183 + particle.getType() 184 ); 185 186 if ( particle.isElement() ) { 187 System.out.println( " element" ); 188 dumpElement( particle.getElement(), indented ); 189 } else if ( particle.isGroup() ) { 190 System.out.println( " group" ); 191 dumpGroup( particle.getGroup(), indented ); 192 } else if ( particle.isWildcard() ) { 193 System.out.println( " wildcard" ); 194 } 195 } 196 197 private static void dumpGroup( XSGroup group, String prefix ) throws SAXException { 198 String indented = " " + prefix; 199 System.out.println( prefix + "group: name=" + group.getName() ); 200 201 XSParticle[] particles = group.getParticles(); 202 int numParticles = particles.length; 203 for ( int i=0; i<numParticles; i++ ) { 204 dumpParticle( particles[i], indented ); 205 } 206 } 207 } 208 | Popular Tags |