001: /*
002: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Adam Megacz
028: */
029:
030: package com.caucho.jaxb.property;
031:
032: import javax.xml.bind.JAXBException;
033: import javax.xml.bind.Unmarshaller;
034: import javax.xml.namespace.QName;
035: import javax.xml.stream.events.*;
036: import javax.xml.stream.XMLStreamException;
037: import javax.xml.stream.XMLStreamReader;
038: import java.io.IOException;
039: import java.lang.reflect.Array;
040: import java.util.ArrayList;
041:
042: import com.caucho.util.L10N;
043:
044: /**
045: * a property for serializing/deserializing arrays
046: */
047: public abstract class ArrayProperty extends IterableProperty {
048: private static final L10N L = new L10N(CDataProperty.class);
049:
050: protected ArrayProperty(Property componentProperty) {
051: _componentProperty = componentProperty;
052: }
053:
054: public static ArrayProperty createArrayProperty(
055: Property componentProperty, Class type)
056: throws JAXBException {
057: if (!type.isPrimitive())
058: return new ObjectArrayProperty(componentProperty, type);
059:
060: if (Double.TYPE.equals(type))
061: return DoubleArrayProperty.PROPERTY;
062:
063: if (Float.TYPE.equals(type))
064: return FloatArrayProperty.PROPERTY;
065:
066: if (Integer.TYPE.equals(type))
067: return IntegerArrayProperty.PROPERTY;
068:
069: if (Long.TYPE.equals(type))
070: return LongArrayProperty.PROPERTY;
071:
072: if (Boolean.TYPE.equals(type))
073: return BooleanArrayProperty.PROPERTY;
074:
075: if (Character.TYPE.equals(type))
076: return CharacterArrayProperty.PROPERTY;
077:
078: if (Short.TYPE.equals(type))
079: return ShortArrayProperty.PROPERTY;
080:
081: /* XXX
082: if (Byte.TYPE.equals(type))
083: return ByteArrayProperty.PROPERTY; */
084:
085: throw new JAXBException(L.l(
086: "{0} is neither primitive, nor non-primitive!", type));
087: }
088:
089: public QName getSchemaType() {
090: return _componentProperty.getSchemaType();
091: }
092:
093: public String getMaxOccurs() {
094: return "unbounded";
095: }
096:
097: protected boolean isPrimitiveType() {
098: return false;
099: }
100:
101: public boolean isXmlPrimitiveType() {
102: return _componentProperty.isXmlPrimitiveType();
103: }
104:
105: public boolean isNullable() {
106: return true;
107: }
108: }
|