Java Code Examples for org.apache.commons.beanutils.PropertyUtils#setSimpleProperty()
The following examples show how to use
org.apache.commons.beanutils.PropertyUtils#setSimpleProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailingServiceImpl.java From openemm with GNU Affero General Public License v3.0 | 6 votes |
private <T> T cloneBean(T dest, T orig) throws IllegalAccessException, InvocationTargetException { PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(orig); for (PropertyDescriptor descriptor : origDescriptors) { String name = descriptor.getName(); if (PropertyUtils.isReadable(orig, name) && PropertyUtils.isWriteable(dest, name)) { try { Object value = PropertyUtils.getSimpleProperty(orig, name); if (!(value instanceof Collection<?>) && !(value instanceof Map<?, ?>)) { PropertyUtils.setSimpleProperty(dest, name, value); } } catch (NoSuchMethodException e) { logger.debug("Error writing to '" + name + "' on class '" + dest.getClass() + "'", e); } } } return dest; }
Example 2
Source File: ExcelWorkSheetHandler.java From excelReader with MIT License | 6 votes |
private void assignValue(Object targetObj, String cellReference, String value) { if (null == targetObj || StringUtils.isEmpty(cellReference) || StringUtils.isEmpty(value)) { return; } try { String propertyName = this.cellMapping.get(cellReference); if (null == propertyName) { LOG.error("Cell mapping doesn't exists!"); } else { PropertyUtils.setSimpleProperty(targetObj, propertyName, value); } } catch (IllegalAccessException iae) { LOG.error(iae.getMessage()); } catch (InvocationTargetException ite) { LOG.error(ite.getMessage()); } catch (NoSuchMethodException nsme) { LOG.error(nsme.getMessage()); } }
Example 3
Source File: PermissionLevelManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Populates the permission level data for the case when the default permission levels * are being created, not the custom levels * @param name * @param typeUuid * @param mask * @return */ private PermissionLevel createDefaultPermissionLevel(String name, String typeUuid, PermissionsMask mask) { if (log.isDebugEnabled()){ log.debug("createDefaultPermissionLevel executing(" + name + "," + typeUuid + "," + mask + ")"); } if (name == null || typeUuid == null || mask == null) { throw new IllegalArgumentException("Null Argument"); } PermissionLevel newPermissionLevel = new PermissionLevelImpl(); Date now = new Date(); newPermissionLevel.setName(name); newPermissionLevel.setUuid(idManager.createUuid()); newPermissionLevel.setCreated(now); newPermissionLevel.setCreatedBy("admin"); newPermissionLevel.setModified(now); newPermissionLevel.setModifiedBy("admin"); newPermissionLevel.setTypeUuid(typeUuid); // set permission properties using reflection for (Iterator<Entry<String, Boolean>> i = mask.entrySet().iterator(); i.hasNext();){ Entry<String, Boolean> entry = i.next(); String key = entry.getKey(); Boolean value = entry.getValue(); try{ PropertyUtils.setSimpleProperty(newPermissionLevel, key, value); } catch (Exception e){ throw new RuntimeException(e); } } return newPermissionLevel; }
Example 4
Source File: PermissionLevelManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public PermissionLevel createPermissionLevel(String name, String typeUuid, PermissionsMask mask){ if (log.isDebugEnabled()){ log.debug("createPermissionLevel executing(" + name + "," + typeUuid + "," + mask + ")"); } if (name == null || typeUuid == null || mask == null) { throw new IllegalArgumentException("Null Argument"); } PermissionLevel newPermissionLevel = new PermissionLevelImpl(); Date now = new Date(); String currentUser = getCurrentUser(); newPermissionLevel.setName(name); newPermissionLevel.setUuid(idManager.createUuid()); newPermissionLevel.setCreated(now); newPermissionLevel.setCreatedBy(currentUser); newPermissionLevel.setModified(now); newPermissionLevel.setModifiedBy(currentUser); newPermissionLevel.setTypeUuid(typeUuid); // set permission properties using reflection for (Iterator<Entry<String, Boolean>> i = mask.entrySet().iterator(); i.hasNext();){ Entry<String, Boolean> entry = i.next(); String key = entry.getKey(); Boolean value = entry.getValue(); try{ PropertyUtils.setSimpleProperty(newPermissionLevel, key, value); } catch (Exception e){ throw new RuntimeException(e); } } return newPermissionLevel; }
Example 5
Source File: FiscalYearMakerImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Determines if an extension record is mapped up and exists for the current record. If so then updates the version number, * object id, and clears the primary keys so they will be relinked when storing the main record * * @param newFiscalYear fiscal year to set * @param currentRecord main record with possible extension reference */ protected void updateExtensionRecord(Integer newFiscalYear, PersistableBusinessObject currentRecord) throws Exception { // check if reference is mapped up if ( !hasExtension() ) { return; } // try to retrieve extension record currentRecord.refreshReferenceObject(KFSPropertyConstants.EXTENSION); PersistableBusinessObject extension = currentRecord.getExtension(); // if found then update fields if (ObjectUtils.isNotNull(extension)) { extension = (PersistableBusinessObject)ProxyHelper.getRealObject(extension); extension.setVersionNumber(ONE); extension.setObjectId(java.util.UUID.randomUUID().toString()); // since this could be a new object (no extension object present on the source record) // we need to set the keys // But...we only need to do this if this was a truly new object, which we can tell by checking // the fiscal year field if ( ((FiscalYearBasedBusinessObject)extension).getUniversityFiscalYear() == null ) { for ( String pkField : getPrimaryKeyPropertyNames() ) { PropertyUtils.setSimpleProperty(extension, pkField, PropertyUtils.getSimpleProperty(currentRecord, pkField)); } } ((FiscalYearBasedBusinessObject)extension).setUniversityFiscalYear(newFiscalYear); } }
Example 6
Source File: PermissionLevelManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Populates the permission level data for the case when the default permission levels * are being created, not the custom levels * @param name * @param typeUuid * @param mask * @return */ private PermissionLevel createDefaultPermissionLevel(String name, String typeUuid, PermissionsMask mask) { if (log.isDebugEnabled()){ log.debug("createDefaultPermissionLevel executing(" + name + "," + typeUuid + "," + mask + ")"); } if (name == null || typeUuid == null || mask == null) { throw new IllegalArgumentException("Null Argument"); } PermissionLevel newPermissionLevel = new PermissionLevelImpl(); Date now = new Date(); newPermissionLevel.setName(name); newPermissionLevel.setUuid(idManager.createUuid()); newPermissionLevel.setCreated(now); newPermissionLevel.setCreatedBy("admin"); newPermissionLevel.setModified(now); newPermissionLevel.setModifiedBy("admin"); newPermissionLevel.setTypeUuid(typeUuid); // set permission properties using reflection for (Iterator<Entry<String, Boolean>> i = mask.entrySet().iterator(); i.hasNext();){ Entry<String, Boolean> entry = i.next(); String key = entry.getKey(); Boolean value = entry.getValue(); try{ PropertyUtils.setSimpleProperty(newPermissionLevel, key, value); } catch (Exception e){ throw new RuntimeException(e); } } return newPermissionLevel; }
Example 7
Source File: PermissionLevelManagerImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public PermissionLevel createPermissionLevel(String name, String typeUuid, PermissionsMask mask){ if (log.isDebugEnabled()){ log.debug("createPermissionLevel executing(" + name + "," + typeUuid + "," + mask + ")"); } if (name == null || typeUuid == null || mask == null) { throw new IllegalArgumentException("Null Argument"); } PermissionLevel newPermissionLevel = new PermissionLevelImpl(); Date now = new Date(); String currentUser = getCurrentUser(); newPermissionLevel.setName(name); newPermissionLevel.setUuid(idManager.createUuid()); newPermissionLevel.setCreated(now); newPermissionLevel.setCreatedBy(currentUser); newPermissionLevel.setModified(now); newPermissionLevel.setModifiedBy(currentUser); newPermissionLevel.setTypeUuid(typeUuid); // set permission properties using reflection for (Iterator<Entry<String, Boolean>> i = mask.entrySet().iterator(); i.hasNext();){ Entry<String, Boolean> entry = i.next(); String key = entry.getKey(); Boolean value = entry.getValue(); try{ PropertyUtils.setSimpleProperty(newPermissionLevel, key, value); } catch (Exception e){ throw new RuntimeException(e); } } return newPermissionLevel; }
Example 8
Source File: AnnotationAndNameMatchingTransactionAttributeSource.java From rice with Educational Community License v2.0 | 5 votes |
/** * If the TransactionAttribute has a setTimeout() method, then this method will invoke it and pass the configured * transaction timeout. This is to allow for proper setting of the transaction timeout on a JTA transaction. */ protected void setTimeout(TransactionAttribute transactionAttribute) { try { if (transactionTimeout != null) { PropertyUtils.setSimpleProperty(transactionAttribute, "timeout", new Integer(transactionTimeout)); } } catch (Exception e) { // failed to set the timeout } }
Example 9
Source File: FHIRProxyXADataSource.java From FHIR with Apache License 2.0 | 4 votes |
/** * This function will use reflection to set each of the properties found in "connectionProps" on the specified * datasource instance using the appropriate setter methods. * * @param datasource * the datasource instance to set the properties on * @param connectionProps * a PropertyGroup containing the properties to be set on the datasource */ private static void setConnectionProperties(XADataSource datasource, PropertyGroup connectionProps) throws Exception { // Configure the datasource according to the connection properties. // We'll do this by visiting each of the individual properties found in the // "connectionProperties" property group, and set each one on the datasource. if (log.isLoggable(Level.FINER)) { log.finer("Setting connection properties on '" + datasource.getClass().getName() + "' instance."); } for (PropertyEntry property : connectionProps.getProperties()) { String propertyName = property.getName(); Object propertyValue = property.getValue(); if (log.isLoggable(Level.FINER)) { String value = (propertyName.toLowerCase().contains("password") ? "********" : propertyValue.toString()); log.finer("Found property '" + propertyName + "' = '" + value + "'."); } try { if ("securityMechanism".equals(propertyName)) { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(datasource, propertyName); if (pd != null) { // OK, let's try this way short securityMechanismValue = (short)(int)propertyValue; log.info("Setting security mechanism: " + securityMechanismValue); Method setSecurityMechanism = PropertyUtils.getWriteMethod(pd); setSecurityMechanism.invoke(datasource, securityMechanismValue); } else { throw new IllegalStateException(propertyName + " not supported on datasource class: " + datasource.getClass().getName()); } } else { // Standard property PropertyUtils.setSimpleProperty(datasource, propertyName, propertyValue); } } catch (Throwable t) { String msg = "Error setting property '" + propertyName + "' on instance of class '" + datasource.getClass().getName() + "."; log.log(Level.SEVERE, msg, t); throw new IllegalStateException(msg, t); } } }
Example 10
Source File: JPAPlugin.java From restcommander with Apache License 2.0 | 4 votes |
private Object makeCompositeKey(Model model) throws Exception { initProperties(); Class<?> idClass = getCompositeKeyClass(); Object id = idClass.newInstance(); PropertyDescriptor[] idProperties = PropertyUtils.getPropertyDescriptors(idClass); if(idProperties == null || idProperties.length == 0) throw new UnexpectedException("Composite id has no properties: "+idClass.getName()); for (PropertyDescriptor idProperty : idProperties) { // do we have a field for this? String idPropertyName = idProperty.getName(); // skip the "class" property... if(idPropertyName.equals("class")) continue; Model.Property modelProperty = this.properties.get(idPropertyName); if(modelProperty == null) throw new UnexpectedException("Composite id property missing: "+clazz.getName()+"."+idPropertyName +" (defined in IdClass "+idClass.getName()+")"); // sanity check Object value = modelProperty.field.get(model); if(modelProperty.isMultiple) throw new UnexpectedException("Composite id property cannot be multiple: "+clazz.getName()+"."+idPropertyName); // now is this property a relation? if yes then we must use its ID in the key (as per specs) if(modelProperty.isRelation){ // get its id if(!Model.class.isAssignableFrom(modelProperty.type)) throw new UnexpectedException("Composite id property entity has to be a subclass of Model: " +clazz.getName()+"."+idPropertyName); // we already checked that cast above @SuppressWarnings("unchecked") Model.Factory factory = Model.Manager.factoryFor((Class<? extends Model>) modelProperty.type); if(factory == null) throw new UnexpectedException("Failed to find factory for Composite id property entity: " +clazz.getName()+"."+idPropertyName); // we already checked that cast above if(value != null) value = factory.keyValue((Model) value); } // now affect the composite id with this id PropertyUtils.setSimpleProperty(id, idPropertyName, value); } return id; }
Example 11
Source File: CourseService.java From tutorials with MIT License | 4 votes |
public static void setValues(Course course, String name, List<String> codes) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { // Setting the simple properties PropertyUtils.setSimpleProperty(course, "name", name); PropertyUtils.setSimpleProperty(course, "codes", codes); }