FileDocCategorySizeDatePackage
TypeConversionConverter.javaAPI DocGlassfish v2 API9998Tue May 22 16:54:46 BST 2007oracle.toplink.essentials.mappings.converters

TypeConversionConverter

public class TypeConversionConverter extends Object implements Converter
Purpose: Type conversion converters are used to explicitly map a database type to a Java type.
author
James Sutherland
since
OracleAS TopLink 10g (10.0.3)

Fields Summary
protected DatabaseMapping
mapping
protected Class
dataClass
Field type
protected String
dataClassName
protected Class
objectClass
Object type
protected String
objectClassName
Constructors Summary
public TypeConversionConverter()
PUBLIC: Default constructor.

    
public TypeConversionConverter(DatabaseMapping mapping)
PUBLIC: Default constructor.

        this.mapping = mapping;
    
Methods Summary
public voidconvertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this converter to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes. This method is implemented by subclasses as necessary.

param
classLoader

        Class dataClass = null;
        Class objectClass = null;
        try{
            if (dataClassName != null){
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                    try {
                        dataClass = (Class)AccessController.doPrivileged(new PrivilegedClassForName(dataClassName, true, classLoader));
                    } catch (PrivilegedActionException exception) {
                        throw ValidationException.classNotFoundWhileConvertingClassNames(dataClassName, exception.getException());
                    }
                } else {
                    dataClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(dataClassName, true, classLoader);
                }
                setDataClass(dataClass);
            }
        } catch (ClassNotFoundException exc){
            throw ValidationException.classNotFoundWhileConvertingClassNames(dataClassName, exc);
        }
        try {
            if (objectClassName != null){
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                    try {
                        objectClass = (Class)AccessController.doPrivileged(new PrivilegedClassForName(objectClassName, true, classLoader));
                    } catch (PrivilegedActionException exception) {
                        throw ValidationException.classNotFoundWhileConvertingClassNames(objectClassName, exception.getException());
                    }
                } else {
                    objectClass = oracle.toplink.essentials.internal.security.PrivilegedAccessHelper.getClassForName(objectClassName, true, classLoader);
                }
                setObjectClass(objectClass);
            }
        } catch (ClassNotFoundException exc){
            throw ValidationException.classNotFoundWhileConvertingClassNames(objectClassName, exc);
        }
    
public java.lang.ObjectconvertDataValueToObjectValue(java.lang.Object fieldValue, oracle.toplink.essentials.sessions.Session session)
INTERNAL: The field value must first be converted to the field type, then the attribute type.

        Object attributeValue = fieldValue;
        if (attributeValue != null) {
            try {
                attributeValue = ((AbstractSession)session).getDatasourcePlatform().convertObject(attributeValue, getDataClass());
            } catch (ConversionException e) {
                throw ConversionException.couldNotBeConverted(mapping, mapping.getDescriptor(), e);
            }

            try {
                attributeValue = ((AbstractSession)session).getDatasourcePlatform().convertObject(attributeValue, getObjectClass());
            } catch (ConversionException e) {
                throw ConversionException.couldNotBeConverted(mapping, mapping.getDescriptor(), e);
            }
        }

        return attributeValue;
    
public java.lang.ObjectconvertObjectValueToDataValue(java.lang.Object attributeValue, oracle.toplink.essentials.sessions.Session session)
INTERNAL: Convert to the field class.

        try {
            return ((AbstractSession)session).getDatasourcePlatform().convertObject(attributeValue, getDataClass());
        } catch (ConversionException e) {
            throw ConversionException.couldNotBeConverted(mapping, mapping.getDescriptor(), e);
        }
    
public java.lang.ClassgetDataClass()
PUBLIC: Returns the class type of the data value.

        return dataClass;
    
public java.lang.StringgetDataClassName()
INTERNAL: Return the name of the data type for the MW usage.

        if ((dataClassName == null) && (dataClass != null)) {
            dataClassName = dataClass.getName();
        }
        return dataClassName;
    
protected oracle.toplink.essentials.mappings.DatabaseMappinggetMapping()
INTERNAL: Return the mapping.

        return mapping;
    
public java.lang.ClassgetObjectClass()
PUBLIC: Returns the class type of the object value.

        return objectClass;
    
public java.lang.StringgetObjectClassName()
INTERNAL: Return the name of the object type for the MW usage.

        if ((objectClassName == null) && (objectClass != null)) {
            objectClassName = objectClass.getName();
        }
        return objectClassName;
    
public voidinitialize(oracle.toplink.essentials.mappings.DatabaseMapping mapping, oracle.toplink.essentials.sessions.Session session)
INTERNAL: Set the mapping.

        this.mapping = mapping;
        // CR#... Mapping must also have the field classification.
        if (getMapping().isDirectToFieldMapping()) {
            AbstractDirectMapping directMapping = (AbstractDirectMapping)getMapping();

            // Allow user to specify field type to override computed value. (i.e. blob, nchar)
            if (directMapping.getFieldClassification() == null) {
                directMapping.setFieldClassification(getDataClass());
            }
            
            // Set the object class from the attribute, if null.
            if (getObjectClass() == null) {
                setObjectClass(directMapping.getAttributeClassification());
            }
        }
    
public booleanisMutable()
INTERNAL: If the converter converts the value to a non-atomic value, i.e. a value that can have its' parts changed without being replaced, then it must return false, serialization can be non-atomic.

        return false;
    
public voidsetDataClass(java.lang.Class dataClass)
PUBLIC: Set the class type of the data value.

        this.dataClass = dataClass;
    
public voidsetDataClassName(java.lang.String dataClassName)
INTERNAL: Set the name of the data type for the MW usage.

        this.dataClassName = dataClassName;
    
public voidsetObjectClass(java.lang.Class objectClass)
PUBLIC: Set the class type of the object value.

        this.objectClass = objectClass;
    
public voidsetObjectClassName(java.lang.String objectClassName)
INTERNAL: Set the name of the object type for the MW usage.

        this.objectClassName = objectClassName;