Example usage for java.lang Class isPrimitive

List of usage examples for java.lang Class isPrimitive

Introduction

In this page you can find the example usage for java.lang Class isPrimitive.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isPrimitive();

Source Link

Document

Determines if the specified Class object represents a primitive type.

Usage

From source file:mil.army.usace.data.nativequery.rdbms.NativeRdbmsQuery.java

protected Object convertType(Object obj, Method method) throws Exception {
    Class methodParam = method.getParameterTypes()[0];
    if (obj == null)
        return null;
    else {/*from   ww w.  ja v  a 2 s. c  o m*/
        if (methodParam.isPrimitive()) {
            return obj;
        } else {
            return convertType(obj, methodParam);
        }
    }
}

From source file:com.evolveum.midpoint.web.component.prism.PrismValuePanel.java

private Panel createTypedInputComponent(String id) {
    //        ValueWrapper valueWrapper = model.getObject();
    //        ItemWrapper itemWrapper =
    final Item item = model.getObject().getItem().getItem();

    Panel panel = null;// w  ww.j a  va  2s  .co  m
    if (item instanceof PrismProperty) {
        final PrismProperty property = (PrismProperty) item;
        PrismPropertyDefinition definition = property.getDefinition();
        QName valueType = definition.getTypeName();

        final String baseExpression = "value.value"; //pointing to prism property real value

        //fixing MID-1230, will be improved with some kind of annotation or something like that
        //now it works only in description
        if (ObjectType.F_DESCRIPTION.equals(definition.getName())) {
            return new TextAreaPanel(id, new PropertyModel(model, baseExpression));
        }

        // the same for requester and approver comments in workflows [mederly] - this is really ugly, as it is specific to each approval form
        if (AssignmentCreationApprovalFormType.F_REQUESTER_COMMENT.equals(definition.getName())
                || AssignmentCreationApprovalFormType.F_COMMENT.equals(definition.getName())) {
            return new TextAreaPanel(id, new PropertyModel(model, baseExpression));
        }

        if (ActivationType.F_ADMINISTRATIVE_STATUS.equals(definition.getName())) {
            return WebMiscUtil.createEnumPanel(ActivationStatusType.class, id,
                    new PropertyModel<ActivationStatusType>(model, baseExpression), this);
        } else if (ActivationType.F_LOCKOUT_STATUS.equals(definition.getName())) {
            return WebMiscUtil.createEnumPanel(LockoutStatusType.class, id,
                    new PropertyModel<LockoutStatusType>(model, baseExpression), this);
        } else {
            // nothing to do
        }

        if (DOMUtil.XSD_DATETIME.equals(valueType)) {
            panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(model, baseExpression));

        } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
            panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(model, baseExpression),
                    model.getObject().isReadonly());

        } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
            panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(model, baseExpression));

        } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
            InputPanel inputPanel;
            PrismPropertyDefinition def = property.getDefinition();

            if (def.getValueEnumerationRef() != null) {
                PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
                String lookupTableUid = valueEnumerationRef.getOid();
                Task task = pageBase.createSimpleTask("loadLookupTable");
                OperationResult result = task.getResult();

                Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(
                        LookupTableType.F_ROW, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
                final PrismObject<LookupTableType> lookupTable = WebModelUtils.loadObject(LookupTableType.class,
                        lookupTableUid, options, pageBase, task, result);

                inputPanel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(model,
                        baseExpression + ".orig", lookupTable.asObjectable()), String.class) {

                    @Override
                    public Iterator<String> getIterator(String input) {
                        return prepareAutoCompleteList(input, lookupTable).iterator();
                    }
                };

            } else {

                inputPanel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression + ".orig"),
                        String.class);
            }

            if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
                inputPanel.getBaseFormComponent().setRequired(true);
            }
            panel = inputPanel;

        } else if (DOMUtil.XSD_BASE64BINARY.equals(valueType)) {
            panel = new UploadDownloadPanel(id, model.getObject().isReadonly()) {

                @Override
                public InputStream getStream() {
                    return new ByteArrayInputStream(
                            (byte[]) ((PrismPropertyValue) model.getObject().getValue()).getValue());
                    //                      return super.getStream();
                }

                @Override
                public void updateValue(byte[] file) {
                    ((PrismPropertyValue) model.getObject().getValue()).setValue(file);
                }

                @Override
                public void uploadFilePerformed(AjaxRequestTarget target) {
                    super.uploadFilePerformed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                }

                @Override
                public void removeFilePerformed(AjaxRequestTarget target) {
                    super.removeFilePerformed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                }

                @Override
                public void uploadFileFailed(AjaxRequestTarget target) {
                    super.uploadFileFailed(target);
                    target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                    target.add(((PageBase) getPage()).getFeedbackPanel());
                }
            };

        } else if (ObjectDeltaType.COMPLEX_TYPE.equals(valueType)) {
            panel = new ModificationsPanel(id, new AbstractReadOnlyModel<DeltaDto>() {
                @Override
                public DeltaDto getObject() {
                    if (model.getObject() == null || model.getObject().getValue() == null
                            || ((PrismPropertyValue) model.getObject().getValue()).getValue() == null) {
                        return null;
                    }
                    PrismContext prismContext = ((PageBase) getPage()).getPrismContext();
                    ObjectDeltaType objectDeltaType = (ObjectDeltaType) ((PrismPropertyValue) model.getObject()
                            .getValue()).getValue();
                    try {
                        ObjectDelta delta = DeltaConvertor.createObjectDelta(objectDeltaType, prismContext);
                        return new DeltaDto(delta);
                    } catch (SchemaException e) {
                        throw new IllegalStateException("Couldn't convert object delta: " + objectDeltaType);
                    }

                }
            });
        } else {
            Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
            if (type != null && type.isPrimitive()) {
                type = ClassUtils.primitiveToWrapper(type);

            }

            if (isEnum(property)) {
                return WebMiscUtil.createEnumPanel(definition, id, new PropertyModel<>(model, baseExpression),
                        this);
            }
            //                  // default QName validation is a bit weird, so let's treat QNames as strings [TODO finish this - at the parsing side]
            //                  if (type == QName.class) {
            //                      type = String.class;
            //                  }

            PrismPropertyDefinition def = property.getDefinition();

            if (def.getValueEnumerationRef() != null) {
                PrismReferenceValue valueEnumerationRef = def.getValueEnumerationRef();
                String lookupTableUid = valueEnumerationRef.getOid();
                Task task = pageBase.createSimpleTask("loadLookupTable");
                OperationResult result = task.getResult();

                Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(
                        LookupTableType.F_ROW, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
                final PrismObject<LookupTableType> lookupTable = WebModelUtils.loadObject(LookupTableType.class,
                        lookupTableUid, options, pageBase, task, result);

                panel = new AutoCompleteTextPanel<String>(id, new LookupPropertyModel<String>(model,
                        baseExpression, lookupTable == null ? null : lookupTable.asObjectable()), type) {

                    @Override
                    public Iterator<String> getIterator(String input) {
                        return prepareAutoCompleteList(input, lookupTable).iterator();
                    }

                    @Override
                    public void checkInputValue(AutoCompleteTextField input, AjaxRequestTarget target,
                            LookupPropertyModel model) {
                        Iterator<String> lookupTableValuesIterator = prepareAutoCompleteList("", lookupTable)
                                .iterator();

                        String value = input.getInput();
                        boolean isValueExist = false;
                        if (value != null) {
                            if (value.trim().equals("")) {
                                isValueExist = true;
                            } else {
                                while (lookupTableValuesIterator.hasNext()) {
                                    String lookupTableValue = lookupTableValuesIterator.next();
                                    if (value.trim().equals(lookupTableValue)) {
                                        isValueExist = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (isValueExist) {
                            input.setModelValue(new String[] { value });
                            target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                        } else {
                            input.error(
                                    "Entered value doesn't match any of available values and will not be saved.");
                            target.add(PrismValuePanel.this.get(ID_FEEDBACK));
                        }
                    }
                };

            } else {
                panel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression), type);
            }
        }
    } else if (item instanceof PrismReference) {
        //           ((PrismReferenceDefinition) item.getDefinition()).
        Class typeFromName = null;
        PrismContext prismContext = item.getPrismContext();
        if (prismContext == null) {
            prismContext = pageBase.getPrismContext();
        }
        QName targetTypeName = ((PrismReferenceDefinition) item.getDefinition()).getTargetTypeName();
        if (targetTypeName != null && prismContext != null) {
            typeFromName = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeName);
        }
        final Class typeClass = typeFromName != null ? typeFromName
                : (item.getDefinition().getTypeClassIfKnown() != null
                        ? item.getDefinition().getTypeClassIfKnown()
                        : FocusType.class);
        panel = new ValueChoosePanel(id, new PropertyModel<>(model, "value"), item.getValues(), false,
                typeClass);

    } else if (item instanceof PrismContainer<?>) {
        ItemWrapper itemWrapper = model.getObject().getItem();
        final PrismContainer container = (PrismContainer) item;
        PrismContainerDefinition definition = container.getDefinition();
        QName valueType = definition.getTypeName();

        if (ShadowAssociationType.COMPLEX_TYPE.equals(valueType)) {

            PrismContext prismContext = item.getPrismContext();
            if (prismContext == null) {
                prismContext = pageBase.getPrismContext();
            }

            ShadowType shadowType = ((ShadowType) itemWrapper.getContainer().getObject().getObject()
                    .asObjectable());
            PrismObject<ResourceType> resource = shadowType.getResource().asPrismObject();
            // HACK. The revive should not be here. Revive is no good. The next use of the resource will
            // cause parsing of resource schema. We need some centralized place to maintain live cached copies
            // of resources.
            try {
                resource.revive(prismContext);
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            RefinedResourceSchema refinedSchema;
            CompositeRefinedObjectClassDefinition rOcDef;
            try {
                refinedSchema = RefinedResourceSchema.getRefinedSchema(resource);
                rOcDef = refinedSchema.determineCompositeObjectClassDefinition(shadowType.asPrismObject());
            } catch (SchemaException e) {
                throw new SystemException(e.getMessage(), e);
            }
            RefinedAssociationDefinition assocDef = rOcDef.findAssociation(itemWrapper.getName());
            RefinedObjectClassDefinition assocTarget = assocDef.getAssociationTarget();

            ObjectQuery query = getAssociationsSearchQuery(prismContext, resource, assocTarget.getTypeName(),
                    assocTarget.getKind(), assocTarget.getIntent());

            List values = item.getValues();
            return new AssociationValueChoosePanel(id, model, values, false, ShadowType.class, query);
        }
    }

    return panel;
}

From source file:com.proteanplatform.protean.entity.EntityTableCellMetadata.java

/**
 * @param clazz//from w w w.ja v a  2s  . c o  m
 * @param anno
 * @throws NoSuchMethodException 
 */
public EntityTableCellMetadata(String name, Class<?> clazz) throws NoSuchMethodException {

    Method method = null;
    Class<?> rtype = clazz;

    String[] tokens = name.split("\\.");
    for (int i = 0; i < tokens.length - 1; ++i) {
        method = rtype.getMethod("get" + StringUtils.capitalize(tokens[i]), new Class[0]);
        methods.add(method);
        rtype = method.getReturnType();
    }

    method = rtype.getMethod("get" + StringUtils.capitalize(tokens[tokens.length - 1]), new Class[0]);
    rtype = method.getReturnType();
    String type = "string"; // determines sortability

    // have to do string, date first, since they can both assign object.
    if (String.class.isAssignableFrom(rtype)) {
        methods.add(method);
    }

    else if (Date.class.isAssignableFrom(rtype)) {
        methods.add(method);
        type = "date";
    }

    else if (rtype == boolean.class || rtype == char.class || rtype == Boolean.class
            || rtype == Character.class) {
        methods.add(method);
    }

    else if (rtype.isPrimitive() || rtype == int.class || rtype == Integer.class || rtype == Long.class
            || rtype == Short.class || rtype == Byte.class || rtype == Double.class || rtype == Float.class) {
        methods.add(method);
        type = "numeric";
    }

    else if (Object.class.isAssignableFrom(rtype)) {
        calculateObjectCell(method);
    }

    column = new TableColumn(name, type, Sorting.BOTH);

}

From source file:io.s4.util.LoadGenerator.java

@SuppressWarnings("unchecked")
private Object makeSettableValue(Property property, Object value) {
    String propertyName = property.getName();
    Class propertyType = property.getType();

    if (propertyType.isArray()) {
        if (!(value instanceof JSONArray)) {
            System.err.println("Type mismatch for field " + propertyName);
            return null;
        }//  ww  w . ja v  a2s  . co  m
        System.out.println("Is array!");
        return makeArray(property, (JSONArray) value);
    } else if (property.isList()) {
        if (!(value instanceof JSONArray)) {
            System.err.println("Type mismatch for field " + propertyName);
            return null;
        }
        return makeList(property, (JSONArray) value);
    } else if (propertyType.isPrimitive()) {
        if (!(value instanceof Number || value instanceof Boolean)) {
            System.err.println("Type mismatch for field " + propertyName
                    + "; expected number or boolean, found " + value.getClass());
            return null;
        }
        return value; // hmm... does this work?
    } else if (propertyType.equals(String.class)) {
        if (!(value instanceof String)) {
            System.err.println(
                    "Type mismatch for field " + propertyName + "; expected String, found " + value.getClass());
            return null;
        }
        return value;
    } else if (property.isNumber()) {
        if (!(value instanceof Integer || value instanceof Long || value instanceof Float
                || value instanceof Double || value instanceof BigDecimal || value instanceof BigInteger)) {
            return null;
        }

        Number adjustedValue = (Number) value;
        if (propertyType.equals(Long.class) && !(value instanceof Long)) {
            adjustedValue = new Long(((Number) value).longValue());
        } else if (propertyType.equals(Integer.class) && !(value instanceof Integer)) {
            adjustedValue = new Integer(((Number) value).intValue());
        } else if (propertyType.equals(Double.class) && !(value instanceof Double)) {
            adjustedValue = new Double(((Number) value).doubleValue());
        } else if (propertyType.equals(Float.class) && !(value instanceof Float)) {
            adjustedValue = new Float(((Number) value).floatValue());
        } else if (propertyType.equals(BigDecimal.class)) {
            adjustedValue = new BigDecimal(((Number) value).longValue());
        } else if (propertyType.equals(BigInteger.class)) {
            adjustedValue = BigInteger.valueOf(((Number) value).longValue());
        }
        return adjustedValue;
    } else if (value instanceof JSONObject) {
        return makeRecord((JSONObject) value, property.getSchema());
    }

    return null;
}

From source file:org.apache.river.springframework.config.ApplicationContextAdapter.java

@Override
public Object getEntry(String component, String name, Class type, Object defaultValue, Object data)
        throws ConfigurationException {
    Objects.requireNonNull(name, "The name parameter must not be null.");
    Objects.requireNonNull(name, "The type parameter must not be null.");

    Object value = null;//from www.j  a va2s  . c  o  m

    try {
        if (component != null && !component.isEmpty()) {
            try {
                value = adaptee.getBean(component + "." + name);
            } catch (NoSuchBeanDefinitionException e) {
            }
        }
        if (value == null) {
            try {
                value = adaptee.getBean(name);
            } catch (NoSuchBeanDefinitionException e) {
            }
        }
    } catch (BeansException e) {
        throw new ConfigurationException("Unable to get configuration value.", e);
    }

    if (value == null) {
        if (defaultValue == Configuration.NO_DEFAULT) {
            throw new NoSuchEntryException("No configuration value found.");
        } else {
            value = defaultValue;
        }
    }

    if (value != null) {
        if ((type.isPrimitive() && (type == boolean.class && value instanceof Boolean)
                || (type == char.class && value instanceof Character)
                || (type == byte.class && value instanceof Byte)
                || (type == short.class && value instanceof Short)
                || (type == int.class && value instanceof Integer)
                || (type == long.class && value instanceof Long)
                || (type == float.class && value instanceof Float)
                || (type == double.class && value instanceof Double)) || type.isInstance(value)) {

        } else {
            throw new IllegalArgumentException("Configuration value cannot be converted to type.");
        }
    }

    return value;
}

From source file:net.lightbody.bmp.proxy.jetty.util.jmx.ModelMBeanImpl.java

/** Define an operation on the managed object.
 * Defines an operation with parameters. Refection is used to
 * determine find the method and it's return type. The description
 * of the method is found with a call to findDescription on
 * "name(signature)". The name and description of each parameter
 * is found with a call to findDescription with
 * "name(partialSignature", the returned description is for the
 * last parameter of the partial signature and is assumed to start
 * with the parameter name, followed by a colon.
 * @param name The name of the method call.
 * @param signature The types of the operation parameters.
 * @param impact Impact as defined in MBeanOperationInfo
 * @param onMBean true if the operation is defined on the mbean
 *//*from   w w w  . j av  a2  s. co m*/
public synchronized void defineOperation(String name, String[] signature, int impact, boolean onMBean) {
    _dirty = true;
    Class oClass = onMBean ? this.getClass() : _object.getClass();
    if (signature == null)
        signature = new String[0];

    try {
        Class[] types = new Class[signature.length];
        MBeanParameterInfo[] pInfo = new MBeanParameterInfo[signature.length];

        // Check types and build methodKey
        String methodKey = name + "(";
        for (int i = 0; i < signature.length; i++) {
            Class type = TypeUtil.fromName(signature[i]);
            if (type == null)
                type = Thread.currentThread().getContextClassLoader().loadClass(signature[i]);
            types[i] = type;
            signature[i] = type.isPrimitive() ? TypeUtil.toName(type) : signature[i];
            methodKey += (i > 0 ? "," : "") + signature[i];
        }
        methodKey += ")";

        // Build param infos
        for (int i = 0; i < signature.length; i++) {
            String description = findDescription(methodKey + "[" + i + "]");
            int colon = description.indexOf(":");
            if (colon < 0) {
                description = "param" + i + ":" + description;
                colon = description.indexOf(":");
            }
            pInfo[i] = new MBeanParameterInfo(description.substring(0, colon).trim(), signature[i],
                    description.substring(colon + 1).trim());
        }

        // build the operation info
        Method method = oClass.getMethod(name, types);
        Class returnClass = method.getReturnType();
        _method.put(methodKey, method);
        _operations.add(new ModelMBeanOperationInfo(name, findDescription(methodKey), pInfo,
                returnClass.isPrimitive() ? TypeUtil.toName(returnClass) : (returnClass.getName()), impact));
    } catch (Exception e) {
        log.warn("operation " + name, e);
        throw new IllegalArgumentException(e.toString());
    }

}

From source file:com.openddal.test.BaseTestCase.java

/**
 * Verify the next method call on the object will throw an exception.
 *
 * @param <T> the class of the object
 * @param verifier the result verifier to call
 * @param obj the object to wrap/*from  www .  jav a 2  s  .c o  m*/
 * @return a proxy for the object
 */
@SuppressWarnings("unchecked")
protected <T> T assertThrows(final ResultVerifier verifier, final T obj) {
    Class<?> c = obj.getClass();
    InvocationHandler ih = new InvocationHandler() {
        private Exception called = new Exception("No method called");

        @Override
        protected void finalize() {
            if (called != null) {
                called.printStackTrace(System.err);
            }
        }

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
            try {
                called = null;
                Object ret = method.invoke(obj, args);
                verifier.verify(ret, null, method, args);
                return ret;
            } catch (InvocationTargetException e) {
                verifier.verify(null, e.getTargetException(), method, args);
                Class<?> retClass = method.getReturnType();
                if (!retClass.isPrimitive()) {
                    return null;
                }
                if (retClass == boolean.class) {
                    return false;
                } else if (retClass == byte.class) {
                    return (byte) 0;
                } else if (retClass == char.class) {
                    return (char) 0;
                } else if (retClass == short.class) {
                    return (short) 0;
                } else if (retClass == int.class) {
                    return 0;
                } else if (retClass == long.class) {
                    return 0L;
                } else if (retClass == float.class) {
                    return 0F;
                } else if (retClass == double.class) {
                    return 0D;
                }
                return null;
            }
        }
    };
    if (!ProxyCodeGenerator.isGenerated(c)) {
        Class<?>[] interfaces = c.getInterfaces();
        if (Modifier.isFinal(c.getModifiers()) || (interfaces.length > 0 && getClass() != c)) {
            // interface class proxies
            if (interfaces.length == 0) {
                throw new RuntimeException("Can not create a proxy for the class " + c.getSimpleName()
                        + " because it doesn't implement any interfaces and is final");
            }
            return (T) Proxy.newProxyInstance(c.getClassLoader(), interfaces, ih);
        }
    }
    try {
        Class<?> pc = ProxyCodeGenerator.getClassProxy(c);
        Constructor<?> cons = pc.getConstructor(InvocationHandler.class);
        return (T) cons.newInstance(ih);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:net.sf.morph.transform.transformers.BaseTransformer.java

/**
 * @{link {@link Converter#convert(Class, Object, Locale)}
 * @param destinationClass//from  w  ww  . j a v a2  s  .  c  o  m
 * @param source
 * @param locale
 * @return
 */
public final Object convert(Class destinationClass, Object source, Locale locale) {
    initialize();

    if (isPerformingLogging() && log.isTraceEnabled()) {
        log.trace("Converting " + ObjectUtils.getObjectDescription(source) + " to destination type "
                + ObjectUtils.getObjectDescription(destinationClass) + " in locale " + locale);
    }

    if (locale == null) {
        locale = getLocale();
    }

    if (source == null && isAutomaticallyHandlingNulls()) {
        if (destinationClass != null && destinationClass.isPrimitive()) {
            throw new TransformationException(destinationClass, source);
        }
        return null;
    }

    try {
        return convertImpl(destinationClass, source, locale);
    } catch (TransformationException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException && !isWrappingRuntimeExceptions()) {
            throw (RuntimeException) e;
        }
        if (isTransformable(destinationClass, ClassUtils.getClass(source))) {
            throw new TransformationException(destinationClass, source, e);
        }
        throw new TransformationException(
                getClass().getName() + " cannot convert " + ObjectUtils.getObjectDescription(source)
                        + " to an instance of " + ObjectUtils.getObjectDescription(destinationClass),
                e);
    }
}

From source file:com.doculibre.constellio.services.SolrServicesImpl.java

@SuppressWarnings("rawtypes")
private static void setProperty(Element element, String attributeName, ConstellioEntity entity) {
    try {//  www  .  j  a v  a2  s  .c  o m
        Method getter = findGetter(entity.getClass(), attributeName);
        Class returnType = getter.getReturnType();
        String setterName = "set" + StringUtils.capitalize(attributeName);
        Method setter = entity.getClass().getMethod(setterName, returnType);

        String attributeValue = element.attributeValue(attributeName);
        Object setterValue;
        if (StringUtils.isEmpty(attributeValue)) {
            if (boolean.class.equals(returnType)) {
                setterValue = false;
            } else if (int.class.equals(returnType)) {
                setterValue = 0;
            } else if (returnType.isPrimitive()) {
                throw new UnsupportedOperationException(setterName + "(" + returnType + ")");
            } else {
                setterValue = null;
            }
        } else if (boolean.class.equals(returnType) || Boolean.class.equals(returnType)) {
            setterValue = Boolean.valueOf(attributeValue);
        } else if (int.class.equals(returnType) || Integer.class.equals(returnType)) {
            setterValue = Integer.valueOf(attributeValue);
        } else if (String.class.equals(returnType)) {
            setterValue = attributeValue;
        } else {
            throw new UnsupportedOperationException(setterName + "(" + returnType + ")");
        }
        setter.invoke(entity, setterValue);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Create a new Instance of a Property//www.  j ava2 s .c  om
 * @param name The name of the property
 * @param type The class of the property
 * @return The new value
 */
protected Object createProperty(String name, Class type) {
    if (type == null) {
        return null;
    }

    // Create Lists, arrays or DynaBeans
    if (type.isArray() || List.class.isAssignableFrom(type)) {
        return createIndexedProperty(name, type);
    }

    if (Map.class.isAssignableFrom(type)) {
        return createMappedProperty(name, type);
    }

    if (DynaBean.class.isAssignableFrom(type)) {
        return createDynaBeanProperty(name, type);
    }

    if (type.isPrimitive()) {
        return createPrimitiveProperty(name, type);
    }

    if (Number.class.isAssignableFrom(type)) {
        return createNumberProperty(name, type);
    }

    return createOtherProperty(name, type);

}