/** * Set get and set method after creating these methods by using * get and set method names */ public void initializeAttributes(Class theJavaClass) throws DescriptorException { if (getAttributeName() == null) { throw DescriptorException.attributeNameNotSpecified(); } try { setGetMethod(Helper.getDeclaredMethod(theJavaClass, getGetMethodName(), (Class[])null)); // The parameter type for the set method must always be the return type of the get method. if(!isWriteOnly()) { Class[] parameterTypes = new Class[1]; parameterTypes[0] = getGetMethodReturnType(); setSetMethod(Helper.getDeclaredMethod(theJavaClass, getSetMethodName(), parameterTypes)); } } catch (NoSuchMethodException ex) { DescriptorException descriptorException = DescriptorException.noSuchMethodWhileInitializingAttributesInMethodAccessor(getSetMethodName(), getGetMethodName(), theJavaClass.getName()); descriptorException.setInternalException(ex); throw descriptorException; } catch (SecurityException exception) { DescriptorException descriptorException = DescriptorException.securityWhileInitializingAttributesInMethodAccessor(getSetMethodName(), getGetMethodName(), theJavaClass.getName()); descriptorException.setInternalException(exception); throw descriptorException; } }
/** * INTERNAL: * Return the GetMethod return type for this MethodAttributeAccessor. * A special check is made to determine if a missing method is a result of failed weaving. * @return */ // Note: SDO overrides this method and will handle a null GetMethod public Class getGetMethodReturnType() throws DescriptorException { // 323403: If the getMethod is missing - check for "_persistence_*_vh" to see if weaving was expected if(null == getGetMethod() && null != getGetMethodName() && (getGetMethodName().indexOf(Helper.PERSISTENCE_FIELDNAME_PREFIX) > -1)) { // warn before a possible NPE on accessing a weaved method that does not exist AbstractSessionLog.getLog().log(SessionLog.FINEST, "no_weaved_vh_method_found_verify_weaving_and_module_order", getGetMethodName(), null, this); // 323403: We cannot continue to process objects that are not weaved - if weaving is enabled // If we allow the getMethodReturnType to continue - we will throw an obscure NullPointerException throw DescriptorException.nullPointerWhileGettingValueThruMethodAccessorCausedByWeavingNotOccurringBecauseOfModuleOrder(getGetMethodName(), "", null); } if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedGetMethodReturnType(getGetMethod())); } catch (PrivilegedActionException exception) { // we should not get here since this call does not throw any checked exceptions return null; } } else { return PrivilegedAccessHelper.getMethodReturnType(getGetMethod()); } }
protected Class getSetMethodParameterType(int index) { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedGetMethodParameterTypes(getSetMethod()))[index]; } catch (PrivilegedActionException exception) { // we should not get here since this call does not throw any checked exceptions return null; } } else { return PrivilegedAccessHelper.getMethodParameterTypes(getSetMethod())[index]; } }
/** * Return the return type of the method accessor. */ public Class getAttributeClass() { if (getGetMethod() == null) { return null; } return getGetMethodReturnType(); }
/** * Set get and set method after creating these methods by using * get and set method names */ protected void initializeAttributes(Class theJavaClass, Class[] getParameterTypes) throws DescriptorException { if (getAttributeName() == null) { throw DescriptorException.attributeNameNotSpecified(); } try { setGetMethod(Helper.getDeclaredMethod(theJavaClass, getGetMethodName(), getParameterTypes)); // The parameter type for the set method must always be the return type of the get method. if(!isWriteOnly()) { setSetMethod(Helper.getDeclaredMethod(theJavaClass, getSetMethodName(), getSetMethodParameterTypes())); } } catch (NoSuchMethodException ex) { DescriptorException descriptorException = DescriptorException.noSuchMethodWhileInitializingAttributesInMethodAccessor(getSetMethodName(), getGetMethodName(), theJavaClass.getName()); descriptorException.setInternalException(ex); throw descriptorException; } catch (SecurityException exception) { DescriptorException descriptorException = DescriptorException.securityWhileInitializingAttributesInMethodAccessor(getSetMethodName(), getGetMethodName(), theJavaClass.getName()); descriptorException.setInternalException(exception); throw descriptorException; } }
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), domainObject, parameters)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, throwableException); } else { throw DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, throwableException); throw DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, exception); } catch (IllegalArgumentException exception) { Object newValue = ConversionManager.getDefaultManager().convertObject(attributeValue, getAttributeClass()); Object[] newParameters = new Object[1]; newParameters[0] = newValue; if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), domainObject, newParameters)); } catch (PrivilegedActionException exc) { PrivilegedAccessHelper.invokeMethod(getSetMethod(), domainObject, newParameters); throw DescriptorException.illegalArgumentWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, exception); } catch (NullPointerException exception) { try {
public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if(variableAttributeAccessor == null){ if(variableAttributeName != null){ this.variableAttributeAccessor = new InstanceVariableAttributeAccessor(); this.variableAttributeAccessor.setAttributeName(variableAttributeName); }else if(variableGetMethodName != null){ this.variableAttributeAccessor = new MethodAttributeAccessor(); this.variableAttributeAccessor.setAttributeName("VARIABLE"); ((MethodAttributeAccessor)this.variableAttributeAccessor).setGetMethodName(variableGetMethodName); if(variableSetMethodName == null){ this.variableAttributeAccessor.setIsWriteOnly(true); }else{ ((MethodAttributeAccessor)this.variableAttributeAccessor).setSetMethodName(variableSetMethodName); } } } this.variableAttributeAccessor.initializeAttributes(this.getReferenceClass()); }
MethodAttributeAccessor aa = new MethodAttributeAccessor(); aa.setAttributeName(locProp.getPropertyName()); aa.setSetMethodName(locProp.getSetMethodName()); aa.setGetMethodName(locProp.getGetMethodName()); descriptor.setLocationAccessor(aa); } else {
/** * Sets the name of the method to be used when setting the value of the back pointer * on the target object of this mapping. If the specified method doesn't exist * on the reference class of this mapping, a DescriptorException will be thrown * during initialize. * * @param methodName - the setter method to be used. */ public void setBidirectionalTargetSetMethodName(String methodName) { if (methodName == null) { return; } if(this.bidirectionalTargetAccessor == null) { this.bidirectionalTargetAccessor = new MethodAttributeAccessor(); } // This is done because setting attribute name by defaults create InstanceVariableAttributeAccessor if (!getBidirectionalTargetAccessor().isMethodAttributeAccessor()) { String attributeName = this.bidirectionalTargetAccessor.getAttributeName(); setBidirectionalTargetAccessor(new MethodAttributeAccessor()); getBidirectionalTargetAccessor().setAttributeName(attributeName); } ((MethodAttributeAccessor)getBidirectionalTargetAccessor()).setSetMethodName(methodName); }
/** * Sets the method name to be used when accessing the value of the back pointer * on the target object of this mapping. If the specified method doesn't exist * on the reference class of this mapping, a DescriptorException will be thrown * during initialize. * * @param methodName - the getter method to be used. */ public void setBidirectionalTargetGetMethodName(String methodName) { if (methodName == null) { return; } if(this.bidirectionalTargetAccessor == null) { bidirectionalTargetAccessor = new MethodAttributeAccessor(); } // This is done because setting attribute name by defaults create InstanceVariableAttributeAccessor if (!getBidirectionalTargetAccessor().isMethodAttributeAccessor()) { String attributeName = this.bidirectionalTargetAccessor.getAttributeName(); setBidirectionalTargetAccessor(new MethodAttributeAccessor()); getBidirectionalTargetAccessor().setAttributeName(attributeName); } ((MethodAttributeAccessor)getBidirectionalTargetAccessor()).setGetMethodName(methodName); }
/** * 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()); } }
getMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName(); setMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getSetMethodName(); accessor.setValueType(mapping.getAttributeClassification());
/** * PUBLIC: * This method is invoked reflectively on the reference object to return the value of the * attribute in the object. This method returns the name of the getMethodName or null if not using method access. */ public String getGetMethodName() { if (!getAttributeAccessor().isMethodAttributeAccessor()) { return null; } return ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodName(); }
/** * PUBLIC: * This method is invoked reflectively on the reference object to set the value of the * attribute in the object. This method returns the name of the setMethodName or null if not using method access. */ public String getSetMethodName() { if (!getAttributeAccessor().isMethodAttributeAccessor()) { return null; } return ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodName(); }
aType = ((MethodAttributeAccessor)colMapping.getAttributeAccessor()).getAttributeClass(); if((aType != null) && List.class.isAssignableFrom(aType)) { member = new ListAttributeImpl(this, colMapping, true); String getMethodName = ((MethodAttributeAccessor)colMapping.getAttributeAccessor()).getGetMethodName(); if(null == getMethodName) {
protected Class[] getSetMethodParameterTypes() { return new Class[] {getGetMethodReturnType()}; }
public Class getGetMethodReturnType() { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return (Class)AccessController.doPrivileged(new PrivilegedGetMethodReturnType(getGetMethod())); } catch (PrivilegedActionException exception) { // we should not get here since this call does not throw any checked exceptions return null; } } else { return PrivilegedAccessHelper.getMethodReturnType(getGetMethod()); } }
/** * Set get and set method after creating these methods by using * get and set method names */ protected void initializeAttributes(Class theJavaClass, Class[] getParameterTypes) throws DescriptorException { if (getAttributeName() == null) { throw DescriptorException.attributeNameNotSpecified(); } try { setGetMethod(Helper.getDeclaredMethod(theJavaClass, getGetMethodName(), getParameterTypes)); // The parameter type for the set method must always be the return type of the get method. if(!isWriteOnly()) { setSetMethod(Helper.getDeclaredMethod(theJavaClass, getSetMethodName(), getSetMethodParameterTypes())); } } catch (NoSuchMethodException ex) { DescriptorException descriptorException = DescriptorException.noSuchMethodWhileInitializingAttributesInMethodAccessor(getSetMethodName(), getGetMethodName(), theJavaClass.getName()); descriptorException.setInternalException(ex); throw descriptorException; } catch (SecurityException exception) { DescriptorException descriptorException = DescriptorException.securityWhileInitializingAttributesInMethodAccessor(getSetMethodName(), getGetMethodName(), theJavaClass.getName()); descriptorException.setInternalException(exception); throw descriptorException; } }
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), domainObject, parameters)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, throwableException); } else { throw DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, throwableException); throw DescriptorException.illegalAccessWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, exception); } catch (IllegalArgumentException exception) { Object newValue = ConversionManager.getDefaultManager().convertObject(attributeValue, getAttributeClass()); Object[] newParameters = new Object[1]; newParameters[0] = newValue; if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { AccessController.doPrivileged(new PrivilegedMethodInvoker(getSetMethod(), domainObject, newParameters)); } catch (PrivilegedActionException exc) { PrivilegedAccessHelper.invokeMethod(getSetMethod(), domainObject, newParameters); throw DescriptorException.illegalArgumentWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileSettingValueThruMethodAccessor(getSetMethodName(), attributeValue, exception); } catch (NullPointerException exception) { try {
public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if(variableAttributeAccessor == null){ if(variableAttributeName != null){ this.variableAttributeAccessor = new InstanceVariableAttributeAccessor(); this.variableAttributeAccessor.setAttributeName(variableAttributeName); }else if(variableGetMethodName != null){ this.variableAttributeAccessor = new MethodAttributeAccessor(); this.variableAttributeAccessor.setAttributeName("VARIABLE"); ((MethodAttributeAccessor)this.variableAttributeAccessor).setGetMethodName(variableGetMethodName); if(variableSetMethodName == null){ this.variableAttributeAccessor.setIsWriteOnly(true); }else{ ((MethodAttributeAccessor)this.variableAttributeAccessor).setSetMethodName(variableSetMethodName); } } } this.variableAttributeAccessor.initializeAttributes(this.getReferenceClass()); }