public void resolveFuzzy(
     String identifier,
     org.eclipse.emf.ecore.EObject container,
     org.eclipse.emf.ecore.EReference reference,
     int position,
     org.emftext.language.office.resource.office.IOfficeReferenceResolveResult<
             org.eclipse.emf.ecore.EObject>
         result) {
   if (container == null) {
     return;
   }
   if (org.emftext.language.office.OfficePackage.eINSTANCE.getEmployee().isInstance(container)) {
     OfficeFuzzyResolveResult<org.emftext.language.office.Office> frr =
         new OfficeFuzzyResolveResult<org.emftext.language.office.Office>(result);
     String referenceName = reference.getName();
     org.eclipse.emf.ecore.EStructuralFeature feature =
         container.eClass().getEStructuralFeature(referenceName);
     if (feature != null
         && feature instanceof org.eclipse.emf.ecore.EReference
         && referenceName != null
         && referenceName.equals("worksIn")) {
       employeeWorksInReferenceResolver.resolve(
           identifier,
           (org.emftext.language.office.Employee) container,
           (org.eclipse.emf.ecore.EReference) feature,
           position,
           true,
           frr);
     }
   }
   if (org.emftext.language.office.OfficePackage.eINSTANCE.getEmployee().isInstance(container)) {
     OfficeFuzzyResolveResult<org.emftext.language.office.Employee> frr =
         new OfficeFuzzyResolveResult<org.emftext.language.office.Employee>(result);
     String referenceName = reference.getName();
     org.eclipse.emf.ecore.EStructuralFeature feature =
         container.eClass().getEStructuralFeature(referenceName);
     if (feature != null
         && feature instanceof org.eclipse.emf.ecore.EReference
         && referenceName != null
         && referenceName.equals("worksWith")) {
       employeeWorksWithReferenceResolver.resolve(
           identifier,
           (org.emftext.language.office.Employee) container,
           (org.eclipse.emf.ecore.EReference) feature,
           position,
           true,
           frr);
     }
   }
 }
  private void handleMultipleResults() {
    org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.EObject> list = null;
    Object temp = container.eGet(reference);
    if (temp instanceof org.eclipse.emf.common.util.EList<?>) {
      list = org.emftext.sdk.concretesyntax.resource.cs.util.CsCastUtil.cast(temp);
    }

    boolean first = true;
    for (org.emftext.sdk.concretesyntax.resource.cs.ICsReferenceMapping<ReferenceType> mapping :
        result.getMappings()) {
      if (first) {
        first = false;
      } else if (list != null) {
        addResultToList(mapping, proxy, list);
      } else {
        new org.emftext.sdk.concretesyntax.resource.cs.util.CsRuntimeUtil()
            .logError(
                container.eClass().getName()
                    + "."
                    + reference.getName()
                    + " has multiplicity 1 but was resolved to multiple elements",
                null);
      }
    }
  }
 /** {@inheritDoc} Overridden for debugging purposes. */
 @Override
 protected Predicate<Method> getPredicate(EObject context, EReference reference) {
   String methodName =
       "scope_" + reference.getEContainingClass().getName() + "_" + reference.getName();
   //		System.out.println(methodName + " ctx " + context.eClass().getName());
   return PolymorphicDispatcher.Predicates.forName(methodName, 2);
 }
  private void setEnabledAll(boolean enabled) {
    for (EClass e : elementSet) {
      prefs.putBoolean(e.getName(), enabled);

      for (EAttribute a : e.getEAllAttributes()) {
        prefs.putBoolean(e.getName() + "." + a.getName(), enabled);
      }

      for (EReference a : e.getEAllContainments()) {
        prefs.putBoolean(e.getName() + "." + a.getName(), enabled);
      }

      for (EReference a : e.getEAllReferences()) {
        prefs.putBoolean(e.getName() + "." + a.getName(), enabled);
      }
    }
  }
Exemplo n.º 5
0
  private void update(
      EReference ref, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) {
    if (eObj != null && eObj instanceof DataPointComponent) {
      eDef =
          ChartDefaultValueUtil.getPercentileDataPointDefObj(
              (DataPointComponent) eObj, (DataPointComponent) eDef);
    }

    update(ref.getEReferenceType(), ref.getName(), eParentObj, eObj, eRef, eDef);
  }
Exemplo n.º 6
0
 private static void getNsURI(StringBuilder s, EObject element) {
   if (element instanceof org.eclipse.ocl.examples.pivot.Package) {
     String nsURI = ((org.eclipse.ocl.examples.pivot.Package) element).getNsURI();
     if (nsURI != null) {
       s.append(nsURI);
       return;
     }
   } else if (element instanceof EPackage) {
     String nsURI = ((EPackage) element).getNsURI();
     if (nsURI != null) {
       s.append(nsURI);
       return;
     }
   }
   EObject eContainer = element.eContainer();
   if (eContainer instanceof org.eclipse.ocl.examples.pivot.Package) {
     String nsURI = ((org.eclipse.ocl.examples.pivot.Package) element).getNsURI();
     if (nsURI != null) {
       s.append(nsURI);
       s.append("#/");
     } else {
       getNsURI(s, eContainer);
     }
   } else if (eContainer instanceof EPackage) {
     String nsURI = ((EPackage) element).getNsURI();
     if (nsURI != null) {
       s.append(nsURI);
       s.append("#/");
     } else {
       getNsURI(s, eContainer);
     }
   } else if (eContainer == null) {
     String name = null;
     if (element instanceof org.eclipse.ocl.examples.pivot.Package) {
       name = ((org.eclipse.ocl.examples.pivot.Package) element).getName();
     } else if (element instanceof EPackage) {
       name = ((EPackage) element).getName();
     }
     if (name == null) {
       name = "$null$";
     }
     s.append(name);
     return;
   } else {
     getNsURI(s, eContainer);
   }
   EReference eFeature = element.eContainmentFeature();
   s.append("@");
   s.append(eFeature.getName());
   if (eFeature.isMany()) {
     int index = ((List<?>) eContainer.eGet(element.eContainingFeature())).indexOf(element);
     s.append(".");
     s.append(index);
   }
 }
