Esempio n. 1
0
 private IScope scope_MetaClass_Type(EObject context, EReference reference) {
   Diagram diagram = EcoreUtil2.getContainerOfType(context, Diagram.class);
   // all eClasses that are direct containments of context's diagram model type
   final EClass diagramModelType = diagram.getModelType();
   if (diagramModelType == null || diagramModelType.getEPackage() == null) {
     return IScope.NULLSCOPE;
   }
   final Predicate<EClassifier> filter =
       new Predicate<EClassifier>() {
         @Override
         public boolean apply(EClassifier input) {
           return input instanceof EClass
               && input != diagramModelType
               && !((EClass) input).isAbstract();
         }
       };
   final Function<EClassifier, IEObjectDescription> toObjDesc =
       new Function<EClassifier, IEObjectDescription>() {
         @Override
         public IEObjectDescription apply(EClassifier input) {
           return EObjectDescription.create(qnProvider.apply(input), input);
         }
       };
   // Implicit import of the EPackage of the Diagram Model type
   final List<ImportNormalizer> normalizer =
       Collections.singletonList(
           new ImportNormalizer(qnProvider.apply(diagramModelType.getEPackage()), true, false));
   final ImportScope importDiagramTypePackage =
       new ImportScope(normalizer, delegateGetScope(context, reference), null, null, false);
   final Iterable<IEObjectDescription> descriptions =
       Iterables.transform(
           Iterables.filter(diagramModelType.getEPackage().getEClassifiers(), filter), toObjDesc);
   // the delegate scope will provide import scopes
   return MapBasedScope.createScope(importDiagramTypePackage, descriptions);
 }
Esempio n. 2
0
 public boolean packageURIsAreEqual(
     org.eclipse.emf.ecore.EClass classA, org.eclipse.emf.ecore.EClass classB) {
   String nsURI_A = classA.getEPackage().getNsURI();
   String nsURI_B = classB.getEPackage().getNsURI();
   if (nsURI_A == null && nsURI_B == null) {
     return true;
   }
   if (nsURI_A != null) {
     return nsURI_A.equals(nsURI_B);
   } else {
     return false;
   }
 }
Esempio n. 3
0
 public static String getFullName(EClass eClass) {
   EPackage ePackage = eClass.getEPackage();
   if (ePackage == null) {
     return eClass.getName();
   }
   return getFullName(ePackage) + "." + eClass.getName();
 }
Esempio n. 4
0
  public void handleRevisions(
      EClass eClass,
      CDOBranch branch,
      long timeStamp,
      boolean exactTime,
      CDORevisionHandler handler) {
    Query query = getObjectContainer().query();
    query.constrain(DB4ORevision.class);
    if (eClass != null) {
      query
          .descend(DB4ORevision.ATTRIBUTE_PACKAGE_NS_URI)
          .constrain(eClass.getEPackage().getNsURI());
      query.descend(DB4ORevision.ATTRIBUTE_CLASS_NAME).constrain(eClass.getName());
    }

    ObjectSet<?> revisions = query.execute();
    if (revisions.isEmpty()) {
      return;
    }

    for (Object revision : revisions.toArray()) {
      CDORevision cdoRevision = DB4ORevision.getCDORevision(getStore(), (DB4ORevision) revision);
      handler.handleRevision(cdoRevision);
    }
  }
  @Override
  /**
   * Create non-ServiceEntity object in SL probe. Checks if there exists another object with the
   * same name but a different class Else returns the existing object or creates using the Factory
   * instance for that class
   */
  protected VMTRootObject createObject(EClass ecls, String name) {
    VMTRootObject obj = null;

    if (name2obj.containsKey(name)) {
      if (name2obj.get(name).eClass().equals(ecls)) {
        obj = name2obj.get(name);
      } else {
        return handleObjectCreationDuplication(obj, ecls, name);
      }
    } else {
      obj = REPOSMAN.getObject(name);
      if (obj != null) {
        if (!obj.eClass().equals(ecls)) {
          return handleObjectCreationDuplication(obj, ecls, name);
        }
      } else {
        obj = (VMTRootObject) ecls.getEPackage().getEFactoryInstance().create(ecls);
        obj.setName(name);
        DISCMAN.incrementCount((VMTManagedEntity) obj);
      }

      name2obj.put(name, obj);
    }

    return obj;
  }
