001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.migration.model22.other;
023:
024: /**
025: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
026: * @version $Revision: 8784 $
027: */
028: public class IntegerValue extends Value {
029:
030: /** The Integer array. */
031: private Integer[] values;
032:
033: public IntegerValue() {
034: this ((Integer) null);
035: }
036:
037: public IntegerValue(Integer integer) {
038: this (new Integer[] { integer });
039: }
040:
041: public IntegerValue(int _value) {
042: this (new int[] { _value });
043: }
044:
045: public IntegerValue(String value) {
046: this (new String[] { value });
047: }
048:
049: public IntegerValue(Integer[] values) {
050: if (values == null) {
051: throw new IllegalArgumentException();
052: }
053: this .values = values;
054: }
055:
056: public IntegerValue(int[] _values) {
057: if (_values == null) {
058: throw new IllegalArgumentException();
059: }
060: values = new Integer[_values.length];
061: for (int i = 0; i < _values.length; i++) {
062: values[i] = new Integer(_values[i]);
063: }
064: }
065:
066: public IntegerValue(String[] values)
067: throws IllegalArgumentException {
068: if (values == null) {
069: throw new IllegalArgumentException();
070: }
071: try {
072: this .values = new Integer[values.length];
073: for (int i = 0; i < values.length; i++) {
074: String value = values[i];
075: if (value != null) {
076: this .values[i] = new Integer(value);
077: }
078: }
079: } catch (NumberFormatException e) {
080: throw new IllegalArgumentException();
081: }
082: }
083:
084: public boolean isInstanceOf(Class clazz) {
085: return clazz != null && clazz.isAssignableFrom(Integer.class);
086: }
087:
088: public String[] asStringArray() {
089: try {
090: return Helper.toStringArray(values,
091: Helper.INTEGER_CONVERTER);
092: } catch (ConversionException impossible) {
093: throw new Error(impossible);
094: }
095: }
096:
097: public String asString() {
098: if (isNull()) {
099: return null;
100: }
101: return values[0].toString();
102: }
103:
104: public Object[] asObjectArray() {
105: return values;
106: }
107: }
|