ilog.views
Class IlvNamedProperty

java.lang.Object
  extended by ilog.views.IlvNamedProperty
All Implemented Interfaces:
IlvPersistentObject, Serializable
Direct Known Subclasses:
IlvSingleValueNamedProperty, IlvThreadedActivityMonitorProperty, SVGHREFProperty

public abstract class IlvNamedProperty
extends Object
implements Serializable, IlvPersistentObject

The class IlvNamedProperty is used to associate potentially persistent properties with a graphic object, a manager, or a manager layer.

These properties are subclasses of IlvNamedProperty, which is an abstract class. A named property is identified by its name and can be stored in an IVL file. To implement the persistence, the method isPersistent in the subclass must return true. In this case, the subclass must be public, because classes from the ilog.views package must be able to write and read the property.

The subclass must provide a constructor with an IlvInputStream argument and must override the write method if some specific data is to be stored, as in the following example:

 public class MyNamedProperty extends IlvNamedProperty 
 { 
  String value;
 
  public MyNamedProperty(IlvInputStream stream) throws IlvReadFileException
  {
    super(stream);
    this.value = stream.readString("value");
  } 

  public MyNamedProperty(String name, String value)
  {
    super(name);
    this.value = value;
  }

  public MyNamedProperty(MyNamedProperty source)
  {
    super(source);
    this.value = source.value;
  }
 
  public IlvNamedProperty copy()
  {
    return new MyNamedProperty(this);
  }

  public boolean isPersistent()
  {
    return true;
  }

  public void write(IlvOutputStream stream) throws IOException
  {
    super.write(stream);
    stream.write("value", value);
  }
 }
 

Note that when a graphic object is copied (IlvGraphic.copy()), a named property will be copied if its copy method returns a non-null value. Note also that, in some cases, if you do not need the property to be persistent, it may be more convenient to use the standard property mechanism (see IlvGraphic.setProperty, IlvManagerLayer.setProperty).

See Also:
IlvPersistentObject, IlvGraphic.setNamedProperty(ilog.views.IlvNamedProperty), IlvGraphic.getNamedProperty(java.lang.String), Serialized Form

Constructor Summary
IlvNamedProperty(IlvInputStream stream)
          Creates a new IlvNamedProperty from an IlvInputStream.
IlvNamedProperty(IlvNamedProperty source)
          Creates a new IlvNamedProperty by copying an existing one.
IlvNamedProperty(String name)
          Creates a new IlvNamedProperty.
 
Method Summary
abstract  IlvNamedProperty copy()
          Copies the named property.
 String getName()
          Returns the name of this named property.
abstract  boolean isPersistent()
          Tells if the property must be saved to an IVL file.
 void write(IlvOutputStream stream)
          Writes the property to an IlvOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvNamedProperty

public IlvNamedProperty(String name)
Creates a new IlvNamedProperty.

Parameters:
name - the name of the property.

IlvNamedProperty

public IlvNamedProperty(IlvNamedProperty source)
Creates a new IlvNamedProperty by copying an existing one.

Parameters:
source - the origin of the copy.

IlvNamedProperty

public IlvNamedProperty(IlvInputStream stream)
                 throws IlvReadFileException
Creates a new IlvNamedProperty from an IlvInputStream. Note that you must provide an overridden version of this method in your subclass if some specific data is to be read from the input stream.

Parameters:
stream - the input stream from which the property must be read.
Throws:
IlvReadFileException - if an error occurs while reading.
Method Detail

write

public void write(IlvOutputStream stream)
           throws IOException
Writes the property to an IlvOutputStream. You must override this method if specific data is to be stored. Note that the first instruction in your implementation of the method must be super.write(stream).

Specified by:
write in interface IlvPersistentObject
Parameters:
stream - the output stream.
Throws:
IOException - standard IO error.

getName

public final String getName()
Returns the name of this named property.


copy

public abstract IlvNamedProperty copy()
Copies the named property. Note that when a graphic object is copied (method copy), the named properties associated with this object are also copied using this method. The only way to avoid the copy is to return null in this method.


isPersistent

public abstract boolean isPersistent()
Tells if the property must be saved to an IVL file. If this method returns true, the property is saved; otherwise it is not saved.



Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.