Class HrefHelper


  • public final class HrefHelper
    extends java.lang.Object
    A collection of static methods used to build 'href' attribute values for REST 'link' elements.
    Author:
    Dmitry Kornilov
    Since:
    EclipseLink 2.6.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BASE_REST_SCHEMAS_URL
      URL to base REST schemas
    • Constructor Summary

      Constructors 
      Constructor Description
      HrefHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildBaseRestSchemaRef​(java.lang.String type)
      Returns a link to standard base schema of given type.
      static java.lang.String buildEntityDescribesHref​(PersistenceContext context, java.lang.String entityName)
      Returns a href to single entity resource without primary key.
      static java.lang.String buildEntityFieldHref​(PersistenceContext context, java.lang.String entityName, java.lang.String entityId, java.lang.String fieldName)
      Builds a link to an entity field.
      static java.lang.String buildEntityHref​(PersistenceContext context, java.lang.String entityName, java.lang.String entityId)
      Returns a href to single entity resource.
      static java.lang.String buildEntityMetadataHref​(PersistenceContext context, java.lang.String entityName)
      Returns a href to entity resource metadata.
      static java.lang.String buildMetadataCatalogHref​(PersistenceContext context)
      Returns a href to metadata catalog.
      static java.lang.String buildQueryDescribesHref​(PersistenceContext context, java.lang.String queryName)
      Returns a href to single entity resource without primary key.
      static java.lang.String buildQueryHref​(PersistenceContext context, java.lang.String queryName, java.lang.String queryParams)
      Returns a href to query resource.
      static java.lang.String buildQueryMetadataHref​(PersistenceContext context, java.lang.String queryName)
      Returns a href to query resource.
      static java.lang.StringBuilder getEntityRoot​(PersistenceContext context, java.lang.String entityName)
      Returns StringBuilder containing entity root: http(s)://root:port/persistence/version/context/entity/entityName
      static java.lang.StringBuilder getMetadataRoot​(PersistenceContext context)
      Returns StringBuilder containing metadata-catalog root: http(s)://root:port/persistence/version/context/metadata-catalog
      static java.lang.StringBuilder getQueryRoot​(PersistenceContext context, java.lang.String queryName)
      Returns StringBuilder containing query root: http(s)://root:port/persistence/version/context/query/queryName
      static java.lang.StringBuilder getRoot​(java.lang.String baseUri, java.lang.String version, java.lang.String context)
      Returns StringBuilder containing application root: http(s)://root:port/persistence/version/context
      static java.lang.StringBuilder getRoot​(PersistenceContext context)
      Returns StringBuilder containing application root: http(s)://root:port/persistence/version/context
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • BASE_REST_SCHEMAS_URL

        public static final java.lang.String BASE_REST_SCHEMAS_URL
        URL to base REST schemas
        See Also:
        Constant Field Values
    • Constructor Detail

      • HrefHelper

        public HrefHelper()
    • Method Detail

      • getRoot

        public static java.lang.StringBuilder getRoot​(java.lang.String baseUri,
                                                      java.lang.String version,
                                                      java.lang.String context)
        Returns StringBuilder containing application root: http(s)://root:port/persistence/version/context
        Parameters:
        baseUri - the base URI
        version - the service version
        context - the persistent unit name
        Returns:
        StringBuilder
      • getRoot

        public static java.lang.StringBuilder getRoot​(PersistenceContext context)
        Returns StringBuilder containing application root: http(s)://root:port/persistence/version/context
        Parameters:
        context - the persistence context
        Returns:
        StringBuilder
      • getMetadataRoot

        public static java.lang.StringBuilder getMetadataRoot​(PersistenceContext context)
        Returns StringBuilder containing metadata-catalog root: http(s)://root:port/persistence/version/context/metadata-catalog
        Parameters:
        context - the persistence context
        Returns:
        StringBuilder
      • getEntityRoot

        public static java.lang.StringBuilder getEntityRoot​(PersistenceContext context,
                                                            java.lang.String entityName)
        Returns StringBuilder containing entity root: http(s)://root:port/persistence/version/context/entity/entityName
        Parameters:
        context - the persistence context
        entityName - the entity name
        Returns:
        StringBuilder
      • getQueryRoot

        public static java.lang.StringBuilder getQueryRoot​(PersistenceContext context,
                                                           java.lang.String queryName)
        Returns StringBuilder containing query root: http(s)://root:port/persistence/version/context/query/queryName
        Parameters:
        context - the persistence context
        queryName - the query name
        Returns:
        StringBuilder
      • buildBaseRestSchemaRef

        public static java.lang.String buildBaseRestSchemaRef​(java.lang.String type)
        Returns a link to standard base schema of given type.
        Parameters:
        type - the schema type
        Returns:
        URL in string
      • buildEntityHref

        public static java.lang.String buildEntityHref​(PersistenceContext context,
                                                       java.lang.String entityName,
                                                       java.lang.String entityId)
        Returns a href to single entity resource. http(s)://root:port/persistence/version/context/entity/id
        Parameters:
        context - persistence context.
        entityName - entity name.
        entityId - entity ID.
        Returns:
        href to given entity.
      • buildEntityFieldHref

        public static java.lang.String buildEntityFieldHref​(PersistenceContext context,
                                                            java.lang.String entityName,
                                                            java.lang.String entityId,
                                                            java.lang.String fieldName)
        Builds a link to an entity field. http(s)://root:port/persistence/version/context/entity/id/attribute
        Parameters:
        context - persistence context.
        entityName - entity name.
        entityId - entity ID.
        fieldName - entity field name.
        Returns:
        href
      • buildEntityMetadataHref

        public static java.lang.String buildEntityMetadataHref​(PersistenceContext context,
                                                               java.lang.String entityName)
        Returns a href to entity resource metadata. http(s)://root:port/persistence/version/context/metadata-catalog/entity
        Parameters:
        context - persistence context.
        entityName - entity name.
        Returns:
        href to given entity.
      • buildEntityDescribesHref

        public static java.lang.String buildEntityDescribesHref​(PersistenceContext context,
                                                                java.lang.String entityName)
        Returns a href to single entity resource without primary key. Used in 'describes' links in resource metadata. http(s)://root:port/persistence/version/context/entity/entityName
        Parameters:
        context - persistence context.
        entityName - entity name.
        Returns:
        href to given entity resource.
      • buildQueryDescribesHref

        public static java.lang.String buildQueryDescribesHref​(PersistenceContext context,
                                                               java.lang.String queryName)
        Returns a href to single entity resource without primary key. Used in 'describes' links in resource metadata. http(s)://root:port/persistence/version/context/query/queryName
        Parameters:
        context - persistence context.
        queryName - query name.
        Returns:
        href to given entity resource.
      • buildMetadataCatalogHref

        public static java.lang.String buildMetadataCatalogHref​(PersistenceContext context)
        Returns a href to metadata catalog. http(s)://root:port/persistence/version/context/metadata-catalog
        Parameters:
        context - persistence context.
        Returns:
        href to resource catalog.
      • buildQueryHref

        public static java.lang.String buildQueryHref​(PersistenceContext context,
                                                      java.lang.String queryName,
                                                      java.lang.String queryParams)
        Returns a href to query resource. http(s)://root:port/persistence/version/context/query/queryName+queryParams
        Parameters:
        context - persistence context.
        queryName - name of the query
        queryParams - query parameters. Optional.
        Returns:
        href to resource catalog.
      • buildQueryMetadataHref

        public static java.lang.String buildQueryMetadataHref​(PersistenceContext context,
                                                              java.lang.String queryName)
        Returns a href to query resource. http(s)://root:port/persistence/version/context/query/queryName
        Parameters:
        context - persistence context.
        queryName - name of the query
        Returns:
        href to resource catalog.