Esempio n. 6
0
 @Override
 public <@NonNull T extends NamedElement> T refreshElement(
     @NonNull Class<T> pivotClass, EClass pivotEClass, @NonNull EModelElement eModelElement) {
   EObject pivotElement = null;
   if (oldIdMap != null) {
     String id = ((XMLResource) eModelElement.eResource()).getID(eModelElement);
     if (id != null) {
       pivotElement = oldIdMap.get(id);
       if ((pivotElement != null) && (pivotElement.eClass() != pivotEClass)) {
         pivotElement = null;
       }
     }
   }
   if (pivotElement == null) {
     EFactory eFactoryInstance = pivotEClass.getEPackage().getEFactoryInstance();
     pivotElement = eFactoryInstance.create(pivotEClass);
   }
   if (!pivotClass.isAssignableFrom(pivotElement.getClass())) {
     throw new ClassCastException();
   }
   @SuppressWarnings("unchecked")
   T castElement = (T) pivotElement;
   Element oldElement = newCreateMap.put(eModelElement, castElement);
   assert oldElement == null;
   return castElement;
 }
 @Test
 public void test_cg_derived_property() throws ParserException, IOException {
   TestOCL ocl = createOCL();
   if (!EMFPlugin.IS_ECLIPSE_RUNNING) {
     OCLinEcoreStandaloneSetup.doSetup();
     //			OCLDelegateDomain.initialize(null);
   }
   MetamodelManager metamodelManager = ocl.getMetamodelManager();
   String metamodelText =
       "import ecore : 'http://www.eclipse.org/emf/2002/Ecore#/';\n"
           + "package pkg : pkg = 'pkg' {\n"
           + "  class A {\n"
           + "    property derivedInteger : Integer { derivation: 99; }\n"
           + "    property derivedDerivedInteger : Integer { derivation: 2 * derivedInteger;}\n"
           + "  }\n"
           + "}\n";
   Resource metamodel = cs2as(ocl, metamodelText);
   Model pivotModel = (Model) metamodel.getContents().get(0);
   org.eclipse.ocl.pivot.Package pivotPackage = pivotModel.getOwnedPackages().get(0);
   org.eclipse.ocl.pivot.Class pivotType = pivotPackage.getOwnedClasses().get(0);
   EClass eClass = metamodelManager.getEcoreOfPivot(EClass.class, pivotType);
   Object testObject = eClass.getEPackage().getEFactoryInstance().create(eClass);
   String textQuery = "self.derivedDerivedInteger";
   ocl.assertQueryEquals(testObject, 198, textQuery);
   ocl.dispose();
 }
Esempio n. 8
0
  static EPackage resolvePackage(EClass contextEClass, String name) {
    EPackage result = null;

    if (name.equals(contextEClass.getEPackage().getName())) {
      // the easy case
      result = contextEClass.getEPackage();
    } else {
      // search the superclass hierarchy for a matching package
      for (EClass next : contextEClass.getEAllSuperTypes()) {
        if (name.equals(next.getEPackage().getName())) {
          result = next.getEPackage();
          break;
        }
      }
    }

    return result;
  }
 /** Default constructor. */
 public BPMN2ObjectImpl() {
   super();
   EClass eClass = eClass();
   // BPMN2 meta model case : all object have an ID
   if (eClass.getEPackage().getName().equals("bpmn2")) {
     EAttribute idAttribute = eClass.getEIDAttribute();
     eSet(idAttribute, EcoreUtil.generateUUID());
   }
 }
 /**
  * @param copyObjs
  * @return 转换为粘贴对象
  */
 private Collection<Object> getPasteObjs(Collection<Object> copyObjs, EClass eclass) {
   List<Object> objs = new ArrayList<Object>();
   Map<EStructuralFeature, EStructuralFeature> map =
       new HashMap<EStructuralFeature, EStructuralFeature>();
   // 由第一个复制对象,找出复制对象和粘贴对象匹配的属性
   Iterator<Object> it = copyObjs.iterator();
   if (it.hasNext()) {
     Object obj = it.next();
     if (obj instanceof EObject) {
       EObject copyObj = (EObject) obj;
       // 如果是同一个编辑器内进行粘贴,直接返回复制对象集合
       if (copyObj.eClass().equals(eclass)) {
         return copyObjs;
       }
       // name一样,则表示属性匹配
       for (EStructuralFeature copyFeature : copyObj.eClass().getEAllStructuralFeatures()) {
         if (!exclude.contains(copyFeature)) {
           for (EStructuralFeature pasteFeature : eclass.getEAllStructuralFeatures()) {
             if (StringUtils.equals(copyFeature.getName(), pasteFeature.getName())) {
               map.put(copyFeature, pasteFeature);
               break;
             }
           }
         }
       }
     }
   }
   // 如果没有匹配的属性,则返回空集合
   if (map.isEmpty()) {
     return objs;
   }
   for (Object obj : copyObjs) {
     EObject copyObj = (EObject) obj;
     EObject pasteObj = eclass.getEPackage().getEFactoryInstance().create(eclass);
     for (Entry<EStructuralFeature, EStructuralFeature> entry : map.entrySet()) {
       EStructuralFeature copyFeature = entry.getKey();
       EStructuralFeature pasteFeature = entry.getValue();
       if (copyFeature instanceof EAttribute) {
         // 设置匹配属性值
         pasteObj.eSet(pasteFeature, copyObj.eGet(copyFeature));
       } else if (copyFeature instanceof EReference) {
         // 设置匹配子集
         Collection<Object> tmp = (Collection<Object>) copyObj.eGet(copyFeature);
         if (tmp != null) {
           pasteObj.eSet(
               pasteFeature,
               getPasteObjs(
                   EcoreUtil.copyAll(tmp), ((EReference) pasteFeature).getEReferenceType()));
         }
       }
     }
     objs.add(pasteObj);
   }
   return objs;
 }
Esempio n. 11
0
    protected boolean isClassAccepted(IEObjectDescription od, Collection<EClass> acceptedClasses) {
      EClass eclass = od.getEClass();
      EPackage epackage = eclass.getEPackage();
      // user supplied filter
      if (acceptedClasses != null
          && acceptedClasses.size() != 0
          && !acceptedClasses.contains(eclass)) return false;

      if (epackage == PPPackage.eINSTANCE) return isAcceptedByPP(od);
      if (epackage == PPTPPackage.eINSTANCE) return isAcceptedByPPTP(od);
      return false;
    }