Exemplo n.º 7
0
 @Override
 public IScope getScope(EObject context, EReference reference) {
   if (log.isDebugEnabled()) {
     log.debug(
         "enter getScope("
             + context
             + ", "
             + reference.getEContainingClass().getName()
             + "#"
             + reference.getName()
             + ")");
   }
   try {
     if (isFeatureCallScope(reference)) {
       if (!(context instanceof XAbstractFeatureCall)) {
         return IScope.NULLSCOPE;
       }
       return createFeatureCallScope((XAbstractFeatureCall) context, reference);
     }
     if (isConstructorCallScope(reference)) {
       return createConstructorCallScope(context, reference);
     }
     if (isTypeScope(reference)) {
       return createTypeScope(context, reference);
     }
     return super.getScope(context, reference);
   } catch (RuntimeException e) {
     log.error("error during scoping", e);
     throw e;
   } finally {
     if (log.isDebugEnabled()) {
       log.debug(
           "leave getScope("
               + context
               + ", "
               + reference.getEContainingClass().getName()
               + "#"
               + reference.getName()
               + ")");
     }
   }
 }
Exemplo n.º 8
0
 @Override
 public Object caseEReference(EReference object) {
   Attribute attrib = new Attribute(object.getName());
   attrib.type = getType(object.getEType());
   attrib.setBounds(object.getLowerBound(), object.getUpperBound());
   attrib.setStatic(false);
   attrib.setScope(Scope.PUBLIC);
   attrib.setContainment(object.isContainment());
   attrib.setDerived(object.isDerived());
   return attrib;
 }
Exemplo n.º 9
0
  private static void checkObject(
      EObject expected,
      EObject actual,
      Set<EStructuralFeature> excludeFeatures,
      Set<EObject> visited) {
    if (expected == null) {
      assertThat(actual, is(nullValue()));
      return;
    }

    if (visited.contains(expected)) return;

    visited.add(expected);

    assertThat(
        "Actual instance for type '" + expected.eClass().getName() + "' must not be null",
        actual,
        is(notNullValue()));

    for (EAttribute attribute : expected.eClass().getEAllAttributes()) {
      if (!excludeFeatures.contains(attribute))
        assertThat(
            "Attribute '"
                + attribute.getName()
                + "' on class '"
                + expected.eClass().getName()
                + "' did not match",
            actual.eGet(attribute),
            is(expected.eGet(attribute)));
    }

    for (EReference reference : expected.eClass().getEAllReferences()) {
      if (excludeFeatures.contains(reference)) continue;

      if (reference.isMany()) {
        @SuppressWarnings("unchecked")
        EList<EObject> expectedObjects = (EList<EObject>) expected.eGet(reference);
        @SuppressWarnings("unchecked")
        EList<EObject> actualObjects = (EList<EObject>) actual.eGet(reference);
        assertThat(
            "Reference size for '" + reference.getName() + "' does not match",
            actualObjects.size(),
            is(expectedObjects.size()));

        for (int i = 0; i < expectedObjects.size(); i++)
          checkObject(expectedObjects.get(i), actualObjects.get(i), excludeFeatures, visited);
      } else
        checkObject(
            (EObject) expected.eGet(reference),
            (EObject) actual.eGet(reference),
            excludeFeatures,
            visited);
    }
  }
 private boolean isAssociatorOrDissociatorFor(
     Method method, EReference eReference, final String prefix) {
   if (method.getParameterTypes().length != 1) {
     return false;
   }
   Class paramType = method.getParameterTypes()[0];
   Class referencedType = eReference.getEReferenceType().getInstanceClass();
   if (!paramType.equals(referencedType)) {
     return false;
   }
   String referenceName = eReference.getName();
   String associatorMethodName = prefix + new MethodNameHelper().titleCase(referenceName);
   if (!method.getName().equals(associatorMethodName)) {
     return false;
   }
   return true;
 }
  /**
   * {@inheritDoc}
   *
   * @generated NOT
   * @see
   *     org.eclipse.emf.emfstore.server.model.versioning.operations.provider.CompositeOperationItemProvider#getChildren(java.lang.Object)
   */
  @SuppressWarnings("unchecked")
  @Override
  public Collection<?> getChildren(Object object) {
    if (object instanceof SemanticCompositeOperation) {
      SemanticCompositeOperation operation = (SemanticCompositeOperation) object;
      ArrayList<Object> result = new ArrayList<Object>();

      OperationsFactory factory = OperationsFactory.eINSTANCE;
      for (EStructuralFeature feature : operation.eClass().getEStructuralFeatures()) {
        if (feature instanceof EReference) {
          EReference reference = (EReference) feature;

          ModelElementGroup referenceGroup = factory.createModelElementGroup();
          String key =
              "_UI_"
                  + reference.getEContainingClass().getName()
                  + "_"
                  + reference.getName()
                  + "_feature";
          referenceGroup.setName(getString(key));
          if (reference.isMany()) {
            List<ModelElementId> value = (List<ModelElementId>) operation.eGet(reference);
            referenceGroup.getModelElements().addAll(value);
          } else {
            ModelElementId value = (ModelElementId) operation.eGet(reference);
            referenceGroup.getModelElements().add(value);
          }
          result.add(referenceGroup);
        }
      }

      OperationGroup detailsGroup = factory.createOperationGroup();
      detailsGroup.setName("Sub Operations");
      detailsGroup.getOperations().addAll(operation.getSubOperations());
      result.add(detailsGroup);

      return result;
    }
    return super.getChildren(object);
  }
Exemplo n.º 12
0
 public String getClassAssociations(EClass eClass) {
   // if associations exist
   if (eClass.getEReferences().size() > 0) {
     StringBuilder sb = new StringBuilder();
     sb.append("\\subsubsection*{Associations}\n");
     sb.append("\\begin{itemize}\n");
     for (EReference eReference : eClass.getEReferences()) {
       sb.append("\\item ");
       // Name
       sb.append(eReference.getName()).append(": ");
       // Type
       // Works only for internal
       sb.append("\\nameref{").append(eReference.getEReferenceType().getName()).append("} ");
       // Mult
       sb.append(getMultiplicity(eReference)).append(" ");
       // Containement
       if (eReference.isContainment()) {
         sb.append("(containment) ");
       }
       // Description
       if (getLatexDocAnnotation(
               eReference, prefs.getPreferenceString(PreferenceConstants.P_DESCRIPTION_KEY))
           != null) {
         sb.append("\\newline\n")
             .append(
                 getLatexDocAnnotation(
                     eReference,
                     prefs.getPreferenceString(PreferenceConstants.P_DESCRIPTION_KEY)));
       }
       sb.append("\n");
     }
     sb.append("\\end{itemize}");
     return sb.toString();
   }
   return "\\subsubsection*{Associations} ~\\\\ No additional associations";
 }
  @Override
  protected void bindReference(Composite parent, EObject object, EReference reference) {
    if ("calledElementRef".equals(reference.getName())) { // $NON-NLS-1$
      if (isModelObjectEnabled(object.eClass(), reference)) {
        if (parent == null) parent = getAttributesParent();

        String displayName = ExtendedPropertiesProvider.getLabel(object, reference);
        ObjectEditor editor =
            new TextAndButtonObjectEditor(this, object, reference) {

              @Override
              protected void buttonClicked(int buttonId) {
                final IInputValidator validator =
                    new IInputValidator() {

                      @Override
                      public String isValid(String newText) {
                        if (newText == null || newText.isEmpty())
                          return Messages.JbpmCallActivityDetailComposite_Error_Empty;
                        if (!JbpmModelUtil.isProcessId(newText))
                          return Messages.JbpmCallActivityDetailComposite_Error_Invalid;
                        return null;
                      }
                    };

                String initialValue = ExtendedPropertiesProvider.getTextValue(object, feature);
                InputDialog dialog =
                    new InputDialog(
                        getShell(),
                        Messages.JbpmCallActivityDetailComposite_Title,
                        Messages.JbpmCallActivityDetailComposite_Message,
                        initialValue,
                        validator);
                if (dialog.open() == Window.OK) {
                  setValue(dialog.getValue());
                }
              }

              @Override
              public boolean setValue(final Object result) {
                if (result != object.eGet(feature)) {
                  TransactionalEditingDomain domain = getDiagramEditor().getEditingDomain();
                  domain
                      .getCommandStack()
                      .execute(
                          new RecordingCommand(domain) {
                            @Override
                            protected void doExecute() {
                              String id = result.toString();
                              CallableElement ce = null;
                              Definitions defs = ModelUtil.getDefinitions(object);
                              for (RootElement re : defs.getRootElements()) {
                                if (re instanceof ExternalProcess) {
                                  if (id.equals(re.getId())) {
                                    ce = (ExternalProcess) re;
                                    break;
                                  }
                                }
                              }
                              if (ce == null) {
                                ce = DroolsFactory.eINSTANCE.createExternalProcess();
                                ce.setName(id);
                                ce.setId(id);
                                defs.getRootElements().add(ce);
                              }

                              object.eSet(feature, ce);
                            }
                          });
                  //							if (getDiagramEditor().getDiagnostics()!=null) {
                  //
                  //	ErrorUtils.showErrorMessage(getDiagramEditor().getDiagnostics().getMessage());
                  //							}
                  //							else {
                  //								ErrorUtils.showErrorMessage(null);
                  //								updateText();
                  //								return true;
                  //							}
                  updateText();
                  return true;
                }
                return false;
              }
            };
        editor.createControl(parent, displayName);
      }
    } else super.bindReference(parent, object, reference);
  }
