KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > sql > SQLColumn


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 /**
19 * An sql:column element in the stylesheet.
20 */

21
22 public class SQLColumn extends XSLGeneralVariable {
23
24     /**
25     * Determine whether this node is an instruction.
26     * @return false - it is not an instruction
27     */

28
29     public boolean isInstruction() {
30         return false;
31     }
32
33     /**
34     * Determine whether this type of element is allowed to contain a template-body
35     * @return false: no, it may not contain a template-body
36     */

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 JavaDoc selectAtt = null;
49         String JavaDoc nameAtt = null;
50
51         for (int a=0; a<atts.getLength(); a++) {
52             String JavaDoc 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 JavaDoc 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         /**
118          * Evaluate the variable (method exists only to satisfy the interface)
119          */

120
121         public ValueRepresentation evaluateVariable(XPathContext context) throws XPathException {
122             throw new UnsupportedOperationException JavaDoc();
123         }
124
125     }
126
127 }
128
129 //
130
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
131
// you may not use this file except in compliance with the License. You may obtain a copy of the
132
// License at http://www.mozilla.org/MPL/
133
//
134
// Software distributed under the License is distributed on an "AS IS" basis,
135
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
136
// See the License for the specific language governing rights and limitations under the License.
137
//
138
// The Original Code is: all this file.
139
//
140
// The Initial Developer of the Original Code is Michael H. Kay.
141
//
142
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
143
//
144
// Contributor(s): none.
145
//
146
Popular Tags