/**
  * Determines if this class represents the same class, or a subclass, of the specified class.
  *
  * <p>cf {@link Class#isAssignableFrom(Class)}, though target and parameter are the opposite way
  * around, ie:
  *
  * <pre>
  * cls1.isAssignableFrom(cls2);
  * </pre>
  *
  * <p>is equivalent to:
  *
  * <pre>
  * spec2.isOfType(spec1);
  * </pre>
  *
  * <p>Callable after {@link #introspectTypeHierarchyAndMembers()} has been called.
  */
 @Override
 public boolean isOfType(final ObjectSpecification specification) {
   // do the comparison using value types because of a possible aliasing/race condition
   // in matchesParameterOf when building up contributed associations
   if (specification.getSpecId().equals(this.getSpecId())) {
     return true;
   }
   for (final ObjectSpecification interfaceSpec : interfaces()) {
     if (interfaceSpec.isOfType(specification)) {
       return true;
     }
   }
   final ObjectSpecification superclassSpec = superclass();
   return superclassSpec != null ? superclassSpec.isOfType(specification) : false;
 }
  @Override
  protected ApplicationAdvice appliesTo(IModel<?> model) {
    if (model instanceof ScalarModel) {
      ScalarModel mo = (ScalarModel) model;
      ObjectSpecification os = mo.getTypeOfSpecification();
      ObjectSpecification locatableSpec =
          getSpecificationLoader().loadSpecification(ReportPrinter.class);
      if (os.isOfType(locatableSpec)) {
        System.out.println(locatableSpec);
        return ApplicationAdvice.APPLIES;
      }

      /* Remove
      Object obj = model.getObject();
      PropertyMemento pm = ((ScalarModel) model).getPropertyMemento();
      if (pm != null && pm.getIdentifier().equals("description")){
      	//return ApplicationAdvice.APPLIES_EXCLUSIVELY;
      }
      if (obj != null) {
      	if (obj instanceof PojoAdapter) {
      		PojoAdapter po = (PojoAdapter) obj;
      		ObjectSpecification os2 =  po.getSpecification();
      		System.out.println(os2.getSingularName());
      		System.out.println(po.getSpecification().getCorrespondingClass().getName());
      		if (po.getSpecification().getCorrespondingClass().isAnnotationPresent(Html.class)) {
      			//return ApplicationAdvice.APPLIES;
      		}
      	}
      }
      */
    }
    return ApplicationAdvice.DOES_NOT_APPLY;
  }
 private void addIfReturnsSubtype(
     final ObjectAction serviceAction,
     final ObjectSpecification actionType,
     final List<ObjectAction> matchingActionsToAppendTo) {
   if (actionType.isOfType(this)) {
     matchingActionsToAppendTo.add(serviceAction);
   }
 }
  @Override
  public ApplicationAdvice appliesTo(IModel<?> model) {
    if (!(model instanceof EntityCollectionModel)) {
      return ApplicationAdvice.DOES_NOT_APPLY;
    }

    EntityCollectionModel entityCollectionModel = (EntityCollectionModel) model;
    if (entityCollectionModel.hasSelectionHandler()) {
      return ApplicationAdvice.DOES_NOT_APPLY;
    }

    ObjectSpecification typeOfSpec = entityCollectionModel.getTypeOfSpecification();
    ObjectSpecification pieChartableSpec =
        IsisContext.getSpecificationLoader().loadSpecification(PieChartable.class);
    return appliesIf(typeOfSpec.isOfType(pieChartableSpec));
  }
Example #5
0
  private FormState validateObject(
      final RequestContext context,
      final ObjectAdapter object,
      final List<ObjectAssociation> fields) {
    final FormState formState = new FormState();
    for (int i = 0; i < fields.size(); i++) {
      final ObjectAssociation field = fields.get(i);
      final String fieldId = field.getId();
      String newEntry = context.getParameter(fieldId);
      if (fields.get(i).isOneToManyAssociation()) {
        continue;
      }
      if (fields
          .get(i)
          .isVisible(IsisContext.getAuthenticationSession(), object, where)
          .isVetoed()) {
        continue;
      }
      if (field.isUsable(IsisContext.getAuthenticationSession(), object, where).isVetoed()) {
        continue;
      }

      if (newEntry != null && newEntry.equals("-OTHER-")) {
        newEntry = context.getParameter(fieldId + "-other");
      }

      if (newEntry == null) {
        // TODO duplicated in EditObject; line 97
        final ObjectSpecification spec = field.getSpecification();
        if (spec.isOfType(IsisContext.getSpecificationLoader().loadSpecification(boolean.class))
            || spec.isOfType(
                IsisContext.getSpecificationLoader().loadSpecification(Boolean.class))) {
          newEntry = FALSE;
        } else {
          continue;
        }
      }
      final FieldEditState fieldState = formState.createField(fieldId, newEntry);

      Consent consent = null;
      if (field.isMandatory() && (newEntry.equals("") || newEntry.equals("NULL"))) {
        consent = new Veto(field.getName() + " required");
        formState.setError("Not all fields have been set");
      } else if (field.getSpecification().containsFacet(ParseableFacet.class)) {
        try {
          final ParseableFacet facet = field.getSpecification().getFacet(ParseableFacet.class);
          final ObjectAdapter originalValue = field.get(object);
          Localization localization = IsisContext.getLocalization();
          final ObjectAdapter newValue =
              facet.parseTextEntry(originalValue, newEntry, localization);
          consent = ((OneToOneAssociation) field).isAssociationValid(object, newValue);
          fieldState.setValue(newValue);
        } catch (final TextEntryParseException e) {
          consent = new Veto(e.getMessage());
          // formState.setError("Not all fields have been entered correctly");
        }

      } else {
        final ObjectAdapter associate =
            newEntry.equals("null") ? null : context.getMappedObject(newEntry);
        if (associate != null) {
          IsisContext.getPersistenceSession().resolveImmediately(associate);
        }
        consent = ((OneToOneAssociation) field).isAssociationValid(object, associate);
        fieldState.setValue(associate);
      }
      if (consent.isVetoed()) {
        fieldState.setError(consent.getReason());
        formState.setError("Not all fields have been entered correctly");
      }
    }

    // TODO check the state of the complete object.
    return formState;
  }