/** * locate an agent of a given class * @param t * @return given agent * @exception CardAgentNotFoundException */ synchronized public static CardAgent getAgent (Class t) throws CardAgentNotFoundException { Iterator i = instance.agents.iterator(); while (i.hasNext()) { CardAgent a = (CardAgent) i.next(); if (a.getClass() == t) return a; } throw new CardAgentNotFoundException (t.getName()); } /**
/** * locate an agent giving its class Name * @param name * @return given agent * @exception CardAgentNotFoundException */ synchronized public static CardAgent getAgent (String name) throws CardAgentNotFoundException { Iterator i = instance.agents.iterator(); while (i.hasNext()) { CardAgent a = (CardAgent) i.next(); if ( a.getClass().getName().endsWith(name) ) return a; } throw new CardAgentNotFoundException (name); } /**
/** * locate an agent giving its unique agent ID * @param id * @return given agent * @exception CardAgentNotFoundException */ synchronized public static CardAgent getAgent (int id) throws CardAgentNotFoundException { Iterator i = instance.agents.iterator(); while (i.hasNext()) { CardAgent a = (CardAgent) i.next(); if (a.getID() == id) return a; } throw new CardAgentNotFoundException (Integer.toString(id)); }
/** * locate an agent able to process a given CardTransaction * @param t CardTransaction holding an Operation to be performed * @return suitable agent * @exception CardAgentNotFoundException */ synchronized public static CardAgent getAgent (CardTransaction t) throws CardAgentNotFoundException { Iterator i = instance.agents.iterator(); while (i.hasNext()) { CardAgent a = (CardAgent) i.next(); if (a.canHandle (t)) return a; } throw new CardAgentNotFoundException (); } }
/** * locate an agent giving a transaction Image * @param b a transaction image * @return given agent * @exception CardAgentNotFoundException */ synchronized public static CardAgent getAgent (byte[] b) throws CardAgentNotFoundException { try { ByteArrayInputStream i = new ByteArrayInputStream (b); ObjectInputStream o = new ObjectInputStream (i); int id = o.readInt(); return getAgent (id); } catch (Exception e) { } throw new CardAgentNotFoundException (); }