List of usage examples for org.apache.commons.collections BeanMap containsKey
public boolean containsKey(Object name)
From source file:nl.nn.adapterframework.jms.JmsRealm.java
/** * copies matching properties to any other class *///from w ww . jav a 2 s .c o m 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. j av a2 s. com*/ * @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... *//*from w w w .j a v a 2s . c o 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:org.red5.io.amf.Output.java
/** {@inheritDoc} */ public void writeObject(Object object, Serializer serializer) { if (checkWriteReference(object)) return;//from www. ja v a2s . c o m storeReference(object); // Create new map out of bean properties BeanMap beanMap = new BeanMap(object); // Set of bean attributes Set<BeanMap.Entry<?, ?>> set = beanMap.entrySet(); if ((set.size() == 0) || (set.size() == 1 && beanMap.containsKey("class"))) { // BeanMap is empty or can only access "class" attribute, skip it writeArbitraryObject(object, serializer); return; } // Write out either start of object marker for class name or "empty" start of object marker Class<?> objectClass = object.getClass(); if (!objectClass.isAnnotationPresent(Anonymous.class)) { buf.put(AMF.TYPE_CLASS_OBJECT); putString(buf, objectClass.getName()); } else { buf.put(AMF.TYPE_OBJECT); } if (object instanceof ICustomSerializable) { ((ICustomSerializable) object).serialize(this, serializer); buf.put((byte) 0x00); buf.put((byte) 0x00); buf.put(AMF.TYPE_END_OF_OBJECT); return; } // Iterate thru entries and write out property names with separators for (BeanMap.Entry<?, ?> entry : set) { if (entry.getKey().toString().equals("class")) { continue; } String keyName = entry.getKey().toString(); // Check if the Field corresponding to the getter/setter pair is transient if (dontSerializeField(objectClass, keyName)) continue; putString(buf, keyName); serializer.serialize(this, entry.getValue()); } // Write out end of object mark buf.put((byte) 0x00); buf.put((byte) 0x00); buf.put(AMF.TYPE_END_OF_OBJECT); }
From source file:org.red5.io.amf3.Output.java
/** {@inheritDoc} */ public void writeObject(Object object, Serializer serializer) { writeAMF3();/*from w ww . ja v a 2 s .com*/ buf.put(AMF3.TYPE_OBJECT); if (hasReference(object)) { putInteger(getReferenceId(object) << 1); return; } storeReference(object); String className = object.getClass().getName(); if (className.startsWith("org.red5.compatibility.")) { // Strip compatibility prefix from classname className = className.substring(23); } if (object instanceof IExternalizable) { // The object knows how to serialize itself. int type = 1 << 1 | 1; if (object instanceof ObjectProxy) { type |= AMF3.TYPE_OBJECT_PROXY << 2; } else { type |= AMF3.TYPE_OBJECT_EXTERNALIZABLE << 2; } putInteger(type); putString(className); amf3_mode += 1; ((IExternalizable) object).writeExternal(new DataOutput(this, serializer)); amf3_mode -= 1; return; } // We have an inline class that is not a reference. // We store the properties using key/value pairs int type = AMF3.TYPE_OBJECT_VALUE << 2 | 1 << 1 | 1; putInteger(type); // Create new map out of bean properties BeanMap beanMap = new BeanMap(object); // Set of bean attributes Set<BeanMap.Entry<?, ?>> set = beanMap.entrySet(); if ((set.size() == 0) || (set.size() == 1 && beanMap.containsKey("class"))) { // BeanMap is empty or can only access "class" attribute, skip it writeArbitraryObject(object, serializer); return; } // Write out either start of object marker for class name or "empty" start of object marker Class<?> objectClass = object.getClass(); if (!objectClass.isAnnotationPresent(Anonymous.class)) { // classname putString(className); } else { putString(""); } // Store key/value pairs amf3_mode += 1; for (BeanMap.Entry<?, ?> entry : set) { String keyName = entry.getKey().toString(); if ("class".equals(keyName)) { continue; } // Check if the Field corresponding to the getter/setter pair is transient if (dontSerializeField(objectClass, keyName)) continue; putString(keyName); serializer.serialize(this, entry.getValue()); } amf3_mode -= 1; // End of object marker putString(""); }
From source file:se.vgregion.service.innovationsslussen.ldap.LdapService.java
AttributesMapper newAttributesMapper(final Class type) { return new AttributesMapper() { @Override/*from w ww . j a v a2s. c om*/ 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; } }; }