Exemplo n.º 14
0
  /**
   *
   * <!-- begin-user-doc -->
   * This method goes over a provided SEType (config file) entities with matching criteria defined
   * in config file. It goes over the attributes required to report on and collects min,max and avg
   * into extension objects for commodity and service entity.
   *
   * <p>Every hour it creates a list of {@link ReportingRecord} objects with data and returns this
   * list.
   * <!-- end-user-doc -->
   *
   * @param hourChanged true if the hour changed from the previous gathering of values.
   * @generated NOT
   */
  @Override
  public EList<ReportingRecord> getReportingRecordList(boolean hourChanged) {
    EList<ReportingRecord> returnList = new BasicEList<ReportingRecord>();
    long hourlyTimeStamp = 0l;
    try {
      RepositoryRegistry rg = RepositoryRegistry.vmtMANAGER;
      Set<VMTRootObject> vObjList = rg.getInstances(getSEType());

      if (hourChanged) {
        hourlyTimeStamp =
            (System.currentTimeMillis()
                - (1000 * 60 * 30)); // Give the record TS of the middle of the last hour
      }

      for (VMTRootObject vObj : vObjList) {
        boolean constraintfailed = false;
        // Check constraints
        for (Constraint constraint : getMatchingCriteria()) {
          if (!constraint.match(vObj)) {
            constraintfailed = true;
            break;
          }
        }

        // and skip if any of the constraints do not match
        if (constraintfailed) {
          continue;
        }

        ServiceEntity se = (ServiceEntity) vObj;
        if (DeployManager.vmtMANAGER.inDeploy(se)) {
          continue;
        }

        // Get the Extension for ServiceEntity
        ServiceEntityReportingExt seExt =
            (ServiceEntityReportingExt)
                se.findExtension(
                    ReportingExtensionsPackage.eINSTANCE.getServiceEntityReportingExt());
        if (seExt == null) {
          seExt = ReportingExtensionsFactory.eINSTANCE.createServiceEntityReportingExt();
          se.getExtendedBy().add(seExt);
        }

        for (NamedElementList neList : getNamedElementList()) {
          if (neList.getNamedElement().size() == 1) {
            EStructuralFeature attribute = (EStructuralFeature) neList.getNamedElement().get(0);
            // Only create a record if the attribute has been set already
            if (vObj.eIsSet(attribute)) {
              Object attributeValue = vObj.eGet(attribute);
              if (attributeValue instanceof List<?>) {
                if (hourChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          seExt, vObj, attribute, null, null, true, hourlyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  // reset only numProduces fields
                  seExt.resetValues(attribute);
                }
                // this condition for numProduces value
                seExt.setMinNumProduces(((List<?>) attributeValue).size());
                seExt.setMaxNumProduces(((List<?>) attributeValue).size());
                seExt.setProducesSum(((List<?>) attributeValue).size());
                // if(logger.isDebugEnabled())logger.debug("numProduces : min = " +
                // seExt.getMinNumProduces() + " max = " + seExt.getMaxNumProduces() + " sum = " +
                // seExt.getProducesSum());
              } else {
                double val = Double.parseDouble(attributeValue.toString());
                if (val > PRICE_THRESHOLD) {
                  val = PRICE_THRESHOLD;
                }

                if (attribute == AnalysisPackage.eINSTANCE.getServiceEntity_PriceIndex()) {
                  if (val < 0) {
                    if (logger.isDebugEnabled()) {
                      logger.error(
                          "SE : " + vObj.toVMTString() + " has a negative value of " + val);
                      for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
                        logger.debug(element.toString());
                      }
                    }
                    continue;
                  }
                }

                List<EAttribute> atts = seExt.getExtAttributes(attribute);
                for (EAttribute att : atts) {
                  seExt.eSet(att, val);
                }
                if (hourChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          seExt, vObj, attribute, null, null, false, hourlyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  // reset only UtilIndex fields
                  seExt.resetValues(attribute);
                }
              }
            }
            // Or get the list of attribute values and create a record for each
          } else {
            EReference reference = (EReference) neList.getNamedElement().get(0);
            ENamedElement commodity = neList.getNamedElement().get(1);
            EStructuralFeature attribute =
                (EStructuralFeature)
                    neList.getNamedElement().get(neList.getNamedElement().size() - 1);

            List<ENamedElement> nesCommodity =
                new ArrayList<ENamedElement>(neList.getNamedElement());
            nesCommodity.remove(neList.getNamedElement().size() - 1);
            List<Object> commodityList = vObj.getValues(nesCommodity);

            for (int i = 0; i < commodityList.size(); i++) {
              Commodity comm = (Commodity) commodityList.get(i);
              // get the attribute value from the commodity if it is set
              if (comm.eIsSet(attribute)) {
                Object attributeValue = comm.eGet(attribute);
                // logger.info("comm att " + comm.getName() + " " + attribute.getName() + " value =
                // " + attributeValue);
                CommodityReportingExt crExt = null;
                for (Extension ext : comm.getExtendedBy()) {
                  if (ext instanceof CommodityReportingExt) {
                    crExt = (CommodityReportingExt) ext;
                    if (crExt.getAttribute() == attribute) {
                      break;
                    } else {
                      crExt = null;
                    }
                  }
                }
                if (crExt == null) {
                  crExt = ReportingExtensionsFactory.eINSTANCE.createCommodityReportingExt();
                  crExt.setAttribute(attribute);
                  comm.getExtendedBy().add(crExt);
                }

                if (hourChanged) {
                  // Record Object
                  ReportingRecord record =
                      this.createReportingRecord(
                          crExt, vObj, attribute, commodity, comm, false, hourlyTimeStamp);
                  if (record != null) {
                    returnList.add(record);
                  }
                  crExt.resetValues();
                }
                // this condition for capacity, used and utilization values
                crExt.setMinUtilization(Double.parseDouble(attributeValue.toString()));
                if (attribute.equals(AnalysisPackage.eINSTANCE.getCommodity_Used())
                    && comm.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_Peak())) {
                  crExt.setMaxUtilization(comm.getPeak());
                } else if (attribute.equals(AnalysisPackage.eINSTANCE.getCommodity_Utilization())
                    && comm.eIsSet(AnalysisPackage.eINSTANCE.getCommodity_PeakUtilization())) {
                  crExt.setMaxUtilization(comm.getPeakUtilization());
                } else {
                  crExt.setMaxUtilization(Double.parseDouble(attributeValue.toString()));
                }
                crExt.setUtilSum(Double.parseDouble(attributeValue.toString()));

                float capacity = comm.getCapacity();
                if (capacity > CAPACITY_THRESHOLD) {
                  if (logger.isDebugEnabled()) {
                    logger.debug(
                        "Capacity for "
                            + se.getDisplayName()
                            + "::"
                            + comm.getDisplayName()
                            + " is "
                            + capacity
                            + ". Capping it to "
                            + CAPACITY_THRESHOLD);
                  }
                  capacity = CAPACITY_THRESHOLD;
                }
                crExt.setCapacity(capacity);
                crExt.setRelation(
                    RelationType.valueOf(reference.getName().toUpperCase()).getValue());
                crExt.setCommodityKey(comm.getKey());
                // if(logger.isDebugEnabled())logger.debug("comm -> " + attribute.getName() + " min
                // = " + crExt.getMinUtilization() + " max = " + crExt.getMaxUtilization() + " sum =
                // " + crExt.getUtilSum() + " cap = " + crExt.getCapacity());
              }
            }
          }
        }
      }
    } catch (Exception e) {
      logger.error("Exception in MetaRecordImpl.getReportingRecordList()", e);
    }
    return returnList;
  }
