1 5 package ve.luz.ica.jackass.client; 6 7 import java.io.BufferedReader ; 8 import java.io.InputStreamReader ; 9 import java.util.ArrayList ; 10 import java.util.List ; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 import org.omg.CORBA.ORB ; 16 import org.omg.CORBA.Object ; 17 18 import ve.luz.ica.jackass.solver.ComponentSolver; 19 import ve.luz.ica.jackass.solver.ComponentSolverHelper; 20 21 29 final class SingleHostSolverManager implements SolverManager 30 { 31 private static final Log LOG = LogFactory.getLog(SingleHostSolverManager.class); 32 private static final String SOLVER_FILE_NAME = "jackass.solvers"; 33 private List solvers; 34 private ORB orb; 35 36 41 public SingleHostSolverManager(ORB newOrb) 42 { 43 this.orb = newOrb; 44 if (LOG.isDebugEnabled()) LOG.debug("Assigned ORB = " + orb); 45 LOG.info("Current dir is " + System.getProperty("user.dir")); 46 try 47 { 48 BufferedReader reader = new BufferedReader (new InputStreamReader ( 49 getClass().getClassLoader().getResourceAsStream(SOLVER_FILE_NAME))); 50 if (LOG.isDebugEnabled()) LOG.debug("Opened configuration file " + SOLVER_FILE_NAME); 51 solvers = new ArrayList (); 52 53 String line; 54 while ((line = reader.readLine()) != null) 55 { 56 ComponentSolver aSolver = ComponentSolverHelper.narrow(orb.string_to_object(line)); 57 if (LOG.isDebugEnabled()) LOG.debug("Processed solver " + line + " as " + aSolver); 59 solvers.add(aSolver); 60 } 61 } 62 catch (Exception e) 63 { 64 if (LOG.isErrorEnabled()) 66 LOG.error("Error creating solvers from configuration file " + SOLVER_FILE_NAME, e); 67 throw new IllegalStateException (e.getMessage()); 68 } 69 } 70 71 public Object [] solve(String componentID) 72 { 73 ComponentSolver solver = selectSolver(); 74 if (LOG.isDebugEnabled()) LOG.debug("Resolving " + componentID); 75 Object [] ret = solver.solve(componentID); 76 if (LOG.isDebugEnabled()) LOG.debug("Result: " + ret); 77 return ret; 78 } 79 80 84 private ComponentSolver selectSolver() 85 { 86 return (ComponentSolver) solvers.get(0); 87 } 88 } 89 | Popular Tags |