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 URLcalculateManagedUrl(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 ManageableInstancecreateInstanceResource(ResourceAccessor accessor, ShapeTreeContext context, URL resourceUrl, ResourceAttributes headers, String body, String contentType) Creates the resource identified by the providedresourceUrland gets a correspondingManageableInstance.Gets a list ofManageableInstances contained in a managed resource that is a container.static ManageableInstancegetInstance(ResourceAccessor accessor, ShapeTreeContext context, URL resourceUrl) Return aManageableInstanceconstructed starting with the resource identified by the providedresourceUrl.booleanIndicates whether the ManageableInstance represents a managed state, with a ManagedResource assigned one or more shape trees by a ShapeTreeManager in a ManagerResourcebooleanIndicates whether the ManageableInstance represents an unmanaged state, with a UnmanagedResource and a MissingManagerResourcebooleanstatic ManageableInstancereloadInstance(ManageableInstance originalInstance) Return a new version of providedManageableInstanceoriginalInstancebooleanIndicates 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 ofManageableInstances contained in a managed resource that is a container.- Returns:
- List of contained
ManageableInstances - Throws:
ShapeTreeException
-
reloadInstance
public static ManageableInstance reloadInstance(ManageableInstance originalInstance) throws ShapeTreeException Return a new version of providedManageableInstanceoriginalInstance- 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 aManageableInstanceconstructed starting with the resource identified by the providedresourceUrl. TheresourceUrlmay target either aManageableResource, or aManagerResource.Both the
ManageableResourceandManagerResourceare retrieved and loaded as specifically typed sub-classes that indicate whether they exist, or (in the case ofManageableResource) whether they are managed.- Parameters:
accessor-ResourceAccessorto use to getInstanceResourcescontext-ShapeTreeContextresourceUrl- URL of the resource to get- Returns:
ManageableInstanceincludingManageableResourceandManagerResource- 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 theShapeTreeManagerattributes- Parsed link headers fromManagerResourceresponse- 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 providedresourceUrland gets a correspondingManageableInstance. This may create either aManageableResourceor aManagerResource. The newly created resource is loaded into the instance, and the correspondingManageableResourceorManagerResourceis 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-ShapeTreeContextresourceUrl- URL of the resource to createheaders- Incoming HTTP headersbody- Body of the resource to createcontentType- Content-type of the resource to create- Returns:
ManageableInstanceincludingManageableResourceandManagerResource- Throws:
ShapeTreeException
-
getResourceAccessor
-
getShapeTreeContext
-
isWasRequestForManager
public boolean isWasRequestForManager() -
getManageableResource
-
getManagerResource
-