org.nuiton.wikitty
Class WikittyCopyOnWrite

java.lang.Object
  extended by org.nuiton.wikitty.WikittyCopyOnWrite
All Implemented Interfaces:
Serializable, Cloneable, Wikitty

public class WikittyCopyOnWrite
extends Object
implements Wikitty

this class wrap a wikitty in a proxy that copy the wikitty before applying any change It is used for caching purpose. This class own a reference to an actual wikitty, multiple instance of this class can own some references to a same actual wikitty. To prevent the target to be modified, a copy is created to prevent side-effect. So, when a wikitty restored from cache is modified, a copy is modified, so if change are cancelled, next restore will restore the original and not the modified version (until the modified version is stored). used in WikittyServiceCached

See Also:
Serialized Form

Field Summary
protected  Wikitty target
           
protected  boolean targetIsACopy
           
 
Constructor Summary
protected WikittyCopyOnWrite(Wikitty target)
          only WikittyService with cache should create instances
 
Method Summary
 void addExtension(List<WikittyExtension> exts)
           
 void addExtension(WikittyExtension ext)
           
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void addToField(String ext, String fieldName, Object value)
           
 void clearDirty()
          Server only used
 void clearField(String ext, String fieldName)
           
 Wikitty clone()
           
 boolean equals(Object obj)
           
 Set<String> fieldNames()
           
 Date getDeleteDate()
           
 WikittyExtension getExtension(String ext)
           
 Collection<WikittyExtension> getExtensionDependencies(String ext, boolean recursively)
           
 Collection<String> getExtensionNames()
           
 Collection<WikittyExtension> getExtensions()
           
 BigDecimal getFieldAsBigDecimal(String ext, String fieldName)
           
 boolean getFieldAsBoolean(String ext, String fieldName)
           
 Date getFieldAsDate(String ext, String fieldName)
           
 double getFieldAsDouble(String ext, String fieldName)
           
 float getFieldAsFloat(String ext, String fieldName)
           
 int getFieldAsInt(String ext, String fieldName)
           
<E> List<E>
getFieldAsList(String ext, String fieldName, Class<E> clazz)
          If object is a set, it is automatically transform to list.
 long getFieldAsLong(String ext, String fieldName)
           
 Object getFieldAsObject(String ext, String fieldName)
           
<E> Set<E>
getFieldAsSet(String ext, String fieldName, Class<E> clazz)
           
 String getFieldAsString(String ext, String fieldName)
           
 String getFieldAsWikitty(String ext, String fieldName)
          return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller
 FieldType getFieldType(String fqfieldName)
          return field type for the given fieldName.
 Object getFqField(String fqFieldName)
           
 String getId()
           
 String getVersion()
           
 boolean hasExtension(String extName)
           
 boolean hasField(String extName, String fieldName)
           
 int hashCode()
           
 boolean isDeleted()
           
 boolean isEmpty()
           
 void removeFromField(String ext, String fieldName, Object value)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
           
 void setDeleteDate(Date delete)
          Server only used
 void setField(String ext, String fieldName, Object value)
           
 void setFqField(String fieldName, Object value)
          Server only used
 void setVersion(String version)
          Server only used
protected  void substituteTargetWithCopy()
          replace target with a clone this method must be called to prevent any modification on target
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

target

protected Wikitty target

targetIsACopy

protected boolean targetIsACopy
Constructor Detail

WikittyCopyOnWrite

protected WikittyCopyOnWrite(Wikitty target)
only WikittyService with cache should create instances

Method Detail

substituteTargetWithCopy

protected void substituteTargetWithCopy()
replace target with a clone this method must be called to prevent any modification on target


equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

clone

public Wikitty clone()
              throws CloneNotSupportedException
Specified by:
clone in interface Wikitty
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface Wikitty

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface Wikitty

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface Wikitty

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface Wikitty

getId

public String getId()
Specified by:
getId in interface Wikitty

isDeleted

public boolean isDeleted()
Specified by:
isDeleted in interface Wikitty

getDeleteDate

public Date getDeleteDate()
Specified by:
getDeleteDate in interface Wikitty

setDeleteDate

public void setDeleteDate(Date delete)
Description copied from interface: Wikitty
Server only used

Specified by:
setDeleteDate in interface Wikitty

addExtension

public void addExtension(WikittyExtension ext)
Specified by:
addExtension in interface Wikitty

addExtension

public void addExtension(List<WikittyExtension> exts)
Specified by:
addExtension in interface Wikitty

hasExtension

public boolean hasExtension(String extName)
Specified by:
hasExtension in interface Wikitty

