/** * 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() instanceof MethodAttributeAccessor)) { return null; } return ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodName(); }
/** * Gets the value of an instance variable in the object. */ public Object getAttributeValueFromObject(Object anObject) throws DescriptorException { try { if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { return AccessController.doPrivileged(new PrivilegedMethodInvoker(getGetMethod(), anObject, (Object[])null)); } catch (PrivilegedActionException exception) { Exception throwableException = exception.getException(); if (throwableException instanceof IllegalAccessException) { throw DescriptorException.illegalAccessWhileGettingValueThruMethodAccessor(getGetMethodName(), anObject.getClass().getName(), throwableException); } else { throw DescriptorException.targetInvocationWhileGettingValueThruMethodAccessor(getGetMethodName(), anObject.getClass().getName(), throwableException); } } } else { return PrivilegedAccessHelper.invokeMethod(getGetMethod(), anObject, (Object[])null); } } catch (IllegalArgumentException exception) { throw DescriptorException.illegalArgumentWhileGettingValueThruMethodAccessor(getGetMethodName(), anObject.getClass().getName(), exception); } catch (IllegalAccessException exception) { throw DescriptorException.illegalAccessWhileGettingValueThruMethodAccessor(getGetMethodName(), anObject.getClass().getName(), exception); } catch (InvocationTargetException exception) { throw DescriptorException.targetInvocationWhileGettingValueThruMethodAccessor(getGetMethodName(), anObject.getClass().getName(), exception); } catch (NullPointerException exception) { // Some JVM's throw this exception for some very odd reason throw DescriptorException.nullPointerWhileGettingValueThruMethodAccessor(getGetMethodName(), anObject.getClass().getName(), exception); } }
/** * 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. 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; } }