List of usage examples for org.apache.commons.collections BeanMap keyIterator
public Iterator keyIterator()
From source file:com.krawler.workflow.module.dao.DataObjectOperationDAOImpl.java
@Override public boolean updateDataObject(Object dataObject, String keyName) { boolean result = true; try {/* w w w . j a va 2 s . c o m*/ StringBuilder query = new StringBuilder( "UPDATE " + getTableName(dataObject.getClass().getSimpleName()) + " SET "); BeanMap bm = new BeanMap(dataObject); ArrayList arr = new ArrayList(); Iterator itr = bm.keyIterator(); while (itr.hasNext()) { String key = (String) itr.next(); if (key.equals(keyName) || "class".equals(key)) continue; query.append(key).append("=?"); arr.add(bm.get(key)); if (itr.hasNext()) query.append(","); } query.append(" WHERE ").append(keyName).append(" = ?"); arr.add(bm.get(keyName)); getJdbcTemplate().update(query.toString(), arr.toArray()); } catch (Exception e) { LOG.warn("Can not update record", e); result = false; } return result; }
From source file:nl.nn.adapterframework.jms.JmsRealm.java
/** * copies matching properties to any other class *//*from w w w .j a v a 2 s.c om*/ public void copyRealm(Object destination) { String logPrefixDest = destination.getClass().getName() + " "; if (destination instanceof INamedObject) { INamedObject namedDestination = (INamedObject) destination; logPrefixDest += "[" + namedDestination.getName() + "] "; } try { BeanMap thisBeanMap = new BeanMap(this); BeanMap destinationBeanMap = new BeanMap(destination); Iterator<String> iterator = thisBeanMap.keyIterator(); while (iterator.hasNext()) { String key = iterator.next(); Object value = thisBeanMap.get(key); if (value != null && !key.equals("class") && destinationBeanMap.containsKey(key)) { PropertyUtils.setProperty(destination, key, value); } } } catch (Exception e) { log.error(logPrefixDest + "unable to copy properties of JmsRealm", e); } log.info(logPrefixDest + "loaded properties from jmsRealm [" + toString() + "]"); }
From source file:org.apache.jackrabbit.core.config.BeanConfig.java
/** * Creates a new instance of the configured bean class. * * @return new bean instance/* w w w .ja v a 2 s . com*/ * @throws ConfigurationException on bean configuration errors */ public Object newInstance() throws ConfigurationException { try { Class objectClass = Class.forName(getClassName(), true, getClassLoader()); Object object = objectClass.newInstance(); BeanMap map = new BeanMap(object); Iterator iterator = map.keyIterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); String value = properties.getProperty(name); if (value != null) { map.put(name, properties.getProperty(name)); } } Iterator it = properties.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); if (map.get(key) == null && properties.getProperty(key) != null) { log.warn(object.getClass().getName() + " does not support '" + key + "'; the setting is ignored."); } } return object; } catch (ClassNotFoundException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " was not found.", e); } catch (InstantiationException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " can not be instantiated.", e); } catch (IllegalAccessException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " is protected.", e); } }
From source file:org.apache.jackrabbit.core.config.BeanConfig.java
/** * Creates a new instance of the configured bean class. * * @return new bean instance/* w w w . j a va 2 s . c o m*/ * @throws ConfigurationException on bean configuration errors */ public Object newInstance() throws ConfigurationException { try { Class objectClass = Class.forName(getClassName(), true, getClassLoader()); Object object = objectClass.newInstance(); BeanMap map = new BeanMap(object); Iterator iterator = map.keyIterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); String value = properties.getProperty(name); if (value != null) { map.put(name, properties.getProperty(name)); } } return object; } catch (ClassNotFoundException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " was not found.", e); } catch (InstantiationException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " can not be instantiated.", e); } catch (IllegalAccessException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " is protected.", e); } }
From source file:org.apache.jackrabbit.core.config.BeanConfig.java
/** * Creates a new instance of the configured bean class. * * @return new bean instance//from ww w .ja v a 2 s. c om * @throws ConfigurationException on bean configuration errors */ public Object newInstance() throws ConfigurationException { try { // Instantiate the object using the default constructor Class objectClass = Class.forName(getClassName(), true, getClassLoader()); Object object = objectClass.newInstance(); // Set all configured bean properties BeanMap map = new BeanMap(object); Iterator iterator = map.keyIterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); String value = properties.getProperty(name); if (value != null) { map.put(name, properties.getProperty(name)); } } if (validate) { // Check that no invalid property names were configured Iterator it = properties.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); if (!map.containsKey(key) && properties.getProperty(key) != null) { String msg = "Configured class " + object.getClass().getName() + " does not contain the property " + key + ". Please fix the repository configuration."; log.error(msg); throw new ConfigurationException(msg); } } } return object; } catch (ClassNotFoundException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " was not found.", e); } catch (InstantiationException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " can not be instantiated.", e); } catch (IllegalAccessException e) { throw new ConfigurationException( "Configured bean implementation class " + getClassName() + " is protected.", e); } }