IGetParameterDefinitionTask task, boolean includeGroups ) { if ( params == null ) return Collections.EMPTY_LIST; List ret = new ArrayList( ); List groups = new ArrayList( ); for ( Iterator it = params.iterator( ); it.hasNext( ); ) { Object o = it.next( ); if ( o instanceof IParameterGroupDefn ) {    if ( !includeGroups ) { IParameterGroupDefn groupDef = ( IParameterGroupDefn ) o; List contents = new ArrayList( convertEngineParameters( groupDef.getContents( ), task, true ) ); ret.addAll( contents );  }   groups.add( o ); } } for ( Iterator it = params.iterator( ); it.hasNext( ); ) { Object o = it.next( ); if ( o instanceof IScalarParameterDefn ) { IScalarParameterDefn engineParam = ( IScalarParameterDefn ) o; Object handle = engineParam.getHandle( ); ScalarParameterHandle scalarParamHandle = null; if ( handle instanceof ScalarParameterHandle ) scalarParamHandle = ( ScalarParameterHandle ) handle; String name = engineParam.getName( );  String pattern = scalarParamHandle == null ? "" : scalarParamHandle.getPattern( ); String displayFormat = engineParam.getDisplayFormat( ); String displayName = engineParam.getDisplayName( ); String helpText = engineParam.getHelpText( ); String promptText = engineParam.getPromptText( ); int dataType = engineParam.getDataType( ); int controlType = engineParam.getControlType( ); boolean hidden = engineParam.isHidden( ); boolean allowNull = engineParam.allowNull( ); boolean allowBlank = engineParam.allowBlank( ); boolean mustMatch = scalarParamHandle == null ? false : scalarParamHandle.isMustMatch( ); boolean concealValue = engineParam.isValueConcealed( );  ParameterGroupDefinition group = null;  for ( Iterator groupIt = groups.iterator( ); groupIt.hasNext( ); ) { IParameterGroupDefn tempGroup = ( IParameterGroupDefn ) groupIt .next( ); if ( tempGroup.getContents( ).contains( engineParam ) ) {   List contents = new ArrayList( convertEngineParameters( tempGroup.getContents( ), task, true ) ); group = new ParameterGroupDefinition( tempGroup .getName( ), tempGroup.getDisplayName( ), contents ); break; } }   Collection selectionList = convertEngineParameterSelectionChoice( task .getSelectionList( name ) );  ParameterDefinition param = new ParameterDefinition( name, pattern, displayFormat, displayName, helpText, promptText, dataType, controlType, hidden, allowNull, allowBlank, mustMatch, concealValue, group, selectionList ); ret.add( param ); } else if ( o instanceof IParameterGroupDefn && includeGroups ) {   IParameterGroupDefn engineParam = ( IParameterGroupDefn ) o;   List contents = new ArrayList( convertEngineParameters( engineParam.getContents( ), task, true ) ); ParameterGroupDefinition paramGroup = new ParameterGroupDefinition( engineParam.getName( ), engineParam.getDisplayName( ), contents ); ret.add( paramGroup ); } } return ret; }
IGetParameterDefinitionTask task, boolean includeGroups ) { if ( params == null ) return Collections.EMPTY_LIST; List ret = new ArrayList( ); List groups = new ArrayList( ); for ( Iterator it = params.iterator( ); it.hasNext( ); ) { Object o = it.next( ); if ( o instanceof IParameterGroupDefn ) {    if ( !includeGroups ) { IParameterGroupDefn groupDef = ( IParameterGroupDefn ) o; List contents = new ArrayList( convertEngineParameters( groupDef.getContents( ), task, true ) ); ret.addAll( contents );  }   groups.add( o ); } } for ( Iterator it = params.iterator( ); it.hasNext( ); ) { Object o = it.next( ); if ( o instanceof IScalarParameterDefn ) { IScalarParameterDefn engineParam = ( IScalarParameterDefn ) o; ParameterGroupDefinition group = null;  for ( Iterator groupIt = groups.iterator( ); groupIt.hasNext( ); ) { IParameterGroupDefn tempGroup = ( IParameterGroupDefn ) groupIt .next( ); boolean cascade = tempGroup instanceof ICascadingParameterGroup; if ( tempGroup.getContents( ).contains( engineParam ) ) {     List contents = new ArrayList( convertEngineParameters( tempGroup.getContents( ), task, true ) ); group = new ParameterGroupDefinition( tempGroup .getName( ), tempGroup.getDisplayName( ), contents, cascade ); break; } } ParameterDefinition param = convertScalarParameter( engineParam, group, task );  ret.add( param ); } else if ( o instanceof IParameterGroupDefn && includeGroups ) {   IParameterGroupDefn engineParam = ( IParameterGroupDefn ) o;  boolean cascade = engineParam instanceof ICascadingParameterGroup; ParameterGroupDefinition paramGroup = new ParameterGroupDefinition( engineParam.getName( ), engineParam.getDisplayName( ), null, cascade ); List contents = convertParametersInGroup( engineParam .getContents( ), paramGroup, task ); paramGroup.setParameters( contents );  ret.add( paramGroup ); } } return ret; }
   	private static Collection convertEngineParameters( Collection params,   			IGetParameterDefinitionTask task, boolean includeGroups )   	{   		if ( params == null )   			return Collections.EMPTY_LIST;   		List ret = new ArrayList( );   		List groups = new ArrayList( );   		for ( Iterator it = params.iterator( ); it.hasNext( ); )   		{   			Object o = it.next( );   			if ( o instanceof IParameterGroupDefn )   			{   				// If we do not want to include groups, i.e. we want a flattened   				// collection of parameters, find all group contents and add to   				// result   				if ( !includeGroups )   				{   					IParameterGroupDefn groupDef = ( IParameterGroupDefn ) o;   					List contents = new ArrayList( convertEngineParameters(   							groupDef.getContents( ), task, true ) );   					ret.addAll( contents );      				}   				// Save all groups so we later can check if a parameter is   				// contained in a group   				groups.add( o );   			}   		}   		for ( Iterator it = params.iterator( ); it.hasNext( ); )   		{   			Object o = it.next( );   			if ( o instanceof IScalarParameterDefn )   			{   				IScalarParameterDefn engineParam = ( IScalarParameterDefn ) o;   				Object handle = engineParam.getHandle( );   				ScalarParameterHandle scalarParamHandle = null;   				if ( handle instanceof ScalarParameterHandle )   					scalarParamHandle = ( ScalarParameterHandle ) handle;   				String name = engineParam.getName( );      				String pattern = scalarParamHandle == null ? ""   						: scalarParamHandle.getPattern( );   				String displayFormat = engineParam.getDisplayFormat( );   				String displayName = engineParam.getDisplayName( );   				String helpText = engineParam.getHelpText( );   				String promptText = engineParam.getPromptText( );   				int dataType = engineParam.getDataType( );   				int controlType = engineParam.getControlType( );   				boolean hidden = engineParam.isHidden( );   				boolean allowNull = engineParam.allowNull( );   				boolean allowBlank = engineParam.allowBlank( );   				boolean mustMatch = scalarParamHandle == null ? false   						: scalarParamHandle.isMustMatch( );   				boolean concealValue = engineParam.isValueConcealed( );      				ParameterGroupDefinition group = null;   				// Find group in which current parameter is a part of   				for ( Iterator groupIt = groups.iterator( ); groupIt.hasNext( ); )   				{   					IParameterGroupDefn tempGroup = ( IParameterGroupDefn ) groupIt   							.next( );   					if ( tempGroup.getContents( ).contains( engineParam ) )   					{   						// Recursion should only be one level,   						// since groups cannot contain groups   						List contents = new ArrayList( convertEngineParameters(   								tempGroup.getContents( ), task, true ) );   						group = new ParameterGroupDefinition( tempGroup   								.getName( ), tempGroup.getDisplayName( ),   								contents );   						break;   					}   				}      				// Convert selection list   				Collection selectionList = convertEngineParameterSelectionChoice( task   						.getSelectionList( name ) );      				ParameterDefinition param = new ParameterDefinition( name,   						pattern, displayFormat, displayName, helpText,   						promptText, dataType, controlType, hidden, allowNull,   						allowBlank, mustMatch, concealValue, group,   						selectionList );   				ret.add( param );   			} else if ( o instanceof IParameterGroupDefn && includeGroups )   			{   				// If this parameter is a group and we are including groups in   				// the result...   				IParameterGroupDefn engineParam = ( IParameterGroupDefn ) o;   				// Need to convert contents. Recursion should only be one level,   				// since groups cannot contain groups   				List contents = new ArrayList( convertEngineParameters(   						engineParam.getContents( ), task, true ) );   				ParameterGroupDefinition paramGroup = new ParameterGroupDefinition(   						engineParam.getName( ), engineParam.getDisplayName( ),   						contents );   				ret.add( paramGroup );   			}   		}   		return ret;   	}