001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.xs;
019:
020: import org.apache.xerces.xs.ShortList;
021: import org.apache.xerces.xs.StringList;
022: import org.apache.xerces.xs.XSElementDeclaration;
023: import org.apache.xerces.xs.XSModel;
024: import org.apache.xerces.xs.XSNotationDeclaration;
025: import org.apache.xerces.xs.XSSimpleTypeDefinition;
026: import org.apache.xerces.xs.XSTypeDefinition;
027: import org.apache.xerces.impl.xs.util.StringListImpl;
028: import org.apache.xerces.xs.ElementPSVI;
029: import org.apache.xerces.xs.XSConstants;
030:
031: /**
032: * Element PSV infoset augmentations implementation.
033: * The following information will be available at the startElement call:
034: * name, namespace, type, notation, validation context
035: *
036: * The following information will be available at the endElement call:
037: * nil, specified, normalized value, member type, validity, error codes,
038: * default
039: *
040: * @xerces.internal
041: *
042: * @author Elena Litani IBM
043: * @version $Id: ElementPSVImpl.java 446734 2006-09-15 20:51:23Z mrglavas $
044: */
045: public class ElementPSVImpl implements ElementPSVI {
046:
047: /** element declaration */
048: protected XSElementDeclaration fDeclaration = null;
049:
050: /** type of element, could be xsi:type */
051: protected XSTypeDefinition fTypeDecl = null;
052:
053: /** true if clause 3.2 of Element Locally Valid (Element) (3.3.4)
054: * is satisfied, otherwise false
055: */
056: protected boolean fNil = false;
057:
058: /** true if the element value was provided by the schema; false otherwise.
059: */
060: protected boolean fSpecified = false;
061:
062: /** schema normalized value property */
063: protected String fNormalizedValue = null;
064:
065: /** schema actual value */
066: protected Object fActualValue = null;
067:
068: /** schema actual value type */
069: protected short fActualValueType = XSConstants.UNAVAILABLE_DT;
070:
071: /** actual value types if the value is a list */
072: protected ShortList fItemValueTypes = null;
073:
074: /** http://www.w3.org/TR/xmlschema-1/#e-notation*/
075: protected XSNotationDeclaration fNotation = null;
076:
077: /** member type definition against which element was validated */
078: protected XSSimpleTypeDefinition fMemberType = null;
079:
080: /** validation attempted: none, partial, full */
081: protected short fValidationAttempted = ElementPSVI.VALIDATION_NONE;
082:
083: /** validity: valid, invalid, unknown */
084: protected short fValidity = ElementPSVI.VALIDITY_NOTKNOWN;
085:
086: /** error codes */
087: protected String[] fErrorCodes = null;
088:
089: /** validation context: could be QName or XPath expression*/
090: protected String fValidationContext = null;
091:
092: /** deferred XSModel **/
093: protected SchemaGrammar[] fGrammars = null;
094:
095: /** the schema information property */
096: protected XSModel fSchemaInformation = null;
097:
098: //
099: // ElementPSVI methods
100: //
101:
102: /**
103: * [schema default]
104: *
105: * @return The canonical lexical representation of the declaration's {value constraint} value.
106: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a>
107: */
108: public String getSchemaDefault() {
109: return fDeclaration == null ? null : fDeclaration
110: .getConstraintValue();
111: }
112:
113: /**
114: * [schema normalized value]
115: *
116: *
117: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value>XML Schema Part 1: Structures [schema normalized value]</a>
118: * @return the normalized value of this item after validation
119: */
120: public String getSchemaNormalizedValue() {
121: return fNormalizedValue;
122: }
123:
124: /**
125: * [schema specified]
126: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
127: * @return true - value was specified in schema, false - value comes from the infoset
128: */
129: public boolean getIsSchemaSpecified() {
130: return fSpecified;
131: }
132:
133: /**
134: * Determines the extent to which the document has been validated
135: *
136: * @return return the [validation attempted] property. The possible values are
137: * NO_VALIDATION, PARTIAL_VALIDATION and FULL_VALIDATION
138: */
139: public short getValidationAttempted() {
140: return fValidationAttempted;
141: }
142:
143: /**
144: * Determine the validity of the node with respect
145: * to the validation being attempted
146: *
147: * @return return the [validity] property. Possible values are:
148: * UNKNOWN_VALIDITY, INVALID_VALIDITY, VALID_VALIDITY
149: */
150: public short getValidity() {
151: return fValidity;
152: }
153:
154: /**
155: * A list of error codes generated from validation attempts.
156: * Need to find all the possible subclause reports that need reporting
157: *
158: * @return Array of error codes
159: */
160: public StringList getErrorCodes() {
161: if (fErrorCodes == null)
162: return null;
163: return new StringListImpl(fErrorCodes, fErrorCodes.length);
164: }
165:
166: // This is the only information we can provide in a pipeline.
167: public String getValidationContext() {
168: return fValidationContext;
169: }
170:
171: /**
172: * [nil]
173: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-nil>XML Schema Part 1: Structures [nil]</a>
174: * @return true if clause 3.2 of Element Locally Valid (Element) (3.3.4) above is satisfied, otherwise false
175: */
176: public boolean getNil() {
177: return fNil;
178: }
179:
180: /**
181: * [notation]
182: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-notation>XML Schema Part 1: Structures [notation]</a>
183: * @return The notation declaration.
184: */
185: public XSNotationDeclaration getNotation() {
186: return fNotation;
187: }
188:
189: /**
190: * An item isomorphic to the type definition used to validate this element.
191: *
192: * @return a type declaration
193: */
194: public XSTypeDefinition getTypeDefinition() {
195: return fTypeDecl;
196: }
197:
198: /**
199: * If and only if that type definition is a simple type definition
200: * with {variety} union, or a complex type definition whose {content type}
201: * is a simple thype definition with {variety} union, then an item isomorphic
202: * to that member of the union's {member type definitions} which actually
203: * validated the element item's normalized value.
204: *
205: * @return a simple type declaration
206: */
207: public XSSimpleTypeDefinition getMemberTypeDefinition() {
208: return fMemberType;
209: }
210:
211: /**
212: * An item isomorphic to the element declaration used to validate
213: * this element.
214: *
215: * @return an element declaration
216: */
217: public XSElementDeclaration getElementDeclaration() {
218: return fDeclaration;
219: }
220:
221: /**
222: * [schema information]
223: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_information">XML Schema Part 1: Structures [schema information]</a>
224: * @return The schema information property if it's the validation root,
225: * null otherwise.
226: */
227: public synchronized XSModel getSchemaInformation() {
228: if (fSchemaInformation == null && fGrammars != null) {
229: fSchemaInformation = new XSModelImpl(fGrammars);
230: }
231: return fSchemaInformation;
232: }
233:
234: /* (non-Javadoc)
235: * @see org.apache.xerces.xs.ItemPSVI#getActualNormalizedValue()
236: */
237: public Object getActualNormalizedValue() {
238: return this .fActualValue;
239: }
240:
241: /* (non-Javadoc)
242: * @see org.apache.xerces.xs.ItemPSVI#getActualNormalizedValueType()
243: */
244: public short getActualNormalizedValueType() {
245: return this .fActualValueType;
246: }
247:
248: /* (non-Javadoc)
249: * @see org.apache.xerces.xs.ItemPSVI#getItemValueTypes()
250: */
251: public ShortList getItemValueTypes() {
252: return this .fItemValueTypes;
253: }
254:
255: /**
256: * Reset() should be called in validator startElement(..) method.
257: */
258: public void reset() {
259: fDeclaration = null;
260: fTypeDecl = null;
261: fNil = false;
262: fSpecified = false;
263: fNotation = null;
264: fMemberType = null;
265: fValidationAttempted = ElementPSVI.VALIDATION_NONE;
266: fValidity = ElementPSVI.VALIDITY_NOTKNOWN;
267: fErrorCodes = null;
268: fValidationContext = null;
269: fNormalizedValue = null;
270: fActualValue = null;
271: fActualValueType = XSConstants.UNAVAILABLE_DT;
272: fItemValueTypes = null;
273: }
274:
275: }
|