--- /dev/null
+/*
+ * Copyright 2008 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.system.adapters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.wamblee.system.core.DefaultRequiredInterface;
+import org.wamblee.system.core.RequiredInterface;
+import org.wamblee.system.core.Scope;
+
+public class ParameterValues {
+ private Class[] _types;
+ private ValueProvider[] _values;
+
+ /**
+ * Constructs the configuration. By default no constructor is selected and
+ * one of {@link #select(Class...)} or
+ * {@link #greedy()} must be called.
+ * @param aClass Class to construct.
+ */
+ public ParameterValues(Class[] aTypes) {
+ _types = aTypes;
+ resetValues();
+ }
+
+ public Class[] getTypes() {
+ return _types;
+ }
+
+ /**
+ * Sets argument i to be optional, meaning that null is allowed to be passed in.
+ * @param aArg Argument to set.
+ */
+ public ParameterValues setOptional(int aArg) {
+ _values[aArg] = new RequiredInterfaceProvider(new DefaultRequiredInterface(
+ "arg" + aArg, _types[aArg], true));
+ return this;
+ }
+
+ /**
+ * Sets the argument i to a fixed value.
+ * @param aArg Argument to set.
+ * @param aValue Value.
+ */
+ public ParameterValues setValue(int aArg, Object aValue) {
+ _values[aArg] = new FixedValueProvider(aValue);
+ return this;
+ }
+
+ /**
+ * Resets the values.
+ */
+ private void resetValues() {
+ _values = new ValueProvider[_types.length];
+ for (int i = 0; i < _values.length; i++) {
+ _values[i] = new RequiredInterfaceProvider(new DefaultRequiredInterface(
+ "arg" + i, _types[i]));
+ }
+ }
+
+ public List<RequiredInterface> getRequiredInterfaces() {
+ List<RequiredInterface> result = new ArrayList<RequiredInterface>();
+ for (ValueProvider provider: _values) {
+ if ( provider instanceof RequiredInterfaceProvider) {
+ result.add( ((RequiredInterfaceProvider)provider).getRequiredInterface());
+ }
+ }
+ return result;
+ }
+
+ public Object[] values(Scope aScope) {
+ Object[] values = new Object[_values.length];
+ for (int i = 0; i < _values.length; i++) {
+ values[i] = _values[i].getValue(aScope);
+ }
+ return values;
+ }
+
+}