Ejemplo n.º 1
0
  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());
    }
  }
 @Override
 protected void addLinksIsisProprietary() {
   if (objectMember.isContributed()) {
     final ObjectAdapter serviceAdapter = contributingServiceAdapter();
     final JsonRepresentation contributedByLink =
         DomainObjectReprRenderer.newLinkToBuilder(
                 rendererContext, Rel.CONTRIBUTED_BY, serviceAdapter)
             .build();
     getLinks().arrayAdd(contributedByLink);
   }
 }
 private Object defaultFor(final ObjectActionParameter param) {
   final ObjectAdapter defaultAdapter = param.getDefault(objectAdapter);
   if (defaultAdapter == null) {
     return null;
   }
   // REVIEW: previously was using the spec of the parameter, but think instead it should be the
   // spec of the adapter itself
   // final ObjectSpecification defaultSpec = param.getSpecification();
   final ObjectSpecification defaultSpec = defaultAdapter.getSpecification();
   return DomainObjectReprRenderer.valueOrRef(rendererContext, defaultAdapter, defaultSpec);
 }
 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();
 }
 private Object choicesFor(final ObjectActionParameter param) {
   final ObjectAdapter[] choiceAdapters = param.getChoices(objectAdapter);
   if (choiceAdapters == null || choiceAdapters.length == 0) {
     return null;
   }
   final List<Object> list = Lists.newArrayList();
   for (final ObjectAdapter choiceAdapter : choiceAdapters) {
     // REVIEW: previously was using the spec of the parameter, but think instead it should be the
     // spec of the adapter itself
     // final ObjectSpecification choiceSpec = param.getSpecification();
     final ObjectSpecification choiceSpec = choiceAdapter.getSpecification();
     list.add(DomainObjectReprRenderer.valueOrRef(rendererContext, choiceAdapter, choiceSpec));
   }
   return list;
 }
Ejemplo n.º 6
0
  private Object propertyChoices() {
    final ObjectAdapter[] choiceAdapters = objectMember.getChoices(objectAdapter);
    if (choiceAdapters == null || choiceAdapters.length == 0) {
      return null;
    }
    final List<Object> list = Lists.newArrayList();
    for (final ObjectAdapter choiceAdapter : choiceAdapters) {
      // REVIEW: previously was using the spec of the member, but think instead it should be the
      // spec of the adapter itself
      // final ObjectSpecification choiceSpec = objectMember.getSpecification();

      // REVIEW: check that it works for ToDoItem$Category, though...
      final ObjectSpecification choiceSpec = objectAdapter.getSpecification();
      list.add(DomainObjectReprRenderer.valueOrRef(rendererContext, choiceAdapter, choiceSpec));
    }
    return list;
  }