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

ClassInstanceConverter

public class ClassInstanceConverter extends Object implements Converter
Purpose: Allows a class name to be converter to and from a new instance of the class.
author
James Sutherland
since
OracleAS TopLink 10g (10.0.3)

Fields Summary
protected DatabaseMapping
mapping
Constructors Summary
public ClassInstanceConverter()
PUBLIC: Default constructor.

    
Methods Summary
public java.lang.ObjectconvertDataValueToObjectValue(java.lang.Object fieldValue, oracle.toplink.essentials.sessions.Session session)
INTERNAL: Convert the class name to a class, then create an instance of the class.

        Object attributeValue = null;
        if (fieldValue != null) {
            Class attributeClass = (Class)((AbstractSession)session).getDatasourcePlatform().convertObject(fieldValue, ClassConstants.CLASS);
            try {
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                    try {
                        attributeValue = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(attributeClass));
                    } catch (PrivilegedActionException exception) {
                        throw ConversionException.couldNotBeConverted(fieldValue, attributeClass, exception.getException());
                    }
                } else {
                    attributeValue = PrivilegedAccessHelper.newInstanceFromClass(attributeClass);
                }
            } catch (Exception exception) {
                throw ConversionException.couldNotBeConverted(fieldValue, attributeClass, exception);
            }
        }

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

        if (attributeValue == null) {
            return null;
        }
        return attributeValue.getClass().getName();
    
protected oracle.toplink.essentials.mappings.DatabaseMappinggetMapping()
INTERNAL: Return the mapping.

        return mapping;
    
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(ClassConstants.STRING);
            }
        }
    
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;