container/components/components/src/main/java/org/mobicents/slee/container/component/validator/UsageInterfaceValidator.java
static boolean validateUsageParameterInterface(ComponentID id, boolean isSlee11, Class<?> usageInterface, List<UsageParameterDescriptor> parameters) {

		boolean passed = true;
		String errorBuffer = new String("");
		try {
			if (!usageInterface.isInterface()) {
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameter interface class is not an interface", "11.2", errorBuffer);
				return passed;
			}

			// Interface constraints
			if (isSlee11 && usageInterface.getPackage() == null) {
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameter interface must be declared in pacakge name space.", "11.2", errorBuffer);
			}

			if (!Modifier.isPublic(usageInterface.getModifiers())) {
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameter interface must be declared as public.", "11.2", errorBuffer);
			}

			// parameters check

			Set<String> ignore = new HashSet<String>();
			ignore.add("java.lang.Object");
			Map<String, Method> interfaceMethods = ClassUtils.getAllInterfacesMethods(usageInterface, ignore);
			Map<String, UsageParameterDescriptor> localParametersMap = new HashMap<String, UsageParameterDescriptor>();

			Set<String> identifiedIncrement = new HashSet<String>();
			Set<String> identifiedGetIncrement = new HashSet<String>();
			Set<String> identifiedSample = new HashSet<String>();
			Set<String> identifiedGetSample = new HashSet<String>();
			// this is for 1.1, get and increment methods must match with type

			// validate parameter names if we are slee11
			if (isSlee11)
				for (UsageParameterDescriptor usage : parameters) {
					char c = usage.getName().charAt(0);
					if (!Character.isLowerCase(c)) {
						passed = false;
						errorBuffer = appendToBuffer(id,
								"Parameter name must start with lower case character and be start of valid jva identifier, parameter name from descriptor: " + usage.getName(), "11.2", errorBuffer);
					}

					localParametersMap.put(usage.getName(), usage);
				}
			// at the end we have to have empty list
			for (Entry<String, Method> entry : interfaceMethods.entrySet()) {
				// String declaredLongMethodName = entry.getKey();

				Method m = entry.getValue();
				String declaredMethodName = m.getName();
				String declaredPrameterName = null;
				Character c = null;
				// he we just do checks, methods against constraints
				// we remove them from parameters map, there is something left
				// or not present in map in case of 1.1

				// some variable that we need to store info about method
				boolean isIncrement = false;
				boolean isGetIncrement = false;
				boolean isGetSample = false;
				boolean isSample = false;

				// 1.0 comp
				if (declaredMethodName.startsWith(_SAMPLE_METHOD_PREFIX)) {
					declaredPrameterName = declaredMethodName.replaceFirst(_SAMPLE_METHOD_PREFIX, "");
					c = declaredPrameterName.charAt(0);
					isSample = true;

					// 1.0 comp
				} else if (declaredMethodName.startsWith(_INCREMENT_METHOD_PREFIX)) {
					declaredPrameterName = declaredMethodName.replaceFirst(_INCREMENT_METHOD_PREFIX, "");
					c = declaredPrameterName.charAt(0);
					isIncrement = true;

					// 1.1 only
				} else if (declaredMethodName.startsWith(_GET_METHOD_PREFIX)) {
					declaredPrameterName = declaredMethodName.replaceFirst(_GET_METHOD_PREFIX, "");
					c = declaredPrameterName.charAt(0);
					if (!isSlee11) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Wrong method declared in parameter usage interface. Get method for counter parameter types are allowed only in JSLEE 1.1, method: "
								+ declaredMethodName, "11.2.X", errorBuffer);
					}
					if (m.getReturnType().getName().compareTo("javax.slee.usage.SampleStatistics") == 0) {
						isGetSample = true;
					} else {
						// we asume thats increment get
						isGetIncrement = true;
					}

				} else {
					passed = false;
					errorBuffer = appendToBuffer(id, "Wrong method decalred in parameter usage interface. Methods must start with either \"get\", \"sample\" or \"increment\", method: "
							+ declaredMethodName, "11.2.X", errorBuffer);
					continue;
				}

				if (!Character.isUpperCase(c)) {
					passed = false;
					errorBuffer = appendToBuffer(id, "Method stripped of prefix, either \"get\", \"sample\" or \"increment\", must have following upper case character,method: " + declaredMethodName,
							"11.2", errorBuffer);

				}

				declaredPrameterName = Introspector.decapitalize(declaredPrameterName);

				if (!isValidJavaIdentifier(declaredPrameterName)) {
					passed = false;
					errorBuffer = appendToBuffer(id, "Parameter name must be valid java identifier: " + declaredPrameterName, "11.2", errorBuffer);
				}

				// well we have indentified parameter, lets store;
				if (isIncrement) {
					if (identifiedIncrement.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedIncrement.add(declaredPrameterName);
						if (!validateParameterSetterSignatureMethod(id, m, "11.2.3")) {
							passed = false;

						}
					}

				} else if (isGetIncrement) {
					if (identifiedGetIncrement.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedGetIncrement.add(declaredPrameterName);
						if (!validateParameterGetterSignatureMethod(id, m, "11.2.2", Long.TYPE)) {
							passed = false;

						}
					}

				} else if (isGetSample) {
					if (identifiedGetSample.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedGetSample.add(declaredPrameterName);
						if (!validateParameterGetterSignatureMethod(id, m, "11.2.4", javax.slee.usage.SampleStatistics.class)) {
							passed = false;

						}
					}

				} else if (isSample) {
					if (identifiedSample.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedSample.add(declaredPrameterName);
						if (!validateParameterSetterSignatureMethod(id, m, "11.2.1")) {
							passed = false;
							errorBuffer = appendToBuffer(id,
									"Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName, "11.2", errorBuffer);
						}
					}

				}

				// UFFF, lets start the play
				// /uh its a bit complicated
			}
			// we siganture here is ok, return types also, no duplicates, left:
			// 1. cross check field types that we found - sample vs increments -
			// there cant be doubles
			// 2. remove all from list, if something is left, bam, we lack one
			// method or have to many :)
			Set<String> agregatedIncrement = new HashSet<String>();
			Set<String> agregatedSample = new HashSet<String>();

			agregatedIncrement.addAll(identifiedGetIncrement);
			agregatedIncrement.addAll(identifiedIncrement);

			agregatedSample.addAll(identifiedGetSample);
			agregatedSample.addAll(identifiedSample);
			Set<String> tmp = new HashSet<String>(agregatedSample);

			tmp.retainAll(agregatedIncrement);
			if (!tmp.isEmpty()) {
				// ugh, its the end
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameters can be associated only with single type - increment or sample, offending parameters: " + Arrays.toString(tmp.toArray()), "11.2",
						errorBuffer);

				return passed;
			}

			if (isSlee11) {
				tmp.clear();
				tmp.addAll(agregatedSample);
				tmp.addAll(agregatedIncrement);

				// localParametersMap.size()!=0 - cause we can have zero of them
				// - usage-parameter may not be present so its generation is
				// turned off
				if (localParametersMap.size() != tmp.size() && localParametersMap.size() != 0) {

					passed = false;

					String errorPart = null;
					if (localParametersMap.size() > tmp.size()) {
						// is there any bettter way?
						for (String s : localParametersMap.keySet())
							tmp.remove(s);
						errorPart = "More parameters are defined in descriptor, offending parameters: " + Arrays.toString(tmp.toArray());
					} else {
						for (String s : tmp)
							localParametersMap.remove(s);
						errorPart = "More parameters are defined in descriptor, offending parameters: " + Arrays.toString(localParametersMap.keySet().toArray());
					}

					errorBuffer = appendToBuffer(id, "Failed to map descriptor defined usage parameters against interface class methods. " + errorPart, "11.2", errorBuffer);

				}
			}
		} finally {
			if (!passed) {
				logger.error(errorBuffer);
				// System.err.println(errorBuffer);
			}
		}

		return passed;
	}
