public class TLcyCompositeDomainObjectConverter extends ALcyDomainObjectConverter
ALcyDomainObjectConverter
.Constructor and Description |
---|
TLcyCompositeDomainObjectConverter() |
Modifier and Type | Method and Description |
---|---|
<T> T |
adapt(Object aDomainObject,
ILcdModel aSourceModel,
Class<T> aDesiredClass)
Creates an adapter object for
aDomainObject contained in
aSourceModel , which will be an instance of aDesiredClass . |
void |
addDomainObjectConverter(ALcyDomainObjectConverter aDomainObjectConverter)
Add a domain object converter to this composite converter with the default priority, which is
defined by the
PRIORITY_DEFAULT field. |
void |
addDomainObjectConverter(ALcyDomainObjectConverter aDomainObjectConverter,
int aPriority)
Add a domain object converter to this composite converter with priority
aPriority . |
boolean |
canAdapt(Object aDomainObject,
ILcdModel aSourceModel,
Class aDesiredClass)
Indicates whether this converter can create an adapter object for
aDomainObject , which will be an instance of aDesiredClass . |
boolean |
canConvert(Object aDomainObject,
ILcdModel aSourceModel,
ILcdModel aTargetModel,
Class aCanAdaptToClass)
Indicates whether this converter is capable of converting a domain object
aDomainObject of aSourceModel into a domain object for the model
aTargetModel . |
Object |
convert(Object aDomainObject,
ILcdModel aSourceModel,
ILcdModel aTargetModel,
Class aCanAdaptToClass)
Converts a domain object
aDomainObject of aSourceModel into a
domain object for the model aTargetModel . |
ALcyDomainObjectConverter |
getDomainObjectConverter(int aIndex)
Retrieve the domain object converter at index
aIndex . |
int |
getDomainObjectConverterCount()
Returns the number of domain object converters contained in this composite converter.
|
int |
getDomainObjectConverterPriority(int aIndex)
Returns the priority, associated with the converter at index
aIndex . |
void |
removeDomainObjectConverter(ALcyDomainObjectConverter aDomainObjectConverter)
Remove the domain object converter
aDomainObjectConverter from this composite converter. |
canConvert, convert
public boolean canAdapt(Object aDomainObject, ILcdModel aSourceModel, Class aDesiredClass)
ALcyDomainObjectConverter
Indicates whether this converter can create an adapter object for
aDomainObject
, which will be an instance of aDesiredClass
. The object
aDomainObject
is contained in aSourceModel
.
The adapter object and the domain object are linked, which means changes made to the adapter object will be passed on to the original object and vice versa.
Since this method indicates whether an adapter object for aDomainObject
can be
created, it must return false
when the adapter object adds information to the
aDomainObject
. The adapter object may only contain less information than the
original object. For example a sphere can be adapted to a circle, since this simply removes the
height information. Adapting a circle to a sphere should not be possible, since the adapter
object (the sphere) contains information that is not available in the original object (the
height). For such cases the convert
method should be used instead.
canAdapt
in class ALcyDomainObjectConverter
aDomainObject
- the original objectaSourceModel
- the model containing aDomainObject
aDesiredClass
- the class of the adapter objecttrue
when this converter can perform the adapt operationpublic <T> T adapt(Object aDomainObject, ILcdModel aSourceModel, Class<T> aDesiredClass)
ALcyDomainObjectConverter
Creates an adapter object for aDomainObject
contained in
aSourceModel
, which will be an instance of aDesiredClass
.
The adapter object and the domain object are linked, which means changes made to the adapter object will be passed on to the original object and vice versa.
An IllegalArgumentException
must be thrown when the converter cannot handle
the domain object, or could not adapt the domain object to an instance of
aDesiredClass
. It is possible to check in advance if this converter is capable of
creating an adapter object for the domain object by calling the canAdapt
method
first.
adapt
in class ALcyDomainObjectConverter
aDomainObject
- the original objectaSourceModel
- the model containing aDomainObject
aDesiredClass
- the class of the adapter objectaDomainObject
, which is an instance of
aDesiredClass
public boolean canConvert(Object aDomainObject, ILcdModel aSourceModel, ILcdModel aTargetModel, Class aCanAdaptToClass)
ALcyDomainObjectConverter
Indicates whether this converter is capable of converting a domain object
aDomainObject
of aSourceModel
into a domain object for the model
aTargetModel
. The parameter aCanAdaptToClass
is passed to this method
to check if the creation of a new domain object is possible in such a way that the adapt
method called with that new domain
object will return an object of instance aCanAdaptToClass
.
Notice that the source and target model may be the same. When the
aCanAdaptToClass
is not important, Object.class
should be passed as
parameter or the ALcyDomainObjectConverter.canConvert(Object, com.luciad.model.ILcdModel,
com.luciad.model.ILcdModel)
method can be used instead.
canConvert
in class ALcyDomainObjectConverter
aDomainObject
- the original domain objectaSourceModel
- the model containing aDomainObject
aTargetModel
- the model for which a new domain object should be created.aCanAdaptToClass
- adapting the resulting new domain object to this class should be
possibletrue
when the conversion can be done by this converterpublic Object convert(Object aDomainObject, ILcdModel aSourceModel, ILcdModel aTargetModel, Class aCanAdaptToClass) throws IllegalArgumentException, TLcdOutOfBoundsException
ALcyDomainObjectConverter
Converts a domain object aDomainObject
of aSourceModel
into a
domain object for the model aTargetModel
. The parameter
aCanAdaptToClass
will influence the creation of the new domain object in such a
way that the adapt
method called with
that new domain object will return an object of instance aCanAdaptToClass
.
Note that the source and target model may be the same. When the
aCanAdaptToClass
is not important, Object.class
should be passed as
parameter or the ALcyDomainObjectConverter.convert(Object, com.luciad.model.ILcdModel,
com.luciad.model.ILcdModel)
method can be used instead.
An IllegalArgumentException
must be thrown when the converter cannot handle
the domain object, or could not convert the domain object in such a way that the resulting
domain object is adaptable to an instance of aCanAdaptToClass
afterwards. It is
possible to check in advance if this converter is capable of converting the domain object by
calling the canConvert
method first.
convert
in class ALcyDomainObjectConverter
aDomainObject
- the original domain objectaSourceModel
- the model containing aDomainObject
aTargetModel
- the model for which a new domain object should be created.aCanAdaptToClass
- adapting the resulting new domain object to this class should be
possibleaTargetModel
, which can be adapted to an
instance of aCanAdaptToClass
IllegalArgumentException
- when the converter could not handle the domain object, or
could not convert the domain object in such a way that the
resulting domain object is adaptable to an instance of
aCanAdaptToClass
afterwards.TLcdOutOfBoundsException
- when restoring the state for the target model failed because
the coordinates could not be properly converted from the
source ILcdModelReference
to the target
ILcdModelReference
.public void addDomainObjectConverter(ALcyDomainObjectConverter aDomainObjectConverter)
PRIORITY_DEFAULT
field.aDomainObjectConverter
- the domain object converter to addpublic void addDomainObjectConverter(ALcyDomainObjectConverter aDomainObjectConverter, int aPriority)
aPriority
.aDomainObjectConverter
- the domain object converter to addaPriority
- the priority for aDomainObjectConverter
. The lower this value, the
higher the prioritypublic void removeDomainObjectConverter(ALcyDomainObjectConverter aDomainObjectConverter)
aDomainObjectConverter
from this composite converter.
When aDomainObjectConverter
is not found, nothing happens and no error will be thrown.aDomainObjectConverter
- the domain object converter to remove.public int getDomainObjectConverterCount()
public ALcyDomainObjectConverter getDomainObjectConverter(int aIndex)
aIndex
. This index must be a number
between 0 and (getDomainObjectConverterCount
-1)aIndex
- index of the converter to retrieve. Must be a number
between 0 and (getDomainObjectConverterCount
-1)aIndex
public int getDomainObjectConverterPriority(int aIndex)
aIndex
. This index must be a number
between 0 and (getDomainObjectConverterCount
-1)aIndex
- index of the converter for which the priority is asked. Must be a number
between 0 and (getDomainObjectConverterCount
-1)aIndex