Class OslcNamespaces
- java.lang.Object
-
- com.sodius.oslc.core.process.query.OslcNamespaces
-
public class OslcNamespaces extends Object
Defines prefix and namespace mappings of a given OSLC schema.- Since:
- 3.6.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OslcNamespaces
and(OslcNamespaces... namespaces)
Combines the receiver's namespaces with the given ones into a new instance.void
applyTo(ServiceProvider provider)
Adds the namespaces as prefix definitions on the given service providerOptional<String>
getNamespace(String prefix)
Returns the namespace associated with the given prefix, if any.Map<String,String>
getNamespaces()
Returns a non-modifiable map of prefix/namespace mappings.Optional<String>
getPrefix(String namespace)
Returns the prefix associated with the given namespace, if any.Optional<String>
getPrefixed(String uri)
Gets the prefixed name of a given URI as long as the namespace is mapped in this instance.Optional<QName>
getQName(String uri)
Splits a URI into a qualified name (namespace + localpart + prefix) as long as the namespace is mapped in this instance.static OslcNamespaces
of(Namespace... namespaces)
Creates a new instance with the given namespaces.static OslcNamespaces
of(Class<?>... resourceClasses)
Returns the namespaces defined in theOslcSchema
annotation of the packages of the given classes.static OslcNamespaces
wellKnown()
Returns the set of well-known namespaces, which includes RDF and OSLC namespaces (Core and domains), as defined by the specifications.
-
-
-
Method Detail
-
wellKnown
public static OslcNamespaces wellKnown()
Returns the set of well-known namespaces, which includes RDF and OSLC namespaces (Core and domains), as defined by the specifications.- Returns:
- the well-known namespaces.
-
of
public static OslcNamespaces of(Class<?>... resourceClasses)
Returns the namespaces defined in theOslcSchema
annotation of the packages of the given classes.- Parameters:
resourceClasses
- classes whose owning package defines aOslcSchema
annotation.- Returns:
- the namespaces defined in the
OslcSchema
annotations. - Throws:
IllegalArgumentException
- if noOslcSchema
annotation is found on a package.
-
of
public static OslcNamespaces of(Namespace... namespaces)
Creates a new instance with the given namespaces.- Parameters:
namespaces
- the namespaces to add- Returns:
- the new instance
-
getPrefix
public Optional<String> getPrefix(String namespace)
Returns the prefix associated with the given namespace, if any.- Parameters:
namespace
- a namespace.- Returns:
- the associated prefix, or an empty
Optional
if none. - Throws:
NullPointerException
- if namespace is null
-
getNamespace
public Optional<String> getNamespace(String prefix)
Returns the namespace associated with the given prefix, if any.- Parameters:
prefix
- a namespace prefix.- Returns:
- the associated namespace, or an empty
Optional
if none. - Throws:
NullPointerException
- if prefix is null
-
getNamespaces
public Map<String,String> getNamespaces()
Returns a non-modifiable map of prefix/namespace mappings.- Returns:
- a map whose keys are prefixes and values are the associated namespaces.
-
and
public OslcNamespaces and(OslcNamespaces... namespaces)
Combines the receiver's namespaces with the given ones into a new instance. If the same namespace is bound to multiple prefixes, the prefix of the last namespace in the list is retained.- Parameters:
namespaces
- the namespaces to combine- Returns:
- a new instance combining the given namespaces
-
applyTo
public void applyTo(ServiceProvider provider)
Adds the namespaces as prefix definitions on the given service provider- Parameters:
provider
- the provider on which to add the prefix definitions- See Also:
ServiceProvider.getPrefixDefinitions()
-
getQName
public Optional<QName> getQName(String uri)
Splits a URI into a qualified name (namespace + localpart + prefix) as long as the namespace is mapped in this instance.- Parameters:
uri
- the URI to split.- Returns:
- the corresponding
QName
if the namespace is mapped in this instance; an emptyOptional
otherwise. - Throws:
NullPointerException
- if the URI is null.IllegalArgumentException
- if the URI is not a namespace URI.- Since:
- 3.7.0
-
getPrefixed
public Optional<String> getPrefixed(String uri)
Gets the prefixed name of a given URI as long as the namespace is mapped in this instance.- Parameters:
uri
- the given URI.- Returns:
- the corresponding prefixed name if the namespace is mapped in this instance; an empty
Optional
otherwise. - Throws:
NullPointerException
- if the URI is null.IllegalArgumentException
- if the URI is not a namespace URI.- Since:
- 3.7.0
-
-