private void addValue() {
    final ObjectAdapter valueAdapter = objectMember.get(objectAdapter);

    // use the runtime type if we have a value, else the compile time type of the member otherwise
    final ObjectSpecification spec =
        valueAdapter != null ? valueAdapter.getSpecification() : objectMember.getSpecification();

    final ValueFacet valueFacet = spec.getFacet(ValueFacet.class);
    if (valueFacet != null) {
      String format = null;
      final Class<?> specClass = spec.getCorrespondingClass();
      if (specClass == java.math.BigDecimal.class) {
        // look for facet on member, else on the value's spec
        final BigDecimalValueFacet bigDecimalValueFacet =
            getFacet(
                BigDecimalValueFacet.class,
                objectMember,
                valueAdapter != null ? valueAdapter.getSpecification() : null);
        if (bigDecimalValueFacet != null) {
          final Integer precision = bigDecimalValueFacet.getPrecision();
          final Integer scale = bigDecimalValueFacet.getScale();
          format = String.format("big-decimal(%d,%d)", precision, scale);
        }
      } else if (specClass == java.math.BigInteger.class) {
        // TODO: need to extend BigIntegerValueFacet similar to BigDecimalValueFacet
      }
      JsonValueEncoder.appendValueAndFormat(spec, valueAdapter, representation, format);
      return;
    }

    final RenderFacet renderFacet = objectMember.getFacet(RenderFacet.class);
    boolean eagerlyRender =
        renderFacet != null
            && renderFacet.value() == Type.EAGERLY
            && rendererContext.canEagerlyRender(valueAdapter);

    if (valueAdapter == null) {
      representation.mapPut("value", NullNode.getInstance());
    } else {
      final TitleFacet titleFacet = spec.getFacet(TitleFacet.class);
      final String title = titleFacet.title(valueAdapter, rendererContext.getLocalization());

      final LinkBuilder valueLinkBuilder =
          DomainObjectReprRenderer.newLinkToBuilder(rendererContext, Rel.VALUE, valueAdapter)
              .withTitle(title);
      if (eagerlyRender) {
        final DomainObjectReprRenderer renderer =
            new DomainObjectReprRenderer(
                rendererContext, getLinkFollowSpecs(), JsonRepresentation.newMap());
        renderer.with(valueAdapter);
        if (mode.isEventSerialization()) {
          renderer.asEventSerialization();
        }

        valueLinkBuilder.withValue(renderer.render());
      }

      representation.mapPut("value", valueLinkBuilder.build());
    }
  }
 private Object argValueFor(final int i) {
   if (objectMember.isContributed()) {
     final ObjectActionParameter actionParameter = objectMember.getParameters().get(i);
     if (actionParameter.getSpecification().isOfType(objectAdapter.getSpecification())) {
       return DomainObjectReprRenderer.newLinkToBuilder(rendererContext, Rel.VALUE, objectAdapter)
           .build();
     }
   }
   // force a null into the map
   return NullNode.getInstance();
 }
Esempio n. 3
0
 public static Schema.Field generateAvroField(SchemaField field) {
   return new Schema.Field(
       field.getName(), generateAvroSchema(field.getType()), null, NullNode.getInstance());
 }