1 /* Copyright 2004 The Apache Software Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package org.apache.xmlbeans.impl.values;
17
18 import org.apache.xmlbeans.SchemaType;
19 import org.apache.xmlbeans.XmlObject;
20 import org.apache.xmlbeans.XmlAnySimpleType;
21 import org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem;
22
23 /**
24 * This class implements the anySimpleType for XML.
25 *
26 */
27 public class XmlAnySimpleTypeImpl extends XmlObjectBase implements XmlAnySimpleType
28 {
29 public XmlAnySimpleTypeImpl(SchemaType type, boolean complex)
30 { _schemaType = type; initComplexType(complex, false); }
31
32 public XmlAnySimpleTypeImpl()
33 { _schemaType = BuiltinSchemaTypeSystem.ST_ANY_SIMPLE; }
34
35 public SchemaType schemaType()
36 { return _schemaType; }
37
38 private SchemaType _schemaType;
39
40 String _textvalue = "";
41
42 protected int get_wscanon_rule()
43 {
44 return SchemaType.WS_PRESERVE;
45 }
46
47 // SIMPLE VALUE ACCESSORS BELOW -------------------------------------------
48 // gets raw text value
49 protected String compute_text(NamespaceManager nsm) { return _textvalue; }
50 protected void set_text(String s)
51 {
52 _textvalue = s;
53 }
54
55 protected void set_nil()
56 {
57 _textvalue = null;
58 }
59
60 // comparators
61 protected boolean equal_to(XmlObject obj)
62 {
63 // compares against another anySimpleType
64 // rule is: lexical values must match.
65 return _textvalue.equals(((XmlAnySimpleType)obj).getStringValue());
66 }
67
68 protected int value_hash_code()
69 {
70 // matches JavaStringHolder's value_hash_code, so we can be hased against strings
71 return (_textvalue == null ? 0 : _textvalue.hashCode());
72 }
73 }