hasField

public boolean hasField(String extName,
                        String fieldName)
Specified by:
hasField in interface Wikitty

getExtension

public WikittyExtension getExtension(String ext)
Specified by:
getExtension in interface Wikitty

getExtensionNames

public Collection<String> getExtensionNames()
Specified by:
getExtensionNames in interface Wikitty

getExtensions

public Collection<WikittyExtension> getExtensions()
Specified by:
getExtensions in interface Wikitty

getExtensionDependencies

public Collection<WikittyExtension> getExtensionDependencies(String ext,
                                                             boolean recursively)
Specified by:
getExtensionDependencies in interface Wikitty

getFieldType

public FieldType getFieldType(String fqfieldName)
Description copied from interface: Wikitty
return field type for the given fieldName.

Specified by:
getFieldType in interface Wikitty
Parameters:
fqfieldName - fully qualified fieldName extension.fieldname
Returns:
field type

setField

public void setField(String ext,
                     String fieldName,
                     Object value)
Specified by:
setField in interface Wikitty

getFieldAsObject

public Object getFieldAsObject(String ext,
                               String fieldName)
Specified by:
getFieldAsObject in interface Wikitty

getFieldAsBoolean

public boolean getFieldAsBoolean(String ext,
                                 String fieldName)
Specified by:
getFieldAsBoolean in interface Wikitty

getFieldAsBigDecimal

public BigDecimal getFieldAsBigDecimal(String ext,
                                       String fieldName)
Specified by:
getFieldAsBigDecimal in interface Wikitty

getFieldAsInt

public int getFieldAsInt(String ext,
                         String fieldName)
Specified by:
getFieldAsInt in interface Wikitty

getFieldAsLong

public long getFieldAsLong(String ext,
                           String fieldName)
Specified by:
getFieldAsLong in interface Wikitty

getFieldAsFloat

public float getFieldAsFloat(String ext,
                             String fieldName)
Specified by:
getFieldAsFloat in interface Wikitty

getFieldAsDouble

public double getFieldAsDouble(String ext,
                               String fieldName)
Specified by:
getFieldAsDouble in interface Wikitty

getFieldAsString

public String getFieldAsString(String ext,
                               String fieldName)
Specified by:
getFieldAsString in interface Wikitty

getFieldAsDate

public Date getFieldAsDate(String ext,
                           String fieldName)
Specified by:
getFieldAsDate in interface Wikitty

getFieldAsWikitty

public String getFieldAsWikitty(String ext,
                                String fieldName)
Description copied from interface: Wikitty
return wikitty id and not wikitty objet because this method can be call on server or client side and it's better to keep conversion between id and objet to the caller

Specified by:
getFieldAsWikitty in interface Wikitty
Parameters:
ext - extension name where this field must to be
fieldName - the field name
Returns:
id of wikitty object or null

getFieldAsList

public <E> List<E> getFieldAsList(String ext,
                                  String fieldName,
                                  Class<E> clazz)
Description copied from interface: Wikitty
If object is a set, it is automatically transform to list.

Specified by:
getFieldAsList in interface Wikitty
Returns:
unmodifiable list

getFieldAsSet

public <E> Set<E> getFieldAsSet(String ext,
                                String fieldName,
                                Class<E> clazz)
Specified by:
getFieldAsSet in interface Wikitty
Returns:
unmodifiable list

addToField

public void addToField(String ext,
                       String fieldName,
                       Object value)
Specified by:
addToField in interface Wikitty

removeFromField

public void removeFromField(String ext,
                            String fieldName,
                            Object value)
Specified by:
removeFromField in interface Wikitty

clearField

public void clearField(String ext,
                       String fieldName)
Specified by:
clearField in interface Wikitty

fieldNames

public Set<String> fieldNames()
Specified by:
fieldNames in interface Wikitty

getFqField

public Object getFqField(String fqFieldName)
Specified by:
getFqField in interface Wikitty

getVersion

public String getVersion()
Specified by:
getVersion in interface Wikitty

setVersion

public void setVersion(String version)
Description copied from interface: Wikitty
Server only used

Specified by:
setVersion in interface Wikitty

clearDirty

public void clearDirty()
Description copied from interface: Wikitty
Server only used

Specified by:
clearDirty in interface Wikitty

setFqField

public void setFqField(String fieldName,
                       Object value)
Description copied from interface: Wikitty
Server only used

Specified by:
setFqField in interface Wikitty
Parameters:
fieldName - fqn (ex: extensionName.fieldName)
value - new value

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Wikitty


Copyright © 2009-2010 CodeLutin. All Rights Reserved.