List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:org.ednovo.gooru.domain.service.classplan.LearnguideServiceImpl.java
@Override public Learnguide createNewCollection(String lesson, String grade, String[] taxonomyCode, User user, String type, Map<String, String> customFieldAndValueMap, String lessonObjectives) { Learnguide collection = new Learnguide(); ContentType contentType = (ContentType) this.getBaseRepository().get(ContentType.class, ContentType.RESOURCE);// w w w. ja va 2 s . c om License license = (License) this.getBaseRepository().get(License.class, License.OTHER); ResourceType resourceType = null; if (type.equalsIgnoreCase(CLASS_PLAN)) { resourceType = (ResourceType) this.getBaseRepository().get(ResourceType.class, ResourceType.Type.CLASSPLAN.getType()); } else if (type.equalsIgnoreCase(CLASS_BOOK)) { resourceType = (ResourceType) this.getBaseRepository().get(ResourceType.class, ResourceType.Type.CLASSBOOK.getType()); } collection.setType(type); collection.setLesson(lesson); collection.setTitle(lesson); collection.setResourceSegments(Learnguide.getSegmentsSkeleton()); collection.setGrade(grade); collection.setContentType(contentType); collection.setGooruOid(UUID.randomUUID().toString()); collection.setLastModified(new Date(System.currentTimeMillis())); collection.setCreatedOn(new Date(System.currentTimeMillis())); collection.setSharing(Sharing.PRIVATE.getSharing()); collection.setUser(user); collection.setOrganization(user.getPrimaryOrganization()); collection.setCreator(user); collection.setLicense(license); collection.setResourceType(resourceType); collection.setUrl(""); collection.setDistinguish(Short.valueOf("0")); collection.setIsFeatured(0); collection.setNarration(""); collection.setRequestPending(0); collection.setGoals(lessonObjectives); // Add taxonomy data List<Code> codeList = new ArrayList<Code>(); if (taxonomyCode != null) { for (String codeId : taxonomyCode) { if (!codeId.equals("-")) { codeList.add((Code) this.getTaxonomyRepository().findCodeByTaxCode(codeId)); } } if (codeList.size() != 0) { Set<Code> taxonomySet = new HashSet<Code>(codeList); collection.setTaxonomySet(taxonomySet); } } this.getLearnguideRepository().save(collection); // Save Resource Folder this.getLearnguideRepository().save(collection); this.getResourceImageUtil().setDefaultThumbnailImageIfFileNotExist((Resource) collection); /* * Commenting this line of code. Organization already saved in resource * level in base class(saveOrUpdate) */ // s3ResourceApiHandler.updateOrganization(collection); UserContentRelationshipUtil.updateUserContentRelationship(collection, user, RELATIONSHIP.CREATE); if (logger.isInfoEnabled()) { logger.info(LogUtil.getApplicationLogStream(LEARN_GUIDE, "Indexing new learnguide with content id as " + collection.getGooruOid())); } final String cacheKey = "e.col.i-" + collection.getContentId().toString(); getRedisService().putValue(cacheKey, JsonSerializer.serializeToJson(collection, true), RedisService.DEFAULT_PROFILE_EXP); indexProcessor.index(collection.getGooruOid(), IndexProcessor.INDEX, COLLECTION); try { revisionHistoryService.createVersion(collection, NEW_COLLECTION); } catch (Exception ex) { ex.printStackTrace(); } return collection; }
From source file:com.streamsets.pipeline.stage.processor.fieldvaluereplacer.FieldValueReplacerProcessor.java
private Object convertToType(String stringValue, Field.Type fieldType, String matchingField) throws ParseException { switch (fieldType) { case BOOLEAN: return Boolean.valueOf(stringValue); case BYTE://ww w .j a va 2 s . c o m return Byte.valueOf(stringValue); case BYTE_ARRAY: return stringValue.getBytes(StandardCharsets.UTF_8); case CHAR: return stringValue.charAt(0); case DATE: DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); return dateFormat.parse(stringValue); case TIME: DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH); return timeFormat.parse(stringValue); case DATETIME: DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ", Locale.ENGLISH); return dateTimeFormat.parse(stringValue); case DECIMAL: return new BigDecimal(stringValue); case DOUBLE: return Double.valueOf(stringValue); case FLOAT: return Float.valueOf(stringValue); case INTEGER: return Integer.valueOf(stringValue); case LONG: return Long.valueOf(stringValue); case SHORT: return Short.valueOf(stringValue); case FILE_REF: throw new IllegalArgumentException( Utils.format(Errors.VALUE_REPLACER_03.getMessage(), fieldType, matchingField)); case LIST_MAP: case LIST: case MAP: default: return stringValue; } }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>// w w w . ja v a 2 s .com * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:adalid.core.programmers.AbstractJavaProgrammer.java
protected String getString(Object object, Class<?> type) { if (object == null || type == null) { return null; }//from www . j a v a 2 s .co m String errmsg = "cannot get \"" + javaLangLess(type) + "\" from \"" + object + "\""; String string = getString(object); try { if (string == null) { return null; } else if (Boolean.class.isAssignableFrom(type)) { return "" + Boolean.valueOf(string); } else if (Character.class.isAssignableFrom(type)) { return getCharacterString(string); } else if (String.class.isAssignableFrom(type)) { return string; } else if (Byte.class.isAssignableFrom(type)) { return "" + Byte.valueOf(string); } else if (Short.class.isAssignableFrom(type)) { return "" + Short.valueOf(string); } else if (Integer.class.isAssignableFrom(type)) { return "" + Integer.valueOf(string); } else if (Long.class.isAssignableFrom(type)) { return "" + Long.valueOf(string); } else if (Float.class.isAssignableFrom(type)) { return "" + Float.valueOf(string); } else if (Double.class.isAssignableFrom(type)) { return "" + Double.valueOf(string); } else if (BigInteger.class.isAssignableFrom(type)) { return "" + new BigInteger(string); } else if (BigDecimal.class.isAssignableFrom(type)) { return "" + new BigDecimal(string); } else if (object instanceof java.util.Date && Date.class.isAssignableFrom(type)) { string = TimeUtils.jdbcDateString(object); return getString(Date.valueOf(string)); } else if (object instanceof java.util.Date && Time.class.isAssignableFrom(type)) { string = TimeUtils.jdbcTimeString(object); return getString(Time.valueOf(string)); } else if (object instanceof java.util.Date && Timestamp.class.isAssignableFrom(type)) { string = TimeUtils.jdbcTimestampString(object); return getString(Timestamp.valueOf(string)); } else { return null; } } catch (IllegalArgumentException ex) { // logger.error(errmsg, ThrowableUtils.getCause(ex)); logger.error(errmsg); return null; } }
From source file:com.cloud.api.dispatch.ParamProcessWorker.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void setFieldValue(final Field field, final BaseCmd cmdObj, final Object paramObj, final Parameter annotation) throws IllegalArgumentException, ParseException { try {//from w w w . j a v a 2s .co m field.setAccessible(true); final CommandType fieldType = annotation.type(); switch (fieldType) { case BOOLEAN: field.set(cmdObj, Boolean.valueOf(paramObj.toString())); break; case DATE: // This piece of code is for maintaining backward compatibility // and support both the date formats(Bug 9724) if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd || cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd || cmdObj instanceof GetUsageRecordsCmd) { final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString()); if (isObjInNewDateFormat) { final DateFormat newFormat = newInputFormat; synchronized (newFormat) { field.set(cmdObj, newFormat.parse(paramObj.toString())); } } else { final DateFormat format = inputFormat; synchronized (format) { Date date = format.parse(paramObj.toString()); if (field.getName().equals("startDate")) { date = messageDate(date, 0, 0, 0); } else if (field.getName().equals("endDate")) { date = messageDate(date, 23, 59, 59); } field.set(cmdObj, date); } } } else { final DateFormat format = inputFormat; synchronized (format) { format.setLenient(false); field.set(cmdObj, format.parse(paramObj.toString())); } } break; case FLOAT: // Assuming that the parameters have been checked for required before now, // we ignore blank or null values and defer to the command to set a default // value for optional parameters ... if (paramObj != null && isNotBlank(paramObj.toString())) { field.set(cmdObj, Float.valueOf(paramObj.toString())); } break; case DOUBLE: // Assuming that the parameters have been checked for required before now, // we ignore blank or null values and defer to the command to set a default // value for optional parameters ... if (paramObj != null && isNotBlank(paramObj.toString())) { field.set(cmdObj, Double.valueOf(paramObj.toString())); } break; case INTEGER: // Assuming that the parameters have been checked for required before now, // we ignore blank or null values and defer to the command to set a default // value for optional parameters ... if (paramObj != null && isNotBlank(paramObj.toString())) { field.set(cmdObj, Integer.valueOf(paramObj.toString())); } break; case LIST: final List listParam = new ArrayList(); final StringTokenizer st = new StringTokenizer(paramObj.toString(), ","); while (st.hasMoreTokens()) { final String token = st.nextToken(); final CommandType listType = annotation.collectionType(); switch (listType) { case INTEGER: listParam.add(Integer.valueOf(token)); break; case UUID: if (token.isEmpty()) break; final Long internalId = translateUuidToInternalId(token, annotation); listParam.add(internalId); break; case LONG: { listParam.add(Long.valueOf(token)); } break; case SHORT: listParam.add(Short.valueOf(token)); break; case STRING: listParam.add(token); break; } } field.set(cmdObj, listParam); break; case UUID: final Long internalId = translateUuidToInternalId(paramObj.toString(), annotation); field.set(cmdObj, internalId); break; case LONG: field.set(cmdObj, Long.valueOf(paramObj.toString())); break; case SHORT: field.set(cmdObj, Short.valueOf(paramObj.toString())); break; case STRING: if ((paramObj != null)) { if (paramObj.toString().length() > annotation.length()) { s_logger.error("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName()); throw new InvalidParameterValueException("Value greater than max allowed length " + annotation.length() + " for param: " + field.getName()); } else { field.set(cmdObj, paramObj.toString()); } } break; case TZDATE: field.set(cmdObj, DateUtil.parseTZDateString(paramObj.toString())); break; case MAP: default: field.set(cmdObj, paramObj); break; } } catch (final IllegalAccessException ex) { s_logger.error("Error initializing command " + cmdObj.getCommandName() + ", field " + field.getName() + " is not accessible."); throw new CloudRuntimeException("Internal error initializing parameters for command " + cmdObj.getCommandName() + " [field " + field.getName() + " is not accessible]"); } }
From source file:com.healthmarketscience.jackcess.impl.ColumnImpl.java
/** * Deserialize a raw byte value for this column into an Object * @param data The raw byte value//from www . java 2 s . c o m * @param order Byte order in which the raw value is stored * @return The deserialized Object * @usage _advanced_method_ */ public Object read(byte[] data, ByteOrder order) throws IOException { ByteBuffer buffer = ByteBuffer.wrap(data).order(order); switch (getType()) { case BOOLEAN: throw new IOException("Tried to read a boolean from data instead of null mask."); case BYTE: return Byte.valueOf(buffer.get()); case INT: return Short.valueOf(buffer.getShort()); case LONG: return Integer.valueOf(buffer.getInt()); case DOUBLE: return Double.valueOf(buffer.getDouble()); case FLOAT: return Float.valueOf(buffer.getFloat()); case SHORT_DATE_TIME: return readDateValue(buffer); case BINARY: return data; case TEXT: return decodeTextValue(data); case MONEY: return readCurrencyValue(buffer); case NUMERIC: return readNumericValue(buffer); case GUID: return readGUIDValue(buffer, order); case UNKNOWN_0D: case UNKNOWN_11: // treat like "binary" data return data; case COMPLEX_TYPE: return new ComplexValueForeignKeyImpl(this, buffer.getInt()); default: throw new IOException("Unrecognized data type: " + _type); } }
From source file:net.openkoncept.vroom.VroomController.java
private Object getParameterValue(Class propType, String id, Object[] paramValues, String format, Map paramMap) { Object value = null;/* ww w .j a v a2s . c o m*/ if (paramValues == null) { if (paramMap != null) { value = paramMap.get(id); if (value instanceof List) { List l = (List) value; paramValues = l.toArray(); value = null; } } } SimpleDateFormat sdf = null; try { String typeName = propType.getName(); if (typeName.indexOf("java.lang.String") != -1) { if (!propType.isArray()) { value = paramValues[0]; } else { value = new String[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = paramValues[i]; } } } else if (typeName.indexOf("java.lang.Character") != -1) { if (!propType.isArray()) { value = new Character(((String) paramValues[0]).charAt(0)); } else { value = new Character[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = new Character(((String) paramValues[i]).charAt(0)); } } } else if (typeName.indexOf("java.lang.Short") != -1) { if (!propType.isArray()) { value = Short.valueOf((String) paramValues[0]); } else { value = new Short[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = Short.valueOf((String) paramValues[i]); } } } else if (typeName.indexOf("java.lang.Integer") != -1) { if (!propType.isArray()) { value = Integer.valueOf((String) paramValues[0]); } else { value = new Integer[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = Integer.valueOf((String) paramValues[i]); } } } else if (typeName.indexOf("java.lang.Long") != -1) { if (!propType.isArray()) { value = Long.valueOf((String) paramValues[0]); } else { value = new Long[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = Long.valueOf((String) paramValues[i]); } } } else if (typeName.indexOf("java.lang.Float") != -1) { if (!propType.isArray()) { value = Float.valueOf((String) paramValues[0]); } else { value = new Float[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = Float.valueOf((String) paramValues[i]); } } } else if (typeName.indexOf("java.lang.Double") != -1) { if (!propType.isArray()) { value = Double.valueOf((String) paramValues[0]); } else { value = new Double[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = Double.valueOf((String) paramValues[i]); } } } else if (typeName.indexOf("java.lang.Boolean") != -1) { if (!propType.isArray()) { value = Boolean.valueOf((String) paramValues[0]); } else { value = new Boolean[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = Boolean.valueOf((String) paramValues[i]); } } } else if (typeName.indexOf("java.util.Date") != -1) { if (format != null) { sdf = new SimpleDateFormat(format); } else { sdf = new SimpleDateFormat(); } if (!propType.isArray()) { value = sdf.parse((String) paramValues[0]); } else { value = new Date[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = sdf.parse((String) paramValues[i]); } } } else if (typeName.indexOf("org.apache.commons.fileupload.FileItem") != -1) { if (!propType.isArray()) { value = paramValues[0]; } else { value = new org.apache.commons.fileupload.FileItem[paramValues.length]; for (int i = 0; i < paramValues.length; i++) { ((Object[]) value)[i] = paramValues[i]; } } } } catch (Exception ex) { value = null; } return value; }
From source file:com.cartmatic.estore.common.helper.ConfigUtil.java
/** * customer is needed to confirm to activate, true or false return. * /*from ww w .ja va 2s .co m*/ * @return */ public Short getIsRegisterCustomerConfirmEnabled() { return Short.valueOf(getConfig("IsCustomerRegisterConfirmEnabled", "0")); }
From source file:org.mifos.accounts.productsmix.struts.action.ProductMixAction.java
private void checkBeforeUpdate(ActionForm form, HttpServletRequest request) throws PageExpiredException, NumberFormatException, ServiceException { ProductMixActionForm prdMixActionForm = (ProductMixActionForm) form; List<PrdOfferingBO> notAllowedProductList = (List<PrdOfferingBO>) SessionUtils .getAttribute(ProductDefinitionConstants.NOTALLOWEDPRODUCTLIST, request); PrdOfferingBO productOff = getPrdMixBusinessService() .getPrdOfferingByID(Short.valueOf(prdMixActionForm.getProductInstance())); productOff.setUserContext(getUserContext(request)); List<PrdOfferingBO> tabAllowed = new ArrayList<PrdOfferingBO>(); boolean showMessage = false; List<PrdOfferingBO> oldNotAllowedProductList = (List<PrdOfferingBO>) SessionUtils .getAttribute(ProductDefinitionConstants.OLDNOTALLOWEDPRODUCTLIST, request); for (PrdOfferingBO prdOff : oldNotAllowedProductList) { for (PrdOfferingBO prdOff2 : notAllowedProductList) { if (prdOff.getPrdOfferingId() == prdOff2.getPrdOfferingId()) { tabAllowed.add(prdOff);//www . j a v a 2 s. com showMessage = true; } } } SessionUtils.setCollectionAttribute(ProductDefinitionConstants.TABALLOWED, tabAllowed, request); SessionUtils.setAttribute(ProductDefinitionConstants.SHOWMESSAGE, showMessage, request); }
From source file:org.j2free.admin.ReflectionMarshaller.java
/** * /*w w w. j ava2 s . com*/ * @param entity * @param parameterMap * @param controller * @return * @throws MarshallingException */ public Object marshallIn(Object entity, Map<String, String[]> parameterMap, Controller controller) throws MarshallingException { Field field; Converter converter; Method setter; String[] newValues; log.debug("Marshalling in instance of " + entity.getClass().getSimpleName()); boolean error = false, success = false, isEntity = false, isCollection = false; Class collectionType; Class fieldType; for (Map.Entry<Field, Converter> ent : instructions.entrySet()) { // reset flags error = success = isEntity = isCollection = false; field = ent.getKey(); converter = ent.getValue(); if (converter.isReadOnly()) { log.debug("Skipping read-only field " + field.getName()); continue; } newValues = parameterMap.get(field.getName()); if (newValues == null || newValues.length == 0) { log.debug("Skipping field " + field.getName() + ", no new value set."); continue; } isEntity = converter.isEntity(); isCollection = converter.isCollection(); fieldType = field.getType(); collectionType = isCollection ? converter.getType() : null; log.debug("Marshalling in field " + field.getName()); // try to get the original value try { if (!field.isAccessible()) { field.setAccessible(true); } if (field.isAccessible()) { log.debug(field.getName() + " is accessible"); if (!isEntity && !isCollection) { log.debug("!isEntity && !isCollection"); // if it's an array, it needs special treatment if (fieldType.isArray()) { log.debug(field.getName() + " is an Array"); Class arrayType = fieldType.getComponentType(); // If we can, just convert with a cast() if (arrayType.isAssignableFrom(String.class)) { log.debug(arrayType.getName() + " is assignable from String.class"); Object[] newArray = new Object[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = arrayType.cast(newValues[i]); } field.set(entity, newArray); } else { if (isInteger(fieldType)) { Integer[] newArray = new Integer[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Integer.valueOf(newValues[i]); } field.set(entity, newArray); } else if (isFloat(fieldType)) { Float[] newArray = new Float[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Float.valueOf(newValues[i]); } field.set(entity, newArray); } else if (isDouble(fieldType)) { Double[] newArray = new Double[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Double.valueOf(newValues[i]); } field.set(entity, newArray); } else if (isShort(fieldType)) { Short[] newArray = new Short[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Short.valueOf(newValues[i]); } field.set(entity, newArray); } else if (isChar(fieldType)) { field.set(entity, ServletUtils.join(newValues, "").toCharArray()); } else if (isLong(fieldType)) { Long[] newArray = new Long[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Long.valueOf(newValues[i]); } field.set(entity, newArray); } else if (isBoolean(fieldType)) { Boolean[] newArray = new Boolean[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Boolean.valueOf(newValues[i]); } field.set(entity, newArray); } else if (isByte(fieldType)) { Byte[] newArray = new Byte[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Byte.valueOf(newValues[i]); } field.set(entity, newArray); } else { throw new MarshallingException( "Don't know how to marshall an array of a non-primitive, and non-assignable type! field = " + field.getName()); } } } else { // Check out if it's assignable via a straight cast, // that could save time if (fieldType.isAssignableFrom(String.class)) { log.debug(fieldType.getName() + " is assignable from String.class"); // this might throw an exception, but we're going // to ignore it because there are other ways of // setting the value if this doesn't work. try { field.set(entity, fieldType.cast(newValues[0])); log.debug("Assigned via cast"); } catch (Exception e) { log.debug("Error setting field by cast", e); } success = true; } // if it wasn't assignable via a straight cast, try // working around it. if (!success) { if (isInteger(fieldType) && !newValues[0].equals("")) { field.setInt(entity, Integer.valueOf(newValues[0])); } else if (isFloat(fieldType) && !newValues[0].equals("")) { field.setFloat(entity, Float.valueOf(newValues[0])); } else if (isDouble(fieldType) && !newValues[0].equals("")) { field.setDouble(entity, Double.valueOf(newValues[0])); } else if (isShort(fieldType) && !newValues[0].equals("")) { field.setShort(entity, Short.valueOf(newValues[0])); } else if (isChar(fieldType)) { field.setChar(entity, newValues[0].charAt(0)); } else if (isLong(fieldType) && !newValues[0].equals("")) { field.setLong(entity, Long.valueOf(newValues[0])); } else if (isBoolean(fieldType) && !newValues[0].equals("")) { field.setBoolean(entity, Boolean.valueOf(newValues[0])); } else if (isByte(fieldType) && !newValues[0].equals("")) { field.setByte(entity, Byte.valueOf(newValues[0])); } else if (isDate(fieldType)) { if (newValues[0].equals("")) { field.set(entity, null); } else { try { field.set(entity, asDate(newValues[0])); } catch (ParseException pe) { log.warn("Error parsing date: " + newValues[0], pe); } } } else if (!newValues[0].equals("")) { log.debug("Not sure how to set " + field.getName() + " of type " + fieldType.getName() + ", attemping cast."); field.set(entity, fieldType.cast(newValues[0])); } else if (newValues[0].equals("")) { log.debug("Skipping field " + field.getName() + ", empty string value passed in."); } } } } else if (isEntity && !isCollection) { log.debug("isEntity && !isCollection"); ReflectionMarshaller innerMarshaller = ReflectionMarshaller.getForClass(fieldType); field.set(entity, controller.proxy(fieldType, innerMarshaller.asIdType(newValues[0]))); } else if (!isEntity && isCollection) { log.debug("!isEntity && isCollection"); throw new MarshallingException("Error, collections of non-entities are not yet supported."); } else if (isEntity && isCollection) { log.debug("isEntity && isCollection"); // for now, this is going to expect the parameter to be a // comma-delimited string of entity ids String[] idsString = newValues[0].toString().split(","); Collection collection = (Collection) field.get(entity); log.debug("newValues.length = " + newValues.length); log.debug("newValues[0] = " + newValues[0]); log.debug("idsString.length = " + idsString.length); if (collection == null) collection = new LinkedList(); collection.clear(); if (idsString.length > 0) { ReflectionMarshaller collectionMarshaller = ReflectionMarshaller .getForClass(collectionType); log.debug("CollectionType = " + collectionType.getName()); for (String idString : idsString) { if (idString.equals("")) { log.debug("Skipping empty idString"); continue; } collection.add( controller.proxy(collectionType, collectionMarshaller.asIdType(idString))); } } field.set(entity, collection); } } else { error = true; } } catch (IllegalAccessException iae) { log.error("Unable to set " + field.getName() + " directly.", iae); error = true; } catch (ClassCastException cce) { log.error("Error setting " + field.getName() + ".", cce); error = true; } // if we hit an error getting it directly, try via the getter if (error) { error = false; try { setter = converter.getSetter(); if (setter != null) { if (!setter.isAccessible()) { setter.setAccessible(true); } if (setter.isAccessible()) { if (!isEntity && !isCollection) { // if it's an array, it needs special treatment if (fieldType.isArray()) { log.debug(field.getName() + " is an Array"); Class arrayType = fieldType.getComponentType(); // If we can, just convert with a cast() if (arrayType.isAssignableFrom(String.class)) { log.debug(arrayType.getName() + " is assignable from String.class"); Object[] newArray = new Object[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = arrayType.cast(newValues[i]); } setter.invoke(entity, newArray); } else { if (isInteger(fieldType)) { Integer[] newArray = new Integer[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Integer.valueOf(newValues[i]); } setter.invoke(entity, (Object[]) newArray); } else if (isFloat(fieldType)) { Float[] newArray = new Float[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Float.valueOf(newValues[i]); } setter.invoke(entity, (Object[]) newArray); } else if (isDouble(fieldType)) { Double[] newArray = new Double[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Double.valueOf(newValues[i]); } setter.invoke(entity, (Object[]) newArray); } else if (isShort(fieldType)) { Short[] newArray = new Short[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Short.valueOf(newValues[i]); } setter.invoke(entity, (Object[]) newArray); } else if (isChar(fieldType)) { setter.invoke(entity, ServletUtils.join(newValues, "").toCharArray()); } else if (isLong(fieldType)) { Long[] newArray = new Long[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Long.valueOf(newValues[i]); } field.set(entity, (Object[]) newArray); } else if (isBoolean(fieldType)) { Boolean[] newArray = new Boolean[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Boolean.valueOf(newValues[i]); } setter.invoke(entity, (Object[]) newArray); } else if (isByte(fieldType)) { Byte[] newArray = new Byte[newValues.length]; for (int i = 0; i < newValues.length; i++) { newArray[i] = Byte.valueOf(newValues[i]); } setter.invoke(entity, (Object[]) newArray); } else { throw new MarshallingException( "Don't know how to marshall an array of a non-primitive, and non-assignable type! field = " + field.getName()); } } } else { // Check out if it's assignable via a straight cast, // that could save time if (fieldType.isAssignableFrom(String.class)) { log.debug(fieldType.getName() + " is assignable from String.class"); // this might throw an exception, but we're going // to ignore it because there are other ways of // setting the value if this doesn't work. try { setter.invoke(entity, fieldType.cast(newValues[0])); } catch (Exception e) { log.debug("Error setting field by cast", e); } success = true; } // if it wasn't assignable via a straight cast, try // working around it. if (!success) { if (isInteger(fieldType)) { setter.invoke(entity, Integer.valueOf(newValues[0])); } else if (isFloat(fieldType)) { setter.invoke(entity, Float.valueOf(newValues[0])); } else if (isDouble(fieldType)) { setter.invoke(entity, Double.valueOf(newValues[0])); } else if (isShort(fieldType)) { setter.invoke(entity, Short.valueOf(newValues[0])); } else if (isChar(fieldType)) { setter.invoke(entity, newValues[0].charAt(0)); } else if (isLong(fieldType)) { setter.invoke(entity, Long.valueOf(newValues[0])); } else if (isBoolean(fieldType)) { setter.invoke(entity, Boolean.valueOf(newValues[0])); } else if (isByte(fieldType)) { setter.invoke(entity, Byte.valueOf(newValues[0])); } else if (isDate(fieldType)) { if (newValues[0].equals("")) { field.set(entity, null); } else { try { setter.invoke(entity, asDate(newValues[0])); } catch (ParseException pe) { log.warn("Error parsing date: " + newValues[0], pe); } } } else { log.debug("Not sure how to set " + field.getName() + " of type " + fieldType.getName() + ", attemping cast."); setter.invoke(entity, fieldType.cast(newValues[0])); } } } } else if (isEntity && !isCollection) { ReflectionMarshaller innerMarshaller = ReflectionMarshaller.getForClass(fieldType); setter.invoke(entity, controller.proxy(fieldType, innerMarshaller.asIdType(newValues[0]))); } else if (!isEntity && isCollection) { throw new MarshallingException( "Error, collections of non-entities are not yet supported."); } else if (isEntity && isCollection) { // for now, this is going to expect the parameter to be a // comma-delimited string of entity ids String[] idsString = newValues[0].toString().split(","); Collection collection = (Collection) field.get(entity); if (collection == null) collection = new LinkedList(); if (idsString.length == 0 && collection.isEmpty()) continue; collection.clear(); if (idsString.length > 0) { ReflectionMarshaller collectionMarshaller = ReflectionMarshaller .getForClass(collectionType); for (String idString : idsString) { if (idString.equals("")) { log.debug("Skipping empty idString"); continue; } collection.add(controller.proxy(collectionType, collectionMarshaller.asIdType(idString))); } } setter.invoke(entity, collection); } } else { error = true; } } else { error = true; } } catch (IllegalAccessException iae) { log.error("Error accessing setter", iae); error = true; } catch (InvocationTargetException ite) { log.error("Error invoking setter", ite); error = true; } } if (error) { throw new MarshallingException("Unable to marshall in field " + field.getName() + "."); } } return entity; }