Exemplo 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());
    }
  }
Exemplo n.º 2
0
  void appendObjectPathsAndDefinitions() {
    // take copy to avoid concurrent modification exception
    final Collection<ObjectSpecification> allSpecs =
        Lists.newArrayList(specificationLoader.allSpecifications());
    for (final ObjectSpecification objectSpec : allSpecs) {

      final DomainServiceFacet domainServiceFacet = objectSpec.getFacet(DomainServiceFacet.class);
      if (domainServiceFacet != null) {
        continue;
      }
      final MixinFacet mixinFacet = objectSpec.getFacet(MixinFacet.class);
      if (mixinFacet != null) {
        continue;
      }
      if (visibility.isPublic() && !Util.isVisibleForPublic(objectSpec)) {
        continue;
      }
      if (objectSpec.isAbstract()) {
        continue;
      }
      if (objectSpec.isValue()) {
        continue;
      }
      // special cases
      if (classExcluder.exclude(objectSpec)) {
        continue;
      }

      final List<OneToOneAssociation> objectProperties = Util.propertiesOf(objectSpec, visibility);
      final List<OneToManyAssociation> objectCollections =
          Util.collectionsOf(objectSpec, visibility);
      final List<ObjectAction> objectActions =
          Util.actionsOf(objectSpec, visibility, classExcluder);

      if (objectProperties.isEmpty() && objectCollections.isEmpty()) {
        continue;
      }
      final ModelImpl isisModel = appendObjectPathAndModelDefinitions(objectSpec);
      updateObjectModel(isisModel, objectSpec, objectProperties, objectCollections);

      for (final OneToManyAssociation objectCollection : objectCollections) {
        appendCollectionTo(objectSpec, objectCollection);
      }

      for (final ObjectAction objectAction : objectActions) {
        appendObjectActionInvokePath(objectSpec, objectAction);
      }
    }
  }
Exemplo n.º 3
0
  private Property modelFor(final ObjectSpecification specification) {
    if (specification == null) {
      return new ObjectProperty();
    }

    // no "simple" representation for void or values
    final Class<?> correspondingClass = specification.getCorrespondingClass();
    if (correspondingClass == void.class || correspondingClass == Void.class) {
      return new ObjectProperty();
    }
    // no "simple" representation for values
    final Property property = valuePropertyFactory.newProperty(correspondingClass);
    if (property != null) {
      // was recognized as a value
      return new ObjectProperty();
    }

    if (specification.isParentedOrFreeCollection()) {
      TypeOfFacet typeOfFacet = specification.getFacet(TypeOfFacet.class);
      if (typeOfFacet != null) {
        ObjectSpecification elementSpec = typeOfFacet.valueSpec();
        if (elementSpec != null) {
          return arrayPropertyOf(elementSpec);
        }
      }
    }

    if (specification.getCorrespondingClass() == java.lang.Object.class) {
      return new ObjectProperty();
    }
    if (specification.getCorrespondingClass() == java.lang.Enum.class) {
      return new StringProperty();
    }
    return newRefProperty(objectTypeFor(specification) + "Repr");
  }
Exemplo n.º 4
0
  void appendServicePathsAndDefinitions() {
    // take copy to avoid concurrent modification exception
    final Collection<ObjectSpecification> allSpecs =
        Lists.newArrayList(specificationLoader.allSpecifications());
    for (final ObjectSpecification serviceSpec : allSpecs) {

      final DomainServiceFacet domainServiceFacet = serviceSpec.getFacet(DomainServiceFacet.class);
      if (domainServiceFacet == null) {
        continue;
      }
      if (visibility.isPublic()
          && domainServiceFacet.getNatureOfService() != NatureOfService.VIEW_REST_ONLY) {
        continue;
      }
      if (domainServiceFacet.getNatureOfService() != NatureOfService.VIEW_MENU_ONLY
          && domainServiceFacet.getNatureOfService() != NatureOfService.VIEW
          && domainServiceFacet.getNatureOfService() != NatureOfService.VIEW_REST_ONLY) {
        continue;
      }

      final List<ObjectAction> serviceActions =
          Util.actionsOf(serviceSpec, visibility, classExcluder);
      if (serviceActions.isEmpty()) {
        continue;
      }
      appendServicePath(serviceSpec);

      for (final ObjectAction serviceAction : serviceActions) {
        appendServiceActionInvokePath(serviceSpec, serviceAction);
      }
    }
  }