Esempio n. 12
0
 private static String getQualifiedName(final EClass clazz, final ResourceSet resourceSet) {
   String _xifexpression = null;
   EPackage _ePackage = clazz.getEPackage();
   String _nsURI = _ePackage.getNsURI();
   boolean _equals = Objects.equal(_nsURI, "http://www.eclipse.org/2008/Xtext");
   if (_equals) {
     String _name = clazz.getName();
     _xifexpression = ("org.eclipse.xtext." + _name);
   } else {
     String _xifexpression_1 = null;
     EPackage _ePackage_1 = clazz.getEPackage();
     String _nsURI_1 = _ePackage_1.getNsURI();
     boolean _equals_1 = Objects.equal(_nsURI_1, "http://www.eclipse.org/emf/2002/Ecore");
     if (_equals_1) {
       String _name_1 = clazz.getName();
       _xifexpression_1 = ("org.eclipse.emf.ecore." + _name_1);
     } else {
       GenClass _genClass = GenModelUtil2.getGenClass(clazz, resourceSet);
       _xifexpression_1 = _genClass.getQualifiedInterfaceName();
     }
     _xifexpression = _xifexpression_1;
   }
   return _xifexpression;
 }
Esempio n. 13
0
 private IScope scope_NodeBehaviorSectionCreateableIn(EObject context, EReference reference) {
   Diagram diagram = EcoreUtil2.getContainerOfType(context, Diagram.class);
   NodeElement nodeElement = EcoreUtil2.getContainerOfType(context, NodeElement.class);
   if (diagram == null || nodeElement == null) {
     return IScope.NULLSCOPE;
   }
   // all eClasses that are direct containments of context's diagram model type
   final EClass diagramModelType = diagram.getModelType();
   if (diagramModelType == null || diagramModelType.getEPackage() == null) {
     return IScope.NULLSCOPE;
   }
   List<EReference> containmentReferences = new ArrayList<EReference>();
   for (EClassifier eClassifiers : diagramModelType.getEPackage().getEClassifiers()) {
     if (eClassifiers instanceof EClass) {
       for (EReference ref : ((EClass) eClassifiers).getEAllContainments()) {
         if (ref.getEType() instanceof EClass
             && ((EClass) ref.getEType()).isSuperTypeOf(nodeElement.getType())) {
           containmentReferences.add(ref);
         }
       }
     }
   }
   return Scopes.scopeFor(containmentReferences);
 }
Esempio n. 14
0
 private void collectAllEPackages(EPackage startEPackage, Set<EPackage> allEPackages) {
   if (allEPackages.contains(startEPackage)) {
     return;
   }
   allEPackages.add(startEPackage);
   for (EClassifier eClassifier : startEPackage.getEClassifiers()) {
     if (eClassifier instanceof EClass) {
       for (EClass superType : ((EClass) eClassifier).getESuperTypes()) {
         if (!superType.eIsProxy()) {
           collectAllEPackages(superType.getEPackage(), allEPackages);
         }
       }
     }
   }
 }
 @Override
 public int category(Object element) {
   if (!groupTypes) {
     return 0;
   }
   if (element instanceof org.eclipse.emf.ecore.EObject) {
     org.eclipse.emf.ecore.EObject eObject = (org.eclipse.emf.ecore.EObject) element;
     org.eclipse.emf.ecore.EClass eClass = eObject.eClass();
     org.eclipse.emf.ecore.EPackage ePackage = eClass.getEPackage();
     int packageID = getEPackageID(ePackage);
     int classifierID = eClass.getClassifierID();
     return packageID + classifierID;
   } else {
     return super.category(element);
   }
 }
 @Override
 public void resourceSetChanged(ResourceSetChangeEvent event) {
   for (Notification notification : event.getNotifications()) {
     if (notification.getNotifier() instanceof EObject
         && notification.getEventType() != Notification.REMOVING_ADAPTER
         && notification.getEventType() != Notification.RESOLVE) {
       EObject eObject = (EObject) notification.getNotifier();
       for (EClass eClass : eObject.eClass().getEAllSuperTypes()) {
         if (SGraphPackage.eINSTANCE == eClass.getEPackage()) {
           validationJob.cancel();
           validationJob.schedule(DELAY);
           return;
         }
       }
     }
   }
 }
Esempio n. 17
0
 @Override
 public @NonNull PackageId getMetapackageId(
     @NonNull EnvironmentFactoryInternal environmentFactory,
     org.eclipse.ocl.pivot.@NonNull Package asPackage) {
   if (asPackage instanceof PivotObjectImpl) {
     EObject eTarget = ((PivotObjectImpl) asPackage).getESObject();
     if (eTarget != null) {
       EClass eClass = eTarget.eClass();
       if (eClass != null) {
         EPackage ePackage = eClass.getEPackage();
         assert !"http://www.eclipse.org/uml2/5.0.0/UML".equals(ePackage.getNsURI());
         assert !"http://www.eclipse.org/uml2/5.0.0/Types".equals(ePackage.getNsURI());
       }
     }
   }
   return IdManager.METAMODEL;
 }
 /** @generated */
 private static ImageDescriptor getProvidedImageDescriptor(ENamedElement element) {
   if (element instanceof EStructuralFeature) {
     EStructuralFeature feature = ((EStructuralFeature) element);
     EClass eContainingClass = feature.getEContainingClass();
     EClassifier eType = feature.getEType();
     if (eContainingClass != null && !eContainingClass.isAbstract()) {
       element = eContainingClass;
     } else if (eType instanceof EClass && !((EClass) eType).isAbstract()) {
       element = eType;
     }
   }
   if (element instanceof EClass) {
     EClass eClass = (EClass) element;
     if (!eClass.isAbstract()) {
       return ComponentsDiagramEditorPlugin.getInstance()
           .getItemImageDescriptor(eClass.getEPackage().getEFactoryInstance().create(eClass));
     }
   }
   // TODO : support structural features
   return null;
 }
