intarsys PDF library API

de.intarsys.pdf.cos
Class COSBasedObject

java.lang.Object
  extended by de.intarsys.pdf.cos.COSBasedObject
All Implemented Interfaces:
ICOSObjectListener, IAttributeSupport
Direct Known Subclasses:
CDSBase, CIDSystemInfo, CIDToGIDMap, CMap, COSCatalog, COSEncryption, COSInfoDict, COSObjectStream, COSTrailer, FDObject, PDObject

public abstract class COSBasedObject
extends Object
implements IAttributeSupport, ICOSObjectListener

The abstract superclass for all objects/data structures that are build on the basic COSObject types.

The base COSObject will represent the state while this wrapper will provide the behavior.

The COSBasedObject and its base COSObject are always closely related, all changes are immediately reflected in both objects.

The COSBasedObject uses a META framework that ensures identity (you will always get the identical COSBasedObject for a COSObject created via META) and defines the lifecycle of the COSBasedObject. A COSBasedObject should always be created using META.createNew or META.createFromCos.

A COSBasedObject based on a COSDictionary can use some convenience methods for generic access to its fields. As a convention, filed names are always declared with the associated COSBasedObject as public static final COSName DK_.

The COSBasedObject implements IAttributeSupport. Client code can use this feature to transparently associate objects with objects from client code, for example for caching or client defined relationships.


Nested Class Summary
static class COSBasedObject.MetaClass
          The meta class implementation
 
Field Summary
static COSBasedObject.MetaClass META
          The meta class instance
 
Method Summary
 void changed(COSObject pObject, Object slot, Object oldValue, Object newValue)
          A COSObject has changed its internal state.
 COSArray cosGetArray()
          Get the base object as a COSArray.
 COSDictionary cosGetDict()
          Get the base object as a COSDictionary.
 COSDocument cosGetDoc()
          The COSDocument for this.
 COSObject cosGetField(COSName name)
          The COSObject associated with name in the receiver or COSNull.
 COSObject cosGetObject()
          The base COSObject for this.
 COSStream cosGetStream()
          Get the base object as a COSStream.
 boolean cosHasField(COSName name)
          Answer true if this has a field named name.
 COSObject cosRemoveField(COSName name)
          Remove a field in this.
 COSObject cosSetField(COSName name, COSObject cosObj)
          Set a field value in this.
 Object getAttribute(Object key)
          get an attribute from the context
 boolean getFieldBoolean(COSName name, boolean defaultValue)
          The value of a field within this as a boolean or the defaultValue if not found or not a COSBoolean.
 CDSDate getFieldDate(COSName name, CDSDate defaultValue)
          The value of a field within this as a CDSDate or the defaultValue if not found or not a COSString.
 float getFieldFixed(COSName name, float defaultValue)
          The value of a field within this as a float or the defaultValue if not found or not a COSNumber.
 float[] getFieldFixedArray(COSName name, float[] defaultValue)
          The value of a field within this as a float[] or the defaultValue if not found or not a COSArray.
 int getFieldInt(COSName name, int defaultValue)
          The value of a field within this as a int or the defaultValue if not found or not a COSNumber.
 String getFieldMLString(COSName name, String defaultValue)
          The value of a field within this as a String or the defaultValue if not found or not a COSString.
 String getFieldString(COSName name, String defaultValue)
          The value of a field within this as a String or the defaultValue if not found or not a COSString.
 void invalidateCaches()
          Invalidate all local caches as the base object may have changed.
 Object removeAttribute(Object key)
          remove an attribute in the context
 Object setAttribute(Object key, Object value)
          set the value of an attribute in the context
 void setFieldBoolean(COSName name, boolean value)
          Set the value of field namewithin this.
 void setFieldFixed(COSName name, float value)
          Set the value of field namewithin this.
 void setFieldInt(COSName name, int value)
          Set the value of field namewithin this.
 void setFieldMLString(COSName name, String value)
          Set the value of field namewithin this.
 void setFieldName(COSName name, String value)
          Set the value of field namewithin this.
 void setFieldObject(COSName name, COSBasedObject value)
          Set the value of field namewithin this.
 void setFieldString(COSName name, String value)
          Set the value of field namewithin this.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

META

public static final COSBasedObject.MetaClass META
The meta class instance

Method Detail

changed

public void changed(COSObject pObject,
                    Object slot,
                    Object oldValue,
                    Object newValue)
Description copied from interface: ICOSObjectListener
A COSObject has changed its internal state. For any COSObject this may be a change in containement (slot == COSObject.SLOT_CONTAINER).

For containers itself, this may be a change in the collection of contained objects. For dictionaries, slot will be the COSName of the changed entry, for arrays slot will be the Integer key. A stream may indicate a change in its byte content using (slot == COSStream.SLOT_BYTES).

A slot value of null may indicate a "changed all" event. For example you can expect for a clear operation on an array only a single "changed all" event.

Specified by:
changed in interface ICOSObjectListener
Parameters:
pObject - The object that has changed
slot - The slot in the object that has changed (or null for unspecified change).
oldValue - The old value of the slot if known.
newValue - The new value of the slot if known.

