001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.databinding.types;
020:
021: import org.apache.axis2.databinding.utils.ConverterUtil;
022:
023: import javax.xml.namespace.QName;
024: import javax.xml.stream.XMLStreamException;
025: import javax.xml.stream.XMLStreamReader;
026: import java.math.BigDecimal;
027:
028: /** this class is the super class of all the union simple types */
029: public abstract class Union {
030: // object to store values
031: protected Object localObject;
032:
033: public Object getObject() {
034: return localObject;
035: }
036:
037: public abstract void setObject(Object localObject);
038:
039: public String toString() {
040: return this .localObject.toString();
041: }
042:
043: /**
044: * method to parse xmlschema objects
045: *
046: * @param xmlStreamReader
047: * @param namespaceURI
048: * @param type
049: * @throws URI.MalformedURIException
050: * @throws XMLStreamException
051: */
052:
053: public void setObject(XMLStreamReader xmlStreamReader,
054: String namespaceURI, String type)
055: throws URI.MalformedURIException, XMLStreamException {
056: String value = xmlStreamReader.getElementText();
057: if ("string".equals(type)) {
058: setObject(value);
059: } else if ("int".equals(type) || "integer".equals(type)) {
060: setObject(new Integer(value));
061: } else if ("boolean".equals(type)) {
062: setObject(new Boolean(value));
063: } else if ("anyURI".equals(type)) {
064: setObject(new URI(value));
065: } else if ("date".equals(type)) {
066: setObject(ConverterUtil.convertToDate(value));
067: } else if ("QName".equals(type)) {
068: if (value.indexOf(":") > 0) {
069: // i.e it has a name space
070: String prefix = value.substring(0, value.indexOf(":"));
071: String localPart = value
072: .substring(value.indexOf(":") + 1);
073: String namespace = xmlStreamReader
074: .getNamespaceURI(prefix);
075: setObject(new QName(namespace, localPart, prefix));
076: } else {
077: setObject(new QName(value));
078: }
079: } else if ("dateTime".equals(type)) {
080: setObject(ConverterUtil.convertToDateTime(value));
081: } else if ("time".equals(type)) {
082: setObject(ConverterUtil.convertToTime(value));
083: } else if ("float".equals(type)) {
084: setObject(new Float(value));
085: } else if ("long".equals(type)) {
086: setObject(new Long(value));
087: } else if ("double".equals(type)) {
088: setObject(new Double(value));
089: } else if ("decimal".equals(type)) {
090: setObject(new BigDecimal(value));
091: } else if ("unsignedLong".equals(type)) {
092: setObject(new UnsignedLong(value));
093: } else if ("unsignedInt".equals(type)) {
094: setObject(new UnsignedInt(value));
095: } else if ("unsignedShort".equals(type)) {
096: setObject(new UnsignedShort(value));
097: } else if ("unsignedByte".equals(type)) {
098: setObject(new UnsignedByte(value));
099: } else if ("positiveInteger".equals(type)) {
100: setObject(new PositiveInteger(value));
101: } else if ("negativeInteger".equals(type)) {
102: setObject(new NegativeInteger(value));
103: } else if ("nonNegativeInteger".equals(type)) {
104: setObject(new NonNegativeInteger(value));
105: } else if ("nonPositiveInteger".equals(type)) {
106: setObject(new NonPositiveInteger(value));
107: } else {
108: throw new RuntimeException("Object not found");
109: }
110: }
111:
112: }
|