001: package net.sf.saxon.expr;
002:
003: /**
004: * This class contains constants identifying dependencies that an XPath expression
005: * might have on its context.
006: */
007:
008: public abstract class StaticProperty {
009:
010: /**
011: * Bit setting: Expression depends on current() item
012: */
013:
014: public static final int DEPENDS_ON_CURRENT_ITEM = 1;
015:
016: /**
017: * Bit setting: Expression depends on context item
018: */
019:
020: public static final int DEPENDS_ON_CONTEXT_ITEM = 1 << 1;
021:
022: /**
023: * Bit setting: Expression depends on position()
024: */
025:
026: public static final int DEPENDS_ON_POSITION = 1 << 2;
027:
028: /**
029: * Bit setting: Expression depends on last()
030: */
031:
032: public static final int DEPENDS_ON_LAST = 1 << 3;
033:
034: /**
035: * Bit setting: Expression depends on the document containing the context node
036: */
037:
038: public static final int DEPENDS_ON_CONTEXT_DOCUMENT = 1 << 4;
039:
040: /**
041: * Bit setting: Expression depends on current-group() and/or current-grouping-key()
042: */
043:
044: public static final int DEPENDS_ON_CURRENT_GROUP = 1 << 5;
045:
046: /**
047: * Bit setting: Expression depends on regex-group()
048: */
049:
050: public static final int DEPENDS_ON_REGEX_GROUP = 1 << 6;
051:
052: /**
053: * Bit setting: Expression depends on local variables
054: */
055:
056: public static final int DEPENDS_ON_LOCAL_VARIABLES = 1 << 7;
057:
058: /**
059: * Bit setting: Expression depends on user-defined functions
060: */
061:
062: public static final int DEPENDS_ON_USER_FUNCTIONS = 1 << 8;
063:
064: /**
065: * Combination of bits representing dependencies on the XSLT context
066: */
067:
068: public static final int DEPENDS_ON_XSLT_CONTEXT = DEPENDS_ON_CURRENT_ITEM
069: | DEPENDS_ON_CURRENT_GROUP | DEPENDS_ON_REGEX_GROUP;
070:
071: /**
072: * Combination of bits representing dependencies on the focus
073: */
074:
075: public static final int DEPENDS_ON_FOCUS = DEPENDS_ON_CONTEXT_ITEM
076: | DEPENDS_ON_POSITION | DEPENDS_ON_LAST
077: | DEPENDS_ON_CONTEXT_DOCUMENT;
078:
079: /**
080: * Combination of bits representing dependencies on the focus, but excluding dependencies
081: * on the current document
082: */
083:
084: public static final int DEPENDS_ON_NON_DOCUMENT_FOCUS = DEPENDS_ON_CONTEXT_ITEM
085: | DEPENDS_ON_POSITION | DEPENDS_ON_LAST;
086:
087: /**
088: * Mask to select all the dependency bits
089: */
090:
091: public static final int DEPENDENCY_MASK = DEPENDS_ON_CONTEXT_DOCUMENT
092: | DEPENDS_ON_CONTEXT_ITEM
093: | DEPENDS_ON_CURRENT_GROUP
094: | DEPENDS_ON_REGEX_GROUP
095: | DEPENDS_ON_CURRENT_ITEM
096: | DEPENDS_ON_FOCUS
097: | DEPENDS_ON_LOCAL_VARIABLES
098: | DEPENDS_ON_USER_FUNCTIONS;
099:
100: /*
101: * Bit set if an empty sequence is allowed
102: */
103:
104: public static final int ALLOWS_ZERO = 1 << 13;
105:
106: /**
107: * Bit set if a single value is allowed
108: */
109:
110: public static final int ALLOWS_ONE = 1 << 14;
111:
112: /**
113: * Bit set if multiple values are allowed
114: */
115:
116: public static final int ALLOWS_MANY = 1 << 15;
117:
118: /**
119: * Mask for all cardinality bits
120: */
121:
122: public static final int CARDINALITY_MASK = ALLOWS_ZERO | ALLOWS_ONE
123: | ALLOWS_MANY;
124:
125: /**
126: * Occurence indicator for "one or more" (+)
127: */
128:
129: public static final int ALLOWS_ONE_OR_MORE = ALLOWS_ONE
130: | ALLOWS_MANY;
131:
132: /**
133: * Occurence indicator for "zero or more" (*)
134: */
135:
136: public static final int ALLOWS_ZERO_OR_MORE = ALLOWS_ZERO
137: | ALLOWS_ONE | ALLOWS_MANY;
138:
139: /**
140: * Occurence indicator for "zero or one" (?)
141: */
142:
143: public static final int ALLOWS_ZERO_OR_ONE = ALLOWS_ZERO
144: | ALLOWS_ONE;
145:
146: /**
147: * Occurence indicator for "exactly one" (default occurrence indicator)
148: */
149:
150: public static final int EXACTLY_ONE = ALLOWS_ONE;
151:
152: /**
153: * Occurence indicator when an empty sequence is required
154: */
155:
156: public static final int EMPTY = ALLOWS_ZERO;
157:
158: /**
159: * Reduce the cardinality value to an integer in the range 0-7
160: */
161:
162: public static final int getCardinalityCode(int cardinality) {
163: return (cardinality & CARDINALITY_MASK) >> 13;
164: }
165:
166: /**
167: * Display the cardinality value as a string (used for diagnostics)
168: */
169:
170: public static final String getCardinalityDescription(int cardinality) {
171: int code = getCardinalityCode(cardinality);
172: String[] names = { "not allowed", "exactly zero",
173: "exactly one", "zero or one", "many", "zero or many",
174: "one or more", "zero or more" };
175: return names[code];
176: }
177:
178: /**
179: * Expression property: this bit is set by getProperties() in the case of
180: * an expression whose item type is node, when the nodes in the result are
181: * guaranteed all to be in the same document as the context node. For
182: * expressions that return values other than nodes, the setting is undefined.
183: */
184:
185: public static final int CONTEXT_DOCUMENT_NODESET = 1 << 16;
186:
187: /**
188: * Expression property: this bit is set by getProperties() in the case of
189: * an expression whose item type is node, when the nodes in the result are
190: * in document order.
191: */
192:
193: public static final int ORDERED_NODESET = 1 << 17;
194:
195: /**
196: * Expression property: this bit is set by getProperties() in the case of
197: * an expression that delivers items in the reverse of the correct order, when unordered
198: * retrieval is requested.
199: */
200:
201: public static final int REVERSE_DOCUMENT_ORDER = 1 << 18;
202:
203: /**
204: * Expression property: this bit is set by getProperties() in the case of
205: * an expression that delivers a set of nodes with the guarantee that no node in the
206: * set will be an ancestor of any other. This property is useful in deciding whether the
207: * results of a path expression are pre-sorted. The property is only used in the case where
208: * the NATURALLY_SORTED property is true, so there is no point in setting it in other cases.
209: */
210:
211: public static final int PEER_NODESET = 1 << 19;
212:
213: /**
214: * Expression property: this bit is set by getProperties() in the case of
215: * an expression that delivers a set of nodes with the guarantee that every node in the
216: * result will be a descendant or self, or attribute or namespace, of the context node
217: */
218:
219: public static final int SUBTREE_NODESET = 1 << 20;
220:
221: /**
222: * Expression property: this bit is set by getProperties() in the case of
223: * an expression that delivers a set of nodes with the guarantee that every node in the
224: * result will be an attribute or namespace of the context node
225: */
226:
227: public static final int ATTRIBUTE_NS_NODESET = 1 << 21;
228:
229: /**
230: * Expression property: this bit is set in the case of an expression that will
231: * never return newly created nodes, nor a value that depends on the identity
232: * of newly created nodes (for example generate-id(new-node())). Expressions
233: * that do create new nodes cannot be moved out of loops as this could cause
234: * too few nodes to be created: for example if f() creates a new node, then
235: * count(for $i in 1 to 5 return f()) must be 5.
236: */
237:
238: public static final int NON_CREATIVE = 1 << 22;
239:
240: /**
241: * Expression property: this bit is set in the case of an expression that delivers
242: * a set of nodes that are all in the same document (not necessarily the same
243: * document as the context node).
244: */
245:
246: public static final int SINGLE_DOCUMENT_NODESET = 1 << 23;
247:
248: /**
249: * Mask for "special properties": that is, all properties other than cardinality
250: * and dependencies
251: */
252:
253: public static final int SPECIAL_PROPERTY_MASK = CONTEXT_DOCUMENT_NODESET
254: | ORDERED_NODESET
255: | REVERSE_DOCUMENT_ORDER
256: | PEER_NODESET
257: | SUBTREE_NODESET
258: | ATTRIBUTE_NS_NODESET
259: | SINGLE_DOCUMENT_NODESET | NON_CREATIVE;
260:
261: // This class is not instantiated
262: private StaticProperty() {
263: }
264: }
265:
266: //
267: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
268: // you may not use this file except in compliance with the License. You may obtain a copy of the
269: // License at http://www.mozilla.org/MPL/
270: //
271: // Software distributed under the License is distributed on an "AS IS" basis,
272: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
273: // See the License for the specific language governing rights and limitations under the License.
274: //
275: // The Original Code is: all this file.
276: //
277: // The Initial Developer of the Original Code is Michael H. Kay.
278: //
279: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
280: //
281: // Contributor(s): none.
282: //
|