package geniusweb.partiesserver.repository; import java.io.IOException; import geniusweb.actions.PartyId; import geniusweb.javavenv.PythonPartyFactory; import geniusweb.party.Capabilities; import geniusweb.party.Party; /** * An approved and ready to run party. */ public class AvailablePythonParty implements AvailableParty { private final PythonPartyFactory partyfactory; private final String name; /** * * @param name the filename. This is not a {@link PartyId}. * @param partyfactory the {@link PythonPartyFactory} for the party. */ public AvailablePythonParty(String name, PythonPartyFactory partyfactory) throws ClassNotFoundException { this.name = name; this.partyfactory = partyfactory; } @Override public String getID() { return name; } @Override public String getName() { return name; } /** * * @return cached copy of what was received from a call to * {@link Party#getDescription()}. */ @Override public String getDescription() { return partyfactory.getDescription(); } /** * * @return cached copy of what was received from a call to * {@link AvailableParty#getCapabilities()} */ @Override public Capabilities getCapabilities() { return partyfactory.getCapabilites(); } @Override public Party getInstance() throws InstantiationFailedException { try { return partyfactory.getInstance(); } catch (IOException e) { throw new InstantiationFailedException( "Failed to create instance of " + name, e); } } @Override public void free() { partyfactory.close(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((partyfactory == null) ? 0 : partyfactory.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AvailablePythonParty other = (AvailablePythonParty) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (partyfactory == null) { if (other.partyfactory != null) return false; } else if (!partyfactory.equals(other.partyfactory)) return false; return true; } @Override public String toString() { return name + " (" + partyfactory + ")"; } }