public abstract class IlvNamedProperty extends Object implements Serializable, IlvPersistentObject
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
).
Constructor and Description |
---|
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 . |
Modifier and Type | Method and Description |
---|---|
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 . |
public IlvNamedProperty(String name)
IlvNamedProperty
.name
- the name of the property.public IlvNamedProperty(IlvNamedProperty source)
IlvNamedProperty
by copying an existing one.source
- the origin of the copy.public IlvNamedProperty(IlvInputStream stream) throws IlvReadFileException
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.stream
- the input stream from which the property must be read.IlvReadFileException
- if an error occurs while reading.public void write(IlvOutputStream stream) throws IOException
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)
.write
in interface IlvPersistentObject
stream
- the output stream.IOException
- standard IO error.public final String getName()
public abstract IlvNamedProperty copy()
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.public abstract boolean isPersistent()
true
, the property
is saved; otherwise it is not saved.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.