Example usage for java.lang Boolean TYPE

List of usage examples for java.lang Boolean TYPE

Introduction

In this page you can find the example usage for java.lang Boolean TYPE.

Prototype

Class TYPE

To view the source code for java.lang Boolean TYPE.

Click Source Link

Document

The Class object representing the primitive type boolean.

Usage

From source file:org.rimudb.PropertyNode.java

public PropertyNode(DataObjectNode parent, Element element, int keySeqeunce) {
    this.name = element.getFirstChild().getNodeValue();
    this.sourceName = this.name;
    this.parent = parent;

    if (parent == null) {
        log.warn("Parent of " + name + " is null");
    }//from   w w w . ja  va 2s .c om

    try {
        pdesc = parent.getPropertyDescriptor(name);
        if (pdesc == null) {
            throw new NullPointerException(
                    "PropertyDescriptor for " + parent.getName() + "." + name + " could not be found.");
        }
        read = pdesc.getReadMethod();
        if (read == null && log.isDebugEnabled()) {
            log.debug("Read method for " + parent.getName() + "." + name + " could not be found.");
        }
        write = pdesc.getWriteMethod();
        if (write == null && log.isDebugEnabled()) {
            log.debug("Write method for " + parent.getName() + "." + name + " could not be found.");
        }
        if (write != null) {
            Class[] parmTypes = write.getParameterTypes();
            parmType = parmTypes[0];
            if (parmType == Integer.TYPE) {
                parmType = Integer.class;
            }
            if (parmType == Long.TYPE) {
                parmType = Long.class;
            }
            if (parmType == Boolean.TYPE) {
                parmType = Boolean.class;
            }
            valueConstructor = null;
            if (parmType != java.sql.Timestamp.class && parmType != java.sql.Date.class) {
                try {
                    valueConstructor = parmType.getConstructor(new Class[] { String.class });
                } catch (NoSuchMethodException e) {
                    log.error("Cannot find a constructor: " + parmType.getName() + "(String s)", e);
                }
            }
        }

        // Set some attributes
        String source = element.getAttribute("source");
        if (source == null)
            source = "";
        fromParent = source.equalsIgnoreCase("parent"); // bypass elements for parent
        constant = source.equalsIgnoreCase("constant");

        String trim = element.getAttribute("trim");
        if (trim == null)
            trim = "none";
        if (trim.equalsIgnoreCase("both"))
            this.trimMode = TRIMBOTH;
        if (trim.equalsIgnoreCase("right"))
            this.trimMode = TRIMRIGHT;

        if (fromParent) {
            sourceName = element.getAttribute("sourceName");
            if (sourceName == null || sourceName.trim().length() == 0) {
                sourceName = this.name;
            }

            sourceParent = element.getAttribute("sourceParent");

            String sourceIsIdentityStr = element.getAttribute("sourceIsIdentity");
            sourceIsIdentity = (sourceIsIdentityStr != null && sourceIsIdentityStr.equalsIgnoreCase("true"));
        }

    } catch (Exception e) {
        log.error("in PropertyNode.PropertyNode", e);
    }

}

From source file:nl.strohalm.cyclos.controls.settings.EditLocalSettingsAction.java

