1 package net.sf.saxon.sql; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.instruct.Executable; 4 import net.sf.saxon.instruct.GeneralVariable; 5 import net.sf.saxon.instruct.InstructionDetails; 6 import net.sf.saxon.instruct.TailCall; 7 import net.sf.saxon.om.AttributeCollection; 8 import net.sf.saxon.om.Name; 9 import net.sf.saxon.om.Navigator; 10 import net.sf.saxon.om.ValueRepresentation; 11 import net.sf.saxon.style.XSLGeneralVariable; 12 import net.sf.saxon.trace.InstructionInfo; 13 import net.sf.saxon.trace.Location; 14 import net.sf.saxon.trans.XPathException; 15 import net.sf.saxon.value.SequenceType; 16 17 18 21 22 public class SQLColumn extends XSLGeneralVariable { 23 24 28 29 public boolean isInstruction() { 30 return false; 31 } 32 33 37 38 public boolean mayContainSequenceConstructor() { 39 return false; 40 } 41 42 public void prepareAttributes() throws XPathException { 43 44 getVariableFingerprint(); 45 46 AttributeCollection atts = getAttributeList(); 47 48 String selectAtt = null; 49 String nameAtt = null; 50 51 for (int a=0; a<atts.getLength(); a++) { 52 String localName = atts.getLocalName(a); 53 if (localName.equals("name")) { 54 nameAtt = atts.getValue(a).trim(); 55 } else if (localName.equals("select")) { 56 selectAtt = atts.getValue(a); 57 } else { 58 checkUnknownAttribute(atts.getNameCode(a)); 59 } 60 } 61 62 if (nameAtt==null) { 63 reportAbsence("name"); 64 } else if (!Name.isQName(nameAtt)) { 65 compileError("Column name must be a valid QName"); 66 } 67 68 if (selectAtt!=null) { 69 select = makeExpression(selectAtt); 70 } 71 72 } 73 74 75 public void validate() throws XPathException { 76 if (!(getParent() instanceof SQLInsert)) { 77 compileError("parent node must be sql:insert"); 78 } 79 select = typeCheck("select", select); 80 try { 81 RoleLocator role = 82 new RoleLocator(RoleLocator.INSTRUCTION, "sql:column/select", 0, null); 83 role.setSourceLocator(new ExpressionLocation(this)); 84 select = TypeChecker.staticTypeCheck(select, 85 SequenceType.SINGLE_ATOMIC, 86 false, role, getStaticContext()); 87 88 } catch (XPathException err) { 89 compileError(err); 90 } 91 } 92 93 public Expression compile(Executable exec) throws XPathException { 94 ColumnInstruction inst = new ColumnInstruction(); 95 initializeInstruction(exec, inst); 96 return inst; 97 } 98 99 public String getColumnName() { 100 return Navigator.getAttributeValue(this, "", "name"); 101 } 102 103 protected static class ColumnInstruction extends GeneralVariable { 104 105 public ColumnInstruction() {} 106 107 public InstructionInfo getInstructionInfo() { 108 InstructionDetails details = (InstructionDetails)super.getInstructionInfo(); 109 details.setConstructType(Location.EXTENSION_INSTRUCTION); 110 return details; 111 } 112 113 public TailCall processLeavingTail(XPathContext context) { 114 return null; 115 } 116 117 120 121 public ValueRepresentation evaluateVariable(XPathContext context) throws XPathException { 122 throw new UnsupportedOperationException (); 123 } 124 125 } 126 127 } 128 129 | Popular Tags |