本文整理汇总了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);
}
}
示例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;
}
示例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 ...
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例12: getWrapper
import org.apache.commons.lang.ClassUtils; //导入方法依赖的package包/类
public Class getWrapper(String premitive) throws ClassNotFoundException {
return ClassUtils.primitiveToWrapper(ClassUtils.getClass(premitive));
}
示例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;
}
示例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;
}