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 BooleanValue extends Value {
029:
030: /** The Boolean array. */
031: private Boolean[] values;
032:
033: public BooleanValue() {
034: this ((Boolean) null);
035: }
036:
037: public BooleanValue(Boolean value) {
038: this (new Boolean[] { value });
039: }
040:
041: public BooleanValue(boolean value) {
042: this (new boolean[] { value });
043: }
044:
045: public BooleanValue(String value) {
046: this (new String[] { value });
047: }
048:
049: public BooleanValue(Boolean[] values) {
050: if (values == null) {
051: throw new IllegalArgumentException();
052: }
053: this .values = values;
054: }
055:
056: public BooleanValue(boolean[] _values) {
057: if (_values == null) {
058: throw new IllegalArgumentException();
059: }
060: values = new Boolean[_values.length];
061: for (int i = 0; i < _values.length; i++) {
062: values[i] = Boolean.valueOf(_values[i]);
063: }
064: }
065:
066: public BooleanValue(String[] values)
067: throws IllegalArgumentException {
068: if (values == null) {
069: throw new IllegalArgumentException();
070: }
071: this .values = new Boolean[values.length];
072: for (int i = 0; i < values.length; i++) {
073: String value = values[i];
074: if (value == null) {
075: this .values[i] = null;
076: } else if ("true".equals(value)) {
077: this .values[i] = Boolean.TRUE;
078: } else if ("false".equals(value)) {
079: this .values[i] = Boolean.FALSE;
080: } else {
081: throw new IllegalArgumentException();
082: }
083: }
084: }
085:
086: public boolean isInstanceOf(Class clazz) {
087: return clazz != null && clazz.isAssignableFrom(Boolean.class);
088: }
089:
090: public String[] asStringArray() {
091: try {
092: return Helper.toStringArray(values,
093: Helper.BOOLEAN_CONVERTER);
094: } catch (ConversionException impossible) {
095: throw new Error(impossible);
096: }
097: }
098:
099: public String asString() {
100: if (isNull()) {
101: return null;
102: }
103: return values[0].toString();
104: }
105:
106: public Object[] asObjectArray() {
107: return values;
108: }
109: }
|