public DataBinder<LocalSettings> getDataBinder() {
    if (dataBinder == null) {

        final BeanBinder<TransactionNumber> transactionNumberBinder = BeanBinder
                .instance(TransactionNumber.class, "transactionNumber");
        transactionNumberBinder.registerBinder("prefix", PropertyBinder.instance(String.class, "prefix"));
        transactionNumberBinder.registerBinder("padLength", PropertyBinder.instance(Integer.TYPE, "padLength"));
        transactionNumberBinder.registerBinder("suffix", PropertyBinder.instance(String.class, "suffix"));
        transactionNumberBinder.registerBinder("enabled", PropertyBinder.instance(Boolean.TYPE, "enabled"));

        final BeanBinder<LocalSettings> binder = BeanBinder.instance(LocalSettings.class);
        binder.registerBinder("applicationName", PropertyBinder.instance(String.class, "applicationName"));
        binder.registerBinder("applicationUsername",
                PropertyBinder.instance(String.class, "applicationUsername"));
        binder.registerBinder("rootUrl", PropertyBinder.instance(String.class, "rootUrl"));

        binder.registerBinder("language", PropertyBinder.instance(Language.class, "language"));
        binder.registerBinder("numberLocale",
                PropertyBinder.instance(LocalSettings.NumberLocale.class, "numberLocale"));
        binder.registerBinder("precision", PropertyBinder.instance(LocalSettings.Precision.class, "precision"));
        binder.registerBinder("highPrecision",
                PropertyBinder.instance(LocalSettings.Precision.class, "highPrecision"));
        binder.registerBinder("decimalInputMethod",
                PropertyBinder.instance(LocalSettings.DecimalInputMethod.class, "decimalInputMethod"));
        binder.registerBinder("datePattern",
                PropertyBinder.instance(LocalSettings.DatePattern.class, "datePattern"));
        binder.registerBinder("timePattern",
                PropertyBinder.instance(LocalSettings.TimePattern.class, "timePattern"));
        binder.registerBinder("timeZone",
                PropertyBinder.instance(TimeZone.class, "timeZone", TimeZoneConverter.instance()));
        binder.registerBinder("containerUrl", PropertyBinder.instance(String.class, "containerUrl"));

        binder.registerBinder("maxIteratorResults",
                PropertyBinder.instance(Integer.TYPE, "maxIteratorResults"));
        binder.registerBinder("maxPageResults", PropertyBinder.instance(Integer.TYPE, "maxPageResults"));
        binder.registerBinder("maxAjaxResults", PropertyBinder.instance(Integer.TYPE, "maxAjaxResults"));
        binder.registerBinder("maxUploadSize", PropertyBinder.instance(Integer.TYPE, "maxUploadSize"));
        binder.registerBinder("maxUploadUnits", PropertyBinder.instance(FileUnits.class, "maxUploadUnits"));
        binder.registerBinder("maxImageWidth", PropertyBinder.instance(Integer.TYPE, "maxImageWidth"));
        binder.registerBinder("maxImageHeight", PropertyBinder.instance(Integer.TYPE, "maxImageHeight"));
        binder.registerBinder("maxThumbnailWidth", PropertyBinder.instance(Integer.TYPE, "maxThumbnailWidth"));
        binder.registerBinder("maxThumbnailHeight",
                PropertyBinder.instance(Integer.TYPE, "maxThumbnailHeight"));

        binder.registerBinder("csvUseHeader", PropertyBinder.instance(Boolean.TYPE, "csvUseHeader"));
        binder.registerBinder("csvRecordSeparator",
                PropertyBinder.instance(LocalSettings.CsvRecordSeparator.class, "csvRecordSeparator"));
        binder.registerBinder("csvValueSeparator",
                PropertyBinder.instance(LocalSettings.CsvValueSeparator.class, "csvValueSeparator"));
        binder.registerBinder("csvStringQuote",
                PropertyBinder.instance(LocalSettings.CsvStringQuote.class, "csvStringQuote"));

        binder.registerBinder("cyclosId", PropertyBinder.instance(String.class, "cyclosId"));
        binder.registerBinder("smsEnabled", PropertyBinder.instance(Boolean.TYPE, "smsEnabled"));
        binder.registerBinder("sendSmsWebServiceUrl",
                PropertyBinder.instance(String.class, "sendSmsWebServiceUrl"));
        binder.registerBinder("smsCustomFieldId", PropertyBinder.instance(Long.TYPE, "smsCustomFieldId"));
        binder.registerBinder("smsChannelName", PropertyBinder.instance(String.class, "smsChannelName"));

        binder.registerBinder("emailRequired", PropertyBinder.instance(Boolean.TYPE, "emailRequired"));
        binder.registerBinder("emailUnique", PropertyBinder.instance(Boolean.TYPE, "emailUnique"));
        binder.registerBinder("transactionNumber", transactionNumberBinder);

        binder.registerBinder("brokeringExpirationPeriod",
                DataBinderHelper.timePeriodBinder("brokeringExpirationPeriod"));
        binder.registerBinder("deleteMessagesOnTrashAfter",
                DataBinderHelper.timePeriodBinder("deleteMessagesOnTrashAfter"));
        binder.registerBinder("deletePendingRegistrationsAfter",
                DataBinderHelper.timePeriodBinder("deletePendingRegistrationsAfter"));
        binder.registerBinder("memberSortOrder",
                PropertyBinder.instance(LocalSettings.SortOrder.class, "memberSortOrder"));
        binder.registerBinder("memberResultDisplay",
                PropertyBinder.instance(LocalSettings.MemberResultDisplay.class, "memberResultDisplay"));
        binder.registerBinder("adDescriptionFormat",
                PropertyBinder.instance(TextFormat.class, "adDescriptionFormat"));
        binder.registerBinder("messageFormat", PropertyBinder.instance(TextFormat.class, "messageFormat"));

        binder.registerBinder("schedulingHour", PropertyBinder.instance(Integer.TYPE, "schedulingHour"));
        binder.registerBinder("schedulingMinute", PropertyBinder.instance(Integer.TYPE, "schedulingMinute"));
        binder.registerBinder("transferListenerClass",
                PropertyBinder.instance(String.class, "transferListenerClass"));

        binder.registerBinder("maxChargebackTime", DataBinderHelper.timePeriodBinder("maxChargebackTime"));
        binder.registerBinder("chargebackDescription",
                PropertyBinder.instance(String.class, "chargebackDescription"));
        binder.registerBinder("showCountersInAdCategories",
                PropertyBinder.instance(Boolean.TYPE, "showCountersInAdCategories"));

        dataBinder = binder;//w  w  w  . ja v a 2 s  .  c o m
    }
    return dataBinder;
}

From source file:be.fedict.commons.eid.consumer.tlv.TlvParser.java

private static <T> T parseThrowing(final byte[] file, final Class<T> tlvClass) throws InstantiationException,
        IllegalAccessException, DataConvertorException, UnsupportedEncodingException {
    final Field[] fields = tlvClass.getDeclaredFields();
    final Map<Integer, Field> tlvFields = new HashMap<Integer, Field>();
    final T tlvObject = tlvClass.newInstance();
    for (Field field : fields) {
        final TlvField tlvFieldAnnotation = field.getAnnotation(TlvField.class);
        if (null != tlvFieldAnnotation) {
            final int tagId = tlvFieldAnnotation.value();
            if (tlvFields.containsKey(new Integer(tagId))) {
                throw new IllegalArgumentException("TLV field duplicate: " + tagId);
            }/*from w w  w  .  j  a v  a2  s  .c om*/
            tlvFields.put(new Integer(tagId), field);
        }
        final OriginalData originalDataAnnotation = field.getAnnotation(OriginalData.class);
        if (null != originalDataAnnotation) {
            field.setAccessible(true);
            field.set(tlvObject, file);
        }
    }

    int idx = 0;
    while (idx < file.length - 1) {
        final byte tag = file[idx];
        idx++;
        byte lengthByte = file[idx];
        int length = lengthByte & 0x7f;
        while ((lengthByte & 0x80) == 0x80) {
            idx++;
            lengthByte = file[idx];
            length = (length << 7) + (lengthByte & 0x7f);
        }
        idx++;
        if (0 == tag) {
            idx += length;
            continue;
        }
        if (tlvFields.containsKey(new Integer(tag))) {
            final Field tlvField = tlvFields.get(new Integer(tag));
            final Class<?> tlvType = tlvField.getType();
            final ConvertData convertDataAnnotation = tlvField.getAnnotation(ConvertData.class);
            final byte[] tlvValue = copy(file, idx, length);
            Object fieldValue;
            if (null != convertDataAnnotation) {
                final Class<? extends DataConvertor<?>> dataConvertorClass = convertDataAnnotation.value();
                final DataConvertor<?> dataConvertor = dataConvertorClass.newInstance();
                fieldValue = dataConvertor.convert(tlvValue);
            } else if (String.class == tlvType) {
                fieldValue = new String(tlvValue, "UTF-8");
            } else if (Boolean.TYPE == tlvType) {
                fieldValue = true;
            } else if (tlvType.isArray() && Byte.TYPE == tlvType.getComponentType()) {
                fieldValue = tlvValue;
            } else {
                throw new IllegalArgumentException("unsupported field type: " + tlvType.getName());
            }
            if (null != tlvField.get(tlvObject) && false == tlvField.getType().isPrimitive()) {
                throw new RuntimeException("field was already set: " + tlvField.getName());
            }
            tlvField.setAccessible(true);
            tlvField.set(tlvObject, fieldValue);
        } else {
            LOG.debug("unknown tag: " + (tag & 0xff) + ", length: " + length);
        }
        idx += length;
    }
    return tlvObject;
}