Esempio n. 19
0
  public Object getNewObject() {
    // Create the instance from the registered factory in case of extensions
    Object object = fTemplate.getEPackage().getEFactoryInstance().create(fTemplate);

    // Sticky
    if (object instanceof ICanvasModelSticky) {
      ICanvasModelSticky sticky = (ICanvasModelSticky) object;
      sticky.setTextPosition(ITextPosition.TEXT_POSITION_MIDDLE_CENTRE);
      if (fParam instanceof Color) {
        String color = ColorFactory.convertColorToString((Color) fParam);
        sticky.setFillColor(color);
      }
      sticky.setBorderColor("#C0C0C0"); // $NON-NLS-1$
    }

    // Block
    else if (object instanceof ICanvasModelBlock) {
      ICanvasModelBlock block = (ICanvasModelBlock) object;
      block.setTextPosition(ITextPosition.TEXT_POSITION_TOP_LEFT);
      block.setBorderColor("#000000"); // $NON-NLS-1$
    }

    // Image
    else if (object instanceof ICanvasModelImage) {
      ICanvasModelImage image = (ICanvasModelImage) object;
      image.setBorderColor("#000000"); // $NON-NLS-1$
    }

    // Canvas Connection
    else if (object instanceof ICanvasModelConnection) {
      ICanvasModelConnection connection = (ICanvasModelConnection) object;
      if (fParam instanceof Integer) {
        connection.setType((Integer) fParam);
      }
    }

    return object;
  }
Esempio n. 20
0
  public EObject getStaticInstance() {
    if (null == staticObj) {
      EClass eClass = eClass();
      if (eClass.isAbstract()) {
        throw new IllegalArgumentException(
            "Cannot create an instance of the abstract type: " + eClass.getName());
      }
      staticObj = eClass.getEPackage().getEFactoryInstance().create(eClass);

      //            System.out.println("New static instance: " + staticObj.hashCode() + " of type "
      // + eClass.getName());

      // Copy over all property values
      EPropertiesHolder props = eProperties();
      if (props.getEClass() != null && props.hasSettings()) {
        List features = eClass.getEAllStructuralFeatures();
        for (Iterator itr = features.iterator(); itr.hasNext(); ) {
          EStructuralFeature feature = (EStructuralFeature) itr.next();

          staticObj.eSet(feature, eGet(feature));
          //                    System.out.println("    F: " + feature.getName());
        }
      }

      // Update all external references
      for (Iterator itr = actions.iterator(); itr.hasNext(); ) {
        Action action = (Action) itr.next();
        action.doIt(staticObj);
      }

      // Update containing resource
      //            List contents = eResource().getContents();
      //            contents.remove(this);
      //            contents.add(staticObj);
    }

    return staticObj;
  }
