Esempio n. 1
0
  @Override
  public @NonNull MAVOTruthValue checkConstraint(
      @NonNull Model model,
      ExtendibleElementConstraint constraint,
      @NonNull MIDLevel constraintLevel) {

    String javaClassName = constraint.getImplementation();
    String modelTypeUri =
        (constraintLevel == MIDLevel.INSTANCES)
            ? ((Model) constraint.eContainer()).getMetatypeUri()
            : ((Model) constraint.eContainer()).getUri();
    try {
      IJavaModelConstraint javaConstraint =
          (IJavaModelConstraint)
              MultiModelTypeRegistry.getTypeBundle(modelTypeUri)
                  .loadClass(javaClassName)
                  .getConstructor()
                  .newInstance();

      return javaConstraint.validate(model);
    } catch (Exception e) {
      MMINTException.print(
          IStatus.WARNING, "Java constraint error, evaluating to false: " + javaClassName, e);
      return MAVOTruthValue.FALSE;
    }
  }
Esempio n. 2
0
  /** @generated NOT */
  public KleisliModel kleisliCreateType(KleisliModelEndpoint containerModelTypeEndpoint)
      throws MMINTException {

    // TODO MMINT[KLEISLI] should try to emulate normal api structure
    if (MultiModelConstraintChecker.isInstancesLevel(this)) {
      throw new MMINTException("Can't execute TYPES level operation on INSTANCES level element");
    }

    Model origModelType = containerModelTypeEndpoint.getTarget();
    String kModelTypeUri =
        getModelTypeExtendedUri(
            (KleisliModelRel) containerModelTypeEndpoint.eContainer(),
            origModelType,
            containerModelTypeEndpoint.getName());
    if (!MultiModelUtils.isFileOrDirectoryInState(kModelTypeUri)) {
      try {
        EPackage origRootModelTypeObj = origModelType.getEMFTypeRoot();
        String origModelTypeUri = origRootModelTypeObj.getNsURI();
        origRootModelTypeObj.setNsURI(
            origModelTypeUri + KleisliReasoningEngine.KLEISLI_MODELTYPE_URI_SUFFIX);
        MultiModelUtils.createModelFileInState(origRootModelTypeObj, kModelTypeUri);
        origRootModelTypeObj.setNsURI(
            origModelTypeUri); // restore original for packages coming from the registry
      } catch (Exception e) {
        throw new MMINTException("Error creating extended metamodel file");
      }
    }

    KleisliModel kModelType = KleisliFactory.eINSTANCE.createKleisliModel();
    kModelType.setUri(kModelTypeUri);
    kModelType.setName(origModelType.getName());
    kModelType.setLevel(MIDLevel.TYPES);
    kModelType.setSupertype(origModelType.getSupertype());
    kModelType.setDynamic(true);
    kModelType.setAbstract(origModelType.isAbstract());
    ExtendibleElementConstraint origConstraint = origModelType.getConstraint();
    if (origConstraint != null) {
      ExtendibleElementConstraint kConstraint =
          MIDFactory.eINSTANCE.createExtendibleElementConstraint();
      kConstraint.setLanguage(origConstraint.getLanguage());
      kConstraint.setImplementation(origConstraint.getImplementation());
      kModelType.setConstraint(kConstraint);
    }
    kModelType.setOrigin(ModelOrigin.CREATED);
    kModelType.setFileExtension(origModelType.getFileExtension());
    containerModelTypeEndpoint.setExtendedTarget(kModelType);

    return kModelType;
  }