public EObject resolveProxy(EObject obj) {
   if (!obj.eIsProxy()) {
     return obj;
   } else {
     return EcoreUtil.resolve(obj, myResourceSet);
   }
 }
Beispiel #2
0
 public EObject resolveJavaObjectURIProxy(InternalEObject proxy, JvmTypeReference sender) {
   if (indexedJvmTypeAccess != null) {
     EObject result = indexedJvmTypeAccess.getIndexedJvmType(proxy.eProxyURI(), getResourceSet());
     if (result != null) {
       return result;
     }
   }
   return EcoreUtil.resolve(proxy, sender);
 }
 @Override
 protected Iterable<IEObjectDescription> getAllLocalElements() {
   Map<String, IEObjectDescription> result = new HashMap<String, IEObjectDescription>();
   for (IEObjectDescription ePkgDesc : parentScope.getAllElements()) {
     EPackage ePkg = (EPackage) ePkgDesc.getEObjectOrProxy();
     ePkg = (EPackage) EcoreUtil.resolve(ePkg, context);
     result.put(ePkg.getNsURI(), EObjectDescription.create(ePkg.getNsURI(), ePkg));
   }
   return result.values();
 }
 private EObject resolveWhenProxy(EObject e, ResourceSet resolveContext) {
   EObject resolvedEObject = e;
   if (e != null && e.eIsProxy()) {
     resolvedEObject = EcoreUtil.resolve(e, resolveContext);
     if (resolvedEObject.eIsProxy()) {
       String msg =
           PluginConstants.Util.getString(
               "XmlElementSqlAspect.Unable_to_resolve_proxy_with_uri",
               ((InternalEObject) e).eProxyURI()); // $NON-NLS-1$
       PluginConstants.Util.log(IStatus.ERROR, msg);
     }
   }
   return resolvedEObject;
 }
  /**
   * Assuming the namespace identifies a classifier, that classifier is returned.
   *
   * @return classifier at namespace
   */
  public static ConcreteClassifier getClassifierAtNamespaces(NamespaceAwareElement me) {

    String fullQualifiedName = me.getNamespacesAsString();
    if (fullQualifiedName == null
        || fullQualifiedName.endsWith(JavaUniquePathConstructor.PACKAGE_SEPARATOR)) {
      return null;
    }

    // Cut the trailing separator
    fullQualifiedName = fullQualifiedName.substring(0, fullQualifiedName.length() - 1);

    ConcreteClassifier proxy = me.getConcreteClassifierProxy(fullQualifiedName);
    return (ConcreteClassifier) EcoreUtil.resolve(proxy, me);
  }
 protected void computeReferencedJvmTypeHighlighting(
     IHighlightedPositionAcceptor acceptor, EObject referencer, CancelIndicator cancelIndicator) {
   for (EReference reference : referencer.eClass().getEAllReferences()) {
     EClass referencedType = reference.getEReferenceType();
     if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_TYPE, referencedType)) {
       List<EObject> referencedObjects = EcoreUtil2.getAllReferencedObjects(referencer, reference);
       if (referencedObjects.size() > 0) operationCanceledManager.checkCanceled(cancelIndicator);
       for (EObject referencedObject : referencedObjects) {
         EObject resolvedReferencedObject = EcoreUtil.resolve(referencedObject, referencer);
         if (resolvedReferencedObject != null && !resolvedReferencedObject.eIsProxy()) {
           highlightReferenceJvmType(acceptor, referencer, reference, resolvedReferencedObject);
         }
       }
     }
   }
 }
 public String check(IEObjectDescription input) {
   if (input instanceof IValidatedEObjectDescription) {
     final IValidatedEObjectDescription validatedDescription =
         (IValidatedEObjectDescription) input;
     JvmIdentifiableElement identifiable = validatedDescription.getEObjectOrProxy();
     if (identifiable.eIsProxy())
       identifiable = (JvmIdentifiableElement) EcoreUtil.resolve(identifiable, context);
     String issueCode;
     if (identifiable.eIsProxy()) issueCode = UNRESOLVABLE_PROXY;
     else if (!validatedDescription.isValid()) {
       if (Strings.isEmpty(validatedDescription.getIssueCode())) issueCode = FEATURE_NOT_VISIBLE;
       else return validatedDescription.getIssueCode();
     } else issueCode = dispatcher.invoke(identifiable, context, reference, validatedDescription);
     validatedDescription.setIssueCode(issueCode);
     return issueCode;
   }
   return null;
 }
  /**
   * Resolve the specified XSDSchemaDirective and resolve against resources in the resource set
   *
   * @param eResource
   * @param recurse
   * @param visited
   * @since 4.3
   */
  protected XSDSchema resolveSchemaDirective(final XSDSchemaDirective directive) {
    XSDSchema resolvedSchema = null;
    if (directive != null) {
      resolvedSchema = directive.getResolvedSchema();

      // Import is not yet resolved, attempt to locate the reference ...
      if (resolvedSchema == null && directive instanceof XSDImportImpl) {
        resolvedSchema = ((XSDImportImpl) directive).importSchema();
      }

      // If the resolvedSchema reference exists but is an eProxy then attempt to resolve it
      if (resolvedSchema != null && resolvedSchema.eIsProxy()) {
        resolvedSchema = (XSDSchema) EcoreUtil.resolve(resolvedSchema, getContainer());
      }

      // Directive is not yet resolved, attempt to locate the referenced
      // XSDResource using the schema location information in the directive
      String location = directive.getSchemaLocation();
      XSDResourceImpl eResource = (XSDResourceImpl) directive.eResource();
      if (resolvedSchema == null && eResource != null && !CoreStringUtil.isEmpty(location)) {
        XSDResourceImpl refdResource = null;

        URI schemaLocationUri = UriHelper.makeAbsoluteUri(eResource.getURI(), location);
        // URI schemaLocationUri = getAbsoluteLocation(eResource.getURI(), location);
        refdResource = (XSDResourceImpl) findByURI(schemaLocationUri, false);

        // Update the directive with the resolved schema
        if (refdResource != null) {
          resolvedSchema = refdResource.getSchema();
          directive.setResolvedSchema(resolvedSchema);
          if (directive instanceof XSDImport) {
            ((XSDSchemaImpl) resolvedSchema).imported((XSDImport) directive);
          } else if (directive instanceof XSDInclude) {
            ((XSDSchemaImpl) resolvedSchema).included((XSDInclude) directive);
          } else if (directive instanceof XSDRedefine) {
            ((XSDSchemaImpl) resolvedSchema).redefined((XSDRedefine) directive);
          }
        }
      }
    }
    return resolvedSchema;
  }