cosGetArray

public COSArray cosGetArray()
Get the base object as a COSArray.

This will throw a ClassCastException if the base type is not appropriate!

Returns:
Get the base object as a COSArray.

cosGetDict

public COSDictionary cosGetDict()
Get the base object as a COSDictionary.

This will throw a ClassCastException if the base type is not appropriate!

Returns:
Get the base object as a COSDictionary.

cosGetDoc

public COSDocument cosGetDoc()
The COSDocument for this.

Returns:
The COSDocument for this.

cosGetField

public COSObject cosGetField(COSName name)
The COSObject associated with name in the receiver or COSNull.

This method requires the base object to be a COSDictionary.

Parameters:
name - The COSDictionary field to read
Returns:
The COSObject associated with name in the receiver or COSNull.

cosGetObject

public COSObject cosGetObject()
The base COSObject for this.

Returns:
The base COSObject for this.

cosGetStream

public COSStream cosGetStream()
Get the base object as a COSStream.

This will throw a ClassCastException if the base type is not appropriate!

Returns:
Get the base object as a COSStream.

cosHasField

public boolean cosHasField(COSName name)
Answer true if this has a field named name.

This method requires the base object to be a COSDictionary.

Parameters:
name - the field to check
Returns:
Answer true if this has a field named name.

cosRemoveField

public COSObject cosRemoveField(COSName name)
Remove a field in this. The previously associated object is returned.

This method requires the base object to be a COSDictionary.

Parameters:
name - the field to remove from the receiver
Returns:
The previously associated object is returned.

cosSetField

public COSObject cosSetField(COSName name,
                             COSObject cosObj)
Set a field value in this. The previously associated object is returned.

This method requires the base object to be a COSDictionary.

Parameters:
name - The field to set
cosObj - The object to set in the field
Returns:
The previously associated object is returned.

getAttribute

public Object getAttribute(Object key)
Description copied from interface: IAttributeSupport
get an attribute from the context

Specified by:
getAttribute in interface IAttributeSupport
Parameters:
key - the name of the attribute to get
Returns:
The value of the attribute to get

getFieldBoolean

public boolean getFieldBoolean(COSName name,
                               boolean defaultValue)
The value of a field within this as a boolean or the defaultValue if not found or not a COSBoolean.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a boolean

getFieldDate

public CDSDate getFieldDate(COSName name,
                            CDSDate defaultValue)
The value of a field within this as a CDSDate or the defaultValue if not found or not a COSString.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a CDSDate

getFieldFixed

public float getFieldFixed(COSName name,
                           float defaultValue)
The value of a field within this as a float or the defaultValue if not found or not a COSNumber.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a float

getFieldFixedArray

public float[] getFieldFixedArray(COSName name,
                                  float[] defaultValue)
The value of a field within this as a float[] or the defaultValue if not found or not a COSArray.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a float[]

getFieldInt

public int getFieldInt(COSName name,
                       int defaultValue)
The value of a field within this as a int or the defaultValue if not found or not a COSNumber.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a int

getFieldMLString

public String getFieldMLString(COSName name,
                               String defaultValue)
The value of a field within this as a String or the defaultValue if not found or not a COSString. The String is "expanded" to containn the correct new line characters.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a String

getFieldString

public String getFieldString(COSName name,
                             String defaultValue)
The value of a field within this as a String or the defaultValue if not found or not a COSString.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
defaultValue - The default value to return if field is not found or not of appropriate type.
Returns:
The value of a field within this as a String

invalidateCaches

public void invalidateCaches()
Invalidate all local caches as the base object may have changed.


removeAttribute

public Object removeAttribute(Object key)
Description copied from interface: IAttributeSupport
remove an attribute in the context

Specified by:
removeAttribute in interface IAttributeSupport
Parameters:
key - the name of the attribute to remove
Returns:
The previously associated object for key

setAttribute

public Object setAttribute(Object key,
                           Object value)
Description copied from interface: IAttributeSupport
set the value of an attribute in the context

Specified by:
setAttribute in interface IAttributeSupport
Parameters:
key - the name of the attribute to set
value - the new value the attribute
Returns:
The previously associated object for key

setFieldBoolean

public void setFieldBoolean(COSName name,
                            boolean value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

setFieldFixed

public void setFieldFixed(COSName name,
                          float value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

setFieldInt

public void setFieldInt(COSName name,
                        int value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

setFieldMLString

public void setFieldMLString(COSName name,
                             String value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

setFieldName

public void setFieldName(COSName name,
                         String value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

setFieldString

public void setFieldString(COSName name,
                           String value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

setFieldObject

public void setFieldObject(COSName name,
                           COSBasedObject value)
Set the value of field namewithin this.

This method requires the base object to be a COSDictionary.

Parameters:
name - The name of the field.
value - The new value of the field.

toString

public String toString()
Overrides:
toString in class Object

intarsys PDF library API

Copyright © 2006 intarsys consulting GmbH. All Rights Reserved.