Ejemplo n.º 1
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  * <!-- begin-model-doc -->
  *
  * @param cr The receiving '<em><b>CR</b></em>' model object.
  * @param diagnostics The chain of diagnostics to which problems are to be appended.
  * @param context The cache of context-specific information.
  *     <!-- end-model-doc -->
  * @generated
  */
 public static boolean validateCR(
     CR cr, DiagnosticChain diagnostics, Map<Object, Object> context) {
   if (VALIDATE_CR__DIAGNOSTIC_CHAIN_MAP__EOCL_INV == null) {
     OCL.Helper helper = EOCL_ENV.createOCLHelper();
     helper.setContext(DatatypesPackage.Literals.CR);
     try {
       VALIDATE_CR__DIAGNOSTIC_CHAIN_MAP__EOCL_INV =
           helper.createInvariant(VALIDATE_CR__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP);
     } catch (ParserException pe) {
       throw new UnsupportedOperationException(pe.getLocalizedMessage());
     }
   }
   if (!EOCL_ENV.createQuery(VALIDATE_CR__DIAGNOSTIC_CHAIN_MAP__EOCL_INV).check(cr)) {
     if (diagnostics != null) {
       diagnostics.add(
           new BasicDiagnostic(
               Diagnostic.ERROR,
               DatatypesValidator.DIAGNOSTIC_SOURCE,
               DatatypesValidator.CR__CR,
               org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE.getString(
                   "_UI_GenericInvariant_diagnostic",
                   new Object[] {
                     "validateCR",
                     org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(cr, context)
                   }),
               new Object[] {cr}));
     }
     return false;
   }
   return true;
 }
Ejemplo n.º 2
0
  public RowSourceHandler(ContainerHandler parent, RowSource rowSource) throws ParserException {
    this.parent = parent;
    OCL ocl = OCL.newInstance(parent.getEnvironment());
    Helper helper = ocl.createOCLHelper();
    OCLExpression expression = helper.createQuery(rowSource.getExpression());
    query = ocl.createQuery(expression);

    environment = parent.getEnvironment().getFactory().createEnvironment(parent.getEnvironment());
    Variable variable = EcoreFactory.eINSTANCE.createVariable();
    variable.setType(((CollectionType) expression.getType()).getElementType());
    varName = rowSource.getVar();
    environment.addElement(varName, variable, true);
  }
Ejemplo n.º 3
0
  private List<FacetValue> performDerivation(Fragment subject, FacetType facetType) {

    DerivationData derivationData = facetType.getDerivationData();
    String valueAsString = null;

    if (derivationData instanceof DirectDerivation) {
      DirectDerivation directDerivation = (DirectDerivation) derivationData;
      String rule = directDerivation.getRule();

      OCLExpression oclExpression = parse(rule);

      if (oclExpression == null) return Collections.emptyList();

      Query query = OCL_ENV.createQuery(oclExpression);
      Object result = null;

      try {
        result = query.evaluate(subject);
      } catch (Exception e) {
        e.printStackTrace();
        result = null;
      }

      valueAsString = result.toString();

      FacetValue derivedValue = null;
      for (FacetValue value : facetType.getValues()) {
        if (value.getName().equals(valueAsString)) {
          derivedValue = value;
          break;
        }
      }

      if (derivedValue == null) {
        derivedValue = FacetManager.buildFacetValue(valueAsString, null, null, null);
        facetType.getValues().add(derivedValue);
      }

      return Collections.singletonList(derivedValue);
    }

    return Collections.emptyList();
  }