From source file:demo.config.PropertyConverter.java

/**
 * Converts the specified value to the target class. If the class is a
 * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned will
 * use the wrapper type (Integer.class, Boolean.class, etc).
 * /*  w  w w .j  a v a 2 s  . c  om*/
 * @param cls
 *            the target class of the converted value
 * @param value
 *            the value to convert
 * @param params
 *            optional parameters used for the conversion
 * @return the converted value
 * @throws ConversionException
 *             if the value is not compatible with the requested type
 * 
 * @since 1.5
 */
static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException {
    if (cls.isInstance(value)) {
        return value; // no conversion needed
    }

    if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
        return toBoolean(value);
    } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) {
        return toCharacter(value);
    } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
        if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
            return toInteger(value);
        } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
            return toLong(value);
        } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
            return toByte(value);
        } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
            return toShort(value);
        } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
            return toFloat(value);
        } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
            return toDouble(value);
        } else if (BigInteger.class.equals(cls)) {
            return toBigInteger(value);
        } else if (BigDecimal.class.equals(cls)) {
            return toBigDecimal(value);
        }
    } else if (Date.class.equals(cls)) {
        return toDate(value, (String) params[0]);
    } else if (Calendar.class.equals(cls)) {
        return toCalendar(value, (String) params[0]);
    } else if (URL.class.equals(cls)) {
        return toURL(value);
    } else if (Locale.class.equals(cls)) {
        return toLocale(value);
    } else if (isEnum(cls)) {
        return convertToEnum(cls, value);
    } else if (Color.class.equals(cls)) {
        return toColor(value);
    } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) {
        return toInternetAddress(value);
    } else if (InetAddress.class.isAssignableFrom(cls)) {
        return toInetAddress(value);
    }

    throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")"
            + " can't be converted to a " + cls.getName() + " object");
}

From source file:nl.strohalm.cyclos.controls.customization.fields.EditCustomFieldAction.java

private static DataBinder<? extends CustomField> getBasicDataBinder(final CustomField.Nature nature) {

    final BeanBinder<Validation> validationBinder = BeanBinder.instance(Validation.class, "validation");
    validationBinder.registerBinder("required", PropertyBinder.instance(Boolean.TYPE, "required"));
    validationBinder.registerBinder("unique", PropertyBinder.instance(Boolean.TYPE, "unique"));
    validationBinder.registerBinder("lengthConstraint",
            DataBinderHelper.rangeConstraintBinder("lengthConstraint"));
    validationBinder.registerBinder("validatorClass", PropertyBinder.instance(String.class, "validatorClass"));

    final BeanBinder<? extends CustomField> binder = BeanBinder.instance(nature.getEntityType());
    binder.registerBinder("id", PropertyBinder.instance(Long.class, "id", IdConverter.instance()));
    binder.registerBinder("internalName", PropertyBinder.instance(String.class, "internalName"));
    binder.registerBinder("name", PropertyBinder.instance(String.class, "name"));
    binder.registerBinder("pattern", PropertyBinder.instance(String.class, "pattern"));
    binder.registerBinder("parent", PropertyBinder.instance(CustomField.class, "parent"));
    binder.registerBinder("description", PropertyBinder.instance(String.class, "description"));
    binder.registerBinder("type", PropertyBinder.instance(CustomField.Type.class, "type"));
    binder.registerBinder("control", PropertyBinder.instance(CustomField.Control.class, "control"));
    binder.registerBinder("size", PropertyBinder.instance(CustomField.Size.class, "size"));
    binder.registerBinder("allSelectedLabel", PropertyBinder.instance(String.class, "allSelectedLabel"));
    binder.registerBinder("validation", validationBinder);
    return binder;
}

From source file:org.sakaiproject.james.PhoenixLauncherMain.java

