List of usage examples for org.apache.commons.collections BeanMap put
public Object put(Object name, Object value) throws IllegalArgumentException, ClassCastException
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 a2s . c om * @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// www .java2 s . c om * @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 w w w .ja va 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); } }
From source file:org.bpmscript.exec.java.JavaChannel.java
/** * Dependency Injection! Wires using a beanmap... */// w w w . j a v a2s .co m @SuppressWarnings("unchecked") protected void wireDefinition() { BeanMap map = new BeanMap(definition); IDefinitionConfiguration definitionConfiguration = scriptChannel .getDefinitionConfiguration(this.definitionName); Map<String, Object> properties = definitionConfiguration.getProperties(); map.putAll(properties); if (map.containsKey("log")) { map.put("log", log); } }
From source file:se.vgregion.portal.innovatinosslussen.domain.TypesBeanTest.java
void doGetterSetterValuesMatch(Object o) throws IllegalAccessException, InstantiationException { BeanMap bm = new BeanMap(o); final String javaLangPackageName = String.class.getPackage().getName(); for (Object key : bm.keySet()) { String name = (String) key; if ("ideaContentPrivate".equals(name) || "ideaPerson".equals(name) || "ideaContentPublic".equals(name)) { continue; }// w w w. ja v a 2 s .c o m if (bm.getWriteMethod(name) != null) { if (bm.getType(name).equals(String.class)) { bm.put(name, name); Assert.assertTrue(name == bm.get(name)); } else { Class clazz = bm.getType(name); if (!clazz.getName().startsWith(javaLangPackageName) && !clazz.isEnum()) { Object value = defaultPrim.get(clazz); if (value == null) { value = clazz.newInstance(); } bm.put(name, value); Assert.assertTrue("1, " + o.getClass() + "." + key, value.equals(bm.get(name))); Assert.assertTrue("2, " + o.getClass() + "." + key, value.hashCode() == bm.get(name).hashCode()); } } } } }
From source file:se.vgregion.service.barium.BariumRestClientIT.java
License:asdf
/** * After this 'test' go to Barium and check the data. Did this seem to be thread safe? * @throws BariumException// w w w .ja v a 2 s . c om */ @Ignore @Test public void toCreateConcurrent() throws BariumException { BariumRestClientImpl client = createBariumRestClient(); client.connect(); for (int i = 0; i < 3; i++) { IdeaObjectFields fields = new IdeaObjectFields(); BeanMap bm = new BeanMap(fields); for (Object key : bm.keySet()) { String name = (String) key; if (bm.getWriteMethod(name) != null && String.class.equals(bm.getType(name))) { bm.put(name, name + " " + i); } } fields.setInstanceName("instanceName (async) " + i + " " + System.currentTimeMillis()); createAsync(client, fields); } try { do { System.out.println("Delaying some to make the threads finish."); Thread.sleep(1000); } while (asyncCount != 0); System.exit(0); } catch (InterruptedException ie) { System.out.println("Child thread interrupted! " + ie); } }
From source file:se.vgregion.service.innovationsslussen.idea.IdeaServiceImplTest.java
private void initDefaultStringValues(Object o) { BeanMap bm = new BeanMap(o); for (Object key : bm.keySet()) { String name = (String) key; if (bm.getWriteMethod(name) != null) { if (bm.getType(name).equals(String.class)) { bm.put(name, name); }/* w ww. ja va 2 s.c o m*/ } } }
From source file:se.vgregion.service.innovationsslussen.ldap.LdapService.java
AttributesMapper newAttributesMapper(final Class type) { return new AttributesMapper() { @Override/*from ww w .j av a2s. com*/ public Object mapFromAttributes(Attributes attributes) throws NamingException { try { return mapFromAttributesImpl(attributes); } catch (Exception e) { throw new RuntimeException(e); } } public Object mapFromAttributesImpl(Attributes attributes) throws NamingException, IllegalAccessException, InstantiationException { Object result = type.newInstance(); BeanMap bm = new BeanMap(result); NamingEnumeration<? extends Attribute> all = attributes.getAll(); while (all.hasMore()) { Attribute attribute = all.next(); String name = toBeanPropertyName(attribute.getID()); if (bm.containsKey(name) && bm.getWriteMethod(name) != null) { bm.put(name, attribute.get()); } } return result; } }; }
From source file:se.vgregion.service.innovationsslussen.ldap.PersonTest.java
@Test public void beanStringPropertiesGetterSetters() { KivPerson person = new KivPerson(); BeanMap bm = new BeanMap(person); int i = 0;/* ww w . j a va 2 s. c o m*/ for (Object key : bm.keySet()) { String name = (String) key; if (bm.getWriteMethod(name) != null) { if (bm.getType(name).equals(String.class)) { String setterValue = "" + i++; bm.put(key, setterValue); String getterValue = (String) bm.get(key); Assert.assertEquals(setterValue, getterValue); } } } }