Exemplo n.º 15
0
 private Property getTargetPropertyEnd(EReference eReference, Association association) {
   return getPropertyByName(association.memberEnd, eReference.getName());
 }
  @Override
  protected Object get(InternalEObject object, EReference eReference, int index) {
    Map<Object, Object> cache = pCore.getActiveCache();
    EventAPI eventAPI = pCore.getEventAPI();
    if (!(eReference.getEType() instanceof EClass)) {
      Object r = super.get(object, eReference, index);
      if (r instanceof PersistentEObject) {
        Vertex v = graph.getVertex(((PersistentEObject) r).id());
        eventAPI.accessEvent(v, ((EObject) r).eClass());
      }
      return r;
    }

    PersistentEObject neoEObject =
        NeoEObjectAdapterFactoryImpl.getAdapter(object, PersistentEObject.class);
    if (eReference.isMany()) {
      NeoEMFIndexedCacheKey key =
          new NeoEMFIndexedCacheKey(neoEObject.id().toString(), eReference, index);
      if (cache.containsKey(key)) {
        pCore.hit();
        VertexWrapper wrapper = (VertexWrapper) cache.get(key);
        eventAPI.accessEvent(wrapper.getV(), wrapper.getEClass());
        return reifyVertex(wrapper);
      } else {
        pCore.miss();
        Vertex vertex = graph.getVertex(object);
        Iterator<Vertex> iterator =
            vertex
                .query()
                .labels(eReference.getName())
                .direction(Direction.OUT)
                .has(POSITION, index)
                .vertices()
                .iterator();
        if (iterator.hasNext()) {
          Vertex referencedVertex = iterator.next();
          InternalEObject reifiedObject = reifyVertex(referencedVertex);
          eventAPI.accessEvent(referencedVertex, graph.resolveInstanceOf(referencedVertex));
          return reifiedObject;
        } else {
          return null;
        }
      }
    } else {
      NeoEMFIndexedCacheKey key =
          new NeoEMFIndexedCacheKey(neoEObject.id().toString(), eReference, -1);
      if (cache.containsKey(key)) {
        pCore.hit();
        VertexWrapper wrapper = (VertexWrapper) cache.get(key);
        eventAPI.accessEvent(wrapper.getV(), wrapper.getEClass());
        return reifyVertex(wrapper);
      } else {
        pCore.miss();
        Vertex vertex = graph.getVertex(object);
        Iterator<Vertex> iterator =
            vertex.getVertices(Direction.OUT, eReference.getName()).iterator();
        if (iterator.hasNext()) {
          Vertex referencedVertex = iterator.next();
          eventAPI.accessEvent(referencedVertex, graph.resolveInstanceOf(referencedVertex));
          InternalEObject reifiedObject = reifyVertex(referencedVertex);
          return reifiedObject;
        } else {
          return null;
        }
      }
    }
  }
