TrustGrapher  r52
A playabale simulator for modelling trust between agents
D:/src/cu/trustGrapher/loading/GraphConfig.java
Go to the documentation of this file.
00001 
00002 package cu.trustGrapher.loading;
00003 
00004 import cu.repsystestbed.algorithms.ReputationAlgorithm;
00005 import cu.repsystestbed.algorithms.TrustAlgorithm;
00006 import java.io.File;
00007 
00008 import aohara.utilities.MyClassLoader;
00009 import aohara.utilities.PropertyManager;
00010 
00016 public class GraphConfig {
00017 
00018     public static String NO_BASE = "noBase", NO_CONFIG = "noConfig", NO_CLASS = "noClass";
00019     private File classFile;
00020     private int index, base, classIndex;
00021     private boolean display;
00022     protected Object algorithm;
00023     protected PropertyManager properties;
00024 
00026 
00034     public GraphConfig(int index, boolean display, int base, int classIndex, String classPath, File propertyFile){
00035         this.index = index;
00036         this.display = display;
00037         this.base = base;
00038         this.classIndex = classIndex;
00039         setProperties(propertyFile);
00040         if (classPath != null){
00041             classFile = new File(classPath);
00042             algorithm = newAlgorithm(classPath);
00043         }else{
00044             classFile = null;
00045             algorithm = null;
00046         }
00047     }
00049 
00055     @Override
00056     public String toString() {
00057         String baseString = (base != -1) ? "" + base : NO_BASE;
00058         String  classString = (classIndex != -1) ? "" + classIndex : NO_CLASS;
00059         String configString = (properties != null) ? properties.getPropertyFile().getPath() : NO_CONFIG;
00060         return display + "," + baseString + "," + classString + "," + configString;
00061     }
00062 
00066     public int getIndex() {
00067         return index;
00068     }
00069     
00070     public String getKey(){
00071         return AlgorithmLoader.GRAPH + index;
00072     }
00073 
00077     public int getBaseIndex() {
00078         return base;
00079     }
00080 
00084     public File getClassFile() {
00085         return classFile;
00086     }
00087 
00091     public String getDisplayName() {
00092         return index + "-" + ( (algorithm != null) ? algorithm.getClass().getSimpleName() : "FeedbackHistory" );
00093     }
00094 
00098     public boolean isDisplayed() {
00099         return display;
00100     }
00101 
00105     public Object getAlgorithm(){
00106         return algorithm;
00107     }
00108 
00112     public File getProperties(){
00113         return (properties != null) ?properties.getPropertyFile() : null;
00114     }
00115 
00119     public boolean isFeedbackGraph(){
00120         return algorithm == null;
00121     }
00122 
00126     public boolean isReputationGraph(){
00127         return algorithm instanceof ReputationAlgorithm;
00128     }
00129 
00133     public boolean isTrustGraph(){
00134         return algorithm instanceof TrustAlgorithm;
00135     }
00136     
00138     
00142     public void setBase(int base) {
00143         this.base = base;
00144     }
00145 
00149     public final void setProperties(File propertyFile) {
00150         if (propertyFile == null){
00151             properties= null;
00152         }else{
00153             properties = (propertyFile.exists()) ? new PropertyManager(propertyFile) : null;
00154         }
00155     }
00156 
00160     public void setDisplay(boolean display){
00161         this.display = display;
00162     }
00163 
00165 
00170     public static Object newAlgorithm(String classPath) {
00171         Object o = MyClassLoader.newClass(classPath);
00172         if ((o instanceof ReputationAlgorithm) || (o instanceof TrustAlgorithm) || classPath.endsWith(".jar")) {
00173             return o;
00174         }
00175         aohara.utilities.ChatterBox.error("TrustClassLoader", "newAlgorithm()", "The file was invalid, no longer exists, or is not a recognized algorithm.\n" + classPath);
00176         return null;
00177     }
00178 }