jPod PDF library

de.intarsys.pdf.cos
Class COSBasedObject

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

public abstract class COSBasedObject
extends Object
implements de.intarsys.tools.attribute.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)
           
 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)
           
 Object setAttribute(Object key, Object value)
           
 COSObject setFieldBoolean(COSName name, boolean value)
          Set the value of field namewithin this.
 COSObject setFieldFixed(COSName name, float value)
          Set the value of field namewithin this.
 COSObject setFieldInt(COSName name, int value)
          Set the value of field namewithin this.
 COSObject setFieldMLString(COSName name, String value)
          Set the value of field namewithin this.
 COSObject setFieldName(COSName name, String value)
          Set the value of field namewithin this.
 COSObject setFieldObject(COSName name, COSBasedObject value)
          Set the value of field namewithin this.
 COSObject 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 containment (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)
Specified by:
getAttribute in interface de.intarsys.tools.attribute.IAttributeSupport

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)
Specified by:
removeAttribute in interface de.intarsys.tools.attribute.IAttributeSupport

setAttribute

public Object setAttribute(Object key,
                           Object value)
Specified by:
setAttribute in interface de.intarsys.tools.attribute.IAttributeSupport

setFieldBoolean

public COSObject 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.
Returns:
The previously associated COSObject is returned.

setFieldFixed

public COSObject 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.
Returns:
The previously associated COSObject is returned.

setFieldInt

public COSObject 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.
Returns:
The previously associated COSObject is returned.

setFieldMLString

public COSObject 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.
Returns:
The previously associated COSObject is returned.

setFieldName

public COSObject 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.
Returns:
The previously associated COSObject is returned.

setFieldObject

public COSObject 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.
Returns:
The previously associated COSObject is returned.

setFieldString

public COSObject 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.
Returns:
The previously associated COSObject is returned.

toString

public String toString()
Overrides:
toString in class Object

jPod PDF library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.