/** * @since 2.3.22 */ public Object tryUnwrapTo(TemplateModel model, Class<?> targetClass) throws TemplateModelException { return tryUnwrapTo(model, targetClass, 0); }
/** * @param typeFlags * Used when unwrapping for overloaded methods and so the {@code targetClass} is possibly too generic. * Must be 0 when unwrapping parameter values for non-overloaded methods, also if * {@link #is2321Bugfixed()} is {@code false}. * @return {@link ObjectWrapperAndUnwrapper#CANT_UNWRAP_TO_TARGET_CLASS} or the unwrapped object. */ Object tryUnwrapTo(TemplateModel model, Class<?> targetClass, int typeFlags) throws TemplateModelException { Object res = tryUnwrapTo(model, targetClass, typeFlags, null); if ((typeFlags & TypeFlags.WIDENED_NUMERICAL_UNWRAPPING_HINT) != 0 && res instanceof Number) { return OverloadedNumberUtil.addFallbackType((Number) res, typeFlags); } else { return res; } }
/** * Attempts to unwrap a model into an object of the desired class. * Generally, this method is the inverse of the {@link #wrap(Object)} * method. It recognizes a wide range of target classes - all Java built-in * primitives, primitive wrappers, numbers, dates, sets, lists, maps, and * native arrays. * @param model the model to unwrap * @param targetClass the class of the unwrapped result; {@code Object.class} of we don't know what the expected type is. * @return the unwrapped result of the desired class * @throws TemplateModelException if an attempted unwrapping fails. * * @see #tryUnwrapTo(TemplateModel, Class) */ public Object unwrap(TemplateModel model, Class<?> targetClass) throws TemplateModelException { final Object obj = tryUnwrapTo(model, targetClass); if (obj == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { throw new TemplateModelException("Can not unwrap model of type " + model.getClass().getName() + " to type " + targetClass.getName()); } return obj; }
Object varargs = Array.newInstance(varArgsCompType, totalArgCount - fixArgCount); for (int i = fixArgCount; i < totalArgCount; ++i) { Object val = unwrapper.tryUnwrapTo((TemplateModel) modelArgs.get(i), varArgsCompType); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { return Integer.valueOf(i + 1); return packedArgs; } else { Object val = unwrapper.tryUnwrapTo((TemplateModel) modelArgs.get(fixArgCount), varArgsCompType); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { return Integer.valueOf(fixArgCount + 1);
Class argType = argTypes[argIdx]; TemplateModel argVal = (TemplateModel) it.next(); Object unwrappedArgVal = w.tryUnwrapTo(argVal, argType); if (unwrappedArgVal == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { throw createArgumentTypeMismarchException(argIdx, argVal, argType); && (unwrappedArgVal = w.tryUnwrapTo(argVal, varargType)) != ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { for (int varargIdx = 0; varargIdx < varargArrayLen; varargIdx++) { TemplateModel varargVal = (TemplateModel) (varargIdx == 0 ? argVal : it.next()); Object unwrappedVarargVal = w.tryUnwrapTo(varargVal, varargItemType); if (unwrappedVarargVal == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { throw createArgumentTypeMismarchException(
for (int i = 0; i < size; i++) { final TemplateModel seqItem = seq.get(i); Object val = tryUnwrapTo(seqItem, componentType, 0, recursionStops); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { if (tryOnly) {
for (int i = 0; i < argsLen; ++i) { int paramIdx = i < paramCount ? i : paramCount - 1; Object pojo = unwrapper.tryUnwrapTo( (TemplateModel) it.next(), unwarappingHints[paramIdx],
Object pojo = unwrapper.tryUnwrapTo( (TemplateModel) it.next(), unwarppingHints[i],
/** * @since 2.3.22 */ public Object tryUnwrapTo(TemplateModel model, Class<?> targetClass) throws TemplateModelException { return tryUnwrapTo(model, targetClass, 0); }
/** * @since 2.3.22 */ public Object tryUnwrapTo(TemplateModel model, Class<?> targetClass) throws TemplateModelException { return tryUnwrapTo(model, targetClass, 0); }
/** * @param typeFlags * Used when unwrapping for overloaded methods and so the {@code targetClass} is possibly too generic. * Must be 0 when unwrapping parameter values for non-overloaded methods, also if * {@link #is2321Bugfixed()} is {@code false}. * @return {@link ObjectWrapperAndUnwrapper#CANT_UNWRAP_TO_TARGET_CLASS} or the unwrapped object. */ Object tryUnwrapTo(TemplateModel model, Class<?> targetClass, int typeFlags) throws TemplateModelException { Object res = tryUnwrapTo(model, targetClass, typeFlags, null); if ((typeFlags & TypeFlags.WIDENED_NUMERICAL_UNWRAPPING_HINT) != 0 && res instanceof Number) { return OverloadedNumberUtil.addFallbackType((Number) res, typeFlags); } else { return res; } }
/** * @param typeFlags * Used when unwrapping for overloaded methods and so the {@code targetClass} is possibly too generic. * Must be 0 when unwrapping parameter values for non-overloaded methods, also if * {@link #is2321Bugfixed()} is {@code false}. * @return {@link ObjectWrapperAndUnwrapper#CANT_UNWRAP_TO_TARGET_CLASS} or the unwrapped object. */ Object tryUnwrapTo(TemplateModel model, Class<?> targetClass, int typeFlags) throws TemplateModelException { Object res = tryUnwrapTo(model, targetClass, typeFlags, null); if ((typeFlags & TypeFlags.WIDENED_NUMERICAL_UNWRAPPING_HINT) != 0 && res instanceof Number) { return OverloadedNumberUtil.addFallbackType((Number) res, typeFlags); } else { return res; } }
/** * Attempts to unwrap a model into an object of the desired class. * Generally, this method is the inverse of the {@link #wrap(Object)} * method. It recognizes a wide range of target classes - all Java built-in * primitives, primitive wrappers, numbers, dates, sets, lists, maps, and * native arrays. * @param model the model to unwrap * @param targetClass the class of the unwrapped result; {@code Object.class} of we don't know what the expected type is. * @return the unwrapped result of the desired class * @throws TemplateModelException if an attempted unwrapping fails. * * @see #tryUnwrapTo(TemplateModel, Class) */ public Object unwrap(TemplateModel model, Class<?> targetClass) throws TemplateModelException { final Object obj = tryUnwrapTo(model, targetClass); if (obj == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { throw new TemplateModelException("Can not unwrap model of type " + model.getClass().getName() + " to type " + targetClass.getName()); } return obj; }
/** * Attempts to unwrap a model into an object of the desired class. * Generally, this method is the inverse of the {@link #wrap(Object)} * method. It recognizes a wide range of target classes - all Java built-in * primitives, primitive wrappers, numbers, dates, sets, lists, maps, and * native arrays. * @param model the model to unwrap * @param targetClass the class of the unwrapped result; {@code Object.class} of we don't know what the expected type is. * @return the unwrapped result of the desired class * @throws TemplateModelException if an attempted unwrapping fails. * * @see #tryUnwrapTo(TemplateModel, Class) */ public Object unwrap(TemplateModel model, Class<?> targetClass) throws TemplateModelException { final Object obj = tryUnwrapTo(model, targetClass); if (obj == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { throw new TemplateModelException("Can not unwrap model of type " + model.getClass().getName() + " to type " + targetClass.getName()); } return obj; }
Object varargs = Array.newInstance(varArgsCompType, totalArgCount - fixArgCount); for (int i = fixArgCount; i < totalArgCount; ++i) { Object val = unwrapper.tryUnwrapTo((TemplateModel) modelArgs.get(i), varArgsCompType); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { return Integer.valueOf(i + 1); return packedArgs; } else { Object val = unwrapper.tryUnwrapTo((TemplateModel) modelArgs.get(fixArgCount), varArgsCompType); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { return Integer.valueOf(fixArgCount + 1);
Object varargs = Array.newInstance(varArgsCompType, totalArgCount - fixArgCount); for (int i = fixArgCount; i < totalArgCount; ++i) { Object val = unwrapper.tryUnwrapTo((TemplateModel) modelArgs.get(i), varArgsCompType); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { return Integer.valueOf(i + 1); return packedArgs; } else { Object val = unwrapper.tryUnwrapTo((TemplateModel) modelArgs.get(fixArgCount), varArgsCompType); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { return Integer.valueOf(fixArgCount + 1);
for (int i = 0; i < size; i++) { final TemplateModel seqItem = seq.get(i); Object val = tryUnwrapTo(seqItem, componentType, 0, recursionStops); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { if (tryOnly) {
for (int i = 0; i < size; i++) { final TemplateModel seqItem = seq.get(i); Object val = tryUnwrapTo(seqItem, componentType, 0, recursionStops); if (val == ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS) { if (tryOnly) {
Object pojo = unwrapper.tryUnwrapTo( (TemplateModel) it.next(), unwarppingHints[i],
Object pojo = unwrapper.tryUnwrapTo( (TemplateModel) it.next(), unwarppingHints[i],