Package org.jboss.errai.marshalling.client.api.exceptions

Examples of org.jboss.errai.marshalling.client.api.exceptions.NoAvailableMarshallerException


  public void marshallToJSON(final BlockBuilder<?> builder,
                             final MetaClass toType,
                             final MappingDefinition definition) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
        If.isNull(loadVariable("a0"))
            .append(Stmt.load("null").returnValue()).finish()
    );

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    if (toMap.isEnum()) {
      builder.append(
          Stmt.declareFinalVariable(
              "json",
              StringBuilder.class,
              Stmt.newObject(StringBuilder.class)
          )
      );
      final ContextualStatementBuilder csb = Stmt.loadVariable("json");
      marshallEnum(csb, Stmt.loadVariable("a0"), toMap);
      builder.append(csb.invoke("toString").returnValue());
      return;
    }

    builder.append(Stmt.declareFinalVariable("ref", boolean.class,
        Stmt.loadVariable("a1").invoke("hasObject", Refs.get("a0"))));

    builder.append(
        Stmt.declareFinalVariable(
            "json",
            StringBuilder.class,
            Stmt.newObject(StringBuilder.class,
                "{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + ",\"" +
                    SerializationParts.OBJECT_ID + "\"")
        )
    );

    builder.append(Stmt.loadVariable("json")
        .invoke("append", ":\"")
        .invoke("append", loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0")))
        .invoke("append", "\"")
    );

    builder.append(
        If.cond(loadVariable("ref"))
            .append(Stmt.loadVariable("json").invoke("append", "}").invoke("toString").returnValue())
            .finish());

    boolean hasEncoded = false;

    ContextualStatementBuilder appendChain = null;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        appendChain = Stmt.loadVariable("json").invoke("append", ",");
        hasEncoded = true;
      }
      else if (i > 0) {
        appendChain.invoke("append", ",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());

      final MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(compType.isAbstract() || compType.isInterface() || compType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here


  public void marshallToJSON(final BlockBuilder<?> builder,
                             final MetaClass toType,
                             final MappingDefinition definition) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
        If.isNull(loadVariable("a0"))
            .append(Stmt.load("null").returnValue()).finish()
    );

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    if (toMap.isEnum()) {
      builder.append(
          Stmt.declareFinalVariable(
              "json",
              StringBuilder.class,
              Stmt.newObject(StringBuilder.class)
          )
      );
      final ContextualStatementBuilder csb = Stmt.loadVariable("json");
      marshallEnum(csb, Stmt.loadVariable("a0"), toMap);
      builder.append(csb.invoke("toString").returnValue());
      return;
    }

    builder.append(Stmt.declareFinalVariable("ref", boolean.class,
        Stmt.loadVariable("a1").invoke("hasObject", Refs.get("a0"))));

    builder.append(
        Stmt.declareFinalVariable(
            "json",
            StringBuilder.class,
            Stmt.newObject(StringBuilder.class,
                "{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + ",\"" +
                    SerializationParts.OBJECT_ID + "\"")
        )
    );

    builder.append(Stmt.loadVariable("json")
        .invoke("append", ":\"")
        .invoke("append", loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0")))
        .invoke("append", "\"")
    );

    builder.append(
        If.cond(loadVariable("ref"))
            .append(Stmt.loadVariable("json").invoke("append", "}").invoke("toString").returnValue())
            .finish());

    boolean hasEncoded = false;

    ContextualStatementBuilder appendChain = null;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        appendChain = Stmt.loadVariable("json").invoke("append", ",");
        hasEncoded = true;
      }
      else if (i > 0) {
        appendChain.invoke("append", ",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());

      final MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(compType.isAbstract() || compType.isInterface() || compType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

  public void marshallToJSON(final BlockBuilder<?> builder,
                             final MetaClass toType,
                             final MappingDefinition definition) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
            If.isNull(loadVariable("a0"))
                    .append(Stmt.load("null").returnValue()).finish()
        );

    if (toMap.isEnum()) {
      builder.append(Stmt.nestedCall(marshallEnum(newStringBuilder(256), Stmt.loadVariable("a0"), toMap))
              .invoke("toString").returnValue());
      return;
    }

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    final Implementations.StringBuilderBuilder sb = newStringBuilder(bufSize)
            .append("{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + "," +
                    string(SerializationParts.OBJECT_ID) + ":\"").append(loadVariable("objId")).append("\"");

    builder.append(
            If.cond(loadVariable("a1").invoke("hasObject", loadVariable("a0")))
                    .append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))))
                    .append(Stmt.nestedCall(newStringBuilder(128).append("{"
                            + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName()))).append(",")
                            .append(string(SerializationParts.OBJECT_ID) + ":\"")
                            .append(loadVariable("objId"))
                            .append("\"}")).invoke("toString").returnValue())
                    .finish());

    builder.append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))));

    builder.append(loadVariable("a1").invoke("recordObject", loadVariable("objId"),
            loadVariable("objId")));

    boolean hasEncoded = false;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        sb.append(",");
        hasEncoded = true;
      }
      else if (i > 0) {
        sb.append(",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());
      final MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(compType.isAbstract() || compType.isInterface() || compType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

  public void marshallToJSON(final BlockBuilder<?> builder,
                             final MetaClass toType,
                             final MappingDefinition definition) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
            If.isNull(loadVariable("a0"))
                    .append(Stmt.load("null").returnValue()).finish()
        );

    if (toMap.isEnum()) {
      builder.append(Stmt.nestedCall(marshallEnum(newStringBuilder(256), Stmt.loadVariable("a0"), toMap))
              .invoke("toString").returnValue());
      return;
    }

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    final Implementations.StringBuilderBuilder sb = newStringBuilder(bufSize)
            .append("{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + "," +
                    string(SerializationParts.OBJECT_ID) + ":\"").append(loadVariable("objId")).append("\"");

    builder.append(
            If.cond(loadVariable("a1").invoke("hasObject", loadVariable("a0")))
                    .append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))))
                    .append(Stmt.nestedCall(newStringBuilder(128).append("{"
                            + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName()))).append(",")
                            .append(string(SerializationParts.OBJECT_ID) + ":\"")
                            .append(loadVariable("objId"))
                            .append("\"}")).invoke("toString").returnValue())
                    .finish());

    builder.append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))));

    builder.append(loadVariable("a1").invoke("recordObject", loadVariable("objId"),
            loadVariable("objId")));

    boolean hasEncoded = false;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        sb.append(",");
        hasEncoded = true;
      }
      else if (i > 0) {
        sb.append(",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());
      final MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(targetType.isAbstract() || targetType.isInterface() || targetType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

  public void marshallToJSON(final BlockBuilder<?> builder,
                             final MetaClass toType,
                             final MappingDefinition definition) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
            If.isNull(loadVariable("a0"))
                    .append(Stmt.load("null").returnValue()).finish()
        );

    if (toMap.isEnum()) {
      builder.append(Stmt.nestedCall(marshallEnum(newStringBuilder(256), Stmt.loadVariable("a0"), toMap))
              .invoke("toString").returnValue());
      return;
    }

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    final Implementations.StringBuilderBuilder sb = newStringBuilder(bufSize)
            .append("{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + "," +
                    string(SerializationParts.OBJECT_ID) + ":\"").append(loadVariable("objId")).append("\"");

    builder.append(
            If.cond(loadVariable("a1").invoke("hasObject", loadVariable("a0")))
                    .append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))))
                    .append(Stmt.nestedCall(newStringBuilder(128).append("{"
                            + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName()))).append(",")
                            .append(string(SerializationParts.OBJECT_ID) + ":\"")
                            .append(loadVariable("objId"))
                            .append("\"}")).invoke("toString").returnValue())
                    .finish());

    builder.append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))));

    builder.append(loadVariable("a1").invoke("recordObject", loadVariable("objId"),
            loadVariable("objId")));

    boolean hasEncoded = false;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        sb.append(",");
        hasEncoded = true;
      }
      else if (i > 0) {
        sb.append(",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());
      final MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(targetType.isAbstract() || targetType.isInterface() || targetType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

  public void marshallToJSON(final BlockBuilder<?> builder,
                             final MetaClass toType,
                             final MappingDefinition definition) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
            If.isNull(loadVariable("a0"))
                    .append(Stmt.load("null").returnValue()).finish()
        );

    if (toMap.isEnum()) {
      builder.append(Stmt.nestedCall(marshallEnum(newStringBuilder(256), Stmt.loadVariable("a0"), toMap))
              .invoke("toString").returnValue());
      return;
    }

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    final Implementations.StringBuilderBuilder sb = newStringBuilder(bufSize)
            .append("{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + "," +
                    string(SerializationParts.OBJECT_ID) + ":\"").append(loadVariable("objId")).append("\"");

    builder.append(
            If.cond(loadVariable("a1").invoke("hasObject", loadVariable("a0")))
                    .append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))))
                    .append(Stmt.nestedCall(newStringBuilder(128).append("{"
                            + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName()))).append(",")
                            .append(string(SerializationParts.OBJECT_ID) + ":\"")
                            .append(loadVariable("objId"))
                            .append("\"}")).invoke("toString").returnValue())
                    .finish());

    builder.append(declareVariable(String.class).named("objId").initializeWith(loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0"))));

    builder.append(loadVariable("a1").invoke("recordObject", loadVariable("objId"),
            loadVariable("objId")));

    boolean hasEncoded = false;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        sb.append(",");
        hasEncoded = true;
      }
      else if (i > 0) {
        sb.append(",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());
      final MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(targetType.isAbstract() || targetType.isInterface() || targetType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

    return bufSize;
  }

  public void marshallToJSON(BlockBuilder<?> builder, MetaClass toType, MappingDefinition definition) {
    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
            Stmt.if_(Bool.isNull(loadVariable("a0")))
                    .append(Stmt.load("null").returnValue()).finish()
        );

    if (toMap.isEnum()) {
      builder.append(Stmt.nestedCall(marshallEnum(newStringBuilder(256), Stmt.loadVariable("a0"), toMap))
              .invoke("toString").returnValue());
      return;
    }

    // builder.append(Stmt.declareVariable(String.class).named("objId").finish());

    int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    Implementations.StringBuilderBuilder sb = newStringBuilder(bufSize)
            .append("{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + "," +
                    string(SerializationParts.OBJECT_ID) + ":\"").append(loadVariable("objId")).append("\"");

    builder.append(
            Stmt.if_(Bool.expr(loadVariable("a1").invoke("hasObjectHash", loadVariable("a0"))))
                    .append(
                        declareVariable(String.class).named("objId").initializeWith(
                            loadVariable("a1").invoke("getObjectHash", Stmt.loadVariable("a0"))))
                    .append(
                        Stmt.nestedCall(
                            newStringBuilder(128).append("{"
                                + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())))
                                .append(",")
                                .append(string(SerializationParts.OBJECT_ID) + ":\"")
                                .append(loadVariable("objId"))
                                .append("\"}")).invoke("toString").returnValue())
                    .finish());

    builder.append(declareVariable(String.class).named("objId").initializeWith(
        loadVariable("a1").invoke("getObjectHash", Stmt.loadVariable("a0"))));

    builder.append(loadVariable("a1").invoke("recordObjectHash", loadVariable("objId"),
            loadVariable("objId")));

    boolean hasEncoded = false;

    int i = 0;
    for (MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      if (!hasEncoded) {
        sb.append(",");
        hasEncoded = true;
      }
      else if (i > 0) {
        sb.append(",");
      }

      MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());

      MetaClass compType = targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();
     
      if (!(targetType.isAbstract() || targetType.isInterface() || targetType.isEnum()) && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember());
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

                             final MappingDefinition definition,
                             final ClassStructureBuilder classStructureBuilder,
                             final BlockBuilder<?> initMethod) {

    if (!context.canMarshal(toType.getFullyQualifiedName())) {
      throw new NoAvailableMarshallerException(toType.getName());
    }

    builder.append(
        If.isNull(loadVariable("a0"))
            .append(Stmt.load("null").returnValue()).finish()
        );

    final int bufSize = calcBufferSize(new ArrayList<MappingDefinition>(), definition);

    if (toMap.isEnum()) {
      builder.append(
          Stmt.declareFinalVariable(
              "json",
              StringBuilder.class,
              Stmt.newObject(StringBuilder.class)
              )
          );
      final ContextualStatementBuilder csb = Stmt.loadVariable("json");
      marshallEnum(csb, Stmt.loadVariable("a0"), toMap);
      builder.append(csb.invoke("toString").returnValue());
      return;
    }

    builder.append(Stmt.declareFinalVariable("ref", boolean.class,
        Stmt.loadVariable("a1").invoke("hasObject", Refs.get("a0"))));

    builder.append(
        Stmt.declareFinalVariable(
            "json",
            StringBuilder.class,
            Stmt.newObject(StringBuilder.class,
                "{" + keyValue(SerializationParts.ENCODED_TYPE, string(toType.getFullyQualifiedName())) + ",\"" +
                    SerializationParts.OBJECT_ID + "\"")
            )
        );

    builder.append(Stmt.loadVariable("json")
        .invoke("append", ":\"")
        .invoke("append", loadVariable("a1").invoke("getObject", Stmt.loadVariable("a0")))
        .invoke("append", "\"")
        );

    builder.append(
        If.cond(loadVariable("ref"))
            .append(Stmt.loadVariable("json").invoke("append", "}").invoke("toString").returnValue())
            .finish());

    boolean hasEncoded = false;

    ContextualStatementBuilder appendChain = null;

    int i = 0;
    for (final MemberMapping mapping : definition.getMemberMappings()) {
      if (!mapping.canRead()) {
        continue;
      }

      BlockBuilder<?> lazyInitMethod = (needsLazyInit(mapping.getType())) ? initMethod : null;
      MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, mapping.getType()
            .asBoxed(), lazyInitMethod);

      if (!hasEncoded) {
        appendChain = Stmt.loadVariable("json").invoke("append", ",");
        hasEncoded = true;
      }
      else if (i > 0) {
        appendChain.invoke("append", ",");
      }

      final MetaClass targetType = GenUtil.getPrimitiveWrapper(mapping.getType());

      final MetaClass compType =
          targetType.isArray() ? targetType.getOuterComponentType().asBoxed() : targetType.asBoxed();

      if (!(compType.isAbstract() || compType.isInterface() || compType.isEnum())
          && !context.canMarshal(compType.getFullyQualifiedName())) {
        throw new NoAvailableMarshallerException(compType.getFullyQualifiedName());
      }

      Statement valueStatement = valueAccessorFor(mapping.getReadingMember(), classStructureBuilder);
      if (targetType.isArray()) {
        valueStatement = context.getArrayMarshallerCallback().marshal(targetType, valueStatement);
View Full Code Here

TOP

Related Classes of org.jboss.errai.marshalling.client.api.exceptions.NoAvailableMarshallerException

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.