Exemplo n.º 5
0
  public static void specification(
      final ObjectSpecification specification, final DebugBuilder debugBuilder) {
    try {
      debugBuilder.appendTitle(specification.getClass().getName());
      debugBuilder.appendAsHexln("Hash code", specification.hashCode());
      debugBuilder.appendln("ID", specification.getIdentifier());
      debugBuilder.appendln("Full Name", specification.getFullIdentifier());
      debugBuilder.appendln("Short Name", specification.getShortIdentifier());
      debugBuilder.appendln("Singular Name", specification.getSingularName());
      debugBuilder.appendln("Plural Name", specification.getPluralName());
      debugBuilder.appendln("Description", specification.getDescription());
      debugBuilder.blankLine();
      debugBuilder.appendln("Features", featureList(specification));
      debugBuilder.appendln(
          "Type", specification.isParentedOrFreeCollection() ? "Collection" : "Object");
      if (specification.superclass() != null) {
        debugBuilder.appendln("Superclass", specification.superclass().getFullIdentifier());
      }
      debugBuilder.appendln("Interfaces", specificationNames(specification.interfaces()));
      debugBuilder.appendln("Subclasses", specificationNames(specification.subclasses()));
      debugBuilder.blankLine();
      debugBuilder.appendln("Service", specification.isService());
      debugBuilder.appendln("Encodable", specification.isEncodeable());
      debugBuilder.appendln("Parseable", specification.isParseable());
      debugBuilder.appendln("Aggregated", specification.isValueOrIsParented());
    } catch (final RuntimeException e) {
      debugBuilder.appendException(e);
    }

    if (specification instanceof DebuggableWithTitle) {
      ((DebuggableWithTitle) specification).debugData(debugBuilder);
    }

    debugBuilder.blankLine();

    debugBuilder.appendln("Facets");
    final Class<? extends Facet>[] facetTypes = specification.getFacetTypes();
    debugBuilder.indent();
    if (facetTypes.length == 0) {
      debugBuilder.appendln("none");
    } else {
      for (final Class<? extends Facet> type : facetTypes) {
        final Facet facet = specification.getFacet(type);
        debugBuilder.appendln(facet.toString());
      }
    }
    debugBuilder.unindent();
    debugBuilder.blankLine();

    debugBuilder.appendln("Fields");
    debugBuilder.indent();
    specificationFields(specification, debugBuilder);
    debugBuilder.unindent();

    debugBuilder.appendln("Object Actions");
    debugBuilder.indent();
    specificationActionMethods(specification, debugBuilder);
    debugBuilder.unindent();
  }
Exemplo n.º 6
0
 @Override
 ObjectAdapter recreateAdapter(
     final ObjectAdapterMemento oam, ConcurrencyChecking concurrencyChecking) {
   ObjectSpecId objectSpecId = oam.objectSpecId;
   ObjectSpecification objectSpec = SpecUtils.getSpecificationFor(objectSpecId);
   final EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
   return encodableFacet.fromEncodedString(oam.encodableValue);
 }
 @Override
 public <Q extends Facet> Q getFacet(final Class<Q> facetType) {
   final Q facet = super.getFacet(facetType);
   Q noopFacet = null;
   if (isNotANoopFacet(facet)) {
     return facet;
   } else {
     noopFacet = facet;
   }
   if (interfaces() != null) {
     final List<ObjectSpecification> interfaces = interfaces();
     for (int i = 0; i < interfaces.size(); i++) {
       final ObjectSpecification interfaceSpec = interfaces.get(i);
       if (interfaceSpec == null) {
         // HACK: shouldn't happen, but occurring on occasion when
         // running
         // XATs under JUnit4. Some sort of race condition?
         continue;
       }
       final Q interfaceFacet = interfaceSpec.getFacet(facetType);
       if (isNotANoopFacet(interfaceFacet)) {
         return interfaceFacet;
       } else {
         if (noopFacet == null) {
           noopFacet = interfaceFacet;
         }
       }
     }
   }
   // search up the inheritance hierarchy
   final ObjectSpecification superSpec = superclass();
   if (superSpec != null) {
     final Q superClassFacet = superSpec.getFacet(facetType);
     if (isNotANoopFacet(superClassFacet)) {
       return superClassFacet;
     }
   }
   return noopFacet;
 }
Exemplo n.º 8
0
  private void init(final ObjectAdapter adapter) {

    final ObjectSpecification specification = adapter.getSpecification();

    final EncodableFacet encodableFacet = specification.getFacet(EncodableFacet.class);
    final boolean isEncodable = encodableFacet != null;
    if (isEncodable) {
      encodableValue = encodableFacet.toEncodedString(adapter);
      type = Type.ENCODEABLE;
      return;
    }

    final RootOid oid = (RootOid) adapter.getOid();
    if (oid.isTransient()) {
      transientMemento = new Memento(adapter);
      type = Type.TRANSIENT;
      return;
    }

    persistentOidStr = oid.enString(getOidMarshaller());
    type = Type.PERSISTENT;
  }
Exemplo n.º 9
0
 static String objectTypeFor(final ObjectSpecification objectSpec) {
   return objectSpec.getFacet(ObjectSpecIdFacet.class).value().asString();
 }
 private TypicalLengthFacet getTypicalLengthFacet(final Class<?> type) {
   final ObjectSpecification paramTypeSpec = getSpecificationLoader().loadSpecification(type);
   return paramTypeSpec.getFacet(TypicalLengthFacet.class);
 }
 private DescribedAsFacet getDescribedAsFacet(final Class<?> type) {
   final ObjectSpecification paramTypeSpec = getSpecificationLoader().loadSpecification(type);
   return paramTypeSpec.getFacet(DescribedAsFacet.class);
 }
Exemplo n.º 12
0
 private BookmarkPolicyFacet getBookmarkPolicyFacetIfAny() {
   final ObjectSpecId specId = getObjectAdapterMemento().getObjectSpecId();
   final ObjectSpecification objectSpec = getSpecificationLoader().lookupBySpecId(specId);
   return objectSpec.getFacet(BookmarkPolicyFacet.class);
 }