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

		Vector zclCommandsDescriptors = null;
		if (isServer)
			zclCommandsDescriptors = zclClusterDescriptor.getZclClientCommandsDescriptors();
		else
			zclCommandsDescriptors = zclClusterDescriptor.getZclServerCommandsDescriptors();

		int count = 0;
		for (int i = 0; i < zclCommandsDescriptors.size(); i++) {
			ZclCommandDescriptor zclCommandDescriptor = (ZclCommandDescriptor) zclCommandsDescriptors.get(i);

			if (zclCommandDescriptor.isResponse())
				continue;

			count++;
		}

		if (count == 0) {
			// jNotifyMethod.body()._return(JExpr._super().invoke(")));
			// jNotifyMethod.body()._return(JExpr.direct("super.notifyZclFrame(clusterId, zclFrame)"));
			return;
		}

		JMethod jNotifyMethod = jClusterClass.method(JMod.PUBLIC, boolean.class, "notifyZclFrame");
		JVar jClusterIdVar = jNotifyMethod.param(short.class, "clusterId");
		JVar jZclFrameVar = jNotifyMethod.param(IZclFrame.class, "zclFrame");
		jNotifyMethod._throws(Exception.class);

		JBlock jBlock = jNotifyMethod.body();

		// generates command signatures

		JVar jHandledVar = jBlock.decl(jModel.BOOLEAN, "handled");
		jBlock.directStatement(jHandledVar.name() + " = super.notifyZclFrame(clusterId, zclFrame);");

		jBlock._if(jHandledVar)._then()._return(jHandledVar);
		JVar jCommandIdVar = jBlock.decl(jModel.INT, "commandId").init(jZclFrameVar.invoke("getCommandId"));

		if (isServer) {
			jBlock._if(jZclFrameVar.invoke("isClientToServer"))._then()
					._throw(JExpr._new(jZclValidationException).arg("invalid direction field"));
		} else {
			jBlock._if(jZclFrameVar.invoke("isServerToClient"))._then()
					._throw(JExpr._new(jZclValidationException).arg("invalid direction field"));
		}

		JVar jVarResponseZclFrame = jBlock.decl(jModel.ref(IZclFrame.class), "responseZclFrame").init(JExpr._null());
		JVar jVarDevice = jBlock.decl(jModel.ref(ZigBeeDevice.class), "device").init(JExpr.invoke("getZigBeeDevice"));
		JVar jStatusCodeVar = jBlock.decl(jModel.INT, "statusCode").init(jModel.ref(ZCL.class).staticRef("SUCCESS"));

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

		boolean implementedPeerRequest = true;

		JVar jVarPeer = null;
		if (!implementedPeerRequest) {
			jVarPeer = jBlock.decl(interfaceClass, "c").init(JExpr._null());

			jBlock.directStatement("// TODO retrieve the peer");
		} else {
			JInvocation jInvocation = JExpr.invoke("getSinglePeerCluster").arg(
					JExpr.direct(interfaceClass.name() + ".class.getName()"));

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

		JConditional lastIf = null;

		JSwitch jSwitch = jBlock._switch(jCommandIdVar);

		for (int i = 0; i < zclCommandsDescriptors.size(); i++) {
			ZclCommandDescriptor zclCommandDescriptor = (ZclCommandDescriptor) zclCommandsDescriptors.get(i);

			if (zclCommandDescriptor.isResponse())
				continue;

			JBlock jCaseBody = jSwitch._case(JExpr.lit(zclCommandDescriptor.getId())).body();
			if (zclCommandDescriptor.getResponse() == null) {
				// The incoming command doesn't have any response (i.e Notify
				// commands), so just behave like the command is consumed.
				jCaseBody.assign(jVarResponseZclFrame,
						JExpr.invoke(getParseCommandName(zclCommandDescriptor)).arg(jVarPeer).arg(jZclFrameVar));

			} else {
				jCaseBody.assign(jVarResponseZclFrame,
						JExpr.invoke(getParseCommandName(zclCommandDescriptor)).arg(jVarPeer).arg(jZclFrameVar));
			}
			jCaseBody._break();
		}

		// Return false since the notify didn't handle the incoming message.
		jSwitch._default().body()._return(JExpr.FALSE);

		// if we need to handle some attributes ...
		JConditional ifBlock = jBlock._if(jVarResponseZclFrame.eq(JExpr._null()));

		JConditional innerIf = ifBlock._then()._if(jZclFrameVar.invoke("isDefaultResponseDisabled").not());

		innerIf._then().assign(jVarResponseZclFrame, JExpr.invoke("getDefaultResponse").arg(jZclFrameVar).arg(jStatusCodeVar));

		JFieldRef jClusterId = jClusterClass.staticRef("CLUSTER_ID");

		ifBlock._else().invoke(jVarDevice, "post").arg(jClusterId).arg(jVarResponseZclFrame);

		// JBlock thenBlock =
		// jBlock._if((jVarResponseZclFrame.eq(JExpr._null()).not()))._then();

		// thenBlock.invoke(jVarDevice,
		// "post").arg(jClusterId).arg(jVarResponseZclFrame);

		jNotifyMethod.body()._return(JExpr.TRUE);
	}