Exemplo n.º 17
0
 private static void getNsURI(@NonNull StringBuilder s, @NonNull EObject element) {
   if (element instanceof org.eclipse.ocl.pivot.Package) {
     String nsURI = ((org.eclipse.ocl.pivot.Package) element).getURI();
     if (nsURI != null) {
       s.append(nsURI);
       return;
     }
   } else if (element instanceof Model) {
     String nsURI = ((Model) element).getExternalURI();
     if (nsURI != null) {
       s.append(nsURI);
       return;
     }
   } else if (element instanceof EPackage) {
     String nsURI = ((EPackage) element).getNsURI();
     if (nsURI != null) {
       s.append(nsURI);
       return;
     }
   }
   EObject eContainer = element.eContainer();
   if ((eContainer instanceof org.eclipse.ocl.pivot.Package) || (eContainer instanceof Model)) {
     String nsURI = ((org.eclipse.ocl.pivot.Package) element).getURI();
     if (nsURI != null) {
       s.append(nsURI);
       s.append("#/");
     } else {
       @SuppressWarnings("null")
       @NonNull
       EObject eContainer2 = eContainer;
       getNsURI(s, eContainer2);
     }
   } else if (eContainer instanceof EPackage) {
     String nsURI = ((EPackage) element).getNsURI();
     if (nsURI != null) {
       s.append(nsURI);
       s.append("#/");
     } else {
       getNsURI(s, eContainer);
     }
   } else if (eContainer == null) {
     String name = null;
     if (element instanceof org.eclipse.ocl.pivot.Package) {
       name = ((org.eclipse.ocl.pivot.Package) element).getName();
     } else if (element instanceof EPackage) {
       name = ((EPackage) element).getName();
     }
     if (name == null) {
       name = "$null$";
     }
     s.append(name);
     return;
   } else {
     getNsURI(s, eContainer);
   }
   EReference eFeature = element.eContainmentFeature();
   s.append("@");
   s.append(eFeature.getName());
   if (eFeature.isMany()) {
     int index = ((List<?>) eContainer.eGet(element.eContainingFeature())).indexOf(element);
     s.append(".");
     s.append(index);
   }
 }
