package com.ibm.devworks;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.ArrayList;
import java.util.List;

public class NumOps {
	private List<Operation> ops = new ArrayList<Operation>();

/*--------- Ioc - DI com o Spring
	public NumOps() {
		getOps().add(new AddOps());
		getOps().add(new SubOps());
		getOps().add(new MulOps());
	}
--------*/

	public void setOps(List<Operation> ops) {
		this.ops = ops;
	}

	public List<Operation> getOps() {
		return ops;
	}
	
	public Operation getOp(int i) {
		Operation retval;
		if (i > getOps().size()) {
			retval = null;
		} else {
			retval = (Operation) getOps().get(i);
		}
		return retval;
	}

	public int size() {
		return getOps().size();
	}

	public static void main(String[] args) {

		ApplicationContext ac = new ClassPathXmlApplicationContext(
		"classpath:numops-applicationContext.xml");
        //		NumOps nop = new NumOps();
		NumOps nop = (NumOps)ac.getBean("numOps");
		
        System.out.println("Executing class: " + NumOps.class.getName());

		for (int i = 0; i < nop.size(); i++) {
			System.out.println("2 " + nop.getOp(i).getDesc() + " 1 is "
					+ nop.getOp(i).op(2, 1));
		}
	}
}
