Holger's
Java API

com.antelmann.imagedb
Class ImageHolder

java.lang.Object
  extended by com.antelmann.mgmt.EntityImpl
      extended by com.antelmann.imagedb.ImageHolder
All Implemented Interfaces:
Entity, Resource, Serializable

public class ImageHolder
extends EntityImpl

ImageHolder serves as a wrapper for image information stored in a database.

Author:
Holger Antelmann
See Also:
Serialized Form

Nested Class Summary
static class ImageHolder.Field
           
 
Field Summary
protected static String defaultType
          defaults to png
 
Fields inherited from class com.antelmann.mgmt.EntityImpl
propertyChangeSupport, props
 
Constructor Summary
ImageHolder()
          convenience constructor; id will be 0
ImageHolder(Integer id)
          time is automatically set to current system time
ImageHolder(Integer id, ImageHolder ih)
           
 
Method Summary
 void clear()
          resets all fields except id; all retrieved fields are also set to false (except for id)
 void clearProperties()
           
 Date getDate()
           
 String getDescription()
           
 Integer getID()
          returns the immutable id that is used for checking equality
 BufferedImage getImage()
          first, the internal buffer is checked; only if this is null, the URL will be checked.
 byte[] getRawImage()
          returns a copy of the raw data
 byte[] getRawThumbnail()
          returns a copy of the raw data
 BufferedImage getThumbnail()
           
 long getTime()
           
 String getTitle()
           
 String getType()
          defaults to png.
 URL getURL()
           
 ImageHolder insertInto(ImageDB db)
          inserts the image to the given database.
 boolean isRetrieved(ImageHolder.Field field)
          determines whether the given field value has already been retrieved, if the ImageHolder is read from a database.
 void loadFromFile(File file)
          convenience method that also puts various attributes into this ImageHolder
 void retrieve(ImageDB db)
          retrieves all available info on this ImageHolder from the database
 void retrieve(ImageDB db, ImageHolder.Field... fields)
          retrieves only the given fields from the database
 void saveToFile(File file)
          convenience method
 void setDescription(String description)
           
 void setImage(Image image)
          stores the data in the configured type format
 void setImage(InputStream stream)
          directly puts the input stream into this object as raw data; the type value is not affected when using this method.
protected  void setRetrieved(ImageHolder.Field field, boolean flag)
           
 void setThumbnail(Image image)
           
 void setThumbnail(InputStream stream)
          directly puts the input stream into this object as raw data; the type value is not affected when using this method.
 void setThumbnail(int width, int height)
          updates the thumbnail based on the return value of getImage().
 void setTime(Date date)
           
 void setTime(long timeInMillis)
           
 void setTitle(String title)
           
 void setType(String type)
          determines the format in which an image is stored.
 void setURL(URL url)
           
 void store(ImageDB db)
          stores the ImageHolder to the given database.
 String toString()
           
 
Methods inherited from class com.antelmann.mgmt.EntityImpl
addPropertyChangeListener, checkPropertyChange, containsPropertyText, enableChangeListenerSupport, equals, equalWithProperties, getProperties, getProperty, getPropertyChangeListeners, hashCode, isChangeListenerSupportEnabled, removeProperty, removePropertyChangeListener, setAll, setProperty, verifyProperties
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultType

protected static String defaultType
defaults to png

Constructor Detail

ImageHolder

public ImageHolder()
convenience constructor; id will be 0


ImageHolder

public ImageHolder(Integer id)
time is automatically set to current system time


ImageHolder

public ImageHolder(Integer id,
                   ImageHolder ih)
Method Detail

getID

public Integer getID()
Description copied from class: EntityImpl
returns the immutable id that is used for checking equality

Specified by:
getID in interface Resource
Overrides:
getID in class EntityImpl

clearProperties

public void clearProperties()

isRetrieved

public boolean isRetrieved(ImageHolder.Field field)
determines whether the given field value has already been retrieved, if the ImageHolder is read from a database. By default (after the ImageHolder is constructed), all fields return false. This method allows to distinguish,whether a field is actually null or whether it hasn't been retrieved from the database, yet. Thus, the method really only applies to ImageHolder objects that are retrieved from the database through an ImageDB.

See Also:
ImageDB

setRetrieved

protected void setRetrieved(ImageHolder.Field field,
                            boolean flag)

clear

public void clear()
resets all fields except id; all retrieved fields are also set to false (except for id)


toString

public String toString()
Overrides:
toString in class Object

getTitle

public String getTitle()

setTitle

public void setTitle(String title)

getType

public String getType()
defaults to png.

See Also:
setType(String)

setType

public void setType(String type)
determines the format in which an image is stored. possible types include png, jpeg, gif, bmp.


getURL

public URL getURL()

setURL

public void setURL(URL url)

getDate

public Date getDate()

getTime

public long getTime()

setTime

public void setTime(long timeInMillis)

setTime

public void setTime(Date date)

getDescription

public String getDescription()

setDescription

public void setDescription(String description)

setThumbnail

public void setThumbnail(int width,
                         int height)
                  throws IOException
updates the thumbnail based on the return value of getImage(). If either width or height is a negative number then a value is substituted to maintain the aspect ratio of the original image dimensions. If both width and height are negative, then the original image dimensions are used. The thumbnail will be created using jpeg encoding. Before calling this method, an image must have been set.

Throws:
IOException
See Also:
getImage()

setImage

public void setImage(InputStream stream)
              throws IOException
directly puts the input stream into this object as raw data; the type value is not affected when using this method. If the stream cannot be read into an image, the image will be reset to null.

Throws:
IOException

setThumbnail

public void setThumbnail(InputStream stream)
                  throws IOException
directly puts the input stream into this object as raw data; the type value is not affected when using this method. If the stream cannot be read into an image, the thumbnail will be reset to null.

Throws:
IOException

setImage

public void setImage(Image image)
              throws IOException
stores the data in the configured type format

Throws:
IOException

setThumbnail

public void setThumbnail(Image image)
                  throws IOException
Throws:
IOException

getThumbnail

public BufferedImage getThumbnail()
                           throws IOException
Throws:
IOException

getRawImage

public byte[] getRawImage()
returns a copy of the raw data


getRawThumbnail

public byte[] getRawThumbnail()
returns a copy of the raw data


getImage

public BufferedImage getImage()
                       throws IOException
first, the internal buffer is checked; only if this is null, the URL will be checked. if both is null, null is returned.

Throws:
IOException

saveToFile

public void saveToFile(File file)
                throws IOException
convenience method

Throws:
IOException

loadFromFile

public void loadFromFile(File file)
                  throws IOException
convenience method that also puts various attributes into this ImageHolder

Throws:
IOException

insertInto

public ImageHolder insertInto(ImageDB db)
                       throws DatabaseException
inserts the image to the given database.

Throws:
DatabaseException
See Also:
ImageDB.insert(ImageHolder)

store

public void store(ImageDB db)
           throws DatabaseException
stores the ImageHolder to the given database.

Throws:
DatabaseException
See Also:
ImageDB.store(ImageHolder, ImageHolder.Field...)

retrieve

public void retrieve(ImageDB db)
              throws DatabaseException
retrieves all available info on this ImageHolder from the database

Throws:
DatabaseException

retrieve

public void retrieve(ImageDB db,
                     ImageHolder.Field... fields)
              throws DatabaseException
retrieves only the given fields from the database

Throws:
DatabaseException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads