@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());
    }
  }
示例#2
0
 public String getClassName() {
   final String fullIdentifier = spec.getFullIdentifier();
   final int lastDot = fullIdentifier.lastIndexOf(".");
   return lastDot > 0 && lastDot < fullIdentifier.length() - 1
       ? fullIdentifier.substring(lastDot + 1, fullIdentifier.length())
       : fullIdentifier;
 }
示例#3
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();
  }
 public static void addTargetBlankIfActionReturnsUrl(
     final AbstractLink link, final ObjectAction action) {
   final ObjectSpecification returnType = action.getReturnType();
   if (returnType != null && "java.net.URL".equals(returnType.getFullIdentifier())) {
     link.add(new AttributeAppender("target", Model.of("_blank")));
     link.add(new CssClassAppender("noVeil"));
   }
 }
 @Override
 public void validateSpecifications(ValidationFailures validationFailures) {
   final Map<ObjectSpecId, ObjectSpecification> specById = Maps.newHashMap();
   for (final ObjectSpecification objSpec : allSpecifications()) {
     final ObjectSpecId objectSpecId = objSpec.getSpecId();
     if (objectSpecId == null) {
       continue;
     }
     final ObjectSpecification existingSpec = specById.put(objectSpecId, objSpec);
     if (existingSpec == null) {
       continue;
     }
     validationFailures.add(
         "Cannot have two entities with same object type (@ObjectType facet or equivalent) Value; "
             + "both %s and %s are annotated with value of ''%s''.",
         existingSpec.getFullIdentifier(), objSpec.getFullIdentifier(), objectSpecId);
   }
 }
  @Override
  protected void resetCollectionParent(
      final DatabaseConnector connector,
      final ObjectAdapter parent,
      final Iterator<ObjectAdapter> elements) {
    LOG.debug("Saving polymorphic list");

    ObjectSpecification elementSpecification;
    while (elements.hasNext()) {
      final ObjectAdapter thisAdapter = elements.next();
      elementSpecification = thisAdapter.getSpecification();

      // Reinstall collection parent
      final StringBuffer update = new StringBuffer();
      update.append("INSERT INTO ");
      update.append(table);
      update.append(" (");
      // list of column names
      super.getIdMapping().appendColumnNames(update);
      update.append("," + getForeignKeyName());
      update.append(", " + itemIdColumnName);
      update.append("," + classColumnName);
      update.append(") VALUES (");

      // Row ID column
      final Object pojo = thisAdapter.getObject();
      final RootOid transientRootOid = oidGenerator.createTransientOid(pojo);

      final RootOid persistentRootOid = oidGenerator.createPersistent(pojo, transientRootOid);

      polyIdMapper.appendObjectId(connector, update, persistentRootOid);

      // polyIdMapper.appendObjectId(connector, update,
      // thisAdapter.getOid());
      update.append(",");

      // Foreign key ID column
      getForeignKeyMapping().appendInsertValues(connector, update, parent);
      update.append(",");

      // item Id column
      final RootOid oid = (RootOid) thisAdapter.getOid();
      getIdMapping().appendObjectId(connector, update, oid);

      // Class name column
      update.append(",?)");
      connector.addToQueryValues(elementSpecification.getFullIdentifier());

      connector.insert(update.toString());
    }
  }
  public boolean hasInstances(final ObjectSpecification specification) {
    ensureOpened();
    ensureInTransaction();

    if (LOG.isDebugEnabled()) {
      LOG.debug("hasInstances: class=" + specification.getFullIdentifier());
    }

    if (!specification.persistability().isPersistable()) {
      LOG.warn("hasInstances: trying to run for non-persistent class " + specification);
      return false;
    }

    final Query query =
        QueryUtil.createQuery(getPersistenceManager(), "o", "select o.id", specification, null);
    throw new NotYetImplementedException();
    // query.set.setMaxResults(1);
    // return !query.getResultList().isEmpty();
  }
示例#8
0
  void updateObjectModel(
      final ModelImpl model,
      final ObjectSpecification objectSpecification,
      final List<OneToOneAssociation> objectProperties,
      final List<OneToManyAssociation> objectCollections) {

    final String objectType = objectTypeFor(objectSpecification);
    final String className = objectSpecification.getFullIdentifier();

    model.type("object").description(String.format("%s (%s)", objectType, className));

    for (OneToOneAssociation objectProperty : objectProperties) {
      model.property(objectProperty.getId(), propertyFor(objectProperty.getSpecification()));
    }

    for (OneToManyAssociation objectCollection : objectCollections) {
      final ObjectSpecification elementSpec = objectCollection.getSpecification();
      model.property(objectCollection.getId(), arrayPropertyOf(elementSpec));
    }
  }
示例#9
0
 public String getPackageName() {
   final String fullIdentifier = spec.getFullIdentifier();
   final int lastDot = fullIdentifier.lastIndexOf(".");
   return lastDot > 0 ? fullIdentifier.substring(0, lastDot) : fullIdentifier;
 }
示例#10
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);
    }
  }
 @Override
 public int compare(final ObjectSpecification o1, final ObjectSpecification o2) {
   return o1.getFullIdentifier().compareTo(o2.getFullIdentifier());
 }
 @Override
 public String apply(final ObjectSpecification from) {
   return from.getFullIdentifier();
 }