private JType generateType(JCodeModel jModel, JPackage jPackage, String type, Object o) throws Exception {

		JDefinedClass jDefinedClass;
		try {
			jDefinedClass = jPackage._class(type);
		} catch (Exception e) {
			return jModel.ref(jPackage.name() + "." + type);
		}

		if (o instanceof ZclCommandDescriptor) {
			boolean isArray = false;

			jDefinedClass.constructor(JMod.PUBLIC);
			JMethod constructor = jDefinedClass.constructor(JMod.PUBLIC);

			ZclCommandDescriptor zclCommandDescriptor = (ZclCommandDescriptor) o;
			Vector zclParametersDescriptors = zclCommandDescriptor.getParametersDescriptors();
			for (int i = 0; i < zclParametersDescriptors.size(); i++) {
				ZclField zclParameterDescriptor = (ZclField) zclParametersDescriptors.get(i);
				String paramDescriptorType = zclParameterDescriptor.getType();

				if (paramDescriptorType.endsWith("[]")) {
					// this is an array
					isArray = true;
				}

				JType jType = jTypeForZbTypename(jModel, jPackage, zclParameterDescriptor.getType(), null);
				jDefinedClass.field(JMod.PUBLIC, jType, zclParameterDescriptor.getName());
				constructor.param(jType, zclParameterDescriptor.getName());

				String source = "this." + zclParameterDescriptor.getName() + " = " + zclParameterDescriptor.getName() + ";";
				constructor.body().directStatement(source);
			}
		}

		System.out.println("Generated class " + type);

		return jDefinedClass;
	}