PDF Clown
0.1.2

org.pdfclown.objects
Class PdfObjectWrapper<TDataObject extends PdfDataObject>

java.lang.Object
  extended by org.pdfclown.objects.PdfObjectWrapper<TDataObject>
All Implemented Interfaces:
Cloneable, IPdfObjectWrapper
Direct Known Subclasses:
Action, Annotation, AnnotationActions, Appearance, AppearanceCharacteristics, AppearanceCharacteristics.IconFitObject, AppearanceStates, Array, Article, ArticleElement, ArticleElements, Bookmark, Bookmarks, Border, CalloutNote.LineObject, ChainedActions, ChoiceItem, ChoiceItems, Color, ColorSpace, Contents, Destination, Document, DocumentActions, EmbeddedFile, ExtGState, Field, FieldActions, Fields, FieldWidgets, FileIdentifier, FileSpecification, Font, Form, Function, Functions, GoToEmbedded.PathElement, Information, LanguageIdentifier, Launch.WinTarget, LayerConfiguration, LayerDefinition, MediaClip, MediaClipData.Viability, MediaOffset, MediaPlayer, MediaPlayers, MediaPlayParameters, MediaPlayParameters.Viability, MediaScreenParameters, MediaScreenParameters.Viability, MediaScreenParameters.Viability.FloatingWindowParameters, Metadata, Movie, Names, Page, PageActions, PageLabel, Pages, PropertyList, Rectangle, RelatedFiles, Rendition, Rendition.Viability, ResourceItems, Resources, SetLayerState.LayerStates, Shading, SoftwareIdentifier, SoftwareIdentifier.Version, Sound, Transition, Tree, ViewerPreferences, XObject

public abstract class PdfObjectWrapper<TDataObject extends PdfDataObject>
extends Object
implements Cloneable, IPdfObjectWrapper

High-level representation of a PDF object.

Specialized objects don't inherit directly from their low-level counterparts (e.g. Contents extends PdfStream, Pages extends PdfArray and so on) because there's no plain one-to one mapping between primitive PDF types and specialized instances: the Content entry of Page dictionaries may be a simple reference to a PdfStream or a PdfArray of references to PdfStreams, Pages collections may be spread across a B-tree instead of a flat PdfArray and so on.

So, in order to hide all these annoying inner workings, I chose to adopt a composition pattern instead of the apparently-reasonable (but actually awkward!) inheritance pattern. Nonetheless, users can navigate through the low-level structure getting the baseDataObject backing this object.