/**
 * Method to call to startup Phoenix from an external (calling) application. Protected to allow access from DaemonLauncher.
 * /*from  w w w .  jav a2 s  .  com*/
 * @param args
 *        the command line arg array
 * @param data
 *        a set of extra parameters to pass to embeddor
 * @param blocking
 *        false if the current thread is expected to return.
 * @return the exit code which should be used to exit the JVM
 * @throws Exception
 *         if an error occurs
 */
protected static final int startup(final String[] args, final Map data, final boolean blocking)
        throws Exception {
    int exitCode;
    try {
        // setup new Policy manager
        // TODO: (done) removed
        // Policy.setPolicy( new FreeNEasyPolicy() );

        // Create engine ClassLoader
        // TODO: (done) removed
        // final URL[] urls = getEngineClassPath();
        // final URLClassLoader classLoader = new URLClassLoader( urls );

        // TODO: add these extra paths to the existing classloader
        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

        // TODO: (done) use the one classloader
        // data.put( "common.classloader", ClassLoader.getSystemClassLoader() );
        data.put("common.classloader", classLoader);

        data.put("container.classloader", classLoader);
        data.put("phoenix.home", new File(findPhoenixHome()));

        // Setup context classloader
        // TODO: (done) removed
        // Thread.currentThread().setContextClassLoader( classLoader );

        // Create main launcher
        final Class clazz = classLoader.loadClass(MAIN_CLASS);
        final Class[] paramTypes = new Class[] { args.getClass(), Map.class, Boolean.TYPE };
        final Method method = clazz.getMethod("main", paramTypes);
        c_frontend = clazz.newInstance();

        // kick the tires and light the fires....
        final Integer integer = (Integer) method.invoke(c_frontend,
                new Object[] { args, data, Boolean.valueOf(blocking) });
        exitCode = integer.intValue();
    } catch (final Exception e) {
        // TODO: (done) changed to a log
        // e.printStackTrace();
        M_log.warn("PhoenixLauncherMain.startup: " + e);
        exitCode = 1;
    }
    return exitCode;
}

From source file:de.hasait.clap.impl.CLAPOptionNode.java

