Class ManageableInstance
java.lang.Object
com.janeirodigital.shapetrees.core.resources.ManageableInstance
A ManageableInstance represents a pairing of a shape tree ManagerResource
and a ManageableResource.
The ManageableInstance may represent a managed
state, where the ManageableResource is a ManagedResource that is
managed by one or more shape trees assigned by the ShapeTreeManager
in the ManagedResource.Conversely, it could represent an unmanaged
state, where the ManageableResource is an UnmanagedResource and the
ManagedResource is a MissingManagedResource. Lastly, it may
represent other state combinations where one or both of the
ManageableResource or ManagedResource are missing.
Both ManageableResource and ManagedResource are looked up and loaded
upon construction of the ManageableInstance, which should be done
through a ResourceAccessor. Once constructed, the ManageableInstance
is immutable.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic URL
calculateManagedUrl
(URL managerUrl, ResourceAttributes attributes) Looks for the presence of the http://www.w3.org/ns/shapetrees#manages HTTP Link Relation in the providedattributes
, with a valid target URL of aManagedResource
.static ManageableInstance
createInstanceResource
(ResourceAccessor accessor, ShapeTreeContext context, URL resourceUrl, ResourceAttributes headers, String body, String contentType) Creates the resource identified by the providedresourceUrl
and gets a correspondingManageableInstance
.Gets a list ofManageableInstance
s contained in a managed resource that is a container.static ManageableInstance
getInstance
(ResourceAccessor accessor, ShapeTreeContext context, URL resourceUrl) Return aManageableInstance
constructed starting with the resource identified by the providedresourceUrl
.boolean
Indicates whether the ManageableInstance represents a managed state, with a ManagedResource assigned one or more shape trees by a ShapeTreeManager in a ManagerResourceboolean
Indicates whether the ManageableInstance represents an unmanaged state, with a UnmanagedResource and a MissingManagerResourceboolean
static ManageableInstance
reloadInstance
(ManageableInstance originalInstance) Return a new version of providedManageableInstance
originalInstance
boolean
Indicates whether the HTTP request that triggered the initialization of the ManageableInstance was targeted towards the ManagerResource or the ManageableResource.
-
Field Details
-
TEXT_TURTLE
- See Also:
-
-
Method Details
-
wasRequestForManager
public boolean wasRequestForManager()Indicates whether the HTTP request that triggered the initialization of the ManageableInstance was targeted towards the ManagerResource or the ManageableResource.- Returns:
- True when the request targeted the ManagerResource
-
isUnmanaged
public boolean isUnmanaged()Indicates whether the ManageableInstance represents an unmanaged state, with a UnmanagedResource and a MissingManagerResource- Returns:
- True when the instance is in an unmanaged state
-
isManaged
public boolean isManaged()Indicates whether the ManageableInstance represents a managed state, with a ManagedResource assigned one or more shape trees by a ShapeTreeManager in a ManagerResource- Returns:
- True when the instance is in an managed state
-
getContainedInstances
Gets a list ofManageableInstance
s contained in a managed resource that is a container.- Returns:
- List of contained
ManageableInstance
s - Throws:
ShapeTreeException
-
reloadInstance
public static ManageableInstance reloadInstance(ManageableInstance originalInstance) throws ShapeTreeException Return a new version of providedManageableInstance
originalInstance
- Parameters:
originalInstance
- Original instance to get a new version of- Returns:
- Reloaded version of
originalInstance
- Throws:
ShapeTreeException
-
getInstance
public static ManageableInstance getInstance(ResourceAccessor accessor, ShapeTreeContext context, URL resourceUrl) throws ShapeTreeException Return aManageableInstance
constructed starting with the resource identified by the providedresourceUrl
. TheresourceUrl
may target either aManageableResource
, or aManagerResource
.Both the
ManageableResource
andManagerResource
are retrieved and loaded as specifically typed sub-classes that indicate whether they exist, or (in the case ofManageableResource
) whether they are managed.- Parameters:
accessor
-ResourceAccessor
to use to getInstanceResource
scontext
-ShapeTreeContext
resourceUrl
- URL of the resource to get- Returns:
ManageableInstance
includingManageableResource
andManagerResource
- Throws:
ShapeTreeException
-
calculateManagedUrl
public static URL calculateManagedUrl(URL managerUrl, ResourceAttributes attributes) throws ShapeTreeException Looks for the presence of the http://www.w3.org/ns/shapetrees#manages HTTP Link Relation in the providedattributes
, with a valid target URL of aManagedResource
. Falls back to a relatively crude inference when the more reliable header isn't available- Parameters:
managerUrl
- URL of theShapeTreeManager
attributes
- Parsed link headers fromManagerResource
response- Returns:
- URL of
ManagedResource
- Throws:
ShapeTreeException
-
createInstanceResource
public static ManageableInstance createInstanceResource(ResourceAccessor accessor, ShapeTreeContext context, URL resourceUrl, ResourceAttributes headers, String body, String contentType) throws ShapeTreeException Creates the resource identified by the providedresourceUrl
and gets a correspondingManageableInstance
. This may create either aManageableResource
or aManagerResource
. The newly created resource is loaded into the instance, and the correspondingManageableResource
orManagerResource
is looked up and loaded into the instance alongside it. They are loaded as specifically typed sub-classes that indicate whether they exist, or (in the case ofManageableResource
), whether they are managed.- Parameters:
context
-ShapeTreeContext
resourceUrl
- URL of the resource to createheaders
- Incoming HTTP headersbody
- Body of the resource to createcontentType
- Content-type of the resource to create- Returns:
ManageableInstance
includingManageableResource
andManagerResource
- Throws:
ShapeTreeException
-
getResourceAccessor
-
getShapeTreeContext
-
isWasRequestForManager
public boolean isWasRequestForManager() -
getManageableResource
-
getManagerResource
-