static boolean validateUsageParameterInterface(ComponentID id, boolean isSlee11, Class<?> usageInterface, List<UsageParameterDescriptor> parameters) {

		boolean passed = true;
		String errorBuffer = new String("");
		try {
			if (!usageInterface.isInterface()) {
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameter interface class is not an interface", "11.2", errorBuffer);
				return passed;
			}

			// Interface constraints
			if (isSlee11 && usageInterface.getPackage() == null) {
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameter interface must be declared in pacakge name space.", "11.2", errorBuffer);
			}

			if (!Modifier.isPublic(usageInterface.getModifiers())) {
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameter interface must be declared as public.", "11.2", errorBuffer);
			}

			// parameters check

			Set<String> ignore = new HashSet<String>();
			ignore.add("java.lang.Object");
			Map<String, Method> interfaceMethods = ClassUtils.getAllInterfacesMethods(usageInterface, ignore);
			Map<String, UsageParameterDescriptor> localParametersMap = new HashMap<String, UsageParameterDescriptor>();

			Set<String> identifiedIncrement = new HashSet<String>();
			Set<String> identifiedGetIncrement = new HashSet<String>();
			Set<String> identifiedSample = new HashSet<String>();
			Set<String> identifiedGetSample = new HashSet<String>();
			// this is for 1.1, get and increment methods must match with type

			// validate parameter names if we are slee11
			if (isSlee11)
				for (UsageParameterDescriptor usage : parameters) {
					char c = usage.getName().charAt(0);
					if (!Character.isLowerCase(c)) {
						passed = false;
						errorBuffer = appendToBuffer(id,
								"Parameter name must start with lower case character and be start of valid jva identifier, parameter name from descriptor: " + usage.getName(), "11.2", errorBuffer);
					}

					localParametersMap.put(usage.getName(), usage);
				}
			// at the end we have to have empty list
			for (Entry<String, Method> entry : interfaceMethods.entrySet()) {
				// String declaredLongMethodName = entry.getKey();

				Method m = entry.getValue();
				String declaredMethodName = m.getName();
				String declaredPrameterName = null;
				Character c = null;
				// he we just do checks, methods against constraints
				// we remove them from parameters map, there is something left
				// or not present in map in case of 1.1

				// some variable that we need to store info about method
				boolean isIncrement = false;
				boolean isGetIncrement = false;
				boolean isGetSample = false;
				boolean isSample = false;

				// 1.0 comp
				if (declaredMethodName.startsWith(_SAMPLE_METHOD_PREFIX)) {
					declaredPrameterName = declaredMethodName.replaceFirst(_SAMPLE_METHOD_PREFIX, "");
					c = declaredPrameterName.charAt(0);
					isSample = true;

					// 1.0 comp
				} else if (declaredMethodName.startsWith(_INCREMENT_METHOD_PREFIX)) {
					declaredPrameterName = declaredMethodName.replaceFirst(_INCREMENT_METHOD_PREFIX, "");
					c = declaredPrameterName.charAt(0);
					isIncrement = true;

					// 1.1 only
				} else if (declaredMethodName.startsWith(_GET_METHOD_PREFIX)) {
					declaredPrameterName = declaredMethodName.replaceFirst(_GET_METHOD_PREFIX, "");
					c = declaredPrameterName.charAt(0);
					if (!isSlee11) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Wrong method declared in parameter usage interface. Get method for counter parameter types are allowed only in JSLEE 1.1, method: "
								+ declaredMethodName, "11.2.X", errorBuffer);
					}
					if (m.getReturnType().getName().compareTo("javax.slee.usage.SampleStatistics") == 0) {
						isGetSample = true;
					} else {
						// we asume thats increment get
						isGetIncrement = true;
					}

				} else {
					passed = false;
					errorBuffer = appendToBuffer(id, "Wrong method decalred in parameter usage interface. Methods must start with either \"get\", \"sample\" or \"increment\", method: "
							+ declaredMethodName, "11.2.X", errorBuffer);
					continue;
				}

				if (!Character.isUpperCase(c)) {
					passed = false;
					errorBuffer = appendToBuffer(id, "Method stripped of prefix, either \"get\", \"sample\" or \"increment\", must have following upper case character,method: " + declaredMethodName,
							"11.2", errorBuffer);

				}

				declaredPrameterName = Introspector.decapitalize(declaredPrameterName);

				if (!isValidJavaIdentifier(declaredPrameterName)) {
					passed = false;
					errorBuffer = appendToBuffer(id, "Parameter name must be valid java identifier: " + declaredPrameterName, "11.2", errorBuffer);
				}

				// well we have indentified parameter, lets store;
				if (isIncrement) {
					if (identifiedIncrement.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedIncrement.add(declaredPrameterName);
						if (!validateParameterSetterSignatureMethod(id, m, "11.2.3")) {
							passed = false;

						}
					}

				} else if (isGetIncrement) {
					if (identifiedGetIncrement.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedGetIncrement.add(declaredPrameterName);
						if (!validateParameterGetterSignatureMethod(id, m, "11.2.2", Long.TYPE)) {
							passed = false;

						}
					}

				} else if (isGetSample) {
					if (identifiedGetSample.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedGetSample.add(declaredPrameterName);
						if (!validateParameterGetterSignatureMethod(id, m, "11.2.4", javax.slee.usage.SampleStatistics.class)) {
							passed = false;

						}
					}

				} else if (isSample) {
					if (identifiedSample.contains(declaredMethodName)) {
						passed = false;
						errorBuffer = appendToBuffer(id, "Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName,
								"11.2", errorBuffer);
					} else {
						identifiedSample.add(declaredPrameterName);
						if (!validateParameterSetterSignatureMethod(id, m, "11.2.1")) {
							passed = false;
							errorBuffer = appendToBuffer(id,
									"Duplicate declaration of usage parameter, possibly twe methods with the same name and different signature, method: " + declaredMethodName, "11.2", errorBuffer);
						}
					}

				}

				// UFFF, lets start the play
				// /uh its a bit complicated
			}
			// we siganture here is ok, return types also, no duplicates, left:
			// 1. cross check field types that we found - sample vs increments -
			// there cant be doubles
			// 2. remove all from list, if something is left, bam, we lack one
			// method or have to many :)
			Set<String> agregatedIncrement = new HashSet<String>();
			Set<String> agregatedSample = new HashSet<String>();

			agregatedIncrement.addAll(identifiedGetIncrement);
			agregatedIncrement.addAll(identifiedIncrement);

			agregatedSample.addAll(identifiedGetSample);
			agregatedSample.addAll(identifiedSample);
			Set<String> tmp = new HashSet<String>(agregatedSample);

			tmp.retainAll(agregatedIncrement);
			if (!tmp.isEmpty()) {
				// ugh, its the end
				passed = false;
				errorBuffer = appendToBuffer(id, "Usage parameters can be associated only with single type - increment or sample, offending parameters: " + Arrays.toString(tmp.toArray()), "11.2",
						errorBuffer);

				return passed;
			}

			if (isSlee11) {
				tmp.clear();
				tmp.addAll(agregatedSample);
				tmp.addAll(agregatedIncrement);

				// localParametersMap.size()!=0 - cause we can have zero of them
				// - usage-parameter may not be present so its generation is
				// turned off
				if (localParametersMap.size() != tmp.size() && localParametersMap.size() != 0) {

					passed = false;

					String errorPart = null;
					if (localParametersMap.size() > tmp.size()) {
						// is there any bettter way?
						for (String s : localParametersMap.keySet())
							tmp.remove(s);
						errorPart = "More parameters are defined in descriptor, offending parameters: " + Arrays.toString(tmp.toArray());
					} else {
						for (String s : tmp)
							localParametersMap.remove(s);
						errorPart = "More parameters are defined in descriptor, offending parameters: " + Arrays.toString(localParametersMap.keySet().toArray());
					}

					errorBuffer = appendToBuffer(id, "Failed to map descriptor defined usage parameters against interface class methods. " + errorPart, "11.2", errorBuffer);

				}
			}
		} finally {
			if (!passed) {
				logger.error(errorBuffer);
				// System.err.println(errorBuffer);
			}
		}

		return passed;
	}
This methods validate component which has usage parameter interface. Its
interface for methods. In case of 1.1 components parameters list must
match evey method defined. In case of 1.0 components parameters list MUST
be empty. It does not validate get usage method, those

@param isSlee11

@param usageInterface
- interface class itself
@param parameters
- list of parameters, in case of 1.0 sbb this MUST be null.
@return