Class ResourceDescriptor
- java.lang.Object
-
- com.sodius.oslc.core.process.model.ResourceDescriptor
-
public class ResourceDescriptor extends Object
Encapsulates aResource
with its properties definitions.- Since:
- 3.3.0
-
-
Constructor Summary
Constructors Constructor Description ResourceDescriptor(com.sodius.oslc.core.rdf.Resource resource, ResourceShape shape, ConfigContext context)
Constructs an instance specifying the resource, its shape and context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigContext
getConfigContext()
Gets the configuration context used by the resource.ResourceShape
getOrCreateShape()
Gets or creates the resource shape of described resource.Optional<URI>
getPropertyDefinition(String name)
Convenient method to resolve a property definition, on this resource descriptor, given its name.List<Object>
getPropertyValues(URI resource, URI definition)
Same asgetPropertyValues(URI, Optional)
, but will only return properties whose subject directly matches the given resource.List<Object>
getPropertyValues(URI definition, Optional<OslcClient> client)
Retrieves all the values of a given property.com.sodius.oslc.core.rdf.Resource
getResource()
Gets the resource.static com.sodius.oslc.core.rdf.Resource
getResource(URI uri, com.sodius.oslc.core.rdf.Model model)
Convenient method to resolve aResource
within aModel
.Optional<ResourceShape>
getShape()
Gets the resource shape.Map<URI,Property>
getValuedProperties()
Gets the properties having a value.
-
-
-
Constructor Detail
-
ResourceDescriptor
public ResourceDescriptor(com.sodius.oslc.core.rdf.Resource resource, ResourceShape shape, ConfigContext context)
Constructs an instance specifying the resource, its shape and context.- Parameters:
resource
- the resource.shape
- the resource shape.context
- the configuration context.- Throws:
NullPointerException
- ifresource
orcontext
arenull
.
-
-
Method Detail
-
getResource
public static com.sodius.oslc.core.rdf.Resource getResource(URI uri, com.sodius.oslc.core.rdf.Model model)
Convenient method to resolve aResource
within aModel
.This method assumes that the
context
, if any, is included already inuri
.- Parameters:
uri
- the resource URI.model
- the containing model.- Returns:
- the corresponding resource.
-
getResource
public com.sodius.oslc.core.rdf.Resource getResource()
Gets the resource.- Returns:
- the resource.
-
getShape
public Optional<ResourceShape> getShape()
Gets the resource shape.- Returns:
- the resource shape.
-
getOrCreateShape
public ResourceShape getOrCreateShape()
Gets or creates the resource shape of described resource.Unlike
getShape()
this method creates a shape based on the property definitions, if nooslc:instanceShape
property was present.- Returns:
- the actual resource shape of the resource if the
oslc:instanceShape
property is present, a made-up shape otherwise.
-
getConfigContext
public ConfigContext getConfigContext()
Gets the configuration context used by the resource.- Returns:
- the configuration context used by the resource.
-
getValuedProperties
public Map<URI,Property> getValuedProperties()
Gets the properties having a value.- Returns:
- URI property definitions mapped to the corresponding Property.
-
getPropertyValues
public List<Object> getPropertyValues(URI definition, Optional<OslcClient> client)
Retrieves all the values of a given property.If a statement object is a
Literal
, the methodLiteral.getValue()
is used to extract the value in its Java-equivalent type; otherwise, if the statement object is aResource
, the object is converted to aURI
and that is what is returned unless the parameterclient
is provided. If an OSLC client is provided, the object URI is fetched looking for thedcterms:title
orrdfs:label
properties. If they are not present in the resulting resource, or any exception is thrown when trying to fetch it, the original object URI is used. This behavior is convenient when, for example, the object of a statement refers to a enumeration resource.- Parameters:
definition
- the property definition.client
- optional OSLC client to resolve, if present, the referenced resource of an statement object looking for thedcterms:title
orrdfs:label
properties. Provide this client when some enumeration types (URIs) are expected in the statement objects.- Returns:
- all the values of the given property definition.
-
getPropertyValues
public List<Object> getPropertyValues(URI resource, URI definition)
Same asgetPropertyValues(URI, Optional)
, but will only return properties whose subject directly matches the given resource.- Parameters:
resource
- the resource to look for properties.definition
- the property definition.- Returns:
- all the values of the given property definition
-
getPropertyDefinition
public Optional<URI> getPropertyDefinition(String name)
Convenient method to resolve a property definition, on this resource descriptor, given its name.- Parameters:
name
- the given name.- Returns:
- an empty
Optional
if no such property definition exists; its contained reference otherwise.
-
-