Esempio n. 21
0
 //
 //	Find all EPackages in the source Resources
 //
 protected @NonNull Map<EPackage, Set<Resource>> analyzeResources(
     @NonNull Collection<Resource> resources) {
   List<Resource> allResources = new ArrayList<Resource>(resources);
   Map<EPackage, Set<Resource>> ePackage2resources = new HashMap<EPackage, Set<Resource>>();
   for (int i = 0; i < allResources.size(); i++) {
     Resource resource = allResources.get(i);
     System.out.println(i + "/" + allResources.size() + " analyzeResources " + resource.getURI());
     //			System.out.println(resource);
     Set<EClass> eClasses = new HashSet<EClass>();
     for (TreeIterator<EObject> tit = resource.getAllContents(); tit.hasNext(); ) {
       @SuppressWarnings("null")
       @NonNull
       EObject eObject = tit.next();
       @SuppressWarnings("null")
       @NonNull
       EClass eClass = eObject.eClass();
       eClasses.add(eClass);
     }
     Set<EPackage> ePackages = new HashSet<EPackage>();
     for (@SuppressWarnings("null") @NonNull EClass eClass : eClasses) {
       ePackages.add(eClass.getEPackage());
       for (@SuppressWarnings("null") @NonNull EClass eSuperClass : eClass.getEAllSuperTypes()) {
         ePackages.add(eSuperClass.getEPackage());
       }
     }
     for (@SuppressWarnings("null") @NonNull EPackage ePackage : ePackages) {
       Set<Resource> ePackageResources = ePackage2resources.get(ePackage);
       if (ePackageResources == null) {
         ePackageResources = new HashSet<Resource>();
         ePackage2resources.put(ePackage, ePackageResources);
       }
       ePackageResources.add(resource);
       List<ConstraintLocator> list = ValidityManager.getConstraintLocators(ePackage.getNsURI());
       if (list != null) {
         for (ConstraintLocator constraintLocator : list) {
           try {
             Collection<Resource> moreResources = constraintLocator.getImports(ePackage, resource);
             if (moreResources != null) {
               for (Resource anotherResource : moreResources) {
                 if (!allResources.contains(anotherResource)) {
                   allResources.add(anotherResource);
                 }
               }
             }
           } catch (Exception e) {
             Set<ConstraintLocator> badConstraintLocators2 = badConstraintLocators;
             if (badConstraintLocators2 == null) {
               synchronized (this) {
                 badConstraintLocators = badConstraintLocators2 = new HashSet<ConstraintLocator>();
               }
             }
             if (!badConstraintLocators2.contains(constraintLocator)) {
               synchronized (badConstraintLocators2) {
                 if (badConstraintLocators2.add(constraintLocator)) {
                   logger.error("ConstraintLocator " + constraintLocator + " failed", e);
                 }
               }
             }
           }
         }
       }
     }
   }
   return ePackage2resources;
 }
 public void initializeUsedGenPackages(final GenModel genModel) {
   this.genModelInitializer.initialize(genModel, true);
   HashSet<EPackage> _hashSet = new HashSet<EPackage>();
   final HashSet<EPackage> referencedEPackages = _hashSet;
   UniqueEList<EPackage> _uniqueEList = new UniqueEList<EPackage>();
   final List<EPackage> ePackages = _uniqueEList;
   EList<GenPackage> _genPackages = genModel.getGenPackages();
   for (final GenPackage genPackage : _genPackages) {
     EPackage _ecorePackage = genPackage.getEcorePackage();
     ePackages.add(_ecorePackage);
   }
   int i = 0;
   int _size = ePackages.size();
   boolean _lessThan = (i < _size);
   boolean _while = _lessThan;
   while (_while) {
     {
       final EPackage ePackage = ePackages.get(i);
       int _plus = (i + 1);
       i = _plus;
       final TreeIterator<EObject> allContents = ePackage.eAllContents();
       boolean _hasNext = allContents.hasNext();
       boolean _while_1 = _hasNext;
       while (_while_1) {
         {
           final EObject eObject = allContents.next();
           if ((eObject instanceof EPackage)) {
             allContents.prune();
           } else {
             EList<EObject> _eCrossReferences = eObject.eCrossReferences();
             for (final EObject eCrossReference : _eCrossReferences) {
               boolean _matched = false;
               if (!_matched) {
                 if (eCrossReference instanceof EClassifier) {
                   final EClassifier _eClassifier = (EClassifier) eCrossReference;
                   _matched = true;
                   final EPackage referencedEPackage = _eClassifier.getEPackage();
                   ePackages.add(referencedEPackage);
                   referencedEPackages.add(referencedEPackage);
                 }
               }
               if (!_matched) {
                 if (eCrossReference instanceof EStructuralFeature) {
                   final EStructuralFeature _eStructuralFeature =
                       (EStructuralFeature) eCrossReference;
                   _matched = true;
                   EClass _eContainingClass = _eStructuralFeature.getEContainingClass();
                   final EPackage referencedEPackage = _eContainingClass.getEPackage();
                   ePackages.add(referencedEPackage);
                   referencedEPackages.add(referencedEPackage);
                 }
               }
             }
           }
         }
         boolean _hasNext_1 = allContents.hasNext();
         _while_1 = _hasNext_1;
       }
     }
     int _size_1 = ePackages.size();
     boolean _lessThan_1 = (i < _size_1);
     _while = _lessThan_1;
   }
   for (final EPackage referencedEPackage : referencedEPackages) {
     GenPackage _findGenPackage = genModel.findGenPackage(referencedEPackage);
     boolean _equals = Objects.equal(_findGenPackage, null);
     if (_equals) {
       ToXcoreMapping _toXcoreMapping = this.mapper.getToXcoreMapping(referencedEPackage);
       XNamedElement _xcoreElement = _toXcoreMapping.getXcoreElement();
       GenBase _gen = this.mapper.getGen(_xcoreElement);
       GenPackage usedGenPackage = ((GenPackage) _gen);
       boolean _equals_1 = Objects.equal(usedGenPackage, null);
       if (_equals_1) {
         GenPackage _findLocalGenPackage = this.findLocalGenPackage(referencedEPackage);
         usedGenPackage = _findLocalGenPackage;
       }
       boolean _notEquals = (!Objects.equal(usedGenPackage, null));
       if (_notEquals) {
         EList<GenPackage> _usedGenPackages = genModel.getUsedGenPackages();
         _usedGenPackages.add(usedGenPackage);
       } else {
         Resource _eResource = genModel.eResource();
         ResourceSet _resourceSet = _eResource.getResourceSet();
         final EList<Resource> resources = _resourceSet.getResources();
         i = 0;
         boolean found = false;
         boolean _and = false;
         int _size_1 = resources.size();
         boolean _lessThan_1 = (i < _size_1);
         if (!_lessThan_1) {
           _and = false;
         } else {
           boolean _not = (!found);
           _and = (_lessThan_1 && _not);
         }
         boolean _while_1 = _and;
         while (_while_1) {
           {
             final Resource resource = resources.get(i);
             boolean _and_1 = false;
             URI _uRI = resource.getURI();
             String _fileExtension = _uRI.fileExtension();
             boolean _equals_2 = "genmodel".equals(_fileExtension);
             if (!_equals_2) {
               _and_1 = false;
             } else {
               EList<EObject> _contents = resource.getContents();
               boolean _isEmpty = _contents.isEmpty();
               boolean _not_1 = (!_isEmpty);
               _and_1 = (_equals_2 && _not_1);
             }
             if (_and_1) {
               EList<EObject> _contents_1 = resource.getContents();
               EObject _get = _contents_1.get(0);
               GenPackage _findGenPackage_1 = ((GenModel) _get).findGenPackage(referencedEPackage);
               usedGenPackage = _findGenPackage_1;
               boolean _notEquals_1 = (!Objects.equal(usedGenPackage, null));
               if (_notEquals_1) {
                 EList<GenPackage> _usedGenPackages_1 = genModel.getUsedGenPackages();
                 _usedGenPackages_1.add(usedGenPackage);
                 found = true;
               }
             }
             int _plus = (i + 1);
             i = _plus;
           }
           boolean _and_1 = false;
           int _size_2 = resources.size();
           boolean _lessThan_2 = (i < _size_2);
           if (!_lessThan_2) {
             _and_1 = false;
           } else {
             boolean _not_1 = (!found);
             _and_1 = (_lessThan_2 && _not_1);
           }
           _while_1 = _and_1;
         }
         boolean _not_1 = (!found);
         if (_not_1) {
           String _plus = ("No GenPackage found for " + referencedEPackage);
           RuntimeException _runtimeException = new RuntimeException(_plus);
           throw _runtimeException;
         }
       }
     }
   }
 }
  @Override
  public boolean process() throws BimserverDatabaseException, QueryException {
    if (getQueryObjectProvider().hasRead(oid)) {
      processPossibleIncludes(null, include);
      return true;
    }

    if (hasRun) {
      return true;
    }
    hasRun = true;
    if (oid == -1) {
      throw new BimserverDatabaseException("Cannot get object for oid " + oid);
    }
    EClass eClass = getQueryObjectProvider().getDatabaseSession().getEClassForOid(oid);
    ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[12]);
    mustStartWith.putInt(getReusable().getPid());
    mustStartWith.putLong(oid);
    ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[16]);
    startSearchWith.putInt(getReusable().getPid());
    startSearchWith.putLong(oid);
    startSearchWith.putInt(-getReusable().getRid());

    SearchingRecordIterator recordIterator =
        getQueryObjectProvider()
            .getDatabaseSession()
            .getKeyValueStore()
            .getRecordIterator(
                eClass.getEPackage().getName() + "_" + eClass.getName(),
                mustStartWith.array(),
                startSearchWith.array(),
                getQueryObjectProvider().getDatabaseSession());
    try {
      Record record = recordIterator.next();
      if (record == null) {
        return true;
      }
      getQueryObjectProvider().incReads();
      ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
      ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
      keyBuffer.getInt(); // pid
      long keyOid = keyBuffer.getLong();
      int keyRid = -keyBuffer.getInt();
      if (keyRid <= getReusable().getRid()) {
        if (valueBuffer.capacity() == 1 && valueBuffer.get(0) == -1) {
          valueBuffer.position(valueBuffer.position() + 1);
          return true;
          // deleted entity
        } else {
          currentObject = convertByteArrayToObject(eClass, eClass, keyOid, valueBuffer, keyRid);

          if (currentObject.eClass().getName().toUpperCase().equals("IFCBOOLEANCLIPPINGRESULT")) {
            System.out.println();
          }

          processPossibleIncludes(null, include);

          //					if (include.hasFields()) {
          //						for (EReference eReference : include.getFields()) {
          //							EReference inverseOrOpposite =
          // getPackageMetaData().getInverseOrOpposite(currentObject.eClass(), eReference);
          //							if (inverseOrOpposite != null) {
          //								currentObject.addUseForSerialization(inverseOrOpposite);
          //							}
          //						}
          //					}

          //					if (currentObject != null) {
          //						if (getQueryPart().isIncludeAllFields()) {
          //							for (EReference eReference : currentObject.eClass().getEAllReferences()) {
          //								currentObject.addUseForSerialization(eReference);
          //							}
          //						}
          //					}
          //
          //					if (include.hasIncludes()) {
          //						for (Include include : include.getIncludes()) {
          //							processPossibleInclude(include);
          //						}
          //					}
        }
      } else {
        return true;
      }
    } finally {
      recordIterator.close();
    }
    return true;
  }
