Package org.rhq.enterprise.communications.command.param

Examples of org.rhq.enterprise.communications.command.param.RequiredParameterDefinitionIterator


        } else {
            existingParamNames = new HashSet();
        }

        // make sure the current set of parameters have all required parameters defined with the proper types
        for (Iterator iter = new RequiredParameterDefinitionIterator(m_parameterDefinitions.values()); iter.hasNext();) {
            ParameterDefinition paramDef = (ParameterDefinition) iter.next();
            if (!existingParamNames.contains(paramDef.getName())) {
                throw new InvalidParameterValueException(LOG.getMsgString(CommI18NResourceKeys.MISSING_REQUIRED_FIELD,
                    paramDef.getName(), this));
            }

            paramValue = getParameterValue(paramDef.getName());
            if (!paramDef.isValidValue(paramValue)) {
                boolean valid = false;

                if (convertIfNecessary) {
                    paramValue = paramDef.convertObject(paramValue);

                    // if we got this far, our invalid value was converted to a valid value
                    valid = true;

                    // overwrite the invalid value with the new valid one
                    m_commandParameters.put(paramDef.getName(), paramValue);
                }

                if (!valid) {
                    throw new InvalidParameterValueException(LOG.getMsgString(
                        CommI18NResourceKeys.BAD_REQUIRED_PARAM_TYPE, paramDef.getName(), paramDef.getType(), paramDef
                            .isNullable(), ((paramValue == null) ? "<null>" : paramValue.getClass().toString()), this));
                }
            }
        }

        // if the current set of parameters has optional parameters defined,
        // make sure their values are of the proper type
        for (Iterator iter = new OptionalParameterDefinitionIterator(m_parameterDefinitions.values()); iter.hasNext();) {
            ParameterDefinition paramDef = (ParameterDefinition) iter.next();
            if (existingParamNames.contains(paramDef.getName())) {
                paramValue = getParameterValue(paramDef.getName());
                if (!paramDef.isValidValue(paramValue)) {
                    boolean valid = false;
                    if (convertIfNecessary) {
                        paramValue = paramDef.convertObject(paramValue);

                        // if we got this far, our invalid value was converted to a valid value
                        valid = true;

                        // overwrite the invalid value with the new valid one
                        m_commandParameters.put(paramDef.getName(), paramValue);
                    }

                    if (!valid) {
                        throw new InvalidParameterValueException(LOG.getMsgString(
                            CommI18NResourceKeys.BAD_OPTIONAL_PARAM_TYPE, paramDef.getName(), paramDef.getType(),
                            paramDef.isNullable(),
                            ((paramValue == null) ? "<null>" : paramValue.getClass().toString()), this));
                    }
                }
            }
        }

        // now make sure the current set of parameters do not contain unused, extra parameters
        for (Iterator iter = existingParamNames.iterator(); iter.hasNext();) {
            String paramName = (String) iter.next();

            if (!m_parameterDefinitions.containsKey(paramName)) {
                throw new InvalidParameterValueException(LOG.getMsgString(CommI18NResourceKeys.UNEXPECTED_PARAM,
                    paramName, this));
            }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.communications.command.param.RequiredParameterDefinitionIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.