org.gcube.contentmanagement.gcubemodellibrary.elements
Class BaseElement

java.lang.Object
  extended by org.gcube.contentmanagement.gcubemodellibrary.elements.BaseElement
All Implemented Interfaces:
GCubeElement
Direct Known Subclasses:
BaseInnerElement, GCubeDocument

public abstract class BaseElement
extends java.lang.Object
implements GCubeElement

Partial implementation of GCubeElements. The implementation is thread-unsafe. Where required, thread-safety is responsibility of clients.

Author:
Federico De Faveri defaveri@isti.cnr.it, Fabio Simeoni (University of Strathclyde)

Method Summary
 GCubeElementProperty addProperty(GCubeElementProperty property)
          Adds a generic property to the element, replacing any property with the same key.
 byte[] bytestream()
          Returns the element's bytestream.
 java.net.URI bytestreamURI()
          Returns a URI to the element's bytestream.
 java.util.Calendar creationTime()
          Returns the creation time of the element.
 boolean equals(java.lang.Object obj)
           
 int hashCode()
           
 java.lang.String id()
          Returns the identifier of the element.
 boolean isNew()
          Indicates whether the element is new within the system or if it proxies instead an existing element.
 java.lang.String language()
          Returns the language of the element.
 java.util.Calendar lastUpdate()
          Returns the time of last update of the element.
 java.lang.Long length()
          Returns the length of the element's bytestream.
 java.lang.String mimeType()
          Returns the Mime type of the element.
 java.lang.String name()
          Returns the descriptive name of the element.
 java.util.Map<java.lang.String,GCubeElementProperty> properties()
          Returns the generic properties of the element.
 GCubeElementProperty property(java.lang.String key)
          Returns a generic property of the element.
 GCubeElementProperty removeProperty(java.lang.String key)
          Remove a generic property of the element.
 java.io.InputStream resolveBytestream()
          Returns an InputStream over the element's bytestream, resolving it if it is referenced by a URI.
 java.lang.String schemaName()
          Returns the descriptive name of the element's schema.
 java.net.URI schemaURI()
          Return the URI of the element's schema.
 void setBytestream(byte[] bytes)
          Sets the element's bytestream.
 void setBytestream(java.io.InputStream stream)
          Sets the element's bytestream.
 void setBytestream(java.io.Reader stream)
          Sets the element's bytestream.
 void setBytestreamURI(java.net.URI uri)
          Sets the URI of the bytestream.
 void setLanguage(java.util.Locale locale)
          Sets the language of the element from the corresponding Locale.
 void setLenght(java.lang.Long length)
          Sets the length;
 void setMimeType(java.lang.String type)
          Sets the content's Mime type.
 void setName(java.lang.String n)
          Sets the element name.
 void setSchemaName(java.lang.String name)
          Sets the descriptive name of the element's schema.
 void setSchemaURI(java.net.URI uri)
          Sets the URI of the element's schema.
 void setType(java.lang.String t)
          Sets the element type.
 java.lang.String toString()
          
 java.lang.String type()
          Returns the type of the element.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gcube.contentmanagement.gcubemodellibrary.elements.GCubeElement
uri
 

Method Detail

isNew

public boolean isNew()
Indicates whether the element is new within the system or if it proxies instead an existing element.

Returns:
true if the element is new, false if it is a proxy.

id

public java.lang.String id()
Returns the identifier of the element.

Specified by:
id in interface GCubeElement
Returns:
the identifier.

creationTime

public java.util.Calendar creationTime()
Returns the creation time of the element.

Specified by:
creationTime in interface GCubeElement
Returns:
the creation time.

lastUpdate

public java.util.Calendar lastUpdate()
Returns the time of last update of the element.

Specified by:
lastUpdate in interface GCubeElement
Returns:
the last update time.

name

public java.lang.String name()
Returns the descriptive name of the element.

Specified by:
name in interface GCubeElement
Returns:
the name.

setName

public void setName(java.lang.String n)
Sets the element name.

Parameters:
n - the name.

type

public java.lang.String type()
Returns the type of the element.

Specified by:
type in interface GCubeElement
Returns:
the name.