private CLAPOptionNode(final CLAP pCLAP, final Class<T> pResultClass, final Character pShortKey,
        final String pLongKey, final boolean pRequired, final Integer pArgCount, final Character pMultiArgSplit,
        final String pDescriptionNLSKey, final String pArgUsageNLSKey) {
    super(pCLAP);

    if (pShortKey != null && pShortKey == getCLAP().getShortOptPrefix()) {
        throw new IllegalArgumentException();
    }//  ww w .  jav a2s  . c  om
    if (pLongKey != null && pLongKey.contains(getCLAP().getLongOptEquals())) {
        throw new IllegalArgumentException();
    }

    if (pArgCount == null) {
        // autodetect using resultClass
        if (pResultClass.isArray() || Collection.class.isAssignableFrom(pResultClass)) {
            _argCount = CLAP.UNLIMITED_ARG_COUNT;
        } else if (pResultClass.equals(Boolean.class) || pResultClass.equals(Boolean.TYPE)) {
            _argCount = 0;
        } else {
            _argCount = 1;
        }
    } else {
        if (pArgCount < 0 && pArgCount != CLAP.UNLIMITED_ARG_COUNT) {
            throw new IllegalArgumentException();
        }

        if (pResultClass.isArray() || Collection.class.isAssignableFrom(pResultClass)) {
            if (pArgCount == 0) {
                throw new IllegalArgumentException();
            }
        } else if (pResultClass.equals(Boolean.class) || pResultClass.equals(Boolean.TYPE)) {
            if (pArgCount != 0 && pArgCount != 1) {
                throw new IllegalArgumentException();
            }
        } else {
            if (pArgCount != 1) {
                throw new IllegalArgumentException();
            }
        }

        _argCount = pArgCount;
    }

    if (pShortKey == null && pLongKey == null && _argCount == 0) {
        throw new IllegalArgumentException();
    }

    if (pResultClass.isArray()) {
        final Class<?> componentType = pResultClass.getComponentType();
        final CLAPConverter<?> converter = pCLAP.getConverter(componentType);
        _mapper = new Mapper<T>() {

            @Override
            public T transform(final String[] pStringValues) {
                final T result = (T) Array.newInstance(componentType, pStringValues.length);
                for (int i = 0; i < pStringValues.length; i++) {
                    try {
                        Array.set(result, i, converter.convert(pStringValues[i]));
                    } catch (final Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                return result;
            }

        };
    } else if (Collection.class.isAssignableFrom(pResultClass)) {
        _mapper = null;
    } else {
        final CLAPConverter<? extends T> converter = pCLAP.getConverter(pResultClass);
        _mapper = new Mapper<T>() {

            @Override
            public T transform(final String[] pStringValues) {
                if (pStringValues.length == 0
                        && (pResultClass.equals(Boolean.class) || pResultClass.equals(Boolean.TYPE))) {
                    return (T) Boolean.TRUE;
                }
                return converter.convert(pStringValues[0]);
            }

        };
    }

    _shortKey = pShortKey;
    _longKey = pLongKey;
    _required = pRequired;
    _multiArgSplit = pMultiArgSplit;
    _descriptionNLSKey = pDescriptionNLSKey;
    _argUsageNLSKey = pArgUsageNLSKey;
    _resultClass = pResultClass;
}

From source file:nl.strohalm.cyclos.utils.conversion.CoercionHelper.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object convert(Class toType, Object value) {
    if ("".equals(value)) {
        value = null;//from  w w  w . j  a  va2s  .com
    }
    // If we do not want a collection, but the value is one, use the first value
    if (value != null && !(Collection.class.isAssignableFrom(toType) || toType.isArray())
            && (value.getClass().isArray() || value instanceof Collection)) {
        final Iterator it = IteratorUtils.getIterator(value);
        if (!it.hasNext()) {
            value = null;
        } else {
            value = it.next();
        }
    }

    // Check for null values
    if (value == null) {
        if (toType.isPrimitive()) {
            // On primitives, use the default value
            if (toType == Boolean.TYPE) {
                value = Boolean.FALSE;
            } else if (toType == Character.TYPE) {
                value = '\0';
            } else {
                value = 0;
            }
        } else {
            // For objects, return null
            return null;
        }
    }

    // Check if the value is already of the expected type
    if (toType.isInstance(value)) {
        return value;
    }

    // If the class is primitive, use the wrapper, so we have an easier work of testing instances
    if (toType.isPrimitive()) {
        toType = ClassUtils.primitiveToWrapper(toType);
    }

    // Convert to well-known types
    if (String.class.isAssignableFrom(toType)) {
        if (value instanceof Entity) {
            final Long entityId = ((Entity) value).getId();
            return entityId == null ? null : entityId.toString();
        }
        return value.toString();
    } else if (Number.class.isAssignableFrom(toType)) {
        if (!(value instanceof Number)) {
            if (value instanceof String) {
                value = new BigDecimal((String) value);
            } else if (value instanceof Date) {
                value = ((Date) value).getTime();
            } else if (value instanceof Calendar) {
                value = ((Calendar) value).getTimeInMillis();
            } else if (value instanceof Entity) {
                value = ((Entity) value).getId();
                if (value == null) {
                    return null;
                }
            } else {
                throw new ConversionException("Invalid number: " + value);
            }
        }
        final Number number = (Number) value;
        if (Byte.class.isAssignableFrom(toType)) {
            return number.byteValue();
        } else if (Short.class.isAssignableFrom(toType)) {
            return number.shortValue();
        } else if (Integer.class.isAssignableFrom(toType)) {
            return number.intValue();
        } else if (Long.class.isAssignableFrom(toType)) {
            return number.longValue();
        } else if (Float.class.isAssignableFrom(toType)) {
            return number.floatValue();
        } else if (Double.class.isAssignableFrom(toType)) {
            return number.doubleValue();
        } else if (BigInteger.class.isAssignableFrom(toType)) {
            return new BigInteger(number.toString());
        } else if (BigDecimal.class.isAssignableFrom(toType)) {
            return new BigDecimal(number.toString());
        }
    } else if (Boolean.class.isAssignableFrom(toType)) {
        if (value instanceof Number) {
            return ((Number) value).intValue() != 0;
        } else if ("on".equalsIgnoreCase(value.toString())) {
            return true;
        } else {
            return Boolean.parseBoolean(value.toString());
        }
    } else if (Character.class.isAssignableFrom(toType)) {
        final String str = value.toString();
        return (str.length() == 0) ? null : str.charAt(0);
    } else if (Calendar.class.isAssignableFrom(toType)) {
        if (value instanceof Date) {
            final Calendar cal = new GregorianCalendar();
            cal.setTime((Date) value);
            return cal;
        }
    } else if (Date.class.isAssignableFrom(toType)) {
        if (value instanceof Calendar) {
            final long millis = ((Calendar) value).getTimeInMillis();
            try {
                return ConstructorUtils.invokeConstructor(toType, millis);
            } catch (final Exception e) {
                throw new IllegalStateException(e);
            }
        }
    } else if (Enum.class.isAssignableFrom(toType)) {
        Object ret;
        try {
            ret = Enum.valueOf(toType, value.toString());
        } catch (final Exception e) {
            ret = null;
        }
        if (ret == null) {
            Object[] possible;
            try {
                possible = (Object[]) toType.getMethod("values").invoke(null);
            } catch (final Exception e) {
                throw new IllegalStateException(
                        "Couldn't invoke the 'values' method for enum " + toType.getName());
            }
            if (StringValuedEnum.class.isAssignableFrom(toType)) {
                final String test = coerce(String.class, value);
                for (final Object item : possible) {
                    if (((StringValuedEnum) item).getValue().equals(test)) {
                        ret = item;
                        break;
                    }
                }
            } else if (IntValuedEnum.class.isAssignableFrom(toType)) {
                final int test = coerce(Integer.TYPE, value);
                for (final Object item : possible) {
                    if (((IntValuedEnum) item).getValue() == test) {
                        ret = item;
                        break;
                    }
                }
            } else {
                throw new ConversionException("Invalid enum: " + value);
            }
        }
        return ret;
    } else if (Entity.class.isAssignableFrom(toType)) {
        final Long id = coerce(Long.class, value);
        return EntityHelper.reference(toType, id);
    } else if (Locale.class.isAssignableFrom(toType)) {
        return LocaleConverter.instance().valueOf(value.toString());
    } else if (Collection.class.isAssignableFrom(toType)) {
        final Collection collection = (Collection) ClassHelper.instantiate(toType);
        final Iterator iterator = IteratorUtils.getIterator(value);
        while (iterator.hasNext()) {
            collection.add(iterator.next());
        }
        return collection;
    } else if (toType.isArray()) {
        final Collection collection = coerceCollection(toType.getComponentType(), value);
        final Object[] array = (Object[]) Array.newInstance(toType.getComponentType(), collection.size());
        return collection.toArray(array);
    }

    // We don't know how to convert the value
    throw new ConversionException("Cannot coerce value to: " + toType.getName());
}

From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java

/**
 * Creates new form ResultsWindows// w  w  w.  j a va 2 s .  com
 */
public ResultsWindows() {
    super();
    System.setProperty("apple.awt.application.name", "ResultWindow");
    //get a reference to the device.
    GraphicsDevice[] ScreenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
    this.device = ScreenDevices[ScreenDevices.length - 1];
    //save the old display mode before changing it.
    dispModeOld = device.getDisplayMode();

    initComponents();
    try {
        Class util = Class.forName("com.apple.eawt.FullScreenUtilities");
        Class params[] = new Class[] { Window.class, Boolean.TYPE };
        Method method = util.getMethod("setWindowCanFullScreen", params);
        method.invoke(util, this, true);
    } catch (Exception e) {
        //System.out.println("OS X Fullscreen FAIL" + e.toString());
        jCheckBoxMenuItem1.setEnabled(true);
    }
    if (!jCheckBoxMenuItem1.isEnabled()) {
        jMenuBar1.remove(jCheckBoxMenuItem1);
    }
    initCustumComponents();
    initClock();
    setSerieResults();
    startChromeCast();
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object convertToObject(Class<?> clazz) {
    if (clazz.isPrimitive()) {
        if (clazz.equals(Long.TYPE)) {
            return new Long(0L);
        } else if (clazz.equals(Integer.TYPE)) {
            return new Integer(0);
        } else if (clazz.equals(Float.TYPE)) {
            return new Float(0F);
        } else if (clazz.equals(Double.TYPE)) {
            return new Double(0D);
        } else if (clazz.equals(Boolean.TYPE)) {
            return new Boolean(false);
        }//w  w w .ja  v a2  s.  c  o  m
    }
    return null;

}