com.partnersoft.codex.editors
Class CogModel

java.lang.Object
  extended by com.partnersoft.codex.CodexResourceModel
      extended by com.partnersoft.codex.editors.CogModel
All Implemented Interfaces:
CodexNodeView

public class CogModel
extends CodexResourceModel

Edits a CodexResource containing Cog XML as a Cog.

Essentially acts as a undoable wrapper around the Cog setter methods.

Copyright 2006-2007 Partner Software, Inc.

Version:
$Id$
Author:
Russell Cagle, Paul Reavis

Field Summary
 
Fields inherited from class com.partnersoft.codex.CodexResourceModel
resource
 
Constructor Summary
CogModel(CodexResource resource)
           
 
Method Summary
 void addCogModelListener(CogModelListener listener)
           
 CodexResource getCodexResource()
          Should return whatever got set in setCodexResource().
 Cog getCog()
          Returns a copy of the cog referred to by this resource.
 java.lang.Object getCogAsObject()
          Returns a copy of the object represented by the cog referred to by this resource.
 java.lang.String getModelLabel()
          Used to label the model in the user interface.
 java.lang.Object getObject(java.lang.String path)
          Returns a part of the cog using Cog.getObject(String).
 java.lang.String getString(java.lang.String path)
          Returns a part of the cog using Cog.getString(String).
 void invalidateModel()
          When another model calls CodexResource.touch(), the resource invalidates all other models through this method.
 void removeCogModelListener(CogModelListener listener)
           
 void save(java.io.OutputStream outie)
          This is the counterpart to CodexResource.touch().
 void setCodexResource(CodexResource resource)
           
 void setCog(Cog newCog)
          Replaces the cog referred to by this resource with the one provided.
 void setCogAsObject(java.lang.Object object)
          Replaces the cog referred to by this resource with the cog representation of the object provided.
 void setObject(java.lang.String path, java.lang.Object newValue)
          Sets a part of the cog using Cog.setObject(String, Object) and the undo stack.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CogModel

public CogModel(CodexResource resource)
Method Detail

addCogModelListener

public void addCogModelListener(CogModelListener listener)

getCodexResource

public CodexResource getCodexResource()
Description copied from class: CodexResourceModel
Should return whatever got set in setCodexResource(). This lets CodexResource manage the parent-child relationship.

Overrides:
getCodexResource in class CodexResourceModel
Returns:

getCogAsObject

public java.lang.Object getCogAsObject()
                                throws java.io.IOException
Returns a copy of the object represented by the cog referred to by this resource. If you plan on modifying it, you have to call setObject() with your modified results, and the model must not have been invalidated in between.

Throws:
java.io.IOException

setCogAsObject

public void setCogAsObject(java.lang.Object object)
                    throws java.io.IOException
Replaces the cog referred to by this resource with the cog representation of the object provided. Throws an IllegalStateException if the resource has been invalidated.

Throws:
java.io.IOException

getCog

public Cog getCog()
Returns a copy of the cog referred to by this resource. If you plan on modifying it, you have to call setCog() with your modified results, and the model must not have been invalidated in between.


setCog

public void setCog(Cog newCog)
            throws java.io.IOException
Replaces the cog referred to by this resource with the one provided. Makes a defensive copy so further modifications to the one provided will not affect the resource. Throws an IllegalStateException if the resource has been invalidated.

Throws:
java.io.IOException

getObject

public java.lang.Object getObject(java.lang.String path)
Returns a part of the cog using Cog.getObject(String).

Parameters:
path -
Returns:
node referred to by path

getString

public java.lang.String getString(java.lang.String path)
Returns a part of the cog using Cog.getString(String).

Parameters:
path -
Returns:
node referred to by path

setObject

public void setObject(java.lang.String path,
                      java.lang.Object newValue)
Sets a part of the cog using Cog.setObject(String, Object) and the undo stack.

Parameters:
path -
newValue -

getModelLabel

public java.lang.String getModelLabel()
Description copied from class: CodexResourceModel
Used to label the model in the user interface.

Specified by:
getModelLabel in class CodexResourceModel
Returns:

invalidateModel

public void invalidateModel()
Description copied from class: CodexResourceModel
When another model calls CodexResource.touch(), the resource invalidates all other models through this method. Models should clear out their internal model. For example, the CogModel should clear out its Cog object. Models should NOT regenerate their internal model.

Specified by:
invalidateModel in class CodexResourceModel

removeCogModelListener

public void removeCogModelListener(CogModelListener listener)

save

public void save(java.io.OutputStream outie)
          throws java.io.IOException
Description copied from class: CodexResourceModel
This is the counterpart to CodexResource.touch(). CodexResource.touch() invalidates the resource's bytes, and then the resource calls CodexResourceModel.save() when it needs its bytes back.

Specified by:
save in class CodexResourceModel
Throws:
java.io.IOException

setCodexResource

public void setCodexResource(CodexResource resource)