Package com.cognitect.transit

Examples of com.cognitect.transit.WriteHandler


        this.handlers = handlers;
    }

    private WriteHandler checkBaseClasses(Class c) {
        for(Class base = c.getSuperclass(); base != Object.class; base = base.getSuperclass()) {
            WriteHandler h = handlers.get(base);
            if(h != null) {
                handlers.put(c, h);
                return h;
            }
        }
View Full Code Here


    private WriteHandler checkBaseInterfaces(Class c) {
        Map<Class, WriteHandler> possibles = new HashMap<Class,WriteHandler>();
        for (Class base = c; base != Object.class; base = base.getSuperclass()) {
            for (Class itf : base.getInterfaces()) {
                WriteHandler h = handlers.get(itf);
                if (h != null) possibles.put(itf, h);
            }
        }
        switch (possibles.size()) {
            case 0: return null;
            case 1: {
                WriteHandler h = possibles.values().iterator().next();
                handlers.put(c, h);
                return h;
            }
            default: throw new RuntimeException("More thane one match for " + c);
        }
View Full Code Here

            default: throw new RuntimeException("More thane one match for " + c);
        }
    }

    public String getTag(Object o) {
        WriteHandler h = getHandler(o);
        if (h == null) return null;
        return h.tag(o);
    }
View Full Code Here

    }

    private WriteHandler getHandler(Object o) {

        Class c = (o != null) ? o.getClass() : null;
        WriteHandler h = null;

        if(h == null) {
            h = handlers.get(c);
        }
        if(h == null) {
View Full Code Here

        emitArrayEnd();
    }

    protected void marshal(Object o, boolean asMapKey, WriteCache cache) throws Exception {

        WriteHandler h = getHandler(o);

        boolean supported = false;
        if(h != null) { // TODO: maybe remove getWriteHandler call and this check and just call tag
            String t = h.tag(o);
            if(t != null) {
                supported = true;
                if(t.length() == 1) {
                    switch(t.charAt(0)) {
                        case '_': emitNil(asMapKey, cache); break;
                        case 's': emitString(null, null, escape((String)h.rep(o)), asMapKey, cache); break;
                        case '?': emitBoolean((Boolean)h.rep(o), asMapKey, cache); break;
                        case 'i': emitInteger(h.rep(o), asMapKey, cache); break;
                        case 'd': emitDouble(h.rep(o), asMapKey, cache); break;
                        case 'b': emitBinary(h.rep(o), asMapKey, cache); break;
                        case '\'': emitTagged(t, h.rep(o), false, cache); break;
                        default: emitEncoded(t, h, o, asMapKey, cache); break;
                    }
                }
                else {
                    if(t.equals("array"))
                        emitArray(h.rep(o), asMapKey, cache);
                    else if(t.equals("map"))
                        emitMap(h.rep(o), asMapKey, cache);
                    else
                        emitEncoded(t, h, o, asMapKey, cache);
                }
                flushWriter();
            }
View Full Code Here

            throw new Exception("Not supported: " + o.getClass());
    }

    protected void marshalTop(Object o, WriteCache cache) throws Exception {

        WriteHandler h = getHandler(o);
        if (h == null) {
            throw new Exception("Not supported: " + o);
        }
        String tag = h.tag(o);
        if (tag == null) {
            throw new Exception("Not supported: " + o);
        }

        if (tag.length() == 1)
View Full Code Here

        this.handlers = handlers;
    }

    private WriteHandler checkBaseClasses(Class c) {
        for(Class base = c.getSuperclass(); base != Object.class; base = base.getSuperclass()) {
            WriteHandler h = handlers.get(base);
            if(h != null) {
                handlers.put(c, h);
                return h;
            }
        }
View Full Code Here

    private WriteHandler checkBaseInterfaces(Class c) {
        Map<Class, WriteHandler> possibles = new HashMap<Class,WriteHandler>();
        for (Class base = c; base != Object.class; base = base.getSuperclass()) {
            for (Class itf : base.getInterfaces()) {
                WriteHandler h = handlers.get(itf);
                if (h != null) possibles.put(itf, h);
            }
        }
        switch (possibles.size()) {
            case 0: return null;
            case 1: {
                WriteHandler h = possibles.values().iterator().next();
                handlers.put(c, h);
                return h;
            }
            default: throw new RuntimeException("More thane one match for " + c);
        }
View Full Code Here

            default: throw new RuntimeException("More thane one match for " + c);
        }
    }

    public String getTag(Object o) {
        WriteHandler h = getHandler(o);
        if (h == null) return null;
        return h.tag(o);
    }
View Full Code Here

    }

    private WriteHandler getHandler(Object o) {

        Class c = (o != null) ? o.getClass() : null;
        WriteHandler h = null;

        if(h == null) {
            h = handlers.get(c);
        }
        if(h == null) {
View Full Code Here

TOP

Related Classes of com.cognitect.transit.WriteHandler

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.