Package org.sf.bee.commons.logging

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


     *
     * @throws MarshallException if there is a problem marshalling java to json.
     */
    public Object marshall(SerializerState state, Object parent, Object java, Object ref)
            throws MarshallException {
        final Logger logger = this.getLogger();
        if (java == null) {
            if (logger.isLoggable(Level.FINE)) {
                logger.fine("marshall null");
            }
            return JSONObject.NULL;
        }

        // check for duplicate objects or circular references
        ProcessedObject p = state.getProcessedObject(java);

        // if this object hasn't been seen before, mark it as seen and continue forth
        if (p == null) {
            state.push(parent, java, ref);
        } else {
            //todo: make test cases to explicitly handle all 4 combinations of the 2 option
            //todo: settings (both on the client and server)

            // handle throwing of circular reference exception and/or serializing duplicates, depending
            // on the options set in the serializer!
            boolean foundCircRef = state.isAncestor(p, parent);

            // throw an exception if a circular reference found, and the
            // serializer option is not set to fixup these circular references
            if (!_fixupCircRefs && foundCircRef) {
                throw new MarshallException("Circular Reference");
            }

            // if its a duplicate only, and we aren't fixing up duplicates or if
            // it is a primitive, and fixing up of primitives is not allowed then
            // re-serialize the object into the json.
            if (!foundCircRef
                    && (!_fixupDuplicates || (!_fixupDuplicatePrimitives && isPrimitive(java)))) {
                //todo: if a duplicate is being reserialized... it will overwrite the original location of the
                //todo: first one found... need to think about the ramifications of this -- optimally, circ refs found
                //todo: underneath duplicates need to point to the "original" one found, but they also need to be fixed
                //todo: up to the correct location, of course.
                state.push(parent, java, ref);
            } else {
                // generate a fix up entry for the duplicate/circular reference
                state.addFixUp(p.getLocation(), ref);
                return CIRC_REF_OR_DUPLICATE;
            }
        }

        try {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE,
                        "marshall class {0}",
                        java.getClass().getName());
            }
            final ISerializer s = this.getSerializer(java.getClass(), null);
            if (s != null) {
View Full Code Here


     *          from AbstractSerializer).
     *
     * @throws Exception If a serialiser has already been registered for a class.
     */
    public void registerSerializer(final ISerializer s) throws Exception {
        final Logger logger = this.getLogger();
        Class classes[] = s.getSerializableClasses();
        ISerializer exists;
        synchronized (_serializerSet) {
            if (_serializableMap == null) {
                _serializableMap = new HashMap<Class, ISerializer>();
            }
            for (int i = 0; i < classes.length; i++) {
                exists = _serializableMap.get(classes[i]);
                if (exists != null && exists.getClass() != s.getClass()) {
                    throw new Exception("different serializer already registered for " + classes[i].getName());
                }
            }
            if (!_serializerSet.contains(s)) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE,
                            "registered serializer {0}",
                            s.getClass().getName());
                }
                s.setOwner(this);
                _serializerSet.add(s);
View Full Code Here

     * @return The found Serializer for the types specified or null if none could
     *         be found.
     */
    private ISerializer getSerializer(final Class clazz,
            final Class jsoClazz) {
        final Logger logger = this.getLogger();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE,
                    "looking for serializer - java:{0} json:{1}",
                    new Object[]{clazz == null ? "null" : clazz.getName(),
                        jsoClazz == null ? "null" : jsoClazz.getName()});
        }

        synchronized (_serializerSet) {
            ISerializer s = (ISerializer) _serializableMap.get(clazz);
            if (s != null && s.canSerialize(clazz, jsoClazz)) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, "direct match serializer {0}",
                            s.getClass().getName());
                }
                return s;
            }
            final Iterator i = _serializerList.iterator();
            while (i.hasNext()) {
                s = (ISerializer) i.next();
                if (s.canSerialize(clazz, jsoClazz)) {
                    if (logger.isLoggable(Level.FINE)) {
                        logger.log(Level.FINE, "search found serializer {0}",
                                s.getClass().getName());
                    }
                    return s;
                }
            }
View Full Code Here

            for (final IBeeEventListener listener:_listeners) {
                result.append("\n ");
                result.append("\t").append(listener.toString());
            }
        } catch (Throwable t) {
            Logger logger = this.getLogger();
            logger.log(Level.WARNING, "Error getting listeners snapshot.", t);
           
            result.append("ERROR [").append(t.toString()).append("]");
        }
        return result.toString();
    }
View Full Code Here

        return this.doEvent(event);
    }
   
    @Override
    public int doEvent(BeeEvent event) {
        Logger logger = this.getLogger();
        //logger.info(String.format("KEY=[%s] Fire %s ", key, event));
        int result = 0;
        IBeeEventListener[] listeners = _listeners.toArray();
        if (listeners.length > 0) {
            for (IBeeEventListener listener : listeners) {
                try {
                    if (null != listener) {
                        listener.onEvent(event);
                        result++;
                        if (logger.isLoggable(Level.FINE)) {
                            final String msg = String.format("Fired event {%s}", event);
                            logger.log(Level.FINE, msg);
                        }
                    } else {
                        if (logger.isLoggable(Level.FINE)) {
                            final String msg = String.format("NULL Listener: Firing event {%s}", event);
                            logger.log(Level.FINE, msg);
                        }
                    }
                } catch (NullPointerException t) {
                    if (logger.isLoggable(Level.FINE)) {
                        final String msg = String.format("Catched a NullPointerException firing event {%s}", event);
                        logger.log(Level.FINE, msg);
                    }
                } catch (Throwable t) {
                    final String msg = String.format("An error occurred in event listener [%s]: {%s}" +
                            "\nEvent is: [%s]",
                            listener, t, event);
                    logger.log(Level.SEVERE, msg, t);
                }
            }
        } else {
            if (logger.isLoggable(Level.FINE)) {
                final String msg = String.format("No listeners for Event: {%s}", event);
                logger.log(Level.FINE, msg);
            }
        }
        return result;
    }
View Full Code Here

     *
     * @param in original content
     * @return size gzipped content
     */
    public byte[] gzip(byte[] in) throws IOException {
        final Logger logger = this.getLogger();
        if (in != null && in.length > 0) {
            long tstart = System.currentTimeMillis();
            final ByteArrayOutputStream bout = new ByteArrayOutputStream();
            GZIPOutputStream gout = new GZIPOutputStream(bout);
            gout.write(in);
            gout.flush();
            gout.close();
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "gzipping took {0} msec",
                        (System.currentTimeMillis() - tstart));
            }
            return bout.toByteArray();
        }
        return new byte[0];
View Full Code Here

        byte[] data = out.toByteArray();
        return new ByteArrayInputStream(data);
    }

    public byte[] gunzip(byte[] in) throws IOException {
        final Logger logger = this.getLogger();
        if (in != null && in.length > 0) {
            long tstart = System.currentTimeMillis();
            final ByteArrayOutputStream bout = new ByteArrayOutputStream();
            final ByteArrayInputStream bin = new ByteArrayInputStream(in);
            final GZIPInputStream gzipInputStream = new GZIPInputStream(bin);
            byte[] buf = new byte[1024]//size can be changed according to programmer's need.
            int len;
            while ((len = gzipInputStream.read(buf)) > 0) {
                bout.write(buf, 0, len);
            }
            bout.flush();
            bout.close();
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "gzipping took {0} msec",
                        (System.currentTimeMillis() - tstart));
            }
            return bout.toByteArray();
        }
        return new byte[0];
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.