Package org.sf.bee.commons.logging

Examples of org.sf.bee.commons.logging.Logger


            final Object javascriptObject,
            final Object requestId,
            final JSONSerializerController serializer,
            final CallbackController cbc,
            final IExceptionTransformer exceptionTransformer) {
        final Logger logger = getLogger();
        JSONRPCResult result;
        // Call the method
        try {
            final boolean isConstructor = accessibleObject instanceof Constructor;

            if (logger.isLoggable(Level.FINE)) {
                if (!isConstructor) {
                    logger.log(Level.FINE, "invoking {0} {1}({2})",
                            new Object[]{
                                ((Method) accessibleObject).getReturnType().getName(),
                                ((Method) accessibleObject).getName(),
                                argSignature(accessibleObject)});
                } else {
                    logger.log(Level.FINE, "invoking {0}" + " " + "(" + "{1})",
                            new Object[]{
                                ((Constructor) accessibleObject).getName(),
                                argSignature(accessibleObject)});
                }
            }
View Full Code Here


     *         there is not a match.
     */
    public AccessibleObject resolveMethod(final Map methodMap,
            final String methodName, final JSONArray arguments,
            final JSONSerializerController serializer) {
        final Logger logger = getLogger();
        // first, match soley by the method name and number of arguments passed in
        // if there is a single match, return the single match
        // if there is no match at all, return null
        // if there are multiple matches, fall through to the second matching phase
        // below
        final AccessibleObjectKey methodKey = new AccessibleObjectKey(
                methodName,
                arguments.length());
        // of AccessibleObject
        final List accessibleObjects = (List) methodMap.get(methodKey);
        if (CollectionUtils.isEmpty(accessibleObjects)) {
            return null;
        } else if (accessibleObjects.size() == 1) {
            return (AccessibleObject) CollectionUtils.getFirst(accessibleObjects);
        } else {
            // second matching phase: there were overloaded methods on the object
            // we are invoking so try and find the best match based on the types of
            // the arguments passed in.

            // try and unmarshall the arguments against each candidate method
            // to determine which one matches the best

            final List<AccessibleObjectCandidate> candidates = new ArrayList<AccessibleObjectCandidate>();
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "looking for method {0}({1})",
                        new Object[]{methodName, argSignature(arguments)});
            }
            for (int i = 0; i < accessibleObjects.size(); i++) {
                AccessibleObject accessibleObject = (AccessibleObject) accessibleObjects.get(i);
                Class[] parameterTypes = null;
                if (accessibleObject instanceof Method) {
                    parameterTypes = ((Method) accessibleObject).getParameterTypes();
                } else if (accessibleObject instanceof Constructor) {
                    parameterTypes = ((Constructor) accessibleObject).getParameterTypes();
                }

                try {
                    final AccessibleObjectCandidate candidate = tryUnmarshallArgs(
                            accessibleObject, arguments,
                            parameterTypes, serializer);
                    if (null != candidate) {
                        candidates.add(candidate);
                        if (logger.isLoggable(Level.FINE)) {
                            logger.log(Level.FINE,
                                    "+++ possible match with method {0}({1})",
                                    new Object[]{methodName, argSignature(accessibleObject)});
                        }
                    }
                } catch (Exception e) {
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE,
                                "xxx {0} in {1}({2})",
                                new Object[]{e.getMessage(), methodName, argSignature(accessibleObject)});
                    }
                }
            }
            // now search through all the candidates and find one which matches
            // the json arguments the closest
            AccessibleObjectCandidate best = null;
            for (int i = 0; i < candidates.size(); i++) {
                AccessibleObjectCandidate c = (AccessibleObjectCandidate) candidates.get(i);
                if (best == null) {
                    best = c;
                    continue;
                }
                final ObjectMatch bestMatch = best.getMatch();
                final ObjectMatch cMatch = c.getMatch();
                if (bestMatch.getMismatch() > cMatch.getMismatch()) {
                    best = c;
                } else if (bestMatch.getMismatch() == cMatch.getMismatch()) {
                    best = betterSignature(best, c);
                }
            }
            if (best != null) {
                AccessibleObject ao = best.getAccessibleObject();
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, "found method {0}({1})",
                            new Object[]{methodName, argSignature(ao)});
                }
                return ao;
            }
        }
View Full Code Here

     *         the traversal.
     * @throws JSONException if something unexpected is found in the data
     */
    private static Object traverse(Object origin, JSONArray refs, boolean fixup)
            throws JSONException {
        final Logger logger = LoggingUtils.getLogger(JSONRPCBridge.class);
        try {
            JSONArray arr = null;
            JSONObject obj = null;
            if (origin instanceof JSONArray) {
                arr = (JSONArray) origin;
            } else {
                obj = (JSONObject) origin;
            }

            // where to stop when traversing
            int stop = refs.length();

            // if looking for the fixup, stop short by one to find the parent of the
            // fixup instead.
            // because the fixup won't exist yet and needs to be created
            if (fixup) {
                stop--;
            }

            // find the target object by traversing the list of references
            for (int i = 0; i < stop; i++) {
                Object next;
                if (arr == null) {
                    next = next(obj, refs.optString(i, null));
                } else {
                    next = next(arr, refs.optInt(i, -1));
                }
                if (next instanceof JSONObject) {
                    obj = (JSONObject) next;
                    arr = null;
                } else {
                    obj = null;
                    arr = (JSONArray) next;
                }
            }
            if (arr == null) {
                return obj;
            }
            return arr;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "unexpected exception", e);
            throw new JSONException("unexpected exception");
        }
    }
