Package org.sf.bee.commons.remoting.jrpc.exceptions.impl

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


                }
            }
        } catch (JSONException e) {
            throw (NoSuchElementException) new NoSuchElementException(e.getMessage()).initCause(e);
        } catch (UnmarshallException e) {
            throw new UnmarshallException("arg " + (i + 1) + " " + e.getMessage(), e);
        }
        AccessibleObjectCandidate candidate = new AccessibleObjectCandidate(
                accessibleObject, parameterTypes, matches);

        return candidate;
View Full Code Here


                }
            }
        } catch (JSONException e) {
            throw (NoSuchElementException) new NoSuchElementException(e.getMessage()).initCause(e);
        } catch (UnmarshallException e) {
            throw new UnmarshallException("arg " + (i + 1) + " could not unmarshall", e);
        }

        return javaArgs;
    }
View Full Code Here

     * @param target target serialized representation of the object that the source object is being unmarshalled to.
     * @throws UnmarshallException if the source object is null, or is not already stored within a ProcessedObject.
     */
    public void setSerialized(Object source, Object target) throws UnmarshallException {
        if (source == null) {
            throw new UnmarshallException("source object may not be null");
        }
        ProcessedObject p = getProcessedObject(source);
        if (p == null) {
            // this should normally never happen- it's a sanity check.
            throw new UnmarshallException("source object must be already registered as a ProcessedObject " + source);
        }
        p.setSerialized(target);
    }
View Full Code Here

        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

        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

        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

        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

        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

        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

        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

TOP

Related Classes of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

Copyright © 2018 www.massapicom. 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.