Package flexjson

Examples of flexjson.JSONContext


import java.util.Map;

public class MapTransformer extends AbstractTransformer {

    public void transform(Object object) {
        JSONContext context = getContext();
        Path path = context.getPath();
        Map value = (Map) object;

        try {
            TypeContext typeContext = getContext().writeOpenObject();
            for (Object key : value.keySet()) {

                path.enqueue(key != null ? key.toString() : null);

                if (context.isIncluded(key != null ? key.toString() : null, value.get(key))) {

                    Transformer transformer = context.getTransformer(null, value.get(key));


                    if(!(transformer instanceof Inline) || !((Inline)transformer).isInline()) {
                        if (!typeContext.isFirst()) getContext().writeComma();
                        typeContext.increment();
View Full Code Here


{
  public void transform(Object object)
  {
    int identityHashCode= System.identityHashCode(object);

    JSONContext context= getContext();

    TypeContext typeContext= context.writeOpenObject();
    context.writeName("@id");
    context.write("" + identityHashCode);

    context.writeComma();
    context.writeName("class");
    context.writeQuoted(NullIterator.class.getName());

    context.writeCloseObject();
  }
View Full Code Here

public class MapTransformer extends AbstractTransformer
{

  public void transform(Object object)
  {
    JSONContext context= getContext();
    Path path= context.getPath();
    Map value= (Map) object;

    TypeContext typeContext= getContext().writeOpenObject();
    for (Object key : value.keySet())
    {

      path.enqueue(key != null ? key.toString() : null);

      if (context.isIncluded(key != null ? key.toString() : null, value.get(key)))
      {

        TransformerWrapper transformer= (TransformerWrapper) context.getTransformer(value.get(key));

        if (!transformer.isInline())
        {
          if (!typeContext.isFirst())
            getContext().writeComma();
View Full Code Here

public class ElementTrasformer extends AbstractTransformer
{
  public void transform(Object object)
  {
    JSONContext context= getContext();
    Element element= (Element) object;
    String id= System.identityHashCode(element) + "";
    element.setAttribute("data-debug-id", id);
    TypeContext typeContext= context.writeOpenObject();

    context.writeName("id");
    context.writeQuoted(id);
    context.writeComma();
    context.writeName("class");
    ClassTransformer classTransformer= new ClassTransformer();
    classTransformer.transform(object.getClass());
    //context.writeQuoted(object.getClass().getName());

    //  context.writeComma();
    //  context.writeName("elements");
    //
    //  NodeList childNodes= element.getChildNodes();
    //  List<Element> elements= new ArrayList<Element>();
    //  for (int i= 0; i < childNodes.getLength(); i++)
    //      elements.add((Element) childNodes.item(i));
    //
    //
    //  TransformerWrapper transformer= (TransformerWrapper) context.getTransformer(elements);
    //
    //  path.enqueue("elements");
    //  transformer.transform(elements);
    //  path.pop();

    context.writeCloseObject();
  }
View Full Code Here

public class DragomeClassTransformer extends AbstractTransformer
{
  public void transform(Object object)
  {
    JSONContext context= getContext();
    Path path= context.getPath();
    String name= ((Class) object).getName();
    name= name.replaceAll("_", ".");//TODO mejorar!!!
    TypeContext typeContext= context.writeOpenObject();

    context.writeName("name");
    context.writeQuoted(name);
    context.writeComma();
    context.writeName("class");
    context.writeQuoted("java.lang.Class");

    context.writeCloseObject();
  }
View Full Code Here

public class ObjectTransformer extends AbstractTransformer
{
  public void transform(Object object)
  {
    JSONContext context= getContext();
    Path path= context.getPath();
    ChainedSet visits= context.getVisits();
    try
    {
      if (!visits.contains(object))
      {
        context.setVisits(new ChainedSet(visits));
        context.getVisits().add(object);
        // traverse object
        BeanAnalyzer analyzer= BeanAnalyzer.analyze(resolveClass(object));
        TypeContext typeContext= context.writeOpenObject();

        context.writeName("@id");
        Integer objectId= getObjectId(object, context);
        context.getReferences().put(System.identityHashCode(object), objectId);
        context.write("" + objectId);

        context.writeComma();
        for (BeanProperty prop : analyzer.getProperties())
        {
          String name= prop.getName();
          path.enqueue(name);
          if (context.isIncluded(prop))
          {
            Object value= prop.getValue(object);
            //if (!context.getVisits().contains(value))
            {
              TransformerWrapper transformer= (TransformerWrapper) context.getTransformer(value);
              if ("class".equals(name)) //revisar esto!!!!
                transformer= new TransformerWrapper(new ClassTransformer());

              if (transformer == null)
                transformer= new TransformerWrapper(new NullTransformer());

              if ((transformer.getTransformer() instanceof ObjectTransformer) || !context.getVisits().contains(value))
              {
                if (!transformer.isInline())
                {
                  if (!typeContext.isFirst())
                    context.writeComma();
                  typeContext.setFirst(false);
                  context.writeName(name);
                }
                typeContext.setPropertyName(name);

                transformer.transform(value);
              }
            }
          }
          path.pop();
        }
        context.writeCloseObject();
        context.setVisits((ChainedSet) context.getVisits().getParent());

      }
      else
      {
        writeReference(object, context);
View Full Code Here

public class CosmEventTransformer extends AbstractTransformer {

  public void transform(Object obj) {
    if (obj instanceof CosmEventBean) {
      CosmEventBean pachubeEventBean = (CosmEventBean) obj;
      JSONContext context = getContext();
      context.writeOpenObject();

      context.writeName("id");
      context.write("\""+pachubeEventBean.getId()+"\"");
      context.writeComma();
      context.writeName("current_value");
      context.write("\""+pachubeEventBean.getValue()+"\"");
      if(null!=pachubeEventBean.getMaxValue() && !pachubeEventBean.getMaxValue().isEmpty())  {
        context.writeComma();
        context.writeName("max_value");
        context.write("\""+pachubeEventBean.getMaxValue()+"\"");
      }
      if(null!=pachubeEventBean.getMinValue() && !pachubeEventBean.getMinValue().isEmpty())   {
        context.writeComma();
        context.writeName("min_value");
        context.write("\""+pachubeEventBean.getMinValue()+"\"");
      }
      context.writeCloseObject();
    }
  }
View Full Code Here

public class SenseEventTransformer extends AbstractTransformer {

  public void transform(Object obj) {
    if (obj instanceof SenseEventBean) {
      SenseEventBean senseEventBean = (SenseEventBean) obj;
      JSONContext context = getContext();
      context.writeOpenObject();
      context.writeName("feed_id");
      context.write("" + senseEventBean.getFeedId());
      context.writeComma();
      context.writeName("value");
      context.write("\"" + senseEventBean.getValue() + "\"");
      context.writeCloseObject();
    }
  }
View Full Code Here

TOP

Related Classes of flexjson.JSONContext

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.