Kanzi Framework  3.9.0
Java API
ObjectRef< ObjectType extends KanziObject > Class Template Reference

The ObjectRef class is used to store an owning reference to a KanziObject instance. More...

Inheritance diagram for ObjectRef< ObjectType extends KanziObject >:
[legend]

Public Member Functions

 ObjectRef (ObjectType object)
 Create an owning reference to the provided KanziObject instance. More...
 
ObjectRef< ObjectType > clone ()
 Creates a new ObjectRef instance that refers to the same Kanzi Object. More...
 
void close ()
 Close the ObjectRef instance. More...
 
ObjectType get ()
 Get the KanziObject derived type that is owned by this ObjectRef. More...
 

Static Public Member Functions

static< ObjectType extends KanziObject > ObjectRef< ObjectType > createObject (long objectReference)
 Create an owning reference from the provided native reference handle. More...
 
static< ResourceType extends Resource > ObjectRef< ResourceType > createResource (long objectReference)
 Create an owning reference from the provided native resource reference handle. More...
 

Detailed Description

The ObjectRef class is used to store an owning reference to a KanziObject instance.

The lifetime of the referred object is at least as long as the objectRef instance.

Calling the close method is highly recommended, most instances should be part of a try-with-resources block to ensure that the close method is automatically called when the variable goes out of scope.

Parameters
<ObjectType>The KanziObject derived type that is owned by this ObjectRef.

Constructor & Destructor Documentation

◆ ObjectRef()

ObjectRef ( ObjectType  object)

Create an owning reference to the provided KanziObject instance.

Parameters
objectObject that is owned by this ObjectRef.

Member Function Documentation

◆ clone()

ObjectRef<ObjectType> clone ( )

Creates a new ObjectRef instance that refers to the same Kanzi Object.

This increases the native reference count for the object. The original and created ObjectRef instances are both required to be closed independently.

◆ close()

void close ( )

Close the ObjectRef instance.

If no other references exist to the underlying KanziObject it is reclaimed.

◆ createObject()

static <ObjectType extends KanziObject> ObjectRef<ObjectType> createObject ( long  objectReference)
static

Create an owning reference from the provided native reference handle.

Use this version when ObjectType does not derive from Resource.

Parameters
objectReferenceNative handle to an existing ObjectReference.
Template Parameters
<ObjectType>The type of object to create.
Returns
A new ObjectRef instance that owns the provided object.

◆ createResource()

static <ResourceType extends Resource> ObjectRef<ResourceType> createResource ( long  objectReference)
static

Create an owning reference from the provided native resource reference handle.

Use this version when ResourceType derives from Resource.

Parameters
objectReferenceNative handle to an existing ObjectReference.
Template Parameters
<ResourceType>The resource type of object to create.
Returns
A new ObjectRef instance that owns the provided object.

◆ get()

ObjectType get ( )

Get the KanziObject derived type that is owned by this ObjectRef.

Returns
The Kanzi Object.