private void generateReadAttributeMethod(JCodeModel jModel, JPackage jPackage, JDefinedClass jClusterClass,
			ZclClusterDescriptor zclClusterDescriptor, boolean isServer) throws Exception {

		Vector zclAttributeDescriptors = null;
		if (isServer)
			zclAttributeDescriptors = zclClusterDescriptor.getZclClientAttributesDescriptors();
		else
			zclAttributeDescriptors = zclClusterDescriptor.getZclServerAttributesDescriptors();

		if (zclAttributeDescriptors.size() == 0)
			return;

		JClass jZCLClass = jModel.ref(ZCL.class);

		JMethod jReadAttibuteMethod = jClusterClass.method(JMod.PROTECTED, boolean.class, "fillAttributeRecord");
		JVar jZclFrameVar = jReadAttibuteMethod.param(IZclFrame.class, "zclResponseFrame");
		JVar jAttrIdVar = jReadAttibuteMethod.param(int.class, "attrId");
		jReadAttibuteMethod._throws(ApplianceException.class);
		jReadAttibuteMethod._throws(ServiceClusterException.class);

		JBlock jBlock = jReadAttibuteMethod.body();

		JClass interfaceClass = getClusterConnectionClass(zclClusterDescriptor, !isServer);
		if (interfaceClass == null) {
			return;
		}

		JVar jVarPeer = null;

		JInvocation jInvocation = JExpr.invoke("getSinglePeerCluster")
				.arg(JExpr.direct(interfaceClass.name() + ".class.getName()"));

		jVarPeer = jBlock.decl(interfaceClass, "c").init(JExpr.cast(interfaceClass, jInvocation));

		JSwitch jSwitch = jBlock._switch(jAttrIdVar);

		JBlock jCaseBody = null;
		for (int i = 0; i < zclAttributeDescriptors.size(); i++) {
			ZclAttributeDescr zclAttributeDescriptor = (ZclAttributeDescr) zclAttributeDescriptors.get(i);

			jCaseBody = jSwitch._case(JExpr.lit(zclAttributeDescriptor.getId())).body();

			JType type = jTypeForZbTypename(jModel, jClusterClass.getPackage(), zclAttributeDescriptor.getTypeName(),
					zclAttributeDescriptor);

			JVar param = jCaseBody.decl(type, "v");

			JInvocation jGetterInvocation = jVarPeer.invoke(this.attributeGetterName(zclAttributeDescriptor));
			if (useDefaultRequestContext) {
				jGetterInvocation.arg(JExpr.ref("endPoint").invoke("getDefaultRequestContext"));
			} else {
				jGetterInvocation.arg(JExpr._null());
			}

			jCaseBody.assign(param, jGetterInvocation);

			JClass jClassZigBeeType = getZclDataTypeJClass(jModel, jClusterClass.getPackage(), jClusterClass,
					zclAttributeDescriptor.getTypeName(), zclAttributeDescriptor);

			jCaseBody.staticInvoke(jModel.ref(ZclDataTypeUI8.class), "zclSerialize").arg(jZclFrameVar)
					.arg(jZCLClass.staticRef("SUCCESS"));
			jCaseBody.invoke(jZclFrameVar, "appendUInt8").arg(jClassZigBeeType.staticRef("ZCL_DATA_TYPE"));
			jCaseBody.staticInvoke(jClassZigBeeType, "zclSerialize").arg(jZclFrameVar).arg(param);

			jCaseBody._break();
		}

		jSwitch._default().body()._return(JExpr.FALSE);
		jBlock._return(JExpr.TRUE);
	}