setType

public void setType(java.lang.String t)
Sets the element type.

Parameters:
t - the type.

mimeType

public java.lang.String mimeType()
Returns the Mime type of the element.

Specified by:
mimeType in interface GCubeElement
Returns:
the Mime type.

setMimeType

public void setMimeType(java.lang.String type)
                 throws java.lang.IllegalArgumentException
Sets the content's Mime type.

Parameters:
type - the Mime type.
Throws:
java.lang.IllegalArgumentException

bytestreamURI

public java.net.URI bytestreamURI()
Returns a URI to the element's bytestream.

Specified by:
bytestreamURI in interface GCubeElement
Returns:
the URI, or null if a URI for the element's bytestream does not exist or is not included in the element.

setBytestreamURI

public void setBytestreamURI(java.net.URI uri)
Sets the URI of the bytestream.

Parameters:
uri - the URI.

resolveBytestream

public java.io.InputStream resolveBytestream()
                                      throws java.io.IOException
Returns an InputStream over the element's bytestream, resolving it if it is referenced by a URI.

Specified by:
resolveBytestream in interface GCubeElement
Returns:
the stream, or null if the element has no bytestream.
Throws:
java.io.IOException

bytestream

public byte[] bytestream()
Returns the element's bytestream.

Specified by:
bytestream in interface GCubeElement
Returns:
the bytestream, or null if the element has no content or does not include it.

setBytestream

public void setBytestream(java.io.InputStream stream)
                   throws java.io.IOException
Sets the element's bytestream.

Parameters:
stream - an InputStream from which the bytestream can be read, or null to overwrite the current value.
Note the stream will be closed when the operation is completed.
Throws:
java.io.IOException - if the stream could not be processed.

setBytestream

public void setBytestream(java.io.Reader stream)
                   throws java.io.IOException
Sets the element's bytestream.

Parameters:
stream - the stream, or null to unset the current value.
Note the stream will be closed when the operation is completed.
Throws:
java.io.IOException - if the stream could not be processed.

setBytestream

public void setBytestream(byte[] bytes)
Sets the element's bytestream.

Parameters:
bytes - the bytes of the stream, or null to unset the current value.

length

public java.lang.Long length()
Returns the length of the element's bytestream.

Specified by:
length in interface GCubeElement
Returns:
the length.

setLenght

public void setLenght(java.lang.Long length)
Sets the length;

Parameters:
length. -

language

public java.lang.String language()
Returns the language of the element.

Specified by:
language in interface GCubeElement
Returns:
the language.

setLanguage

public void setLanguage(java.util.Locale locale)
Sets the language of the element from the corresponding Locale.

Parameters:
locale - the Locale corresponding to the language.

schemaURI

public java.net.URI schemaURI()
Return the URI of the element's schema.

Specified by:
schemaURI in interface GCubeElement
Returns:
the URI.

setSchemaURI

public void setSchemaURI(java.net.URI uri)
Sets the URI of the element's schema.

Parameters:
uri - the URI.

schemaName

public java.lang.String schemaName()
Returns the descriptive name of the element's schema.

Specified by:
schemaName in interface GCubeElement
Returns:
the name.

setSchemaName

public void setSchemaName(java.lang.String name)
Sets the descriptive name of the element's schema.

Parameters:
name - the name.

properties

public java.util.Map<java.lang.String,GCubeElementProperty> properties()
Returns the generic properties of the element.

Specified by:
properties in interface GCubeElement
Returns:
the properties.

property

public GCubeElementProperty property(java.lang.String key)
Returns a generic property of the element.

Specified by:
property in interface GCubeElement
Returns:
the property value, or null if the element has no property with the given key.

addProperty

public GCubeElementProperty addProperty(GCubeElementProperty property)
Adds a generic property to the element, replacing any property with the same key.

Parameters:
property - the property.
Returns:
the property that this property replaces, or null if no such property exists.

removeProperty

public GCubeElementProperty removeProperty(java.lang.String key)
Remove a generic property of the element.

Parameters:
key - the property key.
Returns:
the removed property, or null if the element has no property with the given key.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object