Exemplo n.º 18
0
  /**
   * Updates chart element object.
   *
   * @param expected class of expected chart element.
   * @param name chart element name
   * @param eParentObj container of chart element object.
   * @param eObj chart element object.
   * @param eRef reference chart object to be used to update chart object's values.
   * @param eDef default chart object to be used to update chart object's values.
   */
  public void update(
      EClass expected, String name, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) {
    if (eObj == null) {
      if (eRef != null) {
        if (eRef instanceof IChartObject) {
          eObj = ((IChartObject) eRef).copyInstance();
          ChartElementUtil.setEObjectAttribute(eParentObj, name, eObj, false);
        }
      } else if (eDef != null) {
        if (eDef instanceof IChartObject) {
          eObj = ((IChartObject) eDef).copyInstance();
          ChartElementUtil.setEObjectAttribute(eParentObj, name, eObj, false);
          return;
        }
      }
    }
    if (eObj == null || (eRef == null && eDef == null)) {
      return;
    }

    // Process visible case.
    if (contanisVisibleElement(eObj.eClass())) {
      if (eObj.eIsSet(eObj.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$
      {
        if (eObj.eGet(eObj.eClass().getEStructuralFeature("visible"))
            != Boolean.TRUE) // $NON-NLS-1$
        {
          // If the visible attribute is set to false, directly return, no need
          // to update other attributes.
          return;
        }
      } else {
        // If eObj isn't set visible and the visible attribute of
        // reference object is set to false, directly return, no need to
        // update other attributes.
        if (eRef != null
            && eRef.eIsSet(eRef.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$
        {
          if (eRef.eGet(eRef.eClass().getEStructuralFeature("visible"))
              != Boolean.TRUE) // $NON-NLS-1$
          {
            eObj.eSet(eRef.eClass().getEStructuralFeature("visible"), Boolean.FALSE); // $NON-NLS-1$
            return;
          }
        } else if (eDef != null
            && eDef.eIsSet(eDef.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$
        {
          if (eDef.eGet(eDef.eClass().getEStructuralFeature("visible"))
              != Boolean.TRUE) // $NON-NLS-1$
          {
            eObj.eSet(eDef.eClass().getEStructuralFeature("visible"), Boolean.FALSE); // $NON-NLS-1$
            return;
          }
        }
      }
    }

    EClass eClass = eObj.eClass();

    // attributes
    updateAttrs(eClass, eParentObj, eObj, eRef, eDef);

    // list attributes

    // references
    for (EReference ref : eClass.getEAllReferences()) {
      String childName = ref.getName();
      Object child = eObj.eGet(ref);
      Object refChild = eRef != null ? eRef.eGet(ref) : null;
      Object defChild = eDef != null ? eDef.eGet(ref) : null;
      EObject eChildParntObj = eObj;
      if (child == null) {
        if (refChild != null) {
          if (refChild instanceof IChartObject) {
            child = updateFromReference(childName, refChild, eChildParntObj);
          }
        } else if (defChild != null) {
          if (defChild instanceof IChartObject) {
            child = ((IChartObject) defChild).copyInstance();
            ChartElementUtil.setEObjectAttribute(eChildParntObj, childName, child, false);
            continue;
          }
        }
      }

      if (child != null) {
        if (ref.isMany()) {
          int size = ((List<?>) child).size();
          for (int i = 0; i < size; i++) {
            Object item = ((List<?>) child).get(i);
            Object refItem =
                (refChild == null || (i >= ((List<?>) refChild).size()))
                    ? null
                    : ((List<?>) refChild).get(i);
            Object defItem =
                (defChild == null || (i >= ((List<?>) defChild).size()))
                    ? null
                    : ((List<?>) defChild).get(i);
            update(ref, eObj, (EObject) item, (EObject) refItem, (EObject) defItem);
          }
        } else {
          update(ref, eObj, (EObject) child, (EObject) refChild, (EObject) defChild);
        }
      }
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext)
   */
  public IStatus validate(IValidationContext ctx) {
    if (DependencyChecker.newCheck) {
      return Status.OK_STATUS;
    }
    EObject eObj = ctx.getTarget();
    EMFEventType eType = ctx.getEventType();

    if (DEBUG) {
      if (eObj instanceof NamedElement) {
        NamedElement e = (NamedElement) eObj;
        System.out.println(
            "RelationshipConstraint.validate(): "
                + TngUtil.getTypeText(e)
                + ": '"
                + e.getName()
                + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      }
    }

    MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, 0, "", null); // $NON-NLS-1$

    // In the case of batch mode.
    if (eType == EMFEventType.NULL) {
      Collection features = new ArrayList(referencesToCheckForCircularDependency);
      features.retainAll(eObj.eClass().getEAllReferences());
      for (Iterator iter = features.iterator(); iter.hasNext(); ) {
        EReference ref = (EReference) iter.next();
        if (ref.isMany()) {
          for (Iterator iterator = ((List) eObj.eGet(ref)).iterator(); iterator.hasNext(); ) {
            Object o = iterator.next();
            IStatus status = DependencyChecker.checkCircularDependency(eObj, ref, o);
            if (!status.isOK()) {
              String msg = status.getMessage();
              if (StrUtil.isBlank(msg)) {
                msg =
                    NLS.bind(
                        ValidationResources.circularDependency_error,
                        ref.getEContainingClass().getName(),
                        ref.getName());
              }
              multiStatus.add(new ValidationStatus(IStatus.ERROR, 0, msg, eObj, ref));
            }
          }
        } else {
          Object o = eObj.eGet(ref);
          if (o != null) {
            IStatus status = DependencyChecker.checkCircularDependency(eObj, ref, o);
            if (!status.isOK()) {
              String msg = status.getMessage();
              if (StrUtil.isBlank(msg)) {
                msg =
                    NLS.bind(
                        ValidationResources.circularDependency_error,
                        ref.getEContainingClass().getName(),
                        ref.getName());
              }
              multiStatus.add(new ValidationStatus(IStatus.ERROR, 0, msg, eObj, ref));
            }
          }
        }
      }

      if (multiStatus.isOK()) {
        return ctx.createSuccessStatus();
      } else {
        return multiStatus;
      }
    }

    return ctx.createSuccessStatus();
  }
Exemplo n.º 20
0
 @Override
 public Object set(
     InternalEObject eObject, EStructuralFeature eFeature, int index, Object newValue) {
   IdEObject idEObject = (IdEObject) eObject;
   if (index == NO_INDEX) {
     if (clientIfcModel.getModelState() != ModelState.LOADING) {
       try {
         if (newValue != EStructuralFeature.Internal.DynamicValueHolder.NIL) {
           Bimsie1LowLevelInterface lowLevelInterface =
               clientIfcModel.getBimServerClient().getBimsie1LowLevelInterface();
           if (eFeature.getName().equals("wrappedValue")) {
             // Wrapped objects get the same oid as their "parent" object, so we know which object
             // the client wants to update. That's why we can use idEObject.getOid() here
             // We are making this crazy hack ever crazier, let's iterate over our parents
             // features, and see if there is one matching our wrapped type...
             // Seriously, when there are multiple fields of the same type, this fails miserably, a
             // real fix should probably store the parent-oid + feature name in the wrapped object
             // (requires two extra, volatile, fields),
             // or we just don't support this (just create a new wrapped object too), we could even
             // throw some sort of exception. Hack morally okay because it's client-side...
             EReference foundReference = null;
             if (clientIfcModel.contains(idEObject.getOid())) {
               IdEObject parentObject = clientIfcModel.get(idEObject.getOid());
               int found = 0;
               foundReference = null;
               for (EReference testReference : parentObject.eClass().getEAllReferences()) {
                 if (((EClass) testReference.getEType()).isSuperTypeOf(idEObject.eClass())) {
                   foundReference = testReference;
                   found++;
                   if (found > 1) {
                     throw new RuntimeException(
                         "Sorry, crazy hack could not resolve the right field, please let BIMserver developer know (debug info: "
                             + parentObject.eClass().getName()
                             + ", "
                             + idEObject.eClass().getName()
                             + ")");
                   }
                 }
               }
               if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
                 lowLevelInterface.setWrappedStringAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     foundReference.getName(),
                     idEObject.eClass().getName(),
                     (String) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
                 lowLevelInterface.setWrappedLongAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     foundReference.getName(),
                     idEObject.eClass().getName(),
                     (Long) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
                 lowLevelInterface.setWrappedDoubleAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     foundReference.getName(),
                     idEObject.eClass().getName(),
                     (Double) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
                 lowLevelInterface.setWrappedBooleanAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     foundReference.getName(),
                     idEObject.eClass().getName(),
                     (Boolean) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
                 lowLevelInterface.setWrappedIntegerAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     foundReference.getName(),
                     idEObject.eClass().getName(),
                     (Integer) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
                 throw new RuntimeException(
                     "Unimplemented " + eFeature.getEType().getName() + " " + newValue);
               }
             } else {
               if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
                 lowLevelInterface.setStringAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     (String) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
                 lowLevelInterface.setLongAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     (Long) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
                 lowLevelInterface.setDoubleAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     (Double) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
                 lowLevelInterface.setBooleanAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     (Boolean) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt()
                   || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
                 lowLevelInterface.setIntegerAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     (Integer) newValue);
               } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
                 lowLevelInterface.setByteArrayAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     (Byte[]) newValue);
               } else if (eFeature.getEType() instanceof EEnum) {
                 lowLevelInterface.setEnumAttribute(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     ((Enum<?>) newValue).toString());
               } else if (eFeature instanceof EReference) {
                 if (newValue == null) {
                   lowLevelInterface.setReference(
                       clientIfcModel.getTransactionId(),
                       idEObject.getOid(),
                       eFeature.getName(),
                       -1L);
                 } else {
                   lowLevelInterface.setReference(
                       clientIfcModel.getTransactionId(),
                       idEObject.getOid(),
                       eFeature.getName(),
                       ((IdEObject) newValue).getOid());
                 }
               } else {
                 throw new RuntimeException(
                     "Unimplemented " + eFeature.getEType().getName() + " " + newValue);
               }
             }
           } else {
             if (eFeature.getEType() == EcorePackage.eINSTANCE.getEString()) {
               lowLevelInterface.setStringAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   (String) newValue);
             } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getELong()
                 || eFeature.getEType() == EcorePackage.eINSTANCE.getELongObject()) {
               lowLevelInterface.setLongAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   (Long) newValue);
             } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()
                 || eFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
               lowLevelInterface.setDoubleAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   (Double) newValue);
             } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()
                 || eFeature.getEType() == EcorePackage.eINSTANCE.getEBooleanObject()) {
               lowLevelInterface.setBooleanAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   (Boolean) newValue);
             } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEInt()
                 || eFeature.getEType() == EcorePackage.eINSTANCE.getEIntegerObject()) {
               lowLevelInterface.setIntegerAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   (Integer) newValue);
             } else if (eFeature.getEType() == EcorePackage.eINSTANCE.getEByteArray()) {
               lowLevelInterface.setByteArrayAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   (Byte[]) newValue);
             } else if (eFeature.getEType() instanceof EEnum) {
               lowLevelInterface.setEnumAttribute(
                   clientIfcModel.getTransactionId(),
                   idEObject.getOid(),
                   eFeature.getName(),
                   ((Enum<?>) newValue).toString());
             } else if (eFeature instanceof EReference) {
               if (newValue == null) {
                 lowLevelInterface.setReference(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     -1L);
               } else {
                 lowLevelInterface.setReference(
                     clientIfcModel.getTransactionId(),
                     idEObject.getOid(),
                     eFeature.getName(),
                     ((IdEObject) newValue).getOid());
               }
             } else {
               throw new RuntimeException(
                   "Unimplemented " + eFeature.getEType().getName() + " " + newValue);
             }
           }
         }
       } catch (ServiceException e) {
         LOGGER.error("", e);
       } catch (PublicInterfaceNotFoundException e) {
         LOGGER.error("", e);
       }
     }
   } else {
     if (clientIfcModel.getModelState() != ModelState.LOADING) {
       try {
         Bimsie1LowLevelInterface lowLevelInterface =
             clientIfcModel.getBimServerClient().getBimsie1LowLevelInterface();
         if (newValue instanceof String) {
           lowLevelInterface.setStringAttributeAtIndex(
               clientIfcModel.getTransactionId(),
               idEObject.getOid(),
               eFeature.getName(),
               index,
               (String) newValue);
         } else if (newValue instanceof Double) {
           lowLevelInterface.setDoubleAttributeAtIndex(
               clientIfcModel.getTransactionId(),
               idEObject.getOid(),
               eFeature.getName(),
               index,
               (Double) newValue);
         } else if (newValue instanceof Boolean) {
           lowLevelInterface.setBooleanAttributeAtIndex(
               clientIfcModel.getTransactionId(),
               idEObject.getOid(),
               eFeature.getName(),
               index,
               (Boolean) newValue);
         } else if (newValue instanceof Integer) {
           lowLevelInterface.setIntegerAttributeAtIndex(
               clientIfcModel.getTransactionId(),
               idEObject.getOid(),
               eFeature.getName(),
               index,
               (Integer) newValue);
         } else if (newValue instanceof IdEObject) {
           lowLevelInterface.addReference(
               clientIfcModel.getTransactionId(),
               idEObject.getOid(),
               eFeature.getName(),
               ((IdEObject) newValue).getOid());
         } else {
           throw new RuntimeException(
               "Unimplemented " + eFeature.getEType().getName() + " " + newValue);
         }
       } catch (ServerException e) {
         LOGGER.error("", e);
       } catch (UserException e) {
         LOGGER.error("", e);
       } catch (PublicInterfaceNotFoundException e) {
         LOGGER.error("", e);
       }
     }
   }
   return super.set(eObject, eFeature, index, newValue);
 }