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.XSAttributeDeclaration;
023: import org.apache.xerces.xs.XSSimpleTypeDefinition;
024: import org.apache.xerces.xs.XSTypeDefinition;
025: import org.apache.xerces.impl.xs.util.StringListImpl;
026: import org.apache.xerces.xs.AttributePSVI;
027: import org.apache.xerces.xs.XSConstants;
028:
029: /**
030: * Attribute PSV infoset augmentations implementation.
031: * The PSVI information for attributes will be available at the startElement call.
032: *
033: * @xerces.internal
034: *
035: * @author Elena Litani IBM
036: * @version $Id: AttributePSVImpl.java 446734 2006-09-15 20:51:23Z mrglavas $
037: */
038: public class AttributePSVImpl implements AttributePSVI {
039:
040: /** attribute declaration */
041: protected XSAttributeDeclaration fDeclaration = null;
042:
043: /** type of attribute, simpleType */
044: protected XSTypeDefinition fTypeDecl = null;
045:
046: /** If this attribute was explicitly given a
047: * value in the original document, this is false; otherwise, it is true */
048: protected boolean fSpecified = false;
049:
050: /** schema normalized value property */
051: protected String fNormalizedValue = null;
052:
053: /** schema actual value */
054: protected Object fActualValue = null;
055:
056: /** schema actual value type */
057: protected short fActualValueType = XSConstants.UNAVAILABLE_DT;
058:
059: /** actual value types if the value is a list */
060: protected ShortList fItemValueTypes = null;
061:
062: /** member type definition against which attribute was validated */
063: protected XSSimpleTypeDefinition fMemberType = null;
064:
065: /** validation attempted: none, partial, full */
066: protected short fValidationAttempted = AttributePSVI.VALIDATION_NONE;
067:
068: /** validity: valid, invalid, unknown */
069: protected short fValidity = AttributePSVI.VALIDITY_NOTKNOWN;
070:
071: /** error codes */
072: protected String[] fErrorCodes = null;
073:
074: /** validation context: could be QName or XPath expression*/
075: protected String fValidationContext = null;
076:
077: //
078: // AttributePSVI methods
079: //
080:
081: /**
082: * [schema default]
083: *
084: * @return The canonical lexical representation of the declaration's {value constraint} value.
085: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_default>XML Schema Part 1: Structures [schema default]</a>
086: */
087: public String getSchemaDefault() {
088: return fDeclaration == null ? null : fDeclaration
089: .getConstraintValue();
090: }
091:
092: /**
093: * [schema normalized value]
094: *
095: *
096: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_normalized_value>XML Schema Part 1: Structures [schema normalized value]</a>
097: * @return the normalized value of this item after validation
098: */
099: public String getSchemaNormalizedValue() {
100: return fNormalizedValue;
101: }
102:
103: /**
104: * [schema specified]
105: * @see <a href="http://www.w3.org/TR/xmlschema-1/#e-schema_specified">XML Schema Part 1: Structures [schema specified]</a>
106: * @return true - value was specified in schema, false - value comes from the infoset
107: */
108: public boolean getIsSchemaSpecified() {
109: return fSpecified;
110: }
111:
112: /**
113: * Determines the extent to which the document has been validated
114: *
115: * @return return the [validation attempted] property. The possible values are
116: * NO_VALIDATION, PARTIAL_VALIDATION and FULL_VALIDATION
117: */
118: public short getValidationAttempted() {
119: return fValidationAttempted;
120: }
121:
122: /**
123: * Determine the validity of the node with respect
124: * to the validation being attempted
125: *
126: * @return return the [validity] property. Possible values are:
127: * UNKNOWN_VALIDITY, INVALID_VALIDITY, VALID_VALIDITY
128: */
129: public short getValidity() {
130: return fValidity;
131: }
132:
133: /**
134: * A list of error codes generated from validation attempts.
135: * Need to find all the possible subclause reports that need reporting
136: *
137: * @return list of error codes
138: */
139: public StringList getErrorCodes() {
140: if (fErrorCodes == null)
141: return null;
142: return new StringListImpl(fErrorCodes, fErrorCodes.length);
143: }
144:
145: // This is the only information we can provide in a pipeline.
146: public String getValidationContext() {
147: return fValidationContext;
148: }
149:
150: /**
151: * An item isomorphic to the type definition used to validate this element.
152: *
153: * @return a type declaration
154: */
155: public XSTypeDefinition getTypeDefinition() {
156: return fTypeDecl;
157: }
158:
159: /**
160: * If and only if that type definition is a simple type definition
161: * with {variety} union, or a complex type definition whose {content type}
162: * is a simple thype definition with {variety} union, then an item isomorphic
163: * to that member of the union's {member type definitions} which actually
164: * validated the element item's normalized value.
165: *
166: * @return a simple type declaration
167: */
168: public XSSimpleTypeDefinition getMemberTypeDefinition() {
169: return fMemberType;
170: }
171:
172: /**
173: * An item isomorphic to the attribute declaration used to validate
174: * this attribute.
175: *
176: * @return an attribute declaration
177: */
178: public XSAttributeDeclaration getAttributeDeclaration() {
179: return fDeclaration;
180: }
181:
182: /* (non-Javadoc)
183: * @see org.apache.xerces.xs.ItemPSVI#getActualNormalizedValue()
184: */
185: public Object getActualNormalizedValue() {
186: return this .fActualValue;
187: }
188:
189: /* (non-Javadoc)
190: * @see org.apache.xerces.xs.ItemPSVI#getActualNormalizedValueType()
191: */
192: public short getActualNormalizedValueType() {
193: return this .fActualValueType;
194: }
195:
196: /* (non-Javadoc)
197: * @see org.apache.xerces.xs.ItemPSVI#getItemValueTypes()
198: */
199: public ShortList getItemValueTypes() {
200: return this .fItemValueTypes;
201: }
202:
203: /**
204: * Reset()
205: */
206: public void reset() {
207: fNormalizedValue = null;
208: fActualValue = null;
209: fActualValueType = XSConstants.UNAVAILABLE_DT;
210: fItemValueTypes = null;
211: fDeclaration = null;
212: fTypeDecl = null;
213: fSpecified = false;
214: fMemberType = null;
215: fValidationAttempted = AttributePSVI.VALIDATION_NONE;
216: fValidity = AttributePSVI.VALIDITY_NOTKNOWN;
217: fErrorCodes = null;
218: fValidationContext = null;
219: }
220: }
|