private void parseUrl(String url) {
   if (url == null) return;
   this.uri = null;
   try {
     // TODO check parsing url
     // URL has some valid protocol.
     // Check to see if it is a valid url.
     URL url_inst = new URL(url);
     String protocol2 = url_inst.getProtocol();
     if (protocol2 != null) {
       // XXX : HACK Extreme hacking on...
       // there should be a proper way to handle with spaces and URIs.
       if (protocol2.equalsIgnoreCase(HTTP_PROTOCOL)) {
         this.uri =
             URI.createURI(
                 URI.decode(
                     url.replace("http://platform", "platform:")
                         .replace(
                             "platform::/",
                             "platform:/"))); // .replaceAll("%20", " ")); //$NON-NLS-1$
                                              // //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
       } else if (protocol2.equalsIgnoreCase(PLATFORM_PROTOCOL)) {
         this.uri = URI.createURI(URI.decode(url));
       }
     }
   } catch (MalformedURLException e) {
     // not a valid URL. Just return.
   }
 }
  /** Add the specified list any external resource for this EReference feature */
  protected void processReferenceValue(
      final Resource eResource,
      final EObject eObject,
      final EReference eReference,
      final EObject value,
      final List externalResources,
      final Set unresolvedResourceURIs) {
    if (value == null) {
      return;
    }

    // Check if the object is an EMF proxy ...
    if (value.eIsProxy()) {
      if (value instanceof InternalEObject) {
        final InternalEObject iObject = (InternalEObject) value;
        final URI proxyUri = iObject.eProxyURI();
        CoreArgCheck.isNotNull(proxyUri);

        // Get the URI of the resource ...
        URI resourceUri = proxyUri.trimFragment();

        // Make the relative URI absolute if necessary
        URI baseLocationUri = eResource.getURI();
        URI proxyLocationUri = UriHelper.makeAbsoluteUri(baseLocationUri, resourceUri);
        // URI proxyLocationUri = resourceUri;
        // if (baseLocationUri.isHierarchical() && !baseLocationUri.isRelative() &&
        // proxyUri.isRelative()) {
        // proxyLocationUri = proxyLocationUri.resolve(baseLocationUri);
        // }
        Resource rsrc = findByURI(proxyLocationUri, true);

        // If the resource URI is a workspace relative path (e.g. "/project/.../model.xmi")
        if (rsrc == null && baseLocationUri.isFile() && resourceUri.toString().charAt(0) == '/') {
          String baseLocation = URI.decode(baseLocationUri.toFileString());
          String projectName = resourceUri.segment(0);
          String proxyLocation = URI.decode(resourceUri.toString());
          int index = baseLocation.indexOf(projectName);
          if (index != -1) {
            proxyLocation = baseLocation.substring(0, index - 1) + proxyLocation;
            rsrc = findByURI(URI.createFileURI(proxyLocation), true);
          }
        }

        if (rsrc != null && eResource != rsrc && !externalResources.contains(rsrc)) {
          externalResources.add(rsrc);
        } else if (rsrc == null) {
          unresolvedResourceURIs.add(resourceUri);
        }
      }
    } else {
      Resource rsrc = value.eResource();
      if (eResource != rsrc && !externalResources.contains(rsrc)) {
        externalResources.add(rsrc);
      }
    }
  }
  protected void addConnectorDefinition(
      ConnectorImplementation impl, List<IResource> resourcesToExport)
      throws FileNotFoundException, CoreException {
    final IRepositoryStore store = getDefinitionStore();
    ConnectorDefinition def =
        ((IDefinitionRepositoryStore) store)
            .getDefinition(impl.getDefinitionId(), impl.getDefinitionVersion());
    EMFFileStore file =
        (EMFFileStore) store.getChild(URI.decode(def.eResource().getURI().lastSegment()));

    if (file != null && !file.canBeShared()) {
      File f = new File(file.getEMFResource().getURI().toFileString());
      if (f.exists()) {
        IFile defFile = store.getResource().getFile(f.getName());
        defFile.create(new FileInputStream(f), true, Repository.NULL_PROGRESS_MONITOR);
        resourcesToExport.add(defFile);
        cleanAfterExport.add(defFile);
      }
    } else if (file != null) {
      resourcesToExport.add(file.getResource());
    }

    addDefinitionIcons(resourcesToExport, store, def);
    addDefinitionPropertiesFile(resourcesToExport, store, def);
  }
 public static String getAbsoluteLocation(final File base, final String relativePath) {
   final URI baseLocation = URI.createFileURI(base.getAbsolutePath());
   URI relLocation = URI.createURI(relativePath, false);
   if (baseLocation.isHierarchical() && !baseLocation.isRelative() && relLocation.isRelative())
     relLocation = relLocation.resolve(baseLocation);
   return URI.decode(relLocation.toString());
 }
 /** @since 2.3 */
 @Override
 public List<?> getTargetObjects(Object object, IMarker marker) {
   if (object instanceof AdapterFactoryEditingDomain) {
     ArrayList<Object> result = new ArrayList<Object>();
     AdapterFactoryEditingDomain editingDomain = (AdapterFactoryEditingDomain) object;
     String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
     if (uriAttribute != null) {
       URI uri = URI.createURI(uriAttribute);
       EObject eObject = editingDomain.getResourceSet().getEObject(uri, true);
       if (eObject != null) {
         result.add(editingDomain.getWrapper(eObject));
       }
     }
     String relatedURIsAttribute = marker.getAttribute(EValidator.RELATED_URIS_ATTRIBUTE, null);
     if (relatedURIsAttribute != null) {
       for (String relatedURI : relatedURIsAttribute.split(" ")) {
         URI uri = URI.createURI(URI.decode(relatedURI));
         EObject eObject = editingDomain.getResourceSet().getEObject(uri, true);
         if (eObject != null) {
           result.add(editingDomain.getWrapper(eObject));
         }
       }
     }
     return result;
   } else {
     return super.getTargetObjects(object, marker);
   }
 }
  /**
   * Returns true if the specified URI string is one of the well-known Teiid Designer/EMF
   * identifiers to a global resource such as
   *
   * <p>"http://www.metamatrix.com/metamodels/SimpleDatatypes-instance"
   * "http://www.metamatrix.com/metamodels/UmlPrimitiveTypes-instance"
   * "http://www.metamatrix.com/relationships/BuiltInRelationshipTypes-instance"
   * "http://www.w3.org/2001/XMLSchema" "http://www.w3.org/2001/MagicXMLSchema"
   * "http://www.w3.org/2001/XMLSchema-instance" otherwise false is returned.
   *
   * @param uri the URI string
   */
  public static boolean isGlobalResource(final String uri) {
    if (uri == null) return false;

    // http://www.w3.org/2001/xml.xsd
    //       "http://www.w3.org/2001/XMLSchema"; //$NON-NLS-1$
    //       "http://www.w3.org/2001/MagicXMLSchema"; //$NON-NLS-1$
    //       "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$

    // If the URI is to the Teiid Designer built-in datatypes model ...
    if (uri.startsWith(DatatypeConstants.BUILTIN_DATATYPES_URI)) return true;
    if (uri.endsWith(DatatypeConstants.DATATYPES_MODEL_FILE_NAME)) return true;

    // If the URI is to the Teiid Designer built-in UML primitive types model ...
    if (uri.startsWith(UML_PRIMITIVE_TYPES_INTERNAL_URI)) return true;
    if (uri.endsWith(UML_PRIMITIVE_TYPES_MODEL_FILE_NAME)) return true;
    if (uri.startsWith(UML_METAMODEL_URI)) return true;

    // If the URI is to the Teiid Designer built-in relationship model ...
    if (uri.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_INTERNAL_URI)) return true;
    if (uri.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_MODEL_FILE_NAME)) return true;

    // If the URI is to one of the Emf XMLSchema resources ...
    if (uri.startsWith(ModelerCore.XML_SCHEMA_INSTANCE_GENERAL_URI)
        || uri.startsWith(ModelerCore.XML_MAGIC_SCHEMA_GENERAL_URI)
        || uri.startsWith(ModelerCore.XML_SCHEMA_GENERAL_URI)
        || uri.startsWith(ModelerCore.XML_XSD_GENERAL_URI)) return true;

    // If the URI is in the form of an Eclipse platform path to
    // one of the Emf XMLSchema resources ...
    if (uri.startsWith(
        XML_SCHEMA_ECLIPSE_PLATFORM_URI_PREFIX)) // MagicXMLSchema.xsd suffix on the resource URI
    if (uri.indexOf(XML_MAGIC_SCHEMA_ECLIPSE_PLATFORM_URI_SUFFIX) > 0) return true;
      else if (uri.indexOf(XML_SCHEMA_ECLIPSE_PLATFORM_URI_SUFFIX) > 0) return true;
      else if (uri.indexOf(XML_SCHEMA_INSTANCE_ECLIPSE_PLATFORM_URI_SUFFIX) > 0) return true;

    // Next check if the import reference is to one of our system models
    try {
      final Resource[] systemModels = ModelerCore.getSystemVdbResources();
      for (int i = 0; i != systemModels.length; ++i) {
        final String systemModelUri = URI.decode(systemModels[i].getURI().toString());
        if (uri.equalsIgnoreCase(systemModelUri)) return true;
      }
    } catch (final Exception e) {
      // do nothing
    }

    // Next check if the import reference is to one of our metamodels
    try {
      if (ModelerCore.getMetamodelRegistry().containsURI(uri)) return true;
    } catch (final Exception e) {
      // do nothing
    }

    // MyCode : 18565
    if (isLocalResource(uri)) return false;

    return false;
  }
  /**
   * @param groupFileUri
   * @return
   */
  private File toDestinationFolder(URI groupFileUri) {
    String toReplace = TstGeneral.GROUP_PATH_STR;
    String forReplace = toReplace + "Y";

    String path = URI.decode(groupFileUri.devicePath());
    // modify to destination folder
    path = path.replace(toReplace, forReplace);
    File destFile = new File(path);
    return destFile;
  }
 /** @generated */
 protected void handleElementMoved(IEditorInput input, URI uri) {
   if (input instanceof FileEditorInput) {
     IFile newFile =
         ResourcesPlugin.getWorkspace()
             .getRoot()
             .getFile(new Path(URI.decode(uri.path())).removeFirstSegments(1));
     fireElementMoved(input, newFile == null ? null : new FileEditorInput(newFile));
     return;
   }
   fireElementMoved(input, new URIEditorInput(uri));
 }
 /** @generated */
 protected void handleElementMoved(IEditorInput input, URI uri) {
   if (input instanceof FileEditorInput) {
     IFile newFile =
         ResourcesPlugin.getWorkspace()
             .getRoot()
             .getFile(new Path(URI.decode(uri.path())).removeFirstSegments(1));
     fireElementMoved(input, newFile == null ? null : new FileEditorInput(newFile));
     return;
   }
   // TODO: append suffix to the URI! (use diagram as a parameter)
   fireElementMoved(input, new URIEditorInput(uri));
 }
  /** @generated */
  public StateMachine_MAVONewDiagramFileWizard(
      URI domainModelURI, EObject diagramRoot, TransactionalEditingDomain editingDomain) {
    assert domainModelURI != null : "Domain model uri must be specified"; // $NON-NLS-1$
    assert diagramRoot != null : "Doagram root element must be specified"; // $NON-NLS-1$
    assert editingDomain != null : "Editing domain must be specified"; // $NON-NLS-1$

    myFileCreationPage =
        new WizardNewFileCreationPage(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(
        NLS.bind(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_CreationPageDescription,
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts.StateMachineEditPart
                .MODEL_ID));
    IPath filePath;
    String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment());
    if (domainModelURI.isPlatformResource()) {
      filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true));
    } else if (domainModelURI.isFile()) {
      filePath = new Path(domainModelURI.trimSegments(1).toFileString());
    } else {
      // TODO : use some default path
      throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); // $NON-NLS-1$
    }
    myFileCreationPage.setContainerFullPath(filePath);
    myFileCreationPage.setFileName(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
            .StateMachine_MAVODiagramEditorUtil.getUniqueFileName(
            filePath, fileName, "statemachinediag_mavo")); // $NON-NLS-1$

    diagramRootElementSelectionPage =
        new DiagramRootElementSelectionPage(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageName);
    diagramRootElementSelectionPage.setTitle(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageTitle);
    diagramRootElementSelectionPage.setDescription(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageDescription);
    diagramRootElementSelectionPage.setModelElement(diagramRoot);

    myEditingDomain = editingDomain;
  }
  /**
   * @see
   *     org.teiid.designer.core.container.ResourceFinder#findUnresolvedResourceLocations(org.eclipse.emf.ecore.resource.Resource)
   * @since 4.3
   */
  @Override
  public String[] findUnresolvedResourceLocations(final Resource theResource) {
    final Collection result = new HashSet();
    if (theResource != null) {
      List dummyList = new ArrayList();
      Set unresolvedURIs = new HashSet();

      // just get the unresolved URI's
      addExternallyReferencedResources(theResource, false, true, dummyList, unresolvedURIs);

      // Check each one, decode it and add to result
      for (Iterator iter = unresolvedURIs.iterator(); iter.hasNext(); ) {
        URI uri = (URI) iter.next();
        result.add(URI.decode(uri.toString()));
      }
    }
    return (String[]) result.toArray(new String[result.size()]);
  }
  @Override
  public EObject getEObject(String uriFragment) {
    EList<EObject> contents = getContents();
    String name = URI.decode(uriFragment);
    for (int i = 0; i < contents.size(); i++) {
      EObject root = contents.get(i);

      EList<EObject> children = root.eContents();
      for (int j = 0; j < children.size(); j++) {
        EObject child = children.get(j);

        if (child instanceof NameSupport && name.equals(((NameSupport) child).getName()))
          return child;
      }
    }

    return super.getEObject(uriFragment);
  }
  /**
   * @see org.teiid.designer.core.container#isBuiltInSystemResource(org.eclipse.emf.common.util.URI)
   * @since 4.3
   */
  @Override
  public boolean isBuiltInSystemResource(final URI theUri) {
    if (theUri != null) {
      // If the models are not found in an external resource set then
      // they cannot be one of the built-in shared resources
      if (!isExternalResource(theUri)) {
        return false;
      }

      // Check if the string form of the URI matches one of the expected names
      String uriString = URI.decode(theUri.toString());
      if (uriString.startsWith(SYSTEM_VIRTUAL_INTERNAL_URI)
          || uriString.endsWith(SYSTEM_VIRTUAL_MODEL_FILE_NAME)) {

        return true;
      }
    }
    return false;
  }
 String text(PuppetManifest ele) {
   String s = ele.eResource().getURI().lastSegment();
   return Strings.isEmpty(s) ? "<unnamed>" : URI.decode(s);
 }
  @Override
  public EObject eObjectForURIFragmentSegment(String uriFragmentSegment) {
    int length = uriFragmentSegment.length();
    if (length > 0) {
      // Is the first character a special character, i.e., something other than '@'?
      //
      char firstCharacter = uriFragmentSegment.charAt(0);
      if (firstCharacter != '@') {
        // Is it the start of a source URI of an annotation?
        //
        if (firstCharacter == '%') {
          // Find the closing '%'
          //
          int index = uriFragmentSegment.lastIndexOf("%");
          boolean hasCount = false;
          if (index == length - 1 || (hasCount = uriFragmentSegment.charAt(index + 1) == '.')) {
            // Decode all encoded characters.
            //
            String source = URI.decode(uriFragmentSegment.substring(1, index));

            // Check for a count, i.e., a '.' followed by a number.
            //
            int count = 0;
            if (hasCount) {
              try {
                count = Integer.parseInt(uriFragmentSegment.substring(index + 2));
              } catch (NumberFormatException exception) {
                throw new WrappedException(exception);
              }
            }

            // Look for the annotation with the matching source.
            //
            for (Object object : eContents()) {
              if (object instanceof EAnnotation) {
                EAnnotation eAnnotation = (EAnnotation) object;
                if (source.equals(eAnnotation.getSource()) && count-- == 0) {
                  return eAnnotation;
                }
              }
            }
            return null;
          }
        }

        // Look for trailing count.
        //
        int index = uriFragmentSegment.lastIndexOf(".");
        String name = index == -1 ? uriFragmentSegment : uriFragmentSegment.substring(0, index);
        int count = 0;
        if (index != -1) {
          try {
            count = Integer.parseInt(uriFragmentSegment.substring(index + 1));
          } catch (NumberFormatException exception) {
            // Interpret it as part of the name.
            //
            name = uriFragmentSegment;
          }
        }

        name = URI.decode(name);

        // Look for a matching named element.
        //
        for (Object object : eContents()) {
          if (object instanceof ENamedElement) {
            ENamedElement eNamedElement = (ENamedElement) object;
            if (name.equals(eNamedElement.getName()) && count-- == 0) {
              return eNamedElement;
            }
          }
        }

        return null;
      }
    }

    return super.eObjectForURIFragmentSegment(uriFragmentSegment);
  }
  /** Build elements one by one */
  public void testGroupReviewCreate() {
    R4EReviewGroup group = null;
    // required folder path and group name to build the new group file
    try {
      group = fFactory.createR4EReviewGroup(fGroupPath, GROUP_NAME);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
    }

    assertNotNull(group);
    URI uri = group.eResource().getURI();
    String expectedURI = fGroupPath.appendSegment("Group_One_group_root.xrer").toString();
    assertEquals(expectedURI, uri.toString());

    // Deserialise and assert
    group = null;
    try {
      group = fFactory.openR4EReviewGroup(uri);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
    } catch (CompatibilityException e) {
      e.printStackTrace();
    }

    // validate
    assertNotNull(group);
    assertEquals(GROUP_NAME, group.getName());

    // crate a review
    R4EReview review = null;
    try {
      review = fFactory.createR4EReview(group, REVIEW_NAME1, fUser1);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(REVIEW_NAME1, review.getName());

    // re-open the group
    group = null;
    try {
      group = fFactory.openR4EReviewGroup(uri);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    uri = review.eResource().getURI();
    // read the review
    try {
      review = fFactory.openR4EReview(group, review.getName());
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    } catch (CompatibilityException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(REVIEW_NAME1, review.getName());

    // read the participant
    R4EUser participant = review.getUsersMap().values().iterator().next();
    uri = participant.eResource().getURI();
    try {
      ResourceSet resSet = participant.eResource().getResourceSet();
      participant = fReader.deserializeTopElement(uri, resSet, R4EParticipant.class);
    } catch (ResourceHandlingException e) {
      e.printStackTrace();
      fail("Exception");
    }

    assertEquals(fUser1, participant.getId());

    // Clean up
    File folder = new File(URI.decode(fGroupPath.devicePath()));
    try {
      FileUtils.deleteDirectory(folder);
    } catch (IOException e) {
      e.printStackTrace();
      fail("Exception");
    }
  }
  /**
   * Return a collection EMF resource matching the specified model name.
   *
   * @param modelName The name of the model whose resource/s are returned
   * @return The collection of EMD resources
   */
  private Collection findResourcesByName(final String modelName) {
    CoreArgCheck.isNotEmpty(modelName);

    // get the collection of resources to check
    Collection rsrcs =
        new ArrayList(
            (this.getResources() != null ? this.getResources() : getContainer().getResources()));

    // Add the system models to the collection if not already there
    Resource[] systemModels = ModelerCore.getSystemVdbResources();
    for (int i = 0; i != systemModels.length; ++i) {
      Resource systemModel = systemModels[i];
      if (!rsrcs.contains(systemModel)) {
        rsrcs.add(systemModel);
      }
    }

    // get the editor to get the name of the resources
    ModelEditor modelEditor = ModelerCore.getModelEditor();
    // find all the resource the match the model name
    Collection resources = new ArrayList(1);
    // get the index selector to limit the resource search
    IndexSelector selector = this.getIndexSelector();
    if (selector != null && selector instanceof ModelResourceIndexSelector) {
      // the selector has reference to the resource and references to its imports
      ModelResourceIndexSelector resourceSelector = (ModelResourceIndexSelector) selector;
      // try finding the entity in the selectors resource
      Resource modelResource = resourceSelector.getResource();
      String resourceName = modelEditor.getModelName(modelResource);
      if (resourceName.equalsIgnoreCase(modelName)) {
        resources.add(modelResource);
      } else {
        // check if any if any of the imported resources have the same name
        Iterator importIter = resourceSelector.getModelImports().iterator();
        while (importIter.hasNext()) {
          ModelImport modelImport = (ModelImport) importIter.next();
          String importName = modelImport.getName();
          if (importName.equalsIgnoreCase(modelName)) {
            // compare the import path of the model to the path in the resource
            String importPath = modelImport.getPath();
            for (Iterator resourceIter = rsrcs.iterator(); resourceIter.hasNext(); ) {
              Resource resource = (Resource) resourceIter.next();
              String resourceUri = URI.decode(resource.getURI().toString());
              if (CoreStringUtil.endsWithIgnoreCase(resourceUri, importPath)) {
                resources.add(resource);
                break;
              }
            }
          }
        }
      }
    } else {
      // find the resource that matches the model name
      for (Iterator resourceIter = rsrcs.iterator(); resourceIter.hasNext(); ) {
        Resource resource = (Resource) resourceIter.next();
        String resourceName = modelEditor.getModelName(resource);
        if (resourceName.equalsIgnoreCase(modelName)) {
          resources.add(resource);
          break;
        }
      }
    }
    if (!resources.isEmpty()) {
      return resources;
    }
    // all open resources as model could not be found
    return rsrcs;
  }
  /**
   * @see org.teiid.designer.core.container#isBuiltInResource(org.eclipse.emf.common.util.URI)
   * @since 4.3
   */
  @Override
  public boolean isBuiltInResource(final URI theUri) {
    if (theUri == null) {
      return false;
    }

    // The Container for this ResourceFinder should not have a built-in resouce within its contents.
    // If we find a non-external resource by this URI then return false.
    if (findByURI(theUri, false) != null) {
      return false;
    }

    String uriString = URI.decode(theUri.toString());

    // If the URI is to the Teiid Designer built-in datatypes model
    if (uriString.startsWith(BUILTIN_DATATYPES_URI)
        || uriString.endsWith(DATATYPES_MODEL_FILE_NAME)) {
      return true;
    }

    // If the URI is to the Teiid Designer built-in UML primitive types model
    if (uriString.startsWith(UML_PRIMITIVE_TYPES_INTERNAL_URI)
        || uriString.endsWith(UML_PRIMITIVE_TYPES_MODEL_FILE_NAME)) {
      return true;
    }

    // If the URI is to the Teiid Designer built-in relationship model
    if (uriString.startsWith(RELATIONSHIP_PRIMITIVE_TYPES_INTERNAL_URI)
        || uriString.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_MODEL_FILE_NAME)) {
      return true;
    }

    // If the URI is to one of the XSD global resources
    ResourceSet globalResourceSet = XSDSchemaImpl.getGlobalResourceSet();
    if (globalResourceSet != null && globalResourceSet.getResource(theUri, false) != null) {
      return true;
    }

    // If the URI is a logical URI to one of the XSD global resources
    if (uriString.endsWith(SCHEMA_FOR_SCHEMA_URI_2001_SUFFIX)
        || uriString.endsWith(MAGIC_SCHEMA_URI_2001_SUFFIX)
        || uriString.endsWith(SCHEMA_INSTANCE_URI_2001_SUFFIX)) {

      return true;
    }

    // If the URI is to one of the Teiid Designer metamodel resources
    if (uriString.startsWith(METAMODEL_PREFIX)) {
      return true;
    }

    // If the URI is to one of the IBM UML2 metamodel resources
    if (uriString.startsWith(UML2_METAMODELS_PREFIX)) {
      return true;
    }

    // If the URI is to the Teiid Designer built-in system models
    if (isBuiltInSystemResource(theUri)) {
      return true;
    }

    // If the URI is to one of our metamodels
    try {
      if (ModelerCore.getMetamodelRegistry().containsURI(theUri)) {
        return true;
      }
    } catch (Exception e) {
      // do nothing
    }

    return false;
  }
 private static String normalizeUriToString(final URI uri) {
   final String uriString = new Path(URI.decode(uri.toString())).toString();
   return normalizeUriString(uriString);
 }
  /**
   * Returns true if the specified URI string is one of the well-known Teiid Designer/EMF
   * identifiers to a global resource such as
   *
   * <p>"http://www.metamatrix.com/metamodels/SimpleDatatypes-instance"
   * "http://www.metamatrix.com/metamodels/UmlPrimitiveTypes-instance"
   * "http://www.metamatrix.com/relationships/BuiltInRelationshipTypes-instance"
   * "http://www.w3.org/2001/XMLSchema" "http://www.w3.org/2001/MagicXMLSchema"
   * "http://www.w3.org/2001/XMLSchema-instance" otherwise false is returned.
   *
   * @param uri the URI string
   */
  public static String getGlobalResourceUri(final String uri) {
    if (uri == null) return null;

    // If the URI is to the Teiid Designer built-in datatypes model ...
    if (uri.startsWith(DatatypeConstants.BUILTIN_DATATYPES_URI))
      return DatatypeConstants.BUILTIN_DATATYPES_URI;
    if (uri.endsWith(DatatypeConstants.DATATYPES_MODEL_FILE_NAME))
      return DatatypeConstants.BUILTIN_DATATYPES_URI;

    // If the URI is to the Teiid Designer built-in UML primitive types model ...
    if (uri.startsWith(UML_PRIMITIVE_TYPES_INTERNAL_URI)) return UML_PRIMITIVE_TYPES_INTERNAL_URI;
    if (uri.endsWith(UML_PRIMITIVE_TYPES_MODEL_FILE_NAME)) return UML_PRIMITIVE_TYPES_INTERNAL_URI;
    if (uri.startsWith(UML_METAMODEL_URI)) return UML_METAMODEL_URI;

    // If the URI is to the Teiid Designer built-in relationship model ...
    if (uri.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_INTERNAL_URI))
      return RELATIONSHIP_PRIMITIVE_TYPES_INTERNAL_URI;
    if (uri.endsWith(RELATIONSHIP_PRIMITIVE_TYPES_MODEL_FILE_NAME))
      return RELATIONSHIP_PRIMITIVE_TYPES_INTERNAL_URI;

    // If the URI is to one of the Emf XMLSchema resources ...
    if (uri.startsWith(ModelerCore.XML_SCHEMA_INSTANCE_GENERAL_URI))
      return ModelerCore.XML_SCHEMA_INSTANCE_GENERAL_URI;
    if (uri.startsWith(ModelerCore.XML_SCHEMA_GENERAL_URI))
      return ModelerCore.XML_SCHEMA_GENERAL_URI;
    if (uri.startsWith(ModelerCore.XML_MAGIC_SCHEMA_GENERAL_URI))
      return ModelerCore.XML_MAGIC_SCHEMA_GENERAL_URI;
    if (uri.equals(ModelerCore.XML_XSD_GENERAL_URI)) return ModelerCore.XML_XSD_GENERAL_URI;

    // If the URI is in the form of an Eclipse platform path to
    // one of the Emf XMLSchema resources ...
    if (uri.startsWith(
        XML_SCHEMA_ECLIPSE_PLATFORM_URI_PREFIX)) // MagicXMLSchema.xsd suffix on the resource URI
    if (uri.indexOf(XML_MAGIC_SCHEMA_ECLIPSE_PLATFORM_URI_SUFFIX) > 0)
        return ModelerCore.XML_MAGIC_SCHEMA_GENERAL_URI;
      else if (uri.indexOf(XML_SCHEMA_ECLIPSE_PLATFORM_URI_SUFFIX) > 0)
        return ModelerCore.XML_SCHEMA_GENERAL_URI;
      else if (uri.indexOf(XML_SCHEMA_INSTANCE_ECLIPSE_PLATFORM_URI_SUFFIX) > 0)
        return ModelerCore.XML_SCHEMA_INSTANCE_GENERAL_URI;

    // Next check if the import reference is to one of our system models
    try {
      final Resource[] systemModels = ModelerCore.getSystemVdbResources();
      for (int i = 0; i != systemModels.length; ++i) {
        final String systemModelUri = URI.decode(systemModels[i].getURI().toString());
        if (uri.equalsIgnoreCase(systemModelUri)) return systemModelUri;
      }
    } catch (final Exception e) {
      // do nothing
    }

    // Next check if the import reference is to one of our metamodels
    try {
      if (ModelerCore.getMetamodelRegistry().containsURI(uri)) {
        final URI metamodelUri = ModelerCore.getMetamodelRegistry().getURI(uri);
        return ModelerCore.getMetamodelRegistry()
            .getMetamodelDescriptor(metamodelUri)
            .getNamespaceURI();
      }
    } catch (final Exception e) {
      // do nothing
    }

    return null;
  }