package smartbox; import java.util.*; import java.io.Serializable; import java.lang.reflect.*; public class Component implements Serializable { private Set> requiredInterfaces; private Set> providedInterfaces; private transient Map, Field> fields; // transient because Field not serializable protected Container container; protected String name; public Component() { fields = new HashMap, Field>(); providedInterfaces = new HashSet>(); requiredInterfaces = new HashSet>(); computeRequiredInterfaces(); computeProvidedInterfaces(); container = null; name = this.getClass().getSimpleName(); } // add needed getters & setters public String toString() { return name; } // initializes fields and requiredInterfaces public void computeRequiredInterfaces() { Field[] fieldArray = this.getClass().getDeclaredFields(); for(int i = 0; i < fieldArray.length; i++) { //if the type of field[i] is an interface, then add it to fields and requiredInterfaces ??? } } // initializes provided interfaces public void computeProvidedInterfaces() { // get interfaces implemented by the class of this component and add them to providedInterfaces } // set the field of this object to the provider public void setProvider(Class intf, Component provider) throws Exception { Field field = fields.get(intf); field.set(this, provider); // field probably needs to be public for this. } // needed by file/open public void initComponent() { fields = new HashMap, Field>(); computeProvidedInterfaces(); computeRequiredInterfaces(); } }