View Full Code Here

    public Object marshall(final SerializerState state,
            final Object p, Object o)
            throws MarshallException {
        final JSONObject val = new JSONObject();
        final Logger logger = getLogger();
        final Class oclass = super.getClassNoProxy(o);
        if (null != oclass && !super.isProxy(oclass)) {
            final BeanData bd;
            try {
                bd = BeanSerializer.getBeanData(oclass);
            } catch (IntrospectionException e) {
                throw new MarshallException(oclass.getName()
                        + " is not a bean", e);
            }

            if (_ser.getMarshallClassHints()) {
                try {
                    val.put(IJSONRPCConstants.TAG_JAVACLASS,
                            oclass.getName());
                } catch (Exception e) {
                    throw new MarshallException(
                            "JSONException: " + e.getMessage(), e);
                }
            }
            final Iterator i = bd.readableProps.entrySet().iterator();
            final Object args[] = new Object[0];
            Object result;
            while (i.hasNext()) {
                final Map.Entry ent = (Map.Entry) i.next();
                final String prop = (String) ent.getKey();
                final Method getMethod = (Method) ent.getValue();
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, "invoking {0}()", getMethod.getName());
                }
                try {
                    result = getMethod.invoke(o, args);
                } catch (Throwable e) {
                    if (e instanceof InvocationTargetException) {
View Full Code Here

        return returnValue;
    }

    public Object unmarshall(SerializerState state, Class clazz, Object o)
            throws UnmarshallException {
        final Logger logger = getLogger();
        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);
View Full Code Here

     * @throws IntrospectionException If a problem occurs during getting the bean
     *           info.
     */
    public static BeanData analyzeBean(final Class clazz)
            throws IntrospectionException {
        final Logger logger = LoggingUtils.getLogger(BeanSerializer.class);
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.INFO, "analyzing {0}", clazz.getName());
        }
        final BeanData bd = new BeanData();
        bd.beanInfo = Introspector.getBeanInfo(clazz, Object.class);
        final PropertyDescriptor props[] = bd.beanInfo.getPropertyDescriptors();
        bd.readableProps = new HashMap();
View Full Code Here

        return _serializableClasses;
    }

    public Object marshall(SerializerState state, Object p, Object o)
            throws MarshallException {
        final Logger logger = super.getLogger();
        Class clazz = o.getClass();
        Integer identity = new Integer(System.identityHashCode(o));
        if (bridge.isReference(clazz)) {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("marshalling reference to object " +
                        identity + " of class " + clazz.getName());
            }
            bridge.addReference(o);
            JSONObject jso = new JSONObject();
            try {
                jso.put("JSONRPCType", "Reference");
                jso.put(TAG_JAVACLASS, BeanUtils.getClassName(clazz));
                jso.put("objectID", identity);
            } catch (JSONException e) {
                throw new MarshallException(e.getMessage(), e);
            }
            return jso;
        } else if (bridge.isCallableReference(clazz)) {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("marshalling callable reference to object " +
                        identity + " of class " + clazz.getName());
            }
            bridge.registerObject(identity, o);
            bridge.addReference(o);
View Full Code Here

                "Created instance of Status Monitor.");
    }

    @Override
    public void execute() {
        final Logger logger = this.getLogger();
        try {
            final ResponseObject runtimeStatus = _monitor.getRuntimeStatus();
            final ResponseObject memory = _memory.getMemoryReport();
            final ResponseObject cpu = _cpu.getCpuReport();

            //-- retrieve report --//
            final String report = this.getReport(runtimeStatus,
                    0,
                    memory,
                    cpu);

            if (runtimeStatus.hasErrors()) {
                logger.log(Level.SEVERE,
                        null, runtimeStatus.getLastError());
            }
            if (memory.hasErrors()) {
                logger.log(Level.SEVERE,
                        null, memory.getLastError());
            }
            if (cpu.hasErrors()) {
                logger.log(Level.SEVERE,
                        null, cpu.getLastError());
            }

            logger.info(report.toString());
        } catch (Throwable t) {
            logger.log(Level.SEVERE,
                    "Status Monitor unhandled exception: " + t.getMessage(), t);
        }
    }
View Full Code Here

            }
            if (exists == null) {
                _services.put(name, service);
            }
        }
        final Logger logger = this.getLogger();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE,
                    "registered service {0} as {1}",
                    new Object[]{service.getName(), name});
        }
        return service;
    }
View Full Code Here

        synchronized (_services) {
            final String name = this.getName(endpoint, serviceName);
            final RESTfulService service = _services.get(name);
            if (service != null) {
                _services.remove(name);
                final Logger logger = this.getLogger();
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE,
                            "unregistered class {0} from {1}",
                            new Object[]{service.getName(), name});
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.sf.bee.commons.logging.Logger

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.