Examples of UnmarshallException


Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        BeanData bd;
        try {
            bd = getBeanData(clazz);
        } catch (IntrospectionException e) {
            throw new UnmarshallException(clazz.getName() + " is not a bean", e);
        }

        int match = 0;
        int mismatch = 0;
        Iterator i = bd.writableProps.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry ent = (Map.Entry) i.next();
            String prop = (String) ent.getKey();
            if (jso.has(prop)) {
                match++;
            } else {
                mismatch++;
            }
        }
        if (match == 0) {
            throw new UnmarshallException("bean has no matches");
        }

        // create a concrete ObjectMatch that is always returned in order to satisfy circular reference requirements
        ObjectMatch returnValue = new ObjectMatch(-1);
        state.setSerialized(o, returnValue);

        ObjectMatch m = null;
        ObjectMatch tmp;
        i = jso.keys();
        while (i.hasNext()) {
            String field = (String) i.next();
            Method setMethod = (Method) bd.writableProps.get(field);
            if (setMethod != null) {
                try {
                    Class param[] = setMethod.getParameterTypes();
                    if (param.length != 1) {
                        throw new UnmarshallException("bean " + clazz.getName() + " method " + setMethod.getName() + " does not have one arg");
                    }
                    tmp = _ser.tryUnmarshall(state, param[0], jso.get(field));
                    if (tmp != null) {
                        if (m == null) {
                            m = tmp;
                        } else {
                            m = m.max(tmp);
                        }
                    }
                } catch (UnmarshallException e) {
                    throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage(), e);
                } catch (JSONException e) {
                    throw new UnmarshallException("bean " + clazz.getName() + " " + e.getMessage(), e);
                }
            } else {
                mismatch++;
            }
        }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        BeanData bd;
        try {
            bd = getBeanData(clazz);
        } catch (IntrospectionException e) {
            throw new UnmarshallException(clazz.getName() + " is not a bean", e);
        }
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "instantiating {0}", clazz.getName());
        }
        Object instance;
        try {
            instance = clazz.newInstance();
        } catch (InstantiationException e) {
            throw new UnmarshallException(
                    "could not instantiate bean of type "
                    + clazz.getName() + ", make sure it has a no argument "
                    + "constructor and that it is not an interface or "
                    + "abstract class", e);
        } catch (IllegalAccessException e) {
            throw new UnmarshallException(
                    "could not instantiate bean of type "
                    + clazz.getName(), e);
        } catch (RuntimeException e) {
            throw new UnmarshallException(
                    "could not instantiate bean of type "
                    + clazz.getName(), e);
        }
        state.setSerialized(o, instance);
        Object invokeArgs[] = new Object[1];
        Object fieldVal;
        Iterator i = jso.keys();
        while (i.hasNext()) {
            String field = (String) i.next();
            Method setMethod = (Method) bd.writableProps.get(field);
            if (setMethod != null) {
                try {
                    Class param[] = setMethod.getParameterTypes();
                    fieldVal = _ser.unmarshall(state, param[0], jso.get(field));
                } catch (UnmarshallException e) {
                    throw new UnmarshallException(
                            "could not unmarshall field \"" + field + "\" of bean "
                            + clazz.getName(), e);
                } catch (JSONException e) {
                    throw new UnmarshallException(
                            "could not unmarshall field \"" + field + "\" of bean "
                            + clazz.getName(), e);
                }
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, "invoking {0}({1})",
                            new Object[]{setMethod.getName(), fieldVal});
                }
                invokeArgs[0] = fieldVal;
                try {
                    setMethod.invoke(instance, invokeArgs);
                } catch (Throwable e) {
                    if (e instanceof InvocationTargetException) {
                        e = ((InvocationTargetException) e).getTargetException();
                    }
                    throw new UnmarshallException("bean " + clazz.getName() +
                            "can't invoke " + setMethod.getName() + ": " + e.getMessage(), e);
                }
            }
        }
        return instance;
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        try {
            //TODO: This should really check the return instead of just waiting for
            //an exception. If it returns null, it should fail!
            toPrimitive(clazz, jso);
        } catch (NumberFormatException e) {
            throw new UnmarshallException("not a primitive", e);
        }
        state.setSerialized(jso, ObjectMatch.OKAY);
        return ObjectMatch.OKAY;
    }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        try {
            Object primitive = toPrimitive(clazz, jso);
            state.setSerialized(jso, primitive);
            return primitive;
        } catch (NumberFormatException e) {
            throw new UnmarshallException("cannot convert object " + jso + " to type " + clazz.getName(), e);
        }
    }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        final String val = jso instanceof String ? (String) jso : jso.toString();
        if (clazz == Class.class) {
            try{
            returnValue = Class.forName(val);
            }catch(Exception ex){
                throw new UnmarshallException("Unable to unmarshal object", ex);
            }
        } else {
            returnValue = val;
        }
        state.setSerialized(jso, returnValue);
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        if (!this.isCompatible(java_class)) {
            throw new UnmarshallException("not a List");
        }
        JSONArray jsonlist;
        try {
            jsonlist = jso.getJSONArray("list");
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read list: " + e.getMessage(), e);
        }
        if (jsonlist == null) {
            throw new UnmarshallException("list missing");
        }
        int i = 0;
        ObjectMatch m = new ObjectMatch(-1);
        state.setSerialized(o, m);
        try {
            for (; i < jsonlist.length(); i++) {
                m.setMismatch(_ser.tryUnmarshall(state, null, jsonlist.get(i)).max(m).getMismatch());
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        }
        return m;
    }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        final AbstractList al = new LinkedList();

        JSONArray jsonlist;
        try {
            jsonlist = jso.getJSONArray("list");
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read list: " + e.getMessage(), e);
        }
        if (jsonlist == null) {
            throw new UnmarshallException("list missing");
        }
        state.setSerialized(o, al);
        int i = 0;
        try {
            for (; i < jsonlist.length(); i++) {
                al.add(_ser.unmarshall(state, null, jsonlist.get(i)));
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        }
        return al;
    }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        if (!(java_class.equals("java.util.Dictionary") || java_class.equals("java.util.Hashtable"))) {
            throw new UnmarshallException("not a Dictionary");
        }
        JSONObject jsonmap;
        try {
            jsonmap = jso.getJSONObject("map");
        } catch (JSONException e) {
            throw new UnmarshallException("map missing", e);
        }
        if (jsonmap == null) {
            throw new UnmarshallException("map missing");
        }
        ObjectMatch m = new ObjectMatch(-1);
        state.setSerialized(o, m);

        Iterator i = jsonmap.keys();
        String key = null;
        try {
            while (i.hasNext()) {
                key = (String) i.next();
                m.setMismatch(_ser.tryUnmarshall(state, null, jsonmap.get(key)).max(m).getMismatch());
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
        }

        return m;
    }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        Hashtable ht;
        if (java_class.equals("java.util.Dictionary") || java_class.equals("java.util.Hashtable")) {
            ht = new Hashtable();
        } else {
            throw new UnmarshallException("not a Dictionary");
        }
        JSONObject jsonmap;
        try {
            jsonmap = jso.getJSONObject("map");
        } catch (JSONException e) {
            throw new UnmarshallException("map missing", e);
        }
        if (jsonmap == null) {
            throw new UnmarshallException("map missing");
        }

        state.setSerialized(o, ht);

        Iterator i = jsonmap.keys();
        String key = null;
        try {
            while (i.hasNext()) {
                key = (String) i.next();
                ht.put(key, _ser.unmarshall(state, null, jsonmap.get(key)));
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
        }
        return ht;
    }
View Full Code Here

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        if (!(java_class.equals("java.util.Set") || java_class.equals("java.util.AbstractSet") || java_class.equals("java.util.LinkedHashSet") || java_class.equals("java.util.TreeSet") || java_class.equals("java.util.HashSet"))) {
            throw new UnmarshallException("not a Set");
        }
        JSONObject jsonset;
        try {
            jsonset = jso.getJSONObject("set");
        } catch (JSONException e) {
            throw new UnmarshallException("set missing", e);
        }

        if (jsonset == null) {
            throw new UnmarshallException("set missing");
        }

        ObjectMatch m = new ObjectMatch(-1);
        state.setSerialized(o, m);
        Iterator i = jsonset.keys();
        String key = null;

        try {
            while (i.hasNext()) {
                key = (String) i.next();
                m.setMismatch(_ser.tryUnmarshall(state, null, jsonset.get(key)).max(m).getMismatch());
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("key " + key + " " + e.getMessage(), e);
        }
        return m;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.