public static URI create()

in lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java [36:106]


  public static URI create(final ContextURL contextURL) {
    StringBuilder result = new StringBuilder();
    if (contextURL.getServiceRoot() != null) {
      result.append(contextURL.getServiceRoot());
    } else if (contextURL.getODataPath() != null) {
      String oDataPath = contextURL.getODataPath();
      char[] chars = oDataPath.toCharArray();
      for (int i = 1; i < chars.length - 1; i++) {
        if (chars[i] == '/' && chars[i - 1] != '/') {
          result.append("../");
        }
      }
    }

    result.append(Constants.METADATA);
    if (contextURL.getEntitySetOrSingletonOrType() != null) {
      result.append('#');
      if (contextURL.isCollection()) {
        result.append("Collection(")
            .append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType()))
            .append(")");
      } else {
        result.append(Encoder.encode(contextURL.getEntitySetOrSingletonOrType()));
      }
    }
    if (contextURL.getDerivedEntity() != null) {
      if (contextURL.getEntitySetOrSingletonOrType() == null) {
        throw new IllegalArgumentException("ContextURL: Derived Type without anything to derive from!");
      }
      result.append('/').append(Encoder.encode(contextURL.getDerivedEntity()));
    }
    if (contextURL.getKeyPath() != null) {
      result.append('(').append(contextURL.getKeyPath()).append(')');
    }
    if (contextURL.getNavOrPropertyPath() != null) {
      if (contextURL.getServiceRoot() == null || 
          !contextURL.getServiceRoot().isAbsolute()) {
        String[] paths = contextURL.getNavOrPropertyPath().split("/");
        for (String path : paths) {
          result.insert(0, "../");
        }
      }
      result.append('/').append(contextURL.getNavOrPropertyPath());
    }
    if (contextURL.getSelectList() != null) {
      result.append('(').append(contextURL.getSelectList()).append(')');
    }
    if (contextURL.isReference()) {
      if (contextURL.getServiceRoot() == null ||
          !contextURL.getServiceRoot().isAbsolute()) {
        result.insert(0, "../");
      }
      if (contextURL.getEntitySetOrSingletonOrType() != null) {
        throw new IllegalArgumentException("ContextURL: $ref with Entity Set");
      }
      if (contextURL.isCollection()) {
        result.append('#')
            .append("Collection(")
            .append(ContextURL.Suffix.REFERENCE.getRepresentation())
            .append(")");
      } else {
        result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
      }
    } else if (contextURL.getSuffix() != null) {
      if (contextURL.getEntitySetOrSingletonOrType() == null) {
        throw new IllegalArgumentException("ContextURL: Suffix without preceding Entity Set!");
      }
      result.append('/').append(contextURL.getSuffix().getRepresentation());
    }
    return URI.create(result.toString());
  }