@Override
  public void debugData(final DebugBuilder debug) {
    facetDecoratorSet.debugData(debug);
    debug.appendln();

    debug.appendTitle("Specifications");
    final List<ObjectSpecification> specs = Lists.newArrayList(allSpecifications());
    Collections.sort(specs, ObjectSpecification.COMPARATOR_SHORT_IDENTIFIER_IGNORE_CASE);
    for (final ObjectSpecification spec : specs) {
      StringBuffer str = new StringBuffer();
      str.append(spec.isAbstract() ? "A" : ".");
      str.append(spec.isService() ? "S" : ".");
      str.append(ChoicesFacetUtils.hasChoices(spec) ? "B" : ".");
      str.append(spec.isParentedOrFreeCollection() ? "C" : ".");
      str.append(spec.isNotCollection() ? "O" : ".");
      str.append(spec.isParseable() ? "P" : ".");
      str.append(spec.isEncodeable() ? "E" : ".");
      str.append(spec.isValueOrIsParented() ? "A" : ".");

      final boolean hasIdentity =
          !(spec.isParentedOrFreeCollection() || spec.isParented() || spec.isValue());
      str.append(hasIdentity ? "I" : ".");
      str.append("  ");
      str.append(spec.getFullIdentifier());

      debug.appendPreformatted(spec.getShortIdentifier(), str.toString());
    }
  }
Beispiel #2
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");
  }
Beispiel #3
0
  private static void simpleObject(
      final ObjectAdapter collectionAdapter, final DebugBuilder debugBuilder) {
    debugBuilder.appendln(collectionAdapter.titleString());
    final ObjectSpecification objectSpec = collectionAdapter.getSpecification();
    if (objectSpec.isParentedOrFreeCollection()) {
      final CollectionFacet facet =
          CollectionFacetUtils.getCollectionFacetFromSpec(collectionAdapter);
      int i = 1;
      for (final ObjectAdapter element : facet.collection(collectionAdapter)) {
        debugBuilder.appendln(i++ + " " + element.titleString());
      }
    } else {
      // object is a regular Object
      try {
        final List<ObjectAssociation> fields = objectSpec.getAssociations(Contributed.EXCLUDED);
        for (int i = 0; i < fields.size(); i++) {
          final ObjectAssociation field = fields.get(i);
          final ObjectAdapter obj = field.get(collectionAdapter);

          final String name = field.getId();
          if (obj == null) {
            debugBuilder.appendln(name, "null");
          } else {
            debugBuilder.appendln(name, obj.titleString());
          }
        }
      } catch (final RuntimeException e) {
        debugBuilder.appendException(e);
      }
    }
  }
Beispiel #4
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();
  }
Beispiel #5
0
 public String getClassType() {
   boolean service = false;
   for (ObjectSpecification subspecs : spec.subclasses()) {
     service = service || subspecs.isService();
   }
   return service || spec.isService()
       ? "2 Service"
       : spec.isValue()
           ? "3 Value"
           : spec.isParentedOrFreeCollection() ? "4 Collection" : "1 Object";
 }
 private void addIfReturnsSubtype(
     final ObjectAction serviceAction, final List<ObjectAction> matchingActionsToAppendTo) {
   final ObjectSpecification returnType = serviceAction.getReturnType();
   if (returnType == null) {
     return;
   }
   if (returnType.isParentedOrFreeCollection()) {
     final TypeOfFacet facet = serviceAction.getFacet(TypeOfFacet.class);
     if (facet != null) {
       final ObjectSpecification elementType = facet.valueSpec();
       addIfReturnsSubtype(serviceAction, elementType, matchingActionsToAppendTo);
     }
   } else {
     addIfReturnsSubtype(serviceAction, returnType, matchingActionsToAppendTo);
   }
 }
Beispiel #7
0
  private static void specificationFields(
      final ObjectSpecification specification, final DebugBuilder debugBuilder) {
    final List<ObjectAssociation> fields = specification.getAssociations(Contributed.EXCLUDED);
    debugBuilder.appendln("All");
    debugBuilder.indent();
    for (int i = 0; i < fields.size(); i++) {
      debugBuilder.appendln((i + 1) + "." + fields.get(i).getId());
    }
    debugBuilder.unindent();

    final List<ObjectAssociation> fields2 =
        specification.getAssociations(
            Contributed.EXCLUDED, ObjectAssociation.Filters.VISIBLE_AT_LEAST_SOMETIMES);
    debugBuilder.appendln("Static");
    debugBuilder.indent();
    for (int i = 0; i < fields2.size(); i++) {
      debugBuilder.appendln((i + 1) + "." + fields2.get(i).getId());
    }
    debugBuilder.unindent();
    debugBuilder.appendln();

    try {
      if (fields.size() == 0) {
        debugBuilder.appendln("none");
      } else {
        for (int i = 0; i < fields.size(); i++) {

          final ObjectAssociation field = fields.get(i);
          debugBuilder.appendln(
              (i + 1) + "." + field.getId() + "  (" + field.getClass().getName() + ")");

          debugBuilder.indent();
          final String description = field.getDescription();
          if (description != null && !description.equals("")) {
            debugBuilder.appendln("Description", description);
          }
          final String help = field.getHelp();
          if (help != null && !help.equals("")) {
            debugBuilder.appendln(
                "Help",
                help.substring(0, Math.min(30, help.length())) + (help.length() > 30 ? "..." : ""));
          }

          debugBuilder.appendln("ID", field.getIdentifier());
          debugBuilder.appendln("Short ID", field.getId());
          debugBuilder.appendln("Name", field.getName());
          final String type =
              field.isOneToManyAssociation()
                  ? "Collection"
                  : field.isOneToOneAssociation() ? "Object" : "Unknown";
          debugBuilder.appendln("Type", type);
          final ObjectSpecification fieldSpec = field.getSpecification();
          final boolean hasIdentity =
              !(fieldSpec.isParentedOrFreeCollection()
                  || fieldSpec.isParented()
                  || fieldSpec.isValue());
          debugBuilder.appendln("Has identity", hasIdentity);
          debugBuilder.appendln("Spec", fieldSpec.getFullIdentifier());

          debugBuilder.appendln(
              "Flags",
              (field.isAlwaysHidden() ? "" : "Visible ")
                  + (field.isNotPersisted() ? "Not Persisted " : " ")
                  + (field.isMandatory() ? "Mandatory " : ""));

          final Class<? extends Facet>[] facets = field.getFacetTypes();
          if (facets.length > 0) {
            debugBuilder.appendln("Facets");
            debugBuilder.indent();
            boolean none = true;
            for (final Class<? extends Facet> facet : facets) {
              debugBuilder.appendln(field.getFacet(facet).toString());
              none = false;
            }
            if (none) {
              debugBuilder.appendln("none");
            }
            debugBuilder.unindent();
          }

          debugBuilder.appendln(field.debugData());

          debugBuilder.unindent();
        }
      }
    } catch (final RuntimeException e) {
      debugBuilder.appendException(e);
    }
  }