List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty
public static void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:org.kuali.rice.krad.devtools.pdle.PostDataLoadEncryptionServiceImpl.java
@Override public void encrypt(PersistableBusinessObject businessObject, Set<String> attributeNames) { for (String attributeName : attributeNames) { try {//from w w w . ja v a 2 s. c o m PropertyUtils.setProperty(businessObject, attributeName, encryptionService.encrypt(PropertyUtils.getProperty(businessObject, attributeName))); } catch (Exception e) { throw new RuntimeException(new StringBuffer( "PostDataLoadEncryptionServiceImpl caught exception while attempting to encrypt attribute ") .append(attributeName).append(" of Class ").append(businessObject.getClass()) .toString(), e); } } legacyDataAdapter.save(businessObject); }
From source file:org.kuali.rice.krad.service.impl.PersistenceStructureServiceOjbImpl.java
/** * @see org.kuali.rice.krad.service.PersistenceMetadataService#clearPrimaryKeyFields(java.lang.Object) *//*from w w w . j a v a 2 s. c o m*/ // Unit tests only @Override public Object clearPrimaryKeyFields(Object persistableObject) { if (persistableObject == null) { throw new IllegalArgumentException("invalid (null) persistableObject"); } String className = null; String fieldName = null; try { className = persistableObject.getClass().getName(); List fields = listPrimaryKeyFieldNames(persistableObject.getClass()); for (Iterator i = fields.iterator(); i.hasNext();) { fieldName = (String) i.next(); PropertyUtils.setProperty(persistableObject, fieldName, null); } if (persistableObject instanceof PersistableBusinessObject) { ((PersistableBusinessObject) persistableObject).setObjectId(null); } } catch (NoSuchMethodException e) { throw new IntrospectionException("no setter for property '" + className + "." + fieldName + "'", e); } catch (IllegalAccessException e) { throw new IntrospectionException("problem accessing property '" + className + "." + fieldName + "'", e); } catch (InvocationTargetException e) { throw new IntrospectionException( "problem invoking getter for property '" + className + "." + fieldName + "'", e); } return persistableObject; }
From source file:org.logic2j.contrib.library.pojo.PojoLibrary.java
private void inject(Object pojo, String theExpression, Object newValue) { try {//from w w w .j a v a 2s .c o m PropertyUtils.setProperty(pojo, theExpression, newValue); } catch (IllegalAccessException e) { throw new PrologNonSpecificError( "Could not set property \"" + theExpression + "\" from object: " + pojo + ": " + e); } catch (NoSuchMethodException e) { throw new PrologNonSpecificError( "Could not set property \"" + theExpression + "\" from object: " + pojo + ": " + e); } catch (InvocationTargetException e) { throw new PrologNonSpecificError("Could not set property \"" + theExpression + "\" from object: " + pojo + ": " + e.getTargetException()); } }
From source file:org.moneta.config.ConnectionPoolFactory.java
protected static PropertyDescriptor assignProperty(String dataSourceName, Object poolRelatedBean, String propName, String propValue) { PropertyDescriptor pDesc = null; try {/*from w ww . ja va2s .com*/ pDesc = PropertyUtils.getPropertyDescriptor(poolRelatedBean, propName); } catch (Exception e) { throw new MonetaException("Connection pool property not valid") .addContextValue("Data source name", dataSourceName).addContextValue("Property name", propName); } if (pDesc == null) { return null; } try { PropertyUtils.setProperty(poolRelatedBean, propName, ValueNormalizationUtil.convertString(pDesc.getPropertyType(), propValue)); } catch (Exception e) { throw new MonetaException("Error setting connection pool property", e) .addContextValue("Data source name", dataSourceName).addContextValue("Property name", propName); } return pDesc; }
From source file:org.ms123.common.data.JdoLayerImpl.java
public void insertIntoMaster(SessionContext sc, Object objectInsert, String entityName, Object objectMaster, String fieldName) throws Exception { debug("insertIntoMaster:" + objectMaster + "/" + entityName + "/" + fieldName); if (objectMaster == null) return;//from www .j a v a 2s.c om String propertyName = fieldName; if (fieldName.equals(entityName)) { propertyName = m_inflector.pluralize(entityName).toLowerCase(); } Class clazz = PropertyUtils.getPropertyType(objectMaster, propertyName); if (clazz == null) { clazz = PropertyUtils.getPropertyType(objectMaster, fieldName); } debug("\tinsertIntoMaster.class:" + clazz); if (clazz != null) { if (clazz.equals(java.util.List.class) || clazz.equals(java.util.Set.class)) { Collection l = (Collection) PropertyUtils.getProperty(objectMaster, propertyName); l.add(objectInsert); String relatedToFieldName = getRelatedTo(objectInsert, objectMaster.getClass(), propertyName); if (relatedToFieldName != null) { PropertyUtils.setProperty(objectInsert, relatedToFieldName, objectMaster); } } else { if (fieldName.equals(entityName)) { propertyName = m_inflector.singularize(entityName).toLowerCase(); } PropertyUtils.setProperty(objectMaster, propertyName, objectInsert); } } }
From source file:org.ms123.common.data.JdoLayerImpl.java
public Map updateObject(SessionContext sessionContext, Map dataMap, Map filterMap, Map hintsMap, String entityName, String id, String entityNameParent, String idParent) throws Exception { StoreDesc sdesc = sessionContext.getStoreDesc(); String fieldName = entityName; if (entityNameParent != null) { entityName = constructEntityName(sessionContext, entityName, entityNameParent); }/*from w w w. ja v a2s. c o m*/ String user = sessionContext.getUserName(); checkPermissions(sdesc, user, entityName, dataMap, "write"); String config = sessionContext.getConfigName(); Map retMap = new HashMap(); String classNameUpdate = null; dataMap.put("_isnew", false); dataMap.put("_user", user); PersistenceManager pm = sessionContext.getPM(); Iterator rit = null; Map permittedFields = null; if (filterMap != null) { // Query updateObject`s classNameUpdate = m_inflector.getClassName(entityName); Class updateClazz = getClass(sdesc, classNameUpdate); Map fieldSets = m_settingService.getFieldSets(config, sdesc.getNamespace(), entityName); boolean hasTeamSecurity = hasTeamSecurity(sessionContext, entityName, null); QueryBuilder qb = new QueryBuilder("pg", sdesc, entityName, hasTeamSecurity, config, sessionContext, null, filterMap, hintsMap, fieldSets); String whereClause = "where " + qb.getWhere(); String from = qb.getFrom(null); whereClause = whereClause + getAddWhere(qb, entityName, null, null); String sql = "Select distinct id from " + from + " " + whereClause; debug("sql:" + sql); Query q = pm.newQuery("javax.jdo.query.JPQL", sql); q.declareImports(sdesc.getImports()); List results = (List) q.executeWithMap(qb.getQueryParams()); rit = results.iterator(); } else { Object updateId = null; // Get updateObject from parent over one-to-one Relation,Ex:data/contacts/30329/communication if (idParent == null && entityNameParent != null) { String propertyName = fieldName; if (fieldName.equals(entityName)) { propertyName = m_inflector.singularize(entityName).toLowerCase(); } Object object = null; String classNameMaster = m_inflector.getClassName(entityNameParent); Class masterClazz = getClass(sdesc, classNameMaster); Object masterId = getIdObject(id, sdesc, null); Object objectMaster = pm.getObjectById(masterClazz, masterId); try { object = PropertyUtils.getProperty(objectMaster, propertyName); } catch (Exception e) { debug("e:" + e); } if (object != null) { updateId = PropertyUtils.getProperty(object, "id"); } else { String className = m_inflector.getClassName(entityName); Class updateClazz = getClass(sdesc, className); Object objectUpdate = updateClazz.newInstance(); pm.makePersistent(objectUpdate); PropertyUtils.setProperty(objectMaster, propertyName, objectUpdate); updateId = (Long) PropertyUtils.getProperty(objectUpdate, "id"); } classNameUpdate = m_inflector.getClassName(entityName); } else { permittedFields = sessionContext.getPermittedFields(entityName); updateId = getIdObject(id, sdesc, permittedFields); classNameUpdate = m_inflector.getClassName(entityName); } entityName = m_inflector.getEntityName(entityName); //evaluteFormulas(sessionContext, entityName, dataMap, "in"); debug("moduleName:" + entityName); rit = new DummyIterator(updateId); } int counter = 0; long start = new Date().getTime(); Class updateClazz = getClass(sdesc, classNameUpdate); while (rit.hasNext()) { Object row = rit.next(); counter++; Object updateId = row; Object objectUpdate = null; boolean fCreated = false; try { if (updateId == null) { updateId = "dummy"; } objectUpdate = pm.getObjectById(updateClazz, updateId); } catch (javax.jdo.JDOObjectNotFoundException e) { String pk = null; if (permittedFields != null) { pk = getPrimaryKey(updateClazz); debug("pk:" + pk); } debug("pk:" + pk); Boolean create = true; if (hintsMap != null && hintsMap.get("create") != null) { create = (Boolean) hintsMap.get("create"); } fCreated = create; if (create) { objectUpdate = createObject(sessionContext, entityName); PropertyUtils.setProperty(objectUpdate, pk, updateId); dataMap.put("_isnew", true); } } debug("objectUpdate:" + objectUpdate + "," + updateId + "/" + counter); if (objectUpdate != null) { Object objectUpdatePre = null; if (filterMap == null) { objectUpdatePre = UtilsServiceImpl.copyObject(objectUpdate); } Map<String, String> stateMap = getState(dataMap, objectUpdate); ; evaluteFormulas(sessionContext, entityName, dataMap, "in"); populate(sessionContext, dataMap, objectUpdate, hintsMap); setState(stateMap, objectUpdate); List constraintViolations = validateObject(sessionContext, objectUpdate, objectUpdatePre, entityName, fCreated); if (constraintViolations != null) { retMap.put("constraintViolations", constraintViolations); retMap.put("created", null); break; } if (fCreated) { pm.makePersistent(objectUpdate); retMap.put("id", updateId); retMap.put("created", true); } debug("SEDSC:" + sdesc); if (sdesc.isDataPack()) { //sessionContext.getLuceneSession().addToIndex(objectUpdate); } if (filterMap == null) { Boolean bypassTrigger = (Boolean) sessionContext.getProperty("bypassTrigger"); if (bypassTrigger == null || bypassTrigger == false) { m_triggerService.applyUpdateRules(sessionContext, entityName, objectUpdate, objectUpdatePre); } } if ((counter % 100) == 0) { displayInfo("", start); start = new Date().getTime(); } } else { retMap.put("id", null); retMap.put("created", false); retMap.put("notFound", true); } } return retMap; }
From source file:org.ms123.common.data.JdoLayerImpl.java
public void populate(SessionContext sessionContext, Map from, Object to, Map hintsMap) { PersistenceManager pm = sessionContext.getPM(); if (hintsMap == null) { hintsMap = new HashMap(); }/*from w w w . j a v a 2 s . co m*/ Map<String, String> expressions = (Map) hintsMap.get("__expressions"); if (expressions == null) expressions = new HashMap(); BeanMap beanMap = new BeanMap(to); String entityName = m_inflector.getEntityName(to.getClass().getSimpleName()); debug("populate.from:" + from + ",to:" + to + ",BeanMap:" + beanMap + "/hintsMap:" + hintsMap + "/entityName:" + entityName); if (from == null) { return; } Map permittedFields = sessionContext.getPermittedFields(entityName, "write"); Iterator<String> it = from.keySet().iterator(); while (it.hasNext()) { String key = it.next(); Object oldValue = beanMap.get(key); boolean permitted = m_permissionService.hasAdminRole() || "team".equals(entityName) || sessionContext.isFieldPermitted(key, entityName, "write"); if (!key.startsWith("_") && !permitted) { debug("---->populate:field(" + key + ") no write permission"); continue; } else { debug("++++>populate:field(" + key + ") write permitted"); } String datatype = null; String edittype = null; if (!key.startsWith("_")) { Map config = (Map) permittedFields.get(key); if (config != null) { datatype = (String) config.get("datatype"); edittype = (String) config.get("edittype"); } } if (key.equals(STATE_FIELD) && !m_permissionService.hasAdminRole()) { continue; } if ("auto".equals(edittype)) continue; String mode = null; Map hm = (Map) hintsMap.get(key); if (hm != null) { Object m = hm.get("mode"); if (m != null && m instanceof String) { mode = (String) m; } if (mode == null) { m = hm.get("useit"); if (m != null && m instanceof String) { mode = (String) m; } } } if (mode == null) { mode = "replace"; } Class clazz = beanMap.getType(key); debug("\ttype:" + clazz + "(" + key + "=" + from.get(key) + ")"); if ("_ignore_".equals(from.get(key))) { continue; } if (clazz == null) { debug("\t--- Warning property not found:" + key); } else if (clazz.equals(java.util.Date.class)) { String value = Utils.getString(from.get(key), beanMap.get(key), mode); debug("\tDate found:" + key + "=>" + value); Date date = null; if (value != null) { try { Long val = Long.valueOf(value); date = (Date) ConvertUtils.convert(val, Date.class); debug("\tdate1:" + date); } catch (Exception e) { try { DateTime dt = new DateTime(value); date = new Date(dt.getMillis()); debug("\tdate2:" + date); } catch (Exception e1) { try { int space = value.indexOf(" "); if (space != -1) { value = value.substring(0, space) + "T" + value.substring(space + 1); DateTime dt = new DateTime(value); date = new Date(dt.getMillis()); } debug("\tdate3:" + date); } catch (Exception e2) { debug("\terror setting date:" + e); } } } } debug("\tsetting date:" + date); beanMap.put(key, date); } else if (clazz.equals(java.util.Map.class)) { info("!!!!!!!!!!!!!!!!!!!Map not implemented"); } else if (clazz.equals(java.util.List.class) || clazz.equals(java.util.Set.class)) { boolean isList = clazz.equals(java.util.List.class); boolean isSimple = false; if (datatype != null && datatype.startsWith("list_")) { isSimple = true; } try { Class type = TypeUtils.getTypeForField(to, key); debug("type:" + type + " fill with: " + from.get(key) + ",list:" + beanMap.get(key) + "/mode:" + mode); Collection valList = isList ? new ArrayList() : new HashSet(); Object fromVal = from.get(key); if (fromVal instanceof String && ((String) fromVal).length() > 0) { info("FromVal is StringSchrott, ignore"); continue; } if (from.get(key) instanceof Collection) { valList = (Collection) from.get(key); } if (valList == null) { valList = isList ? new ArrayList() : new HashSet(); } Collection toList = (Collection) PropertyUtils.getProperty(to, key); debug("toList:" + toList); debug("valList:" + valList); if (toList == null) { toList = isList ? new ArrayList() : new HashSet(); PropertyUtils.setProperty(to, key, toList); } if ("replace".equals(mode)) { boolean isEqual = false; if (isSimple) { isEqual = Utils.isCollectionEqual(toList, valList); if (!isEqual) { toList.clear(); } debug("\tisEqual:" + isEqual); } else { List deleteList = new ArrayList(); String namespace = sessionContext.getStoreDesc().getNamespace(); for (Object o : toList) { if (type.getName().endsWith(".Team")) { int status = m_teamService.getTeamStatus(namespace, new BeanMap(o), null, sessionContext.getUserName()); debug("populate.replace.teamStatus:" + status + "/" + new HashMap(new BeanMap(o))); if (status != -1) { pm.deletePersistent(o); deleteList.add(o); } } else { pm.deletePersistent(o); deleteList.add(o); } } for (Object o : deleteList) { toList.remove(o); } } debug("populate.replace.toList:" + toList + "/" + type.getName()); if (isSimple) { if (!isEqual) { for (Object o : valList) { toList.add(o); } } } else { for (Object o : valList) { Map valMap = (Map) o; Object n = type.newInstance(); if (type.getName().endsWith(".Team")) { valMap.remove("id"); Object desc = valMap.get("description"); Object name = valMap.get("name"); Object dis = valMap.get("disabled"); String teamid = (String) valMap.get("teamid"); Object ti = Utils.getTeamintern(sessionContext, teamid); if (desc == null) { valMap.put("description", PropertyUtils.getProperty(ti, "description")); } if (name == null) { valMap.put("name", PropertyUtils.getProperty(ti, "name")); } if (dis == null) { valMap.put("disabled", false); } pm.makePersistent(n); populate(sessionContext, valMap, n, null); PropertyUtils.setProperty(n, "teamintern", ti); } else { pm.makePersistent(n); populate(sessionContext, valMap, n, null); } debug("populated.add:" + new HashMap(new BeanMap(n))); toList.add(n); } } } else if ("remove".equals(mode)) { if (isSimple) { for (Object o : valList) { if (toList.contains(o)) { toList.remove(o); } } } else { for (Object ol : valList) { Map map = (Map) ol; Object o = Utils.listContainsId(toList, map, "teamid"); if (o != null) { toList.remove(o); pm.deletePersistent(o); } } } } else if ("add".equals(mode)) { if (isSimple) { for (Object o : valList) { toList.add(o); } } else { for (Object ol : valList) { Map map = (Map) ol; Object o = Utils.listContainsId(toList, map, "teamid"); if (o != null) { populate(sessionContext, map, o, null); } else { o = type.newInstance(); if (type.getName().endsWith(".Team")) { Object desc = map.get("description"); Object name = map.get("name"); Object dis = map.get("disabled"); String teamid = (String) map.get("teamid"); Object ti = Utils.getTeamintern(sessionContext, teamid); if (desc == null) { map.put("description", PropertyUtils.getProperty(ti, "description")); } if (name == null) { map.put("name", PropertyUtils.getProperty(ti, "name")); } if (dis == null) { map.put("disabled", false); } pm.makePersistent(o); populate(sessionContext, map, o, null); PropertyUtils.setProperty(o, "teamintern", ti); } else { pm.makePersistent(o); populate(sessionContext, map, o, null); } toList.add(o); } } } } else if ("assign".equals(mode)) { if (!isSimple) { for (Object ol : valList) { Map map = (Map) ol; Object o = Utils.listContainsId(toList, map); if (o != null) { debug("id:" + map + " already assigned"); } else { Object id = map.get("id"); Boolean assign = Utils.getBoolean(map.get("assign")); Object obj = pm.getObjectById(type, id); if (assign) { toList.add(obj); } else { toList.remove(obj); } } } } } } catch (Exception e) { e.printStackTrace(); debug("populate.list.failed:" + key + "=>" + from.get(key) + ";" + e); } } else if (clazz.equals(java.lang.Boolean.class)) { try { beanMap.put(key, ConvertUtils.convert(from.get(key), Boolean.class)); } catch (Exception e) { debug("populate.boolean.failed:" + key + "=>" + from.get(key) + ";" + e); } } else if (clazz.equals(java.lang.Double.class)) { String value = Utils.getString(from.get(key), beanMap.get(key), mode); try { beanMap.put(key, Double.valueOf(value)); } catch (Exception e) { debug("populate.double.failed:" + key + "=>" + value + ";" + e); } } else if (clazz.equals(java.lang.Long.class)) { try { beanMap.put(key, ConvertUtils.convert(from.get(key), Long.class)); } catch (Exception e) { debug("populate.long.failed:" + key + "=>" + from.get(key) + ";" + e); } } else if (clazz.equals(java.lang.Integer.class)) { debug("Integer:" + ConvertUtils.convert(from.get(key), Integer.class)); try { beanMap.put(key, ConvertUtils.convert(from.get(key), Integer.class)); } catch (Exception e) { debug("populate.integer.failed:" + key + "=>" + from.get(key) + ";" + e); } } else if ("binary".equals(datatype) || clazz.equals(byte[].class)) { InputStream is = null; InputStream is2 = null; try { if (from.get(key) instanceof FileItem) { FileItem fi = (FileItem) from.get(key); String name = fi.getName(); byte[] bytes = IOUtils.toByteArray(fi.getInputStream()); if (bytes != null) { debug("bytes:" + bytes.length); } beanMap.put(key, bytes); is = fi.getInputStream(); is2 = fi.getInputStream(); } else if (from.get(key) instanceof Map) { Map map = (Map) from.get(key); String storeLocation = (String) map.get("storeLocation"); is = new FileInputStream(new File(storeLocation)); is2 = new FileInputStream(new File(storeLocation)); byte[] bytes = IOUtils.toByteArray(is); if (bytes != null) { debug("bytes2:" + bytes.length); } is.close(); beanMap.put(key, bytes); is = new FileInputStream(new File(storeLocation)); } else if (from.get(key) instanceof String) { String value = (String) from.get(key); if ("ignore".equals(value)) { debug("ignore:"); return; } if (value.startsWith("data:")) { int ind = value.indexOf(";base64,"); byte b[] = Base64.decode(value.substring(ind + 8)); beanMap.put(key, b); is = new ByteArrayInputStream(b); is2 = new ByteArrayInputStream(b); } else { byte b[] = value.getBytes(); beanMap.put(key, b); is = new ByteArrayInputStream(b); is2 = new ByteArrayInputStream(b); } } else { debug("populate.byte[].no a FileItem:" + key + "=>" + from.get(key)); continue; } Tika tika = new Tika(); TikaInputStream stream = TikaInputStream.get(is); TikaInputStream stream2 = TikaInputStream.get(is2); String text = tika.parseToString(is); debug("Text:" + text); try { beanMap.put("text", text); } catch (Exception e) { beanMap.put("text", text.getBytes()); } //@@@MS Hardcoded try { Detector detector = new DefaultDetector(); MediaType mime = detector.detect(stream2, new Metadata()); debug("Mime:" + mime.getType() + "|" + mime.getSubtype() + "|" + mime.toString()); beanMap.put("type", mime.toString()); from.put("type", mime.toString()); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); debug("populate.byte[].failed:" + key + "=>" + from.get(key) + ";" + e); } finally { try { is.close(); is2.close(); } catch (Exception e) { } } } else { boolean ok = false; try { Class type = TypeUtils.getTypeForField(to, key); if (type != null) { Object o = type.newInstance(); boolean hasAnn = type.isAnnotationPresent(PersistenceCapable.class); debug("hasAnnotation:" + hasAnn); if (o instanceof javax.jdo.spi.PersistenceCapable || hasAnn) { Object id = null; try { Object _id = from.get(key); if (_id != null) { if (_id instanceof Map) { id = ((Map) _id).get("id"); } else { String s = String.valueOf(_id); if (s.indexOf("/") >= 0) { _id = Utils.extractId(s); } Class idClass = PropertyUtils.getPropertyType(o, "id"); id = (idClass.equals(Long.class)) ? Long.valueOf(_id + "") : _id; } } } catch (Exception e) { } if (id != null && !"".equals(id) && !"null".equals(id)) { debug("\tId2:" + id); Object relatedObject = pm.getObjectById(type, id); List<Collection> candidates = TypeUtils.getCandidateLists(relatedObject, to, null); if (candidates.size() == 1) { Collection l = candidates.get(0); debug("list.contains:" + l.contains(to)); if (!l.contains(to)) { l.add(to); } } beanMap.put(key, relatedObject); } else { Object relatedObject = beanMap.get(key); debug("\trelatedObject:" + relatedObject); if (relatedObject != null) { List<Collection> candidates = TypeUtils.getCandidateLists(relatedObject, to, null); if (candidates.size() == 1) { Collection l = candidates.get(0); debug("list.contains:" + l.contains(to)); if (l.contains(to)) { l.remove(to); } } } beanMap.put(key, null); } ok = true; } } } catch (Exception e) { e.printStackTrace(); } if (!ok) { String value = Utils.getString(from.get(key), beanMap.get(key), mode); // debug("populate:" + key + "=>" + value); // debug("String:" + ConvertUtils.convert(from.get(key), String.class)); try { beanMap.put(key, value); } catch (Exception e) { debug("populate.failed:" + key + "=>" + value + ";" + e); } } } String expression = expressions.get(key); if (!isEmpty(expression)) { beanMap.put(key, oldValue); Map scriptCache = (Map) sessionContext.getProperty("scriptCache"); if (scriptCache == null) { scriptCache = new HashMap(); sessionContext.setProperty("scriptCache", scriptCache); } Object result = Utils.eval(expression, beanMap, scriptCache); try { if ("string".equals(datatype) && !(result instanceof String)) { beanMap.put(key, ConvertUtils.convert(result, String.class)); } else { beanMap.put(key, result); } } catch (Exception e) { info("Cannot set value for(" + key + "):" + result + "/" + e.getMessage()); } } } }
From source file:org.ms123.common.data.JdoLayerImpl.java
private void setDefaultValues(Class clazz, Object o) throws Exception { debug("----->setDefaultValues.clazz:" + clazz + "/" + o); Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { java.lang.annotation.Annotation[] anns = fields[i].getDeclaredAnnotations(); for (int j = 0; j < anns.length; j++) { try { Class atype = anns[j].annotationType(); if (!(anns[j] instanceof javax.jdo.annotations.Column)) { continue; }/*from w w w . jav a2s . co m*/ Method methDf = atype.getDeclaredMethod("defaultValue"); //Method methAn = atype.getDeclaredMethod("allowsNull");//@@@MS ???? String df = (String) methDf.invoke(anns[j], new Object[0]); //String al = (String) methAn.invoke(anns[j], new Object[0]); if (df != null && df.length() > 0) { Class type = TypeUtils.getTypeForField(o, fields[i].getName()); Object v = ConvertUtils.convert(df, type); debug("setDefaultValues:" + fields[i].getName() + ":" + v + "/" + type); PropertyUtils.setProperty(o, fields[i].getName(), v); } } catch (Exception e) { debug("setDefaultValues.e:" + e); } } } }
From source file:org.ms123.common.data.JdoLayerImpl.java
private void setState(Map<String, String> stateMap, Object objectUpdate) { String stateOld = stateMap.get("stateOld"); String stateNew = stateMap.get("stateNew"); try {//from ww w . ja v a 2 s . com if (m_permissionService.hasAdminRole() /*&& !isStateEqual(stateOld,stateNew)*/) { PropertyUtils.setProperty(objectUpdate, STATE_FIELD, stateNew); } else { PropertyUtils.setProperty(objectUpdate, STATE_FIELD, null); } } catch (Exception e) { debug("setState:" + e); } }
From source file:org.ms123.common.data.MultiOperations.java
private static void setStateToNew(Object object) { try {// w w w .j a v a 2 s . c om boolean hasState = PropertyUtils.isWriteable(object, STATE_FIELD); if (hasState) { PropertyUtils.setProperty(object, STATE_FIELD, null); } } catch (Exception e) { } }