当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtils.primitiveToWrapper方法代码示例

本文整理汇总了Java中org.apache.commons.lang.ClassUtils.primitiveToWrapper方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.primitiveToWrapper方法的具体用法?Java ClassUtils.primitiveToWrapper怎么用?Java ClassUtils.primitiveToWrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.ClassUtils的用法示例。


在下文中一共展示了ClassUtils.primitiveToWrapper方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
@Override
public Number convert(final Class<? extends Number> targetType, final String value) {
	if (StringUtils.isBlank(value)) {
		if (targetType.isPrimitive()) {
			return convert(targetType, "0");
		}
		return null;
	}
	if (targetType == Number.class) {
		return new Float(value);
	}
	final Class<? extends Number> wrapperType = targetType.isPrimitive() ? ClassUtils.primitiveToWrapper(targetType)
			: targetType;
	try {
		return wrapperType.getConstructor(String.class).newInstance(value);
	} catch (final InstantiationException | IllegalAccessException | InvocationTargetException
			| NoSuchMethodException e) {
		throw new IllegalArgumentException(e);
	}
}
 
开发者ID:liefke,项目名称:org.fastnate,代码行数:21,代码来源:CsvNumberConverter.java

示例2: unmarshal

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * TODO: decide if this method should be marked @NotNull.
 * Basically the problem is with primitives. When parsed, they sometimes return null. The question is if it's correct.
 */
<T> T unmarshal(@NotNull XNode xnode, @NotNull Class<T> beanClass, @NotNull ParsingContext pc) throws SchemaException {
	T value = unmarshalInternal(xnode, beanClass, pc);
	if (PrismContextImpl.isExtraValidation() && value != null) {
		Class<?> requested = ClassUtils.primitiveToWrapper(beanClass);
		Class<?> actual = ClassUtils.primitiveToWrapper(value.getClass());
		if (!requested.isAssignableFrom(actual)) {
			throw new AssertionError("Postcondition fail: unmarshal returned a value of " + value + " ("
					+ actual + ") which is not of requested type (" + requested + ")");
		}
	}
	return value;
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:17,代码来源:BeanUnmarshaller.java

示例3: isTypeCompliant

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public static <T> boolean isTypeCompliant(@Nullable T value, @Nullable Class<?> expectedClass) {
	if (value == null || expectedClass == null) {
		return true;
	}
	Class<?> wrapped = ClassUtils.primitiveToWrapper(expectedClass);
	return wrapped.isAssignableFrom(((Object) value).getClass());		// auto-boxing of primitive types

	// TODO PolyString vs String - should be treated here?
	// TODO int vs long vs ...
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:11,代码来源:JavaTypeConverter.java

示例4: createTypedInputComponent

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private InputPanel createTypedInputComponent(String id, PrismPropertyDefinition definition) {
    QName valueType = definition.getTypeName();

    final String baseExpression = ACValueConstructionDto.F_VALUE;

    InputPanel panel;
    if (DOMUtil.XSD_DATETIME.equals(valueType)) {
        panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(getModel(), baseExpression));
    } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
        panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(getModel(), baseExpression));
    } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
        panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(getModel(), baseExpression));
    } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
        panel = new TextPanel<String>(id, new PropertyModel<String>(getModel(), baseExpression + ".orig"), String.class);
    } else {
        Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
        if (type != null && type.isPrimitive()) {
            type = ClassUtils.primitiveToWrapper(type);
        }
        panel = new TextPanel<String>(id, new PropertyModel<String>(getModel(), baseExpression),
                type);

        if (ObjectType.F_NAME.equals(definition.getName())) {
            panel.getBaseFormComponent().setRequired(true);
        }
    }

    return panel;
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:30,代码来源:ACAttributeValuePanel.java

