List of usage examples for org.apache.commons.collections BeanMap BeanMap
public BeanMap(Object bean)
BeanMap
that operates on the specified bean. From source file:org.red5.io.amf3.Output.java
/** {@inheritDoc} */ public void writeObject(Object object, Serializer serializer) { writeAMF3();/*ww w . j a v a2 s. c om*/ 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:org.red5.server.io.test.AbstractIOTest.java
public void testJavaBean() { log.debug("Testing list"); TestJavaBean beanIn = new TestJavaBean(); beanIn.setTestString("test string here"); beanIn.setTestBoolean((System.currentTimeMillis() % 2 == 0) ? true : false); beanIn.setTestBooleanObject((System.currentTimeMillis() % 2 == 0) ? Boolean.TRUE : Boolean.FALSE); beanIn.setTestNumberObject(Integer.valueOf((int) System.currentTimeMillis() / 1000)); serializer.serialize(out, beanIn);//from w w w . j av a2 s.c o m dumpOutput(); Object mapOrBean = deserializer.deserialize(in); Assert.assertEquals(beanIn.getClass().getName(), mapOrBean.getClass().getName()); Map map = (mapOrBean instanceof Map) ? (Map) mapOrBean : new BeanMap(mapOrBean); Set entrySet = map.entrySet(); Iterator it = entrySet.iterator(); Map beanInMap = new BeanMap(beanIn); Assert.assertEquals(beanInMap.size(), map.size()); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String propOut = (String) entry.getKey(); Object valueOut = entry.getValue(); Assert.assertTrue(beanInMap.containsKey(propOut)); Assert.assertEquals(valueOut, beanInMap.get(propOut)); } resetOutput(); }
From source file:org.red5.server.net.rtmp.status.StatusObjectService.java
/** * Serializes status object/* w w w. j av a2 s . c o m*/ * @param out Byte buffer for output object * @param statusObject Status object to serialize */ public void serializeStatusObject(ByteBuffer out, StatusObject statusObject) { Map statusMap = new BeanMap(statusObject); Output output = new Output(out); serializer.serialize(output, statusMap); }
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; }/* ww w. j av a2 s .c om*/ 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.BariumRestClientImpl.java
/** * To url./*from ww w .j a va 2 s .c o m*/ * * @param ideaObjectFields the idea object fields * @return the string */ String toUrl(IdeaObjectFields ideaObjectFields) { StringBuilder sb = new StringBuilder(); sb.append("message=START"); sb.append("&template=565d4c81-4baa-451b-aacc-5f7ae295bfaf"); BeanMap bm = new BeanMap(ideaObjectFields); for (Object entryObj : bm.entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryObj; if ("class".equals(entry.getKey())) { continue; } Object value = entry.getValue(); if (value != null) { String name = IdeaObjectFields.SPECIAL_FIELD_MAPPINGS_REVERSE.get(entry.getKey()); if (name == null) { name = entry.getKey(); } sb.append("&"); sb.append(name); sb.append("="); try { value = URLEncoder.encode(value + "", "utf-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } sb.append(value); } } return sb.toString(); }
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/*from ww w. j av a 2s .com*/ */ @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.IdeaServiceImpl.java
boolean same(Object i1, Object i2) { if (i1 == i2) { return true; }//from www . ja v a 2 s .co m if (i1 == null || i2 == null) { return false; } Map bm1 = new HashMap(new BeanMap(i1)); Map bm2 = new HashMap(new BeanMap(i2)); if (!bm1.equals(bm2)) { return false; } return true; }
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);// ww w .j ava 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 a v a 2 s .c o m 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.LdapService.java
AndFilter toAndCondition(Object obj) { AndFilter filter = new AndFilter(); BeanMap bm = new BeanMap(obj); Class type = obj.getClass();//ww w . java 2 s. co m for (Object entryObj : bm.entrySet()) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryObj; String property = entry.getKey(); if (bm.getWriteMethod(property) != null) { Object value = entry.getValue(); if (value != null && !"".equals(value.toString().trim())) { String ldapPropertyName = getPlainNameOrExplicit(type, property); filter.and(newAttributeFilter(ldapPropertyName, value.toString())); } } } return filter; }