/**
   * 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);
  }
  /**
   * Converts the namespaces array of the given namespace aware element into a String representation
   * using package (.) and class ($) delimiters. The method uses the classpath to determine for each
   * element of the namespace if it identifies a package or a class.
   *
   * @param naElement
   * @return single string representation of namespace
   */
  public static String getNamespacesAsString(NamespaceAwareElement me) {

    JavaClasspath javaClasspath = JavaClasspath.get(me);
    String containerName = "";

    Iterator<String> it = me.getNamespaces().iterator();
    while (it.hasNext()) {
      String namespaceFragment = it.next();
      // Does it point at a classifier or a package as container?
      String assumedPackageName =
          containerName + namespaceFragment + JavaUniquePathConstructor.PACKAGE_SEPARATOR;
      String assumedClassifierName =
          containerName + namespaceFragment + JavaUniquePathConstructor.CLASSIFIER_SEPARATOR;

      if (it.hasNext()) {
        if (javaClasspath.existsPackage(assumedClassifierName)) {
          containerName = assumedClassifierName;
        } else {
          // Assume package
          containerName = assumedPackageName;
        }
      } else {
        if (javaClasspath.existsPackage(assumedPackageName)) {
          // A package is always available as key
          containerName = assumedPackageName;
        } else {
          // Assume classifier that is not key, but value in the map
          containerName = assumedClassifierName;
        }
      }
    }

    return containerName;
  }