Package com.espertech.esper.client.util

Examples of com.espertech.esper.client.util.EventPropertyRendererContext


     * @param options rendering options
     */
    public JSONRendererImpl(EventType eventType, JSONRenderingOptions options)
    {
        EventPropertyRenderer propertyRenderer = null;
        EventPropertyRendererContext propertyRendererContext = null;
        if (options.getRenderer() != null) {
            propertyRenderer = options.getRenderer();
            propertyRendererContext = new EventPropertyRendererContext(eventType, true);
        }

        rendererOptions = new RendererMetaOptions(options.isPreventLooping(), false, propertyRenderer, propertyRendererContext);
        meta = new RendererMeta(eventType, new Stack<EventTypePropertyPair>(), rendererOptions);
    }
View Full Code Here


                simpleProp.getOutput().render(value, buf);
                delimiter = COMMA_DELIMITER_NEWLINE;
            }
        }
        else {
            EventPropertyRendererContext context = rendererOptions.getRendererContext();
            context.setStringBuilderAndReset(buf);
            for (GetterPair simpleProp : simpleProps)
            {
                Object value = simpleProp.getGetter().get(theEvent);
                writeDelimitedIndentedProp(buf, delimiter, level, simpleProp.getName());
                context.setDefaultRenderer(simpleProp.getOutput());
                context.setPropertyName(simpleProp.getName());
                context.setPropertyValue(value);
                rendererOptions.getRenderer().render(context);
                delimiter = COMMA_DELIMITER_NEWLINE;
            }
        }

        GetterPair[] indexProps = meta.getIndexProperties();
        for (GetterPair indexProp : indexProps)
        {
            Object value = indexProp.getGetter().get(theEvent);
            writeDelimitedIndentedProp(buf, delimiter, level, indexProp.getName());

            if (value == null)
            {
                buf.append("null");
            }
            else
            {
                if (!value.getClass().isArray())
                {
                    buf.append("[]");
                }
                else
                {
                    buf.append('[');
                    String arrayDelimiter = "";

                    if (rendererOptions.getRenderer() == null) {
                        for (int i = 0; i < Array.getLength(value); i++)
                        {
                            Object arrayItem = Array.get(value, i);
                            buf.append(arrayDelimiter);
                            indexProp.getOutput().render(arrayItem, buf);
                            arrayDelimiter = ", ";
                        }
                    }
                    else {
                        EventPropertyRendererContext context = rendererOptions.getRendererContext();
                        context.setStringBuilderAndReset(buf);
                        for (int i = 0; i < Array.getLength(value); i++)
                        {
                            Object arrayItem = Array.get(value, i);
                            buf.append(arrayDelimiter);
                            context.setPropertyName(indexProp.getName());
                            context.setPropertyValue(arrayItem);
                            context.setIndexedPropertyIndex(i);
                            context.setDefaultRenderer(indexProp.getOutput());
                            rendererOptions.getRenderer().render(context);
                            arrayDelimiter = ", ";
                        }
                    }
                    buf.append(']');
                }
            }
            delimiter = COMMA_DELIMITER_NEWLINE;
        }

        GetterPair[] mappedProps = meta.getMappedProperties();
        for (GetterPair mappedProp : mappedProps)
        {
            Object value = mappedProp.getGetter().get(theEvent);

            if ((value != null) && (!(value instanceof Map)))
            {
                log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead");
                continue;
            }

            writeDelimitedIndentedProp(buf, delimiter, level, mappedProp.getName());

            if (value == null)
            {
                buf.append("null");
                buf.append(NEWLINE);
            }
            else
            {
                Map<String, Object> map = (Map<String, Object>) value;
                if (map.isEmpty())
                {
                    buf.append("{}");
                    buf.append(NEWLINE);
                }
                else
                {
                    buf.append('{');
                    buf.append(NEWLINE);

                    String localDelimiter = "";
                    Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
                    for (;it.hasNext();)
                    {
                        Map.Entry<String, Object> entry = it.next();
                        if (entry.getKey() == null)
                        {
                            continue;
                        }

                        buf.append(localDelimiter);
                        ident(buf, level + 1);
                        buf.append('\"');
                        buf.append(entry.getKey());
                        buf.append("\": ");

                        if (entry.getValue() == null)
                        {
                            buf.append("null");
                        }
                        else
                        {
                            OutputValueRenderer outRenderer = OutputValueRendererFactory.getOutputValueRenderer(entry.getValue().getClass(), rendererOptions);
                            if (rendererOptions.getRenderer() == null) {
                                outRenderer.render(entry.getValue(), buf);
                            }
                            else {
                                EventPropertyRendererContext context = rendererOptions.getRendererContext();
                                context.setStringBuilderAndReset(buf);
                                context.setPropertyName(mappedProp.getName());
                                context.setPropertyValue(entry.getValue());
                                context.setMappedPropertyKey(entry.getKey());
                                context.setDefaultRenderer(outRenderer);
                                rendererOptions.getRenderer().render(context);
                            }
                        }
                        localDelimiter = COMMA_DELIMITER_NEWLINE;
                    }
View Full Code Here

     * @param options rendering options
     */
    public XMLRendererImpl(EventType eventType, XMLRenderingOptions options)
    {
        EventPropertyRenderer propertyRenderer = null;
        EventPropertyRendererContext propertyRendererContext = null;
        if (options.getRenderer() != null) {
            propertyRenderer = options.getRenderer();
            propertyRendererContext = new EventPropertyRendererContext(eventType, false);
        }

        rendererMetaOptions = new RendererMetaOptions(options.isPreventLooping(), true, propertyRenderer, propertyRendererContext);
        meta = new RendererMeta(eventType, new Stack<EventTypePropertyPair>(), rendererMetaOptions);
        this.options = options;
View Full Code Here

                buf.append('>');
                if (rendererMetaOptions.getRenderer() == null) {
                    indexProp.getOutput().render(arrayItem, buf);
                }
                else {
                    EventPropertyRendererContext context = rendererMetaOptions.getRendererContext();
                    context.setStringBuilderAndReset(buf);
                    context.setPropertyName(indexProp.getName());
                    context.setPropertyValue(arrayItem);
                    context.setIndexedPropertyIndex(i);
                    context.setDefaultRenderer(indexProp.getOutput());
                    rendererMetaOptions.getRenderer().render(context);
                }
                buf.append("</");
                buf.append(indexProp.getName());
                buf.append('>');
                buf.append(NEWLINE);
            }
        }

        GetterPair[] mappedProps = meta.getMappedProperties();
        for (GetterPair mappedProp : mappedProps)
        {
            Object value = mappedProp.getGetter().get(theEvent);

            if ((value != null) && (!(value instanceof Map)))
            {
                log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead");
                continue;
            }

            ident(buf, level);
            buf.append('<');
            buf.append(mappedProp.getName());

            if (value != null)
            {
                Map<String, Object> map = (Map<String, Object>) value;
                if (!map.isEmpty())
                {
                    Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
                    for (;it.hasNext();)
                    {
                        Map.Entry<String, Object> entry = it.next();
                        if ((entry.getKey() == null) || (entry.getValue() == null))
                        {
                            continue;
                        }

                        buf.append(" ");
                        buf.append(entry.getKey());
                        buf.append("=\"");
                        OutputValueRenderer outputValueRenderer = OutputValueRendererFactory.getOutputValueRenderer(entry.getValue().getClass(), rendererMetaOptions);

                        if (rendererMetaOptions.getRenderer() == null) {
                            outputValueRenderer.render(entry.getValue(), buf);
                        }
                        else {
                            EventPropertyRendererContext context = rendererMetaOptions.getRendererContext();
                            context.setStringBuilderAndReset(buf);
                            context.setPropertyName(mappedProp.getName());
                            context.setPropertyValue(entry.getValue());
                            context.setMappedPropertyKey(entry.getKey());
                            context.setDefaultRenderer(outputValueRenderer);
                            rendererMetaOptions.getRenderer().render(context);
                        }

                        buf.append("\"");
                    }
View Full Code Here

            buf.append("=\"");
            if (rendererMetaOptions.getRenderer() == null) {
                simpleProp.getOutput().render(value, buf);
            }
            else {
                EventPropertyRendererContext context = rendererMetaOptions.getRendererContext();
                context.setStringBuilderAndReset(buf);
                context.setPropertyName(simpleProp.getName());
                context.setPropertyValue(value);
                context.setDefaultRenderer(simpleProp.getOutput());
                rendererMetaOptions.getRenderer().render(context);
            }
            buf.append('"');
        }
    }
View Full Code Here

            if (rendererMetaOptions.getRenderer() == null) {
                simpleProp.getOutput().render(value, buf);
            }
            else {
                EventPropertyRendererContext context = rendererMetaOptions.getRendererContext();
                context.setStringBuilderAndReset(buf);
                context.setPropertyName(simpleProp.getName());
                context.setPropertyValue(value);
                context.setDefaultRenderer(simpleProp.getOutput());
                rendererMetaOptions.getRenderer().render(context);
            }
           
            buf.append("</");
            buf.append(simpleProp.getName());
            buf.append('>');
            buf.append(NEWLINE);
        }

        GetterPair[] indexProps = meta.getIndexProperties();
        for (GetterPair indexProp : indexProps)
        {
            Object value = indexProp.getGetter().get(theEvent);

            if (value == null)
            {
                continue;
            }
            if (!value.getClass().isArray())
            {
                log.warn("Property '" + indexProp.getName() + "' returned a non-array object");
                continue;
            }
            for (int i = 0; i < Array.getLength(value); i++)
            {
                Object arrayItem = Array.get(value, i);

                if (arrayItem == null)
                {
                    continue;
                }

                ident(buf, level);
                buf.append('<');
                buf.append(indexProp.getName());
                buf.append('>');
                if (rendererMetaOptions.getRenderer() == null) {
                    indexProp.getOutput().render(arrayItem, buf);
                }
                else {
                    EventPropertyRendererContext context = rendererMetaOptions.getRendererContext();
                    context.setStringBuilderAndReset(buf);
                    context.setPropertyName(indexProp.getName());
                    context.setPropertyValue(arrayItem);
                    context.setIndexedPropertyIndex(i);
                    context.setDefaultRenderer(indexProp.getOutput());
                    rendererMetaOptions.getRenderer().render(context);
                }
                buf.append("</");
                buf.append(indexProp.getName());
                buf.append('>');
                buf.append(NEWLINE);
            }
        }

        GetterPair[] mappedProps = meta.getMappedProperties();
        for (GetterPair mappedProp : mappedProps)
        {
            Object value = mappedProp.getGetter().get(theEvent);

            if ((value != null) && (!(value instanceof Map)))
            {
                log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead");
                continue;
            }

            ident(buf, level);
            buf.append('<');
            buf.append(mappedProp.getName());
            buf.append('>');
            buf.append(NEWLINE);

            if (value != null)
            {
                Map<String, Object> map = (Map<String, Object>) value;
                if (!map.isEmpty())
                {
                    String localDelimiter = "";
                    Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
                    for (;it.hasNext();)
                    {
                        Map.Entry<String, Object> entry = it.next();
                        if (entry.getKey() == null)
                        {
                            continue;
                        }

                        buf.append(localDelimiter);
                        ident(buf, level + 1);
                        buf.append('<');
                        buf.append(entry.getKey());
                        buf.append('>');

                        if (entry.getValue() != null)
                        {
                            OutputValueRenderer outputValueRenderer = OutputValueRendererFactory.getOutputValueRenderer(entry.getValue().getClass(), rendererMetaOptions);
                            if (rendererMetaOptions.getRenderer() == null) {
                                outputValueRenderer.render(entry.getValue(), buf);
                            }
                            else {
                                EventPropertyRendererContext context = rendererMetaOptions.getRendererContext();
                                context.setStringBuilderAndReset(buf);
                                context.setPropertyName(mappedProp.getName());
                                context.setPropertyValue(entry.getValue());
                                context.setMappedPropertyKey(entry.getKey());
                                context.setDefaultRenderer(outputValueRenderer);
                                rendererMetaOptions.getRenderer().render(context);
                            }
                        }

                        buf.append('<');
View Full Code Here

     * @param options rendering options
     */
    public JSONRendererImpl(EventType eventType, JSONRenderingOptions options)
    {
        EventPropertyRenderer propertyRenderer = null;
        EventPropertyRendererContext propertyRendererContext = null;
        if (options.getRenderer() != null) {
            propertyRenderer = options.getRenderer();
            propertyRendererContext = new EventPropertyRendererContext(eventType, true);
        }

        rendererOptions = new RendererMetaOptions(options.isPreventLooping(), false, propertyRenderer, propertyRendererContext);
        meta = new RendererMeta(eventType, new Stack<EventTypePropertyPair>(), rendererOptions);
    }
View Full Code Here

                simpleProp.getOutput().render(value, buf);
                delimiter = COMMA_DELIMITER_NEWLINE;
            }
        }
        else {
            EventPropertyRendererContext context = rendererOptions.getRendererContext();
            context.setStringBuilderAndReset(buf);
            for (GetterPair simpleProp : simpleProps)
            {
                Object value = simpleProp.getGetter().get(theEvent);
                writeDelimitedIndentedProp(buf, delimiter, level, simpleProp.getName());
                context.setDefaultRenderer(simpleProp.getOutput());
                context.setPropertyName(simpleProp.getName());
                context.setPropertyValue(value);
                rendererOptions.getRenderer().render(context);
                delimiter = COMMA_DELIMITER_NEWLINE;
            }
        }

        GetterPair[] indexProps = meta.getIndexProperties();
        for (GetterPair indexProp : indexProps)
        {
            Object value = indexProp.getGetter().get(theEvent);
            writeDelimitedIndentedProp(buf, delimiter, level, indexProp.getName());

            if (value == null)
            {
                buf.append("null");
            }
            else
            {
                if (!value.getClass().isArray())
                {
                    buf.append("[]");
                }
                else
                {
                    buf.append('[');
                    String arrayDelimiter = "";

                    if (rendererOptions.getRenderer() == null) {
                        for (int i = 0; i < Array.getLength(value); i++)
                        {
                            Object arrayItem = Array.get(value, i);
                            buf.append(arrayDelimiter);
                            indexProp.getOutput().render(arrayItem, buf);
                            arrayDelimiter = ", ";
                        }
                    }
                    else {
                        EventPropertyRendererContext context = rendererOptions.getRendererContext();
                        context.setStringBuilderAndReset(buf);
                        for (int i = 0; i < Array.getLength(value); i++)
                        {
                            Object arrayItem = Array.get(value, i);
                            buf.append(arrayDelimiter);
                            context.setPropertyName(indexProp.getName());
                            context.setPropertyValue(arrayItem);
                            context.setIndexedPropertyIndex(i);
                            context.setDefaultRenderer(indexProp.getOutput());
                            rendererOptions.getRenderer().render(context);
                            arrayDelimiter = ", ";
                        }
                    }
                    buf.append(']');
                }
            }
            delimiter = COMMA_DELIMITER_NEWLINE;
        }

        GetterPair[] mappedProps = meta.getMappedProperties();
        for (GetterPair mappedProp : mappedProps)
        {
            Object value = mappedProp.getGetter().get(theEvent);

            if ((value != null) && (!(value instanceof Map)))
            {
                log.warn("Property '" + mappedProp.getName() + "' expected to return Map and returned " + value.getClass() + " instead");
                continue;
            }

            writeDelimitedIndentedProp(buf, delimiter, level, mappedProp.getName());

            if (value == null)
            {
                buf.append("null");
                buf.append(NEWLINE);
            }
            else
            {
                Map<String, Object> map = (Map<String, Object>) value;
                if (map.isEmpty())
                {
                    buf.append("{}");
                    buf.append(NEWLINE);
                }
                else
                {
                    buf.append('{');
                    buf.append(NEWLINE);

                    String localDelimiter = "";
                    Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
                    for (;it.hasNext();)
                    {
                        Map.Entry<String, Object> entry = it.next();
                        if (entry.getKey() == null)
                        {
                            continue;
                        }

                        buf.append(localDelimiter);
                        ident(buf, level + 1);
                        buf.append('\"');
                        buf.append(entry.getKey());
                        buf.append("\": ");

                        if (entry.getValue() == null)
                        {
                            buf.append("null");
                        }
                        else
                        {
                            OutputValueRenderer outRenderer = OutputValueRendererFactory.getOutputValueRenderer(entry.getValue().getClass(), rendererOptions);
                            if (rendererOptions.getRenderer() == null) {
                                outRenderer.render(entry.getValue(), buf);
                            }
                            else {
                                EventPropertyRendererContext context = rendererOptions.getRendererContext();
                                context.setStringBuilderAndReset(buf);
                                context.setPropertyName(mappedProp.getName());
                                context.setPropertyValue(entry.getValue());
                                context.setMappedPropertyKey(entry.getKey());
                                context.setDefaultRenderer(outRenderer);
                                rendererOptions.getRenderer().render(context);
                            }
                        }
                        localDelimiter = COMMA_DELIMITER_NEWLINE;
                    }
View Full Code Here

TOP

Related Classes of com.espertech.esper.client.util.EventPropertyRendererContext

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.