public static QueryMetadataContext buildQueryMetadataContext(
      final EObject eObject, final boolean restrictSearch) {
    Collection resources = null;
    Container container = null;
    try {
      // assume model container...modler metadata is for workspace
      container = ModelerCore.getModelContainer();
      ModelWorkspace workspace = ModelerCore.getModelWorkspace();
      if (workspace.isOpen()) {
        resources = Arrays.asList(workspace.getEmfResources());
      } else {
        resources = container.getResources();
      }
    } catch (CoreException e) {
      TransformationPlugin.Util.log(e);
    }

    // find the resoucre for the eObject in the container
    Resource resource = ModelerCore.getModelEditor().findResource(container, eObject);
    // create a indexSelector for this resource and instantiate transformation validator
    ModelResourceIndexSelector selector = new ModelResourceIndexSelector(resource);
    QueryMetadataContext context = new QueryMetadataContext(selector);
    // set the resource scope (all model resources in open model projects)
    context.setResources(resources);
    // set the restrict search flag
    context.setRestrictedSearch(restrictSearch);
    return context;
  }
 /**
  * Return a reference to a {@link QueryMetadataInterface} implementation that for the given
  * eObject , its resourceand the resources that depend ont it. This assumes the Eobject is in a
  * modelContainer, should be used only for workspace validation.
  *
  * @param eObject The eObject for which metadata instance is returned
  * @param restrictSearch A boolean indicating if the search needs to be restricted to model
  *     imports or if the whole workspace needs to be searched
  * @return the QueryMetadataInterface implementation; never null
  */
 public QueryMetadataInterface getModelerMetadata(
     final EObject eObject, final boolean restrictSearch) {
   CoreArgCheck.isNotNull(eObject);
   QueryMetadataContext context = buildQueryMetadataContext(eObject, restrictSearch);
   Container container = null;
   try {
     container = ModelerCore.getModelContainer();
   } catch (CoreException e) {
     TransformationPlugin.Util.log(e);
   }
   return getModelerMetadata(context, container);
 }
 /* (non-Javadoc)
  * @See org.teiid.designer.core.workspace.ModelWorkspace#findModelResource(org.eclipse.emf.ecore.EObject)
  */
 @Override
 public ModelResource findModelResource(final EObject eObject) {
   CoreArgCheck.isNotNull(eObject);
   try {
     final Container container = ModelerCore.getModelContainer();
     Resource resource = ModelerCore.getModelEditor().findResource(container, eObject, false);
     if (resource != null) {
       return findModelResource(resource);
     }
   } catch (CoreException err) {
     ModelerCore.Util.log(err);
   }
   return null;
 }
  private static boolean isLocalResource(final String uri) {

    boolean found = false;
    try {
      final String uriName = URI.createURI(uri).lastSegment();
      final Resource[] systemModels =
          ModelerCore.getModelContainer().getResourceFinder().findByName(uriName, false, false);

      for (int i = 0; i != systemModels.length; ++i) {
        final URI resUri = systemModels[i].getURI();
        if (resUri.lastSegment().equalsIgnoreCase(uriName)) found = true;
      }

    } catch (final Exception e) {
      ModelerCore.Util.log(e);
    }

    return found;
  }