1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import java.util.Enumeration ; 23 import java.util.Vector ; 24 25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 26 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL; 27 import com.sun.org.apache.bcel.internal.generic.InstructionList; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.AttributeSetMethodGenerator; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; 35 import com.sun.org.apache.xml.internal.utils.XMLChar; 36 37 42 final class AttributeSet extends TopLevelElement { 43 44 private static final String AttributeSetPrefix = "$as$"; 46 47 private QName _name; 49 private UseAttributeSets _useSets; 50 private AttributeSet _mergeSet; 51 private String _method; 52 private boolean _ignore = false; 53 54 57 public QName getName() { 58 return _name; 59 } 60 61 65 public String getMethodName() { 66 return _method; 67 } 68 69 75 public void ignore() { 76 _ignore = true; 77 } 78 79 83 public void parseContents(Parser parser) { 84 85 final String name = getAttribute("name"); 87 88 if (!XMLChar.isValidQName(name)) { 89 ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, name, this); 90 parser.reportError(Constants.ERROR, err); 91 } 92 _name = parser.getQNameIgnoreDefaultNs(name); 93 if ((_name == null) || (_name.equals(EMPTYSTRING))) { 94 ErrorMsg msg = new ErrorMsg(ErrorMsg.UNNAMED_ATTRIBSET_ERR, this); 95 parser.reportError(Constants.ERROR, msg); 96 } 97 98 final String useSets = getAttribute("use-attribute-sets"); 100 if (useSets.length() > 0) { 101 if (!Util.isValidQNames(useSets)) { 102 ErrorMsg err = new ErrorMsg(ErrorMsg.INVALID_QNAME_ERR, useSets, this); 103 parser.reportError(Constants.ERROR, err); 104 } 105 _useSets = new UseAttributeSets(useSets, parser); 106 } 107 108 final Vector contents = getContents(); 111 final int count = contents.size(); 112 for (int i=0; i<count; i++) { 113 SyntaxTreeNode child = (SyntaxTreeNode)contents.elementAt(i); 114 if (child instanceof XslAttribute) { 115 parser.getSymbolTable().setCurrentNode(child); 116 child.parseContents(parser); 117 } 118 else if (child instanceof Text) { 119 } 121 else { 122 ErrorMsg msg = new ErrorMsg(ErrorMsg.ILLEGAL_CHILD_ERR, this); 123 parser.reportError(Constants.ERROR, msg); 124 } 125 } 126 127 parser.getSymbolTable().setCurrentNode(this); 129 } 130 131 134 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 135 136 if (_ignore) return (Type.Void); 137 138 _mergeSet = stable.addAttributeSet(this); 140 141 _method = AttributeSetPrefix + getXSLTC().nextAttributeSetSerial(); 142 143 if (_useSets != null) _useSets.typeCheck(stable); 144 typeCheckContents(stable); 145 return Type.Void; 146 } 147 148 151 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 152 153 if (_ignore) return; 154 155 methodGen = new AttributeSetMethodGenerator(_method, classGen); 157 158 if (_mergeSet != null) { 161 final ConstantPoolGen cpg = classGen.getConstantPool(); 162 final InstructionList il = methodGen.getInstructionList(); 163 final String methodName = _mergeSet.getMethodName(); 164 165 il.append(classGen.loadTranslet()); 166 il.append(methodGen.loadDOM()); 167 il.append(methodGen.loadIterator()); 168 il.append(methodGen.loadHandler()); 169 final int method = cpg.addMethodref(classGen.getClassName(), 170 methodName, ATTR_SET_SIG); 171 il.append(new INVOKESPECIAL(method)); 172 } 173 174 if (_useSets != null) _useSets.translate(classGen, methodGen); 177 178 final Enumeration attributes = elements(); 180 while (attributes.hasMoreElements()) { 181 SyntaxTreeNode element = (SyntaxTreeNode)attributes.nextElement(); 182 if (element instanceof XslAttribute) { 183 final XslAttribute attribute = (XslAttribute)element; 184 attribute.translate(classGen, methodGen); 185 } 186 } 187 final InstructionList il = methodGen.getInstructionList(); 188 il.append(RETURN); 189 190 methodGen.stripAttributes(true); 191 methodGen.setMaxLocals(); 192 methodGen.setMaxStack(); 193 methodGen.removeNOPs(); 194 classGen.addMethod(methodGen.getMethod()); 195 } 196 197 public String toString() { 198 StringBuffer buf = new StringBuffer ("attribute-set: "); 199 final Enumeration attributes = elements(); 201 while (attributes.hasMoreElements()) { 202 final XslAttribute attribute = 203 (XslAttribute)attributes.nextElement(); 204 buf.append(attribute); 205 } 206 return(buf.toString()); 207 } 208 } 209 | Popular Tags |