示例5: getKeyValue

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private Object getKeyValue(Number result, Class<?> returnType) {
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    if (result == null || returnType == void.class) {
        return null;
    }
    if (returnType == result.getClass()) {
        return result;
    }
    // 将结果转成方法的返回类型
    if (returnType == Integer.class) {
        return result.intValue();
    } else if (returnType == Long.class) {
        return result.longValue();
    } else if (returnType == Boolean.class) {
        return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE;
    } else if (returnType == Double.class) {
        return result.doubleValue();
    } else if (returnType == Float.class) {
        return result.floatValue();
    } else if (returnType == Number.class) {
        return result;
    } else if (returnType == String.class
            || returnType == CharSequence.class) {
        return String.valueOf(result);
    } else {
        return null;
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:31,代码来源:PreparedStatementHandler.java

示例6: isInstance

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Returns if the given object is an instance of the specified class, handling primitives as objects
 */
public static boolean isInstance(Class<?> clazz, final Object object) {
    if (clazz.isPrimitive()) {
        clazz = ClassUtils.primitiveToWrapper(clazz);
    }
    return clazz.isInstance(object);
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:10,代码来源:ClassHelper.java

示例7: getFromJavaType

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public static Type getFromJavaType(Class type)
{
  for (Type supportType : Type.values()) {
    if (supportType.getJavaType() == ClassUtils.primitiveToWrapper(type)) {
      return supportType;
    }
  }

  return OBJECT;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:11,代码来源:TupleSchemaRegistry.java

示例8: ToStringFieldHandler

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Creates a new instance of this handler.
 *
 * @param type
 *            the class of the associated field
 * @throws NoSuchMethodException
 *             if the string constructor for the given type was not found
 */
public ToStringFieldHandler(final Class<T> type) throws NoSuchMethodException {
	Class<T> wrapper = ClassUtils.primitiveToWrapper(type);
	this.constructor = wrapper.getConstructor(String.class);
	Type elementType = null;
	while (wrapper != null && elementType == null) {
		elementType = TYPES.get(wrapper);
		wrapper = (Class<T>) wrapper.getSuperclass();
	}
	this.type = elementType == null ? Type.TEXT : elementType;
}
 
开发者ID:liefke,项目名称:org.portletbeans,代码行数:19,代码来源:ToStringFieldHandler.java

示例9: getWrapper

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private Type getWrapper(Type t) {
    if (t instanceof Class) {
        if (((Class) t).isPrimitive()) {
            t = ClassUtils.primitiveToWrapper((Class) t);
        }
    }
    return t;
}
 
开发者ID:ggkochanski,项目名称:itest,代码行数:9,代码来源:SimpleJsonFormatter.java

示例10: createConverter

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Creates a converter for a primitive type.
 *
 * @param <T>
 *            the generic type
 * @param <E>
 *            the element type
 * @param attribute
 *            the accessor for the attribute that contains the value, not nessecarily of the target type
 * @param targetType
 *            the primitive type
 * @param mapKey
 *            indicates that the converter is for the key of a map
 * @return the converter or {@link UnsupportedTypeConverter} if no converter is available
 */
@SuppressWarnings("unchecked")
public static <T, E extends Enum<E>> ValueConverter<T> createConverter(final AttributeAccessor attribute,
		final Class<T> targetType, final boolean mapKey) {
	if (attribute.isAnnotationPresent(Lob.class)) {
		return (ValueConverter<T>) new LobConverter();
	}
	if (String.class == targetType) {
		return (ValueConverter<T>) new StringConverter(attribute, mapKey);
	}
	if (Date.class.isAssignableFrom(targetType)) {
		return (ValueConverter<T>) new DateConverter(attribute, mapKey);
	}
	if (Calendar.class.isAssignableFrom(targetType)) {
		return (ValueConverter<T>) new CalendarConverter(attribute, mapKey);
	}
	if (Enum.class.isAssignableFrom(targetType)) {
		return (ValueConverter<T>) new EnumConverter<>(attribute, (Class<E>) targetType, mapKey);
	}
	final Class<T> type = ClassUtils.primitiveToWrapper(targetType);
	if (Character.class == type) {
		return (ValueConverter<T>) new CharConverter();
	}
	if (Boolean.class == type) {
		return (ValueConverter<T>) new BooleanConverter();
	}
	if (Number.class.isAssignableFrom(type)) {
		return (ValueConverter<T>) new NumberConverter((Class<Number>) type);
	}
	if (Serializable.class.isAssignableFrom(type)) {
		return (ValueConverter<T>) new SerializableConverter();
	}
	return (ValueConverter<T>) new UnsupportedTypeConverter(attribute);
}
 
开发者ID:liefke,项目名称:org.fastnate,代码行数:49,代码来源:PrimitiveProperty.java

示例11: translate

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<E> translate(SIFDataObject sifData, String zoneId) throws SifTranslationException {
    Class<?> wrappedSifClass = ClassUtils.primitiveToWrapper(sifData.getClass());

    if (!sifPrototype.equals(wrappedSifClass)) {
        throw new SifTranslationException("Unsupported SIF data type");
    }
    return doTranslate((T) sifData, zoneId);
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:11,代码来源:AbstractTranslationTask.java

示例12: getWrapper

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public Class getWrapper(String premitive) throws ClassNotFoundException {
    return ClassUtils.primitiveToWrapper(ClassUtils.getClass(premitive));
}
 
开发者ID:jeddict,项目名称:jeddict,代码行数:4,代码来源:VariableDefSnippet.java

示例13: checkValueType

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
private Object checkValueType(Object value, ValueFilter filter) throws QueryException {

        Class expectedType = linkDefinition.getTargetDefinition().getJaxbClass();
        if (expectedType == null || value == null) {
            return value;   // nothing to check here
        }

        if (expectedType.isPrimitive()) {
            expectedType = ClassUtils.primitiveToWrapper(expectedType);
        }

        //todo remove after some time [lazyman]
        //attempt to fix value type for polystring (if it was string in filter we create polystring from it)
        if (PolyString.class.equals(expectedType) && (value instanceof String)) {
            LOGGER.debug("Trying to query PolyString value but filter contains String '{}'.", filter);
			String orig = (String) value;
			value = new PolyString(orig, context.getPrismContext().getDefaultPolyStringNormalizer().normalize(orig));
        }
        //attempt to fix value type for polystring (if it was polystringtype in filter we create polystring from it)
        if (PolyString.class.equals(expectedType) && (value instanceof PolyStringType)) {
            LOGGER.debug("Trying to query PolyString value but filter contains PolyStringType '{}'.", filter);
            PolyStringType type = (PolyStringType) value;
            value = new PolyString(type.getOrig(), type.getNorm());
        }

        if (String.class.equals(expectedType) && (value instanceof QName)) {
            //eg. shadow/objectClass
            value = RUtil.qnameToString((QName) value);
        }

        if (value instanceof RawType) {     // MID-3850: but it's quite a workaround. Maybe we should treat RawType's earlier than this.
            try {
                return ((RawType) value).getParsedRealValue(expectedType);
            } catch (SchemaException e) {
                throw new QueryException("Couldn't parse value " + value + " as " + expectedType + ": " + e.getMessage(), e);
            }
        }

        if (!expectedType.isAssignableFrom(value.getClass())) {
            throw new QueryException("Value should be type of '" + expectedType + "' but it's '"
                    + value.getClass() + "', filter '" + filter + "'.");
        }
        return value;
    }
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:45,代码来源:PropertyRestriction.java

示例14: getFields

import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
/**
 * Recupera todos os campos descobertos no relacionamento
 * @return
 */
public JRField[] getFields(){
	
	JRField[] keyFields = new JRDesignField[this.fields.size()];
	
	int i=0;
	for (JazzJRNavigableField jrField : this.fields) {
		
		String name = jrField.getName();
		JRDesignField jrDesignField = new JRDesignField();
		jrDesignField.setName(name);
		jrDesignField.setDescription(jrField.getDescription());
		
		Class<?> valueClass = jrField.getValueClass();
		valueClass = ClassUtils.primitiveToWrapper(valueClass);
		
		
		
		jrDesignField.setValueClass(valueClass);
		jrDesignField.setValueClassName(valueClass.getName());
		
		keyFields[i] = jrDesignField;
		
		
		//System.out.println("<field name=\""+name+"\" class=\""+valueClass.getName()+"\"/>");
		
		//<field name="exv_pk" class="java.lang.Long"/>
		
		i++;
	}
	
	return keyFields;
}
 
开发者ID:darciopacifico,项目名称:omr,代码行数:37,代码来源:JazzJRDataSource.java


注:本文中的org.apache.commons.lang.ClassUtils.primitiveToWrapper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。