Version:
0.1.2, 12/28/12
Author:
Stefano Chizzolini (http://www.stefanochizzolini.it)

Constructor Summary
protected PdfObjectWrapper()
          Instantiates an empty wrapper.
protected PdfObjectWrapper(Document context, TDataObject baseDataObject)
          Instantiates a wrapper registering the specified base data object into the specified document context.
protected PdfObjectWrapper(File context, TDataObject baseDataObject)
          Instantiates a wrapper registering the specified base data object into the specified file context.
protected PdfObjectWrapper(PdfDirectObject baseObject)
          Instantiates a wrapper from the specified base object.
 
Method Summary
protected  void checkCompatibility(Object feature)
          Checks whether the specified feature is compatible with the document's conformance version.
 Object clone(Document context)
          Gets a clone of the object, registered inside the given document context.
 boolean delete()
          Removes the object from its document context.
 boolean equals(Object obj)
           
 boolean exists()
          Gets whether the underlying data object is concrete.
 TDataObject getBaseDataObject()
          Gets the underlying data object.
 PdfDirectObject getBaseObject()
          Gets the underlying reference object, if available; otherwise, gets the underlying data object.
static PdfDirectObject getBaseObject(PdfObjectWrapper<?> wrapper)
          Gets the PDF object backing the specified wrapper.
 PdfIndirectObject getContainer()
          Gets the indirect object containing the base object.
 PdfIndirectObject getDataContainer()
          Gets the indirect object containing the base data object.
 Document getDocument()
          Gets the document context.
 File getFile()
          Gets the file context.
 Metadata getMetadata()
          Gets the metadata associated to this object.
protected  PdfString retrieveName()
          Retrieves the name possibly associated to this object, walking through the document's name dictionary.
protected  PdfDirectObject retrieveNamedBaseObject()
          Retrieves the object name, if available; otherwise, behaves like getBaseObject().
protected  void setBaseObject(PdfDirectObject value)
           
 void setMetadata(Metadata value)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PdfObjectWrapper

protected PdfObjectWrapper()
Instantiates an empty wrapper.


PdfObjectWrapper

protected PdfObjectWrapper(PdfDirectObject baseObject)
Instantiates a wrapper from the specified base object.

Parameters:
baseObject - PDF object backing this wrapper. MUST be a reference every time available.

PdfObjectWrapper

protected PdfObjectWrapper(Document context,
                           TDataObject baseDataObject)
Instantiates a wrapper registering the specified base data object into the specified document context.

Parameters:
context - Document context into which the specified data object has to be registered.
baseDataObject - PDF data object backing this wrapper.
See Also:
PdfObjectWrapper(File, PdfDataObject)

PdfObjectWrapper

protected PdfObjectWrapper(File context,
                           TDataObject baseDataObject)
Instantiates a wrapper registering the specified base data object into the specified file context.

Parameters:
context - File context into which the specified data object has to be registered.
baseDataObject - PDF data object backing this wrapper.
See Also:
PdfObjectWrapper(Document, PdfDataObject)
Method Detail

getBaseObject

public static PdfDirectObject getBaseObject(PdfObjectWrapper<?> wrapper)
Gets the PDF object backing the specified wrapper.

Parameters:
wrapper - Object to extract the base from.

clone

public Object clone(Document context)
Gets a clone of the object, registered inside the given document context.

Parameters:
context - Which document the clone has to be registered in.

delete

public boolean delete()
Removes the object from its document context.

The object is no more usable after this method returns.

Returns:
Whether the object was actually decontextualized (only indirect objects can be decontextualized).

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

exists

public boolean exists()
Gets whether the underlying data object is concrete.


getBaseDataObject

public TDataObject getBaseDataObject()
Gets the underlying data object.


getContainer

public PdfIndirectObject getContainer()
Gets the indirect object containing the base object.


getDataContainer

public PdfIndirectObject getDataContainer()
Gets the indirect object containing the base data object.


getDocument

public Document getDocument()
Gets the document context.


getFile

public File getFile()
Gets the file context.


getMetadata

public Metadata getMetadata()
Gets the metadata associated to this object.

Returns:
null, if base data object's type isn't suitable (only PdfDictionary and PdfStream objects are allowed).

setMetadata

public void setMetadata(Metadata value)
Throws:
UnsupportedOperationException - If base data object's type isn't suitable (only PdfDictionary and PdfStream objects are allowed).
See Also:
getMetadata()

getBaseObject

public PdfDirectObject getBaseObject()
Description copied from interface: IPdfObjectWrapper
Gets the underlying reference object, if available; otherwise, gets the underlying data object.

Specified by:
getBaseObject in interface IPdfObjectWrapper

checkCompatibility

protected void checkCompatibility(Object feature)
Checks whether the specified feature is compatible with the document's conformance version.

Parameters:
feature - Entity whose compatibility has to be checked. Supported types:
Throws:
RuntimeException - In case of version conflict (see Strict compatibility mode).
Since:
0.1.0

retrieveName

protected PdfString retrieveName()
Retrieves the name possibly associated to this object, walking through the document's name dictionary.


retrieveNamedBaseObject

protected PdfDirectObject retrieveNamedBaseObject()
Retrieves the object name, if available; otherwise, behaves like getBaseObject().


setBaseObject

protected void setBaseObject(PdfDirectObject value)

PDF Clown
0.1.2

Project home page

Copyright © 2006-2013 Stefano Chizzolini. Some Rights Reserved.
This documentation is available under the terms of the GNU Free Documentation License.