Package cu.repsystestbed.parse

Source Code of cu.repsystestbed.parse.CCmdLineParser

package cu.repsystestbed.parse;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.jcommando.Command;
import org.jcommando.Grouping;

import cu.repsystestbed.algorithms.Algorithm;
import cu.repsystestbed.data.Feedback;
import cu.repsystestbed.exceptions.WorkflowParserException;
import cu.repsystestbed.graphs.FeedbackHistoryEdgeFactory;
import cu.repsystestbed.graphs.FeedbackHistoryGraph;
import cu.repsystestbed.graphs.ReputationGraph;
import cu.repsystestbed.graphs.TrustGraph;
import cu.repsystestbed.util.DefaultArffFeedbackGenerator;
import cu.repsystestbed.util.ReputationGraphCreator;
import cu.repsystestbed.util.TrustGraphCreator;
import cu.repsystestbed.util.Util;

public class CCmdLineParser extends CommandLineParser
{
 
  static private Logger logger = Logger.getLogger(CCmdLineParser.class);
 
  //temporary variables
  String t_algName = null;
  String t_cp = null;
 
  String t_graphName = null;
  String t_graphType = null;
  String t_graphInputFile = null;
 
  String t_workflowName = null;
  String t_workflowDefn = null;
 
  //private variables
  private Hashtable<String, Object> m_storage;
 
  public CCmdLineParser(Hashtable<String, Object> storage)
  {
    super();
    Util.assertNotNull(storage);
    m_storage = storage;
  }
 
  public Hashtable<String, Object> getStorage()
  {
    return m_storage;
  }


  @Override
  public void doCreate()
  {
    try
    {
      System.out.println("create called");
      if(t_algName !=null)
      {
        Util.assertNotNull(t_cp);
        logger.debug("Algorithm name is: " + t_algName);
        logger.debug("Algorithm cp is: " + t_cp);
             
        Algorithm alg = createAlgorithmInstance(t_cp);
        m_storage.put(new String(t_algName), alg);


      }
      else if(t_graphName != null)
      {
        Util.assertNotNull(t_graphType);
       
        logger.debug("Graph name is: " + t_graphName);
        logger.debug("Graph type is: " + t_graphType);
        logger.debug("Input file is: " + t_graphInputFile);
       
        if(t_graphType.toLowerCase().equals("fhg"))
        {
          DefaultArffFeedbackGenerator gen = new DefaultArffFeedbackGenerator();
          ArrayList<Feedback> feedbacks = (ArrayList<Feedback>) gen.generateHardcoded(t_graphInputFile);
          FeedbackHistoryGraph fhg = new FeedbackHistoryGraph(new FeedbackHistoryEdgeFactory());
          fhg.addFeedbacks(feedbacks, false);
          m_storage.put(t_graphName, fhg);
        }
        else if(t_graphType.toLowerCase().equals("rg"))
        {
          ReputationGraphCreator gen = new ReputationGraphCreator();
          ReputationGraph rg = gen.createGraph(t_graphInputFile);
          m_storage.put(t_graphName, rg);
        }
        else if(t_graphType.toLowerCase().equals("tg"))
        {
          TrustGraphCreator gen = new TrustGraphCreator();
          TrustGraph tg = gen.createGraph(t_graphInputFile);
          m_storage.put(t_graphName, tg);
        }
        else
        {
          throw new Exception("Unknown graphType.");
        }
       
       
      }
    }       
    catch(Exception e)
    {
      logger.error(e);

    }

    //reset the variables
    t_algName = null;
    t_cp = null;
    t_graphName = null;
    t_graphType = null;
    t_graphInputFile = null;
    t_workflowName = null;
    t_workflowDefn = null;
  }

  @Override
  public void doExecute()
  {
    // TODO Auto-generated method stub
   
  }

  @Override
  public void setAlg(String algname)
  {
    logger.debug("alg called");
    t_algName = algname;
  }


  @Override
  public void setClasspath(String classpath)
  {
    logger.debug("classpath called");
    t_cp = classpath;
  }
 
  public Algorithm createAlgorithmInstance(String classPath) throws WorkflowParserException
  {
    try
    {
      Algorithm alg = (Algorithm) Util.newClass(classPath);
      return alg;
     
    }
    catch(Exception e)
    {
      throw new WorkflowParserException("Could not load algorithm " + classPath, e);
    }
  }
 
 

  public static void main(String[] args) throws Exception
  {
    BasicConfigurator.configure();

    Hashtable<String, Object> storage = new Hashtable<String, Object>();
    CCmdLineParser parser = new CCmdLineParser(storage);
    parser.parse(args);
    args = new String[]{"--alg", "et", "--classpath", "C:\\Users\\partheinstein\\RepSysTestbed\\war\\WEB-INF\\classes\\cu\\repsystestbed\\algorithms\\examples\\EigenTrust.class"};
    parser.parse(args);
    WorkflowParser2 wfParser = new WorkflowParser2("fhg>et", parser.getStorage());
   
  }

  @Override
  public void setGraph(String graphname)
  {
    logger.debug("graph called");
    t_graphName = graphname;
  }

  @Override
  public void setGraphtype(String graphtype)
  {
    logger.debug("setGraphtype called");
    t_graphType = graphtype;
   
  }

  @Override
  public void setInputfile(String inputfile)
  {
    logger.debug("setInputfile called");
    t_graphInputFile = inputfile;
   
  }



}
TOP

Related Classes of cu.repsystestbed.parse.CCmdLineParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.