From 78289e848b499635ad67493737f70b8298476399 Mon Sep 17 00:00:00 2001 From: Matt Tucker Date: Mon, 25 Aug 2003 20:03:53 +0000 Subject: [PATCH] Yanked code for doing parsing of Javabeans since it's not really supported anyway. git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2068 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/PrivateDataManager.java | 73 +------------------ 1 file changed, 2 insertions(+), 71 deletions(-) diff --git a/source/org/jivesoftware/smackx/PrivateDataManager.java b/source/org/jivesoftware/smackx/PrivateDataManager.java index 64bd4e054..15fa84fc3 100644 --- a/source/org/jivesoftware/smackx/PrivateDataManager.java +++ b/source/org/jivesoftware/smackx/PrivateDataManager.java @@ -60,7 +60,6 @@ import org.jivesoftware.smackx.packet.*; import org.jivesoftware.smackx.provider.*; import org.xmlpull.v1.XmlPullParser; -import java.beans.PropertyDescriptor; import java.util.Map; import java.util.Hashtable; @@ -296,17 +295,10 @@ public class PrivateDataManager { String elementName = parser.getName(); String namespace = parser.getNamespace(); // See if any objects are registered to handle this private data type. - Object provider = getPrivateDataProvider(elementName, namespace); + PrivateDataProvider provider = getPrivateDataProvider(elementName, namespace); // If there is a registered provider, use it. if (provider != null) { - if (provider instanceof PrivateDataProvider) { - privateData = ((PrivateDataProvider)provider).parsePrivateData(parser); - } - // Otherwise it's a JavaBean, so use introspection. - else { - privateData = parseWithIntrospection(elementName, (Class)provider, - parser); - } + privateData = provider.parsePrivateData(parser); } // Otherwise, use a DefaultPrivateData instance to store the private data. else { @@ -349,67 +341,6 @@ public class PrivateDataManager { } } - private static PrivateData parseWithIntrospection(String elementName, Class objectClass, - XmlPullParser parser) throws Exception - { - boolean done = false; - PrivateData object = (PrivateData)objectClass.newInstance(); - while (!done) { - int eventType = parser.next(); - if (eventType == XmlPullParser.START_TAG) { - String name = parser.getName(); - String stringValue = parser.nextText(); - PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass); - // Load the class type of the property. - Class propertyType = descriptor.getPropertyType(); - // Get the value of the property by converting it from a - // String to the correct object type. - Object value = decode(propertyType, stringValue); - // Set the value of the bean. - descriptor.getWriteMethod().invoke(object, new Object[] { value }); - } - else if (eventType == XmlPullParser.END_TAG) { - if (parser.getName().equals(elementName)) { - done = true; - } - } - } - return object; - } - - /** - * Decodes a String into an object of the specified type. If the object - * type is not supported, null will be returned. - * - * @param type the type of the property. - * @param value the encode String value to decode. - * @return the String value decoded into the specified type. - */ - private static Object decode(Class type, String value) throws Exception { - if (type.getName().equals("java.lang.String")) { - return value; - } - if (type.getName().equals("boolean")) { - return Boolean.valueOf(value); - } - if (type.getName().equals("int")) { - return Integer.valueOf(value); - } - if (type.getName().equals("long")) { - return Long.valueOf(value); - } - if (type.getName().equals("float")) { - return Float.valueOf(value); - } - if (type.getName().equals("double")) { - return Double.valueOf(value); - } - if (type.getName().equals("java.lang.Class")) { - return Class.forName(value); - } - return null; - } - /** * An IQ packet to hold PrivateData GET results. */