/** * PUBLIC: * Default constructor. */ public DatabaseMapping() { this.isOptional = true; this.isReadOnly = false; this.attributeAccessor = new InstanceVariableAttributeAccessor(); }
/** * Returns the class type of the attribute. */ @Override public Class getAttributeClass() { if (getAttributeField() == null) { return null; } return getAttributeType(); }
/** * instanceVariableName is converted to Field type. */ public void initializeAttributes(Class theJavaClass) throws DescriptorException { if (getAttributeName() == null) { throw DescriptorException.attributeNameNotSpecified(); } try { setAttributeField(Helper.getField(theJavaClass, getAttributeName())); } catch (NoSuchFieldException exception) { throw DescriptorException.noSuchFieldWhileInitializingAttributesInInstanceVariableAccessor(getAttributeName(), theJavaClass.getName(), exception); } catch (SecurityException exception) { throw DescriptorException.securityWhileInitializingAttributesInInstanceVariableAccessor(getAttributeName(), theJavaClass.getName(), exception); } }
/** * Returns the value of the attribute on the specified object. */ public Object getAttributeValueFromObject(Object anObject) throws DescriptorException { try { // PERF: Direct variable access. if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedGetValueFromField(this.attributeField, anObject)); } catch (PrivilegedActionException exception) { throw DescriptorException.illegalAccesstWhileGettingValueThruInstanceVaraibleAccessor(getAttributeName(), anObject.getClass().getName(), exception.getException()); } } else { // PERF: Direct-var access. return this.attributeField.get(anObject); } } catch (IllegalArgumentException exception) { throw DescriptorException.illegalArgumentWhileGettingValueThruInstanceVariableAccessor(getAttributeName(), getAttributeType().getName(), anObject.getClass().getName(), exception); } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccesstWhileGettingValueThruInstanceVaraibleAccessor(getAttributeName(), anObject.getClass().getName(), exception); } catch (NullPointerException exception) { String className = null; if (anObject != null) { // Some JVM's throw this exception for some very odd reason className = anObject.getClass().getName(); } throw DescriptorException.nullPointerWhileGettingValueThruInstanceVariableAccessor(getAttributeName(), className, exception); } }
AccessController.doPrivileged(new PrivilegedSetValueInField(this.attributeField, anObject, value)); } catch (PrivilegedActionException exception) { throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exception.getException()); Class fieldClass = getAttributeClass(); if (org.eclipse.persistence.internal.helper.Helper.isPrimitiveWrapper(fieldClass)) { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ AccessController.doPrivileged(new PrivilegedSetValueInField(this.attributeField, anObject, ConversionManager.getDefaultManager().convertObject(Integer.valueOf(0), fieldClass))); } catch (PrivilegedActionException exc) { throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), null, exc.getException()); throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), null, exception); Object newValue = ConversionManager.getDefaultManager().convertObject(value, getAttributeClass()); if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { throw DescriptorException.illegalArgumentWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), getAttributeType().getName(), value, exception); } catch (IllegalAccessException exception) { if (value == null) { return; throw DescriptorException.illegalAccessWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), anObject.getClass().getName(), value, exception); } catch (NullPointerException exception) { try { Class fieldClass = getAttributeClass(); if (org.eclipse.persistence.internal.helper.Helper.isPrimitiveWrapper(fieldClass) && (value == null)) {
/** * INTERNAL: * To validate mappings declaration */ public void validateBeforeInitialization(AbstractSession session) throws DescriptorException { super.validateBeforeInitialization(session); if (getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Class attributeType = ((InstanceVariableAttributeAccessor)getAttributeAccessor()).getAttributeType(); this.indirectionPolicy.validateDeclaredAttributeType(attributeType, session.getIntegrityChecker()); } else if (getAttributeAccessor().isMethodAttributeAccessor()) { Class returnType = ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodReturnType(); this.indirectionPolicy.validateGetMethodReturnType(returnType, session.getIntegrityChecker()); Class parameterType = ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodParameterType(); this.indirectionPolicy.validateSetMethodParameterType(parameterType, session.getIntegrityChecker()); } }
Field field = attributeAccessor.getAttributeField(); field = mapping.getDescriptor().getJavaClass().getDeclaredField(attributeAccessor.getAttributeName());
} else { InstanceVariableAttributeAccessor aa = new InstanceVariableAttributeAccessor(); aa.setAttributeName(locProp.getPropertyName()); descriptor.setLocationAccessor(aa);
/** * Allow any initialization to be performed with the descriptor class. */ public void initializeAttributes(Class descriptorClass) throws DescriptorException { this.attributeName = attributeName.intern(); super.initializeAttributes(descriptorClass); }
} else if(mapping.getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { aField = ((InstanceVariableAttributeAccessor)mapping.getAttributeAccessor()).getAttributeField(); aField = ((InstanceVariableAttributeAccessor)inheritingTypeMember.getMapping().getAttributeAccessor()).getAttributeField();
AccessController.doPrivileged(new PrivilegedSetValueInField(this.attributeField, anObject, value)); } catch (PrivilegedActionException exception) { throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exception.getException()); Class fieldClass = getAttributeClass(); if (org.eclipse.persistence.internal.helper.Helper.isPrimitiveWrapper(fieldClass)) { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ AccessController.doPrivileged(new PrivilegedSetValueInField(this.attributeField, anObject, ConversionManager.getDefaultManager().convertObject(new Integer(0), fieldClass))); } catch (PrivilegedActionException exc) { throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exc.getException()); throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exception); Object newValue = ConversionManager.getDefaultManager().convertObject(value, getAttributeClass()); if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { throw DescriptorException.illegalArgumentWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), getAttributeType().getName(), value, exception); } catch (IllegalAccessException exception) { if (value == null) { return; throw DescriptorException.illegalAccessWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), anObject.getClass().getName(), value, exception); } catch (NullPointerException exception) { try { Class fieldClass = getAttributeClass(); if (org.eclipse.persistence.internal.helper.Helper.isPrimitiveWrapper(fieldClass) && (value == null)) {
/** * Returns the value of the attribute on the specified object. */ @Override public Object getAttributeValueFromObject(Object anObject) throws DescriptorException { try { // PERF: Direct variable access. if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedGetValueFromField(this.attributeField, anObject)); } catch (PrivilegedActionException exception) { throw DescriptorException.illegalAccesstWhileGettingValueThruInstanceVaraibleAccessor(getAttributeName(), anObject.getClass().getName(), exception.getException()); } } else { // PERF: Direct-var access. return this.attributeField.get(anObject); } } catch (IllegalArgumentException exception) { throw DescriptorException.illegalArgumentWhileGettingValueThruInstanceVariableAccessor(getAttributeName(), getAttributeType().getName(), anObject.getClass().getName(), exception); } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccesstWhileGettingValueThruInstanceVaraibleAccessor(getAttributeName(), anObject.getClass().getName(), exception); } catch (NullPointerException exception) { String className = null; if (anObject != null) { // Some JVM's throw this exception for some very odd reason className = anObject.getClass().getName(); } throw DescriptorException.nullPointerWhileGettingValueThruInstanceVariableAccessor(getAttributeName(), className, exception); } }
/** * INTERNAL: * To validate mappings declaration */ public void validateBeforeInitialization(AbstractSession session) throws DescriptorException { super.validateBeforeInitialization(session); this.indirectionPolicy.validateContainerPolicy(session.getIntegrityChecker()); if (getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Class attributeType = ((InstanceVariableAttributeAccessor)getAttributeAccessor()).getAttributeType(); this.indirectionPolicy.validateDeclaredAttributeTypeForCollection(attributeType, session.getIntegrityChecker()); } else if (getAttributeAccessor().isMethodAttributeAccessor()) { Class returnType = ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodReturnType(); this.indirectionPolicy.validateGetMethodReturnTypeForCollection(returnType, session.getIntegrityChecker()); Class parameterType = ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodParameterType(); this.indirectionPolicy.validateSetMethodParameterTypeForCollection(parameterType, session.getIntegrityChecker()); } }
Field field = attributeAccessor.getAttributeField(); field = mapping.getDescriptor().getJavaClass().getDeclaredField(attributeAccessor.getAttributeName());
} else { InstanceVariableAttributeAccessor aa = new InstanceVariableAttributeAccessor(); aa.setAttributeName(locProp.getPropertyName()); descriptor.setLocationAccessor(aa);
/** * Allow any initialization to be performed with the descriptor class. */ public void initializeAttributes(Class descriptorClass) throws DescriptorException { this.attributeName = attributeName.intern(); super.initializeAttributes(descriptorClass); }
member = new ListAttributeImpl(this, colMapping); } else if(colMapping.getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Field aField = ((InstanceVariableAttributeAccessor)colMapping.getAttributeAccessor()).getAttributeField(); aField = ((InstanceVariableAttributeAccessor)inheritingTypeMember.getMapping().getAttributeAccessor()).getAttributeField();
AccessController.doPrivileged(new PrivilegedSetValueInField(this.attributeField, anObject, value)); } catch (PrivilegedActionException exception) { throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exception.getException()); Class fieldClass = getAttributeClass(); if (org.eclipse.persistence.internal.helper.Helper.isPrimitiveWrapper(fieldClass)) { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ AccessController.doPrivileged(new PrivilegedSetValueInField(this.attributeField, anObject, ConversionManager.getDefaultManager().convertObject(Integer.valueOf(0), fieldClass))); } catch (PrivilegedActionException exc) { throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exc.getException()); throw DescriptorException.nullPointerWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), value, exception); Object newValue = ConversionManager.getDefaultManager().convertObject(value, getAttributeClass()); if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { throw DescriptorException.illegalArgumentWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), getAttributeType().getName(), value, exception); } catch (IllegalAccessException exception) { if (value == null) { return; throw DescriptorException.illegalAccessWhileSettingValueThruInstanceVariableAccessor(getAttributeName(), anObject.getClass().getName(), value, exception); } catch (NullPointerException exception) { try { Class fieldClass = getAttributeClass(); if (org.eclipse.persistence.internal.helper.Helper.isPrimitiveWrapper(fieldClass) && (value == null)) {
/** * PUBLIC: * Default constructor. */ public DatabaseMapping() { this.isOptional = true; this.isReadOnly = false; this.attributeAccessor = new InstanceVariableAttributeAccessor(); }
/** * Returns the class type of the attribute. */ public Class getAttributeClass() { if (getAttributeField() == null) { return null; } return getAttributeType(); }