Beispiel #9
0
  /**
   * Given an element, return its type, or null if it does not have a type. This is slightly more
   * complicated than just calling getType() since an element may not have a type at all, it may
   * reference another element.
   *
   * @param feature
   * @return the type of the element
   */
  public static XSDTypeDefinition getResolvedType(XSDFeature feature) {

    // Special case of elements referencing stale XSD complex types
    if (feature instanceof XSDElementDeclaration
        && ((XSDElementDeclaration) feature).getTypeDefinition()
            instanceof XSDComplexTypeDefinition) {

      XSDElementDeclaration element = (XSDElementDeclaration) feature;

      // We have a type, but types can be proxies, and proxies can become
      // stale if the referenced
      // type changes, so before we return it, re-resolve the proxy and
      // then return it
      XSDComplexTypeDefinition oldType = (XSDComplexTypeDefinition) element.getTypeDefinition();
      EObject newType = EcoreUtil.resolve(element.getTypeDefinition(), element);
      if (oldType != newType) {
        // We only return the resolved type if the name and the namespace has not changed.  Changing
        // the name
        // and namespace is essentially an unresolved BO.
        String oldName = oldType.getName();
        String newName = ((XSDTypeDefinition) newType).getName();
        String oldTNS = oldType.getTargetNamespace();
        String newTNS = ((XSDTypeDefinition) newType).getTargetNamespace();

        if (((oldName == newName) || (oldName != null && oldName.equals(newName)))
            && ((oldTNS == newTNS) || (oldTNS != null && oldTNS.equals(newTNS))))
          element.setTypeDefinition((XSDTypeDefinition) newType);
      }
      return element.getTypeDefinition();

    } else if (feature.getType() != null) {
      return feature.getType();
    } else if (feature.getResolvedFeature() != null
        && feature.getResolvedFeature().getType() != null) {
      // We reference another element
      return feature.getResolvedFeature().getType();
    } else {
      return null;
    }
  }
  /**
   * refresh representations.
   *
   * @param dAnalysis {@link DAnalysis} to refresh.
   * @param view current {@link DView}
   */
  public void refreshRepresentations(final DAnalysis dAnalysis, final DView view) {
    TransactionalEditingDomain transactionalEditingDomain =
        TransactionUtil.getEditingDomain(dAnalysis);
    boolean hasAlreadyModel = false;
    // The old representations have no a model.
    if (view instanceof DRepresentationContainer) {
      if (!((DAnalysis) view.eContainer()).getModels().isEmpty()) {
        // Set hasAlreadyModel to true only if almost one of the models
        // is not a proxy
        for (EObject model : ((DAnalysis) view.eContainer()).getModels()) {
          if (!model.eIsProxy()) {
            hasAlreadyModel = true;
          }
        }
      } else if (!hasAlreadyModel) {
        final Map<EObject, AnyType> extension =
            ((XMIResource) dAnalysis.eResource()).getEObjectToExtensionMap();
        final AnyType viewSettings = extension.get(view);
        if (viewSettings != null) {
          for (final FeatureMap.Entry feature : viewSettings.getMixed()) {
            if ("model".equals(feature.getEStructuralFeature().getName())) {
              ((DAnalysis) view.eContainer())
                  .getModels()
                  .add(
                      EcoreUtil.resolve(
                          (EObject) feature.getValue(), view.eResource().getResourceSet()));
              hasAlreadyModel = true;
            }
          }
        }
      }
    }

    // Command prepareImportsFromSessionCommand = new
    // PrepareImportsFromSessionCommand(this, view);
    MigrationCommandExecutor migrationCommandExecutor = new MigrationCommandExecutor();

    Command prepareImportsFromSessionCommand =
        new IdentityCommand() {
          @Override
          public void execute() {
            // Not seem to be necessary (done by handle view command)
            // initAnalysis(view);
            for (final EObject model : ((DAnalysis) view.eContainer()).getModels()) {
              if (!model.eIsProxy()) {
                InterpreterRegistry.prepareImportsFromSession(
                    SiriusPlugin.getDefault().getInterpreterRegistry().getInterpreter(model),
                    SessionManager.INSTANCE.getSession(model));
              }
            }
            for (DRepresentation dRepresentation : view.getOwnedRepresentations()) {
              DialectManager.INSTANCE.refresh(dRepresentation, new NullProgressMonitor());
            }
          }

          @Override
          public boolean canUndo() {
            return false;
          }
        };

    migrationCommandExecutor.execute(transactionalEditingDomain, prepareImportsFromSessionCommand);

    // This method calls a RecordingCommand
    refreshLostDiagramElements(view);

    refreshAllElementsVisibility(view, transactionalEditingDomain, migrationCommandExecutor);

    // if (!hasAlreadyModel) {
    // deinformModel((DRepresentationContainer) view);
    // }
    // Recompute the models references after the refresh.
    // Command cleanModelsCommand = new CleanModelsCommand(this, dAnalysis,
    // true);
    // migrationCommandExecutor.execute(transactionalEditingDomain,
    // cleanModelsCommand);
  }
  @Override
  public boolean performFinish() {
    _wizardPage.setPageComplete(false);
    TransactionalEditingDomain myEditingDomain = DataModelerUtils.getDataModelerEditingDomain();

    _schema = _wizardPage.getSchema();

    if (_schema.eIsProxy())
      _schema = (ESchema) EcoreUtil.resolve(_schema, myEditingDomain.getResourceSet());

    if (!_schema.eIsProxy()) _resource = _schema.eResource();

    if (_resource == null) return true;

    String path = _resource.getURI().toPlatformString(true);

    LinkedList<IFile> affectedFiles = new LinkedList<IFile>();

    IResource workspaceResource =
        ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));

    if (workspaceResource instanceof IFile) affectedFiles.add((IFile) workspaceResource);

    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            myEditingDomain,
            "Comando de creación de diagramas", //$NON-NLS-1$
            affectedFiles) {

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {

            _diagram =
                ViewService.createDiagram(
                    _schema,
                    SchemaEditPart.MODEL_ID,
                    DatamodelerDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            _diagram.setName(_wizardPage.getDiagramName());
            _resource.getContents().add(_diagram);

            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new NullProgressMonitor(), null);

      _resource.save(DatamodelerDiagramEditorUtil.getSaveOptions());

      final URI diagramURI = EcoreUtil.getURI(_diagram);

      Display.getCurrent()
          .asyncExec(
              new Runnable() {

                @Override
                public void run() {
                  if (diagramURI.toPlatformString(true) != null)
                    try {
                      UtilsDataModelerUI.openDiagram(diagramURI, _diagram.getName());
                    } catch (PartInitException ex) {
                      DatamodelerDiagramEditorPlugin.getInstance()
                          .logError("Unable to open editor", ex); // $NON-NLS-1$
                    }
                }
              });

    } catch (ExecutionException e) {
      DatamodelerDiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    } catch (IOException ex) {
      DatamodelerDiagramEditorPlugin.getInstance()
          .logError("Save operation failed for: " + _resource.getURI(), ex); // $NON-NLS-1$
    }

    return true;
  }