Esempio n. 24
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  */
 public Anchor createTargetAnchor(EClass eClass) {
   Anchor newAnchor = (Anchor) eClass.getEPackage().getEFactoryInstance().create(eClass);
   setTargetAnchor(newAnchor);
   return newAnchor;
 }
 @Override
 public EObject create(EClass eClass) {
   if (EMFModelManager.replacedClasses.contains(eClass))
     return eClass.getEPackage().getEFactoryInstance().create(eClass);
   return delegate.create(eClass);
 }
Esempio n. 26
0
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated NOT
  */
 public Bendpoints createBendpoints(EClass eClass) {
   Bendpoints newBendpoints =
       (Bendpoints) eClass.getEPackage().getEFactoryInstance().create(eClass);
   setBendpoints(newBendpoints);
   return newBendpoints;
 }
Esempio n. 27
0
  // TODO ! need new presentation of set-text-selection command or hide args
  protected void convertSimple(Command command, ICommandFormatter formatter, boolean hasInput) {
    String commandName = CoreUtils.getScriptletNameByClass(command.eClass());
    formatter.addCommandName(commandName);

    Map<EStructuralFeature, Command> bindingMap = new HashMap<EStructuralFeature, Command>();
    for (Binding b : command.getBindings()) {
      bindingMap.put(b.getFeature(), b.getCommand());
    }

    List<EStructuralFeature> attributes = CoreUtils.getFeatures(command.eClass());

    boolean forced = false;
    boolean bigTextCommand =
        commandName.equals("upload-file") || commandName.equals("match-binary");

    for (EStructuralFeature feature : attributes) {
      if (feature.getEAnnotation(CoreUtils.INTERNAL_ANN) != null) continue;
      if (feature.getEAnnotation(CoreUtils.INPUT_ANN) != null && hasInput) continue;
      String name = feature.getName();
      if (isForced(commandName, name)) forced = true;
      Object val = command.eGet(feature);
      boolean skippped = true;
      Object defaultValue = feature.getDefaultValue();
      boolean isDefault = val == null || val.equals(defaultValue);
      if (!isDefault) {
        if (feature instanceof EAttribute) {
          EAttribute attr = (EAttribute) feature;
          String type = attr.getEAttributeType().getInstanceTypeName();
          if (val instanceof List<?>) {
            List<?> list = (List<?>) val;
            for (Object o : list) {
              String value = convertValue(o, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                formatter.addAttrValue(value);
                skippped = false;
              }
            }
          } else {
            if (val.equals(true)) {
              forced = true;
              formatter.addAttrName(name, forced);
            } else {
              String value = convertValue(val, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                if (bigTextCommand) formatter.addAttrValueWithLineBreak(value);
                else formatter.addAttrValue(value);
                skippped = false;
              }
            }
          }
        } else {
          EReference ref = (EReference) feature;
          EClass eclass = ref.getEReferenceType();
          if (eclass.getEPackage() == CorePackage.eINSTANCE
              && eclass.getClassifierID() == CorePackage.COMMAND) {
            boolean singleLine = !(val instanceof Sequence);
            formatter.addAttrName(name, forced);
            formatter.openGroup(singleLine);
            doConvert((Command) val, formatter, true);
            formatter.closeGroup(singleLine);
            skippped = false;
          } else {
            IParamConverter<?> converter =
                ParamConverterManager.getInstance().getConverter(eclass.getInstanceClass());
            if (converter != null) {
              try {
                String strVal = String.format("\"%s\"", converter.convertToCode(val));
                formatter.addAttrValue(strVal);
              } catch (CoreException e) {
                CorePlugin.log(e.getStatus());
              }
            }
          }
        }
      } else {
        Command c = bindingMap.get(feature);
        if (c != null) {
          formatter.addAttrName(name, forced);
          formatter.openExec();
          doConvert(c, formatter, hasInput);
          formatter.closeExec();
          skippped = false;
        }
      }
      if (skippped) forced = true;
    }
  }
  /**
   * createObject handles if the probe created an object with same UUID as another existing object
   *
   * @param ecls
   * @param entityName
   * @param entityUuid
   * @return VMTRootobject
   */
  private VMTRootObject createObject(EClass ecls, String entityName, String entityUuid) {
    VMTRootObject obj = null;
    VMTRootObject newObj = null;
    String finalUuid = null;
    if (entityUuid != null) {
      finalUuid = REPOSMAN.hashUuid(entityUuid);
    }

    obj = name2obj.get(entityName);

    if (obj == null) {
      // this is an initial discovery, check if a different probe created an object with the same
      // uuid
      obj = REPOSMAN.getObject(finalUuid);
      if (obj != null) {
        // This object was created by a different probe
        if (!obj.eClass().equals(ecls)) {
          newObj = createObject(ecls, entityName, finalUuid + entityName);
          handleSameUUID(
              (VMTManagedEntity) obj,
              (VMTManagedEntity) newObj,
              entityName,
              ecls,
              false,
              VMTSeverity.MAJOR);
        } else {
          if (logger.isTraceEnabled() && obj instanceof VirtualApplication)
            logger.trace(
                target.getNameOrAddress()
                    + "### : "
                    + obj.toVMTString()
                    + " already was created by another probe with uuid "
                    + obj.getUuid());
        }
      } else {
        // This is the first object created with such a uuid
        obj = (VMTRootObject) ecls.getEPackage().getEFactoryInstance().create(ecls);
        if (finalUuid != null) obj.setUuid(finalUuid);
        obj.setName(entityName);
        if (logger.isTraceEnabled() && obj instanceof VirtualApplication)
          logger.trace(
              target.getNameOrAddress()
                  + ": created NEW object "
                  + obj.toVMTString()
                  + " with uuid "
                  + obj.getUuid());
        DISCMAN.incrementCount((VMTManagedEntity) obj);
      }
    } else if (!obj.eClass().equals(ecls)) {
      // object of a different class with the same uuid was created by this probe
      //			newObj = createObject(ecls, entityName, finalUuid + entityName);
      //			handleSameUUID((VMTManagedEntity)obj, (VMTManagedEntity)newObj, finalUuid, ecls,
      // VMTSeverity.WARNING);
      handleSameUUID((VMTManagedEntity) obj, null, entityName, ecls, false, VMTSeverity.MAJOR);
      newObj = null;
    }

    if (newObj != null) obj = newObj;

    name2obj.put(entityName, obj);
    return obj;
  } // end createObject()
  /**
   * Generates the object described in the given instanciationInstruction.
   *
   * @param instanciationInstruction the instantiation instruction to inspect
   * @param importedPackageURIS the URIs corresponding to all the packages imported in this
   *     ModelingUnit
   * @param linkResolver the entity used in order to resolve links
   * @param modelingUnitGenerator the dispatcher to use for calling the correct generator on
   *     sub-elements
   * @return the object described in the given instanciationInstruction
   */
  public static EObject generate(
      InstanciationInstruction instanciationInstruction,
      List<String> importedPackageURIS,
      ModelingUnitLinkResolver linkResolver,
      ModelingUnitGenerator modelingUnitGenerator) {

    ModelingUnitGenerator.clearCompilationStatus(instanciationInstruction);

    EObject createdElement = null;
    // Step 1 : resolving the link to the metaType (thanks to the linkResolver)
    String metaTypeHref = instanciationInstruction.getMetaType().getTypeName();
    try {
      EClass metaType =
          (EClass)
              linkResolver.resolveEClassifierUsingPackage(
                  instanciationInstruction, importedPackageURIS, metaTypeHref);
      instanciationInstruction.getMetaType().setResolvedType(metaType);

      // Step 2 : instantiate correctly this entity
      // Step 2.1 : Creation using the factory
      createdElement = metaType.getEPackage().getEFactoryInstance().create(metaType);

      // Step 2.2 : If a name has been associated to this instance
      if (instanciationInstruction.getName() != null) {
        // We determine if this name can be assigned to any attribute
        for (EAttribute attribute : metaType.getEAllAttributes()) {
          if (isConcernedByNameAttribute(attribute)) {
            // if so, we set this attribute
            createdElement.eSet(attribute, instanciationInstruction.getName());
          }
        }
      }
      // Step 2.3 : We set all the structuralFeatureAffectation associated to this instance
      // leaving the other attributes to default values.
      for (StructuralFeatureAffectation sfa : instanciationInstruction.getStructuralFeatures()) {
        StructuralFeatureGenerator.generateFeatureAndAddToClass(
            sfa, createdElement, linkResolver, modelingUnitGenerator);
      }
    } catch (ResolveException e) {
      // If the metaType of the element to generate cannot be resolved
      // We generate a compilation status
      modelingUnitGenerator
          .getInformationHolder()
          .registerCompilationExceptionAsCompilationStatus(
              new CompilationException(
                  e.getInvalidInstruction(),
                  CompilationErrorType.INVALID_REFERENCE_ERROR,
                  e.getMessage()));
      // And we create a sample object, in order to let the compilation running
      createdElement = EcoreFactory.eINSTANCE.createEObject();
    } catch (IllegalArgumentException e) {
      modelingUnitGenerator
          .getInformationHolder()
          .registerCompilationExceptionAsCompilationStatus(
              new CompilationException(
                  instanciationInstruction,
                  CompilationErrorType.INVALID_VALUE_ERROR,
                  e.getMessage()));
      // And we create a sample object, in order to let the compilation running
      createdElement = EcoreFactory.eINSTANCE.createEObject();
    }

    // Step 3 : Registration of the generated element
    // Step 3.1 : we add the generated element in the current created Elements list
    modelingUnitGenerator
        .getInformationHolder()
        .addNameToCreatedElementEntry(
            instanciationInstruction.getName(), createdElement, instanciationInstruction);

    if (createdElement instanceof EPackage) {
      linkResolver.unregisterEPackage((EPackage) createdElement);
    }

    // Step 3.2 : if any unresolved contribution instructions were contributed to this element
    // We resolve these contributions
    for (final UnresolvedContributionHolder contributionHolder :
        modelingUnitGenerator
            .getInformationHolder()
            .getContributionsAssociatedTo(instanciationInstruction.getName())) {
      ContributionInstructionGenerator.generate(
          contributionHolder.getReferencedContribution(), modelingUnitGenerator, linkResolver);
    }

    return createdElement;
  }
Esempio n. 30
0
  public void queryXRefs(final QueryXRefsContext context) {
    final int branchID = context.getBranch().getID();

    for (final CDOID target : context.getTargetObjects().keySet()) {
      for (final EClass eClass : context.getSourceCandidates().keySet()) {
        final String eClassName = eClass.getName();
        final String nsURI = eClass.getEPackage().getNsURI();
        final List<EReference> eReferences = context.getSourceCandidates().get(eClass);
        getObjectContainer()
            .query(
                new Predicate<DB4ORevision>() {
                  private static final long serialVersionUID = 1L;

                  private boolean moreResults = true;

                  @Override
                  public boolean match(DB4ORevision revision) {
                    if (!moreResults) {
                      return false;
                    }

                    if (!revision.getClassName().equals(eClassName)) {
                      return false;
                    }

                    if (!revision.getPackageURI().equals(nsURI)) {
                      return false;
                    }

                    if (!(revision.getBranchID() == branchID)) {
                      return false;
                    }

                    CDOID id = DB4ORevision.getCDOID(revision.getID());
                    for (EReference eReference : eReferences) {
                      Object obj = revision.getValues().get(eReference.getFeatureID());
                      if (obj instanceof List) {
                        List<?> list = (List<?>) obj;
                        int index = 0;
                        for (Object element : list) {
                          CDOID ref = DB4ORevision.getCDOID(element);
                          if (ObjectUtil.equals(ref, target)) {
                            moreResults = context.addXRef(target, id, eReference, index);
                          }

                          ++index;
                        }
                      } else {
                        CDOID ref = DB4ORevision.getCDOID(obj);
                        if (ObjectUtil.equals(ref, target)) {
                          moreResults = context.addXRef(target, id, eReference, 0);
                        }
                      }
                    }

                    return false;
                  }
                });
      }
    }
  }