|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object gov.nasa.arc.brahms.vm.api.convert.ConverterManager
public class ConverterManager
ConverterManager is a manager responsible for supporting the conversion between Brahms objects and Java objects. It maintains a list of the supported Brahms/Java converters responsible for properly converting between Brahms objects/types and Java objects/types.
There are a couple of guidelines to follow to have the conversion work properly:
To convert a Java object to Brahms or vice versa:
// create a conversion context (used to ensure that we // don't get into cycles with nested objects and don't // reconvert an already converted reference ConverterManager oCM = JAPI.getConverterManager(); ConversionContext oContext = new ConversionContext(); oContext.setBrahmsContext(getContext()); // convert to Brahms MyJavaClass oJavaObject = ... IObject oConvertedBrahmsObject = oCM.toBrahms(oJavaObject, oContext); // clear the conversion cache oContext.clearBrahmsConverted(); oContext.clearJavaConverted(); // convert to Java IObject oBrahmsObject = ... MyJavaClass oConvertedJavaObject = (MyJavaClass)oCM.toJava(oBrahmsObject, oContext); // clear the conversion cache oContext.clearBrahmsConverted(); oContext.clearJavaConverted();
Constructor Summary | |
---|---|
ConverterManager()
Constructor, creates a new ConverterManager. |
Method Summary | |
---|---|
void |
addBrahmsConverter(IType brahmsType,
java.lang.String type)
Adds the specified converter supporting conversion from/to the specified brahmsType. |
void |
addConverterType(java.lang.String name,
IConverter converter)
Adds the specified converter identified by the specified name. |
void |
addJavaConverter(java.lang.Class<?> javaType,
java.lang.String type)
Adds the specified converter type supporting conversion from/to the specified javaType. |
BrahmsClassDescriptor |
getBrahmsClassDescriptor(java.lang.String qualifiedName)
Returns the BrahmsClassDescriptor for the Brahms class with the specified qualified name. |
IConverter |
getBrahmsConverter(IType brahmsType)
Returns the converter supporting conversion from/to the specified brahmsType. |
BrahmsGroupDescriptor |
getBrahmsGroupDescriptor(java.lang.String qualifiedName)
Returns the BrahmsGroupDescriptor for the Brahms group with the specified qualified name. |
IConverter |
getConverterType(java.lang.String name)
Returns the IConverter with the specified name. |
IConverter |
getJavaConverter(java.lang.Class<?> javaType)
Returns the converter supporting conversion from/to the specified javaType. |
protected void |
initialize()
Create the base set of converters. |
boolean |
isPrimitive(java.lang.Class<?> c)
Indicates whether the type identified by the specified class is a primitive type. |
IObject |
toBrahms(java.lang.Object obj,
ConversionContext ctx)
Converts the specified Java object into its matching Brahms object representation. |
java.lang.Object |
toJava(IObject obj,
ConversionContext ctx)
Converts the specified Brahms object into its matching Java object representation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConverterManager()
Method Detail |
---|
protected void initialize()
public void addConverterType(java.lang.String name, IConverter converter)
name
- the name of the converter typeconverter
- the IConverterpublic IConverter getConverterType(java.lang.String name)
name
- the name of the converter type
public void addJavaConverter(java.lang.Class<?> javaType, java.lang.String type)
javaType
- the Class with the java typetype
- the name of the converter typepublic void addBrahmsConverter(IType brahmsType, java.lang.String type)
brahmsType
- the IType with the brahms typetype
- the name of the converter typepublic IConverter getJavaConverter(java.lang.Class<?> javaType)
javaType
- the Class for which the converter is to be returned
public IConverter getBrahmsConverter(IType brahmsType)
brahmsType
- the IType for which the converter is to be returned
public BrahmsClassDescriptor getBrahmsClassDescriptor(java.lang.String qualifiedName)
qualifiedName
- the class' qualified name
public BrahmsGroupDescriptor getBrahmsGroupDescriptor(java.lang.String qualifiedName)
qualifiedName
- the class' qualified name
public boolean isPrimitive(java.lang.Class<?> c)
c
- the Class to test
public java.lang.Object toJava(IObject obj, ConversionContext ctx) throws ExternalException
obj
- the Brahms IObject to convertctx
- the IContext used to interact with the Brahms object
ExternalException
- if there was a problem converting the objectpublic IObject toBrahms(java.lang.Object obj, ConversionContext ctx) throws ExternalException
obj
- the java Object to convertctx
- the IContext used to interact with the Brahms object
ExternalException
- if there was a problem converting the object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |