/** * 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 */ 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; } }
/** * INTERNAL: * To validate mappings decleration */ public void validateBeforeInitialization(AbstractSession session) throws DescriptorException { super.validateBeforeInitialization(session); if (getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Class attributeType = ((InstanceVariableAttributeAccessor)getAttributeAccessor()).getAttributeType(); getIndirectionPolicy().validateDeclaredAttributeType(attributeType, session.getIntegrityChecker()); } else if (getAttributeAccessor() instanceof MethodAttributeAccessor) { Class returnType = ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodReturnType(); getIndirectionPolicy().validateGetMethodReturnType(returnType, session.getIntegrityChecker()); Class parameterType = ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodParameterType(); getIndirectionPolicy().validateSetMethodParameterType(parameterType, session.getIntegrityChecker()); } }
/** * INTERNAL: * To validate mappings declaration */ public void validateBeforeInitialization(AbstractSession session) throws DescriptorException { super.validateBeforeInitialization(session); getIndirectionPolicy().validateContainerPolicy(session.getIntegrityChecker()); if (getAttributeAccessor() instanceof InstanceVariableAttributeAccessor) { Class attributeType = ((InstanceVariableAttributeAccessor)getAttributeAccessor()).getAttributeType(); getIndirectionPolicy().validateDeclaredAttributeTypeForCollection(attributeType, session.getIntegrityChecker()); } else if (getAttributeAccessor() instanceof MethodAttributeAccessor) { Class returnType = ((MethodAttributeAccessor)getAttributeAccessor()).getGetMethodReturnType(); getIndirectionPolicy().validateGetMethodReturnTypeForCollection(returnType, session.getIntegrityChecker()); Class parameterType = ((MethodAttributeAccessor)getAttributeAccessor()).getSetMethodParameterType(); getIndirectionPolicy().validateSetMethodParameterTypeForCollection(parameterType, session.getIntegrityChecker()); } }