eventinjector-cli

16:35:47.504 INFO  jd.cli.Main - Decompiling eventinjector-cli.jar
package org.tizen.injector;

import jline.ArgumentCompletor.AbstractArgumentDelimiter;

class Delimiter
  extends ArgumentCompletor.AbstractArgumentDelimiter
{
  public boolean isDelimiterChar(String buffer, int pos)
  {
    if (pos <= 0) {
      return false;
    }
    if (buffer.charAt(pos) == ' ') {
      return !isDelimiterChar(buffer, pos - 1);
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.Delimiter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector;

import java.util.ArrayList;
import org.tizen.injector.device.Device;
import org.tizen.injector.device.EmulatorDevice;
import org.tizen.injector.device.ExitDevice;
import org.tizen.injector.device.HelpDevice;
import org.tizen.injector.device.Record;
import org.tizen.injector.device.device.Battery;
import org.tizen.injector.device.device.EarJack;
import org.tizen.injector.device.device.RSSI;
import org.tizen.injector.device.device.SDCard;
import org.tizen.injector.device.device.USBDevice;
import org.tizen.injector.device.location.Location;
import org.tizen.injector.device.modem.Call;
import org.tizen.injector.device.modem.SMS;
import org.tizen.injector.device.nfc.Nfc;
import org.tizen.injector.device.sensor.Motion;
import org.tizen.injector.device.sensor.Sensor;

public class DeviceList
{
  private ArrayList<Device> deviceList = new ArrayList();
  private Nfc nfc = new Nfc();
  
  public DeviceList()
  {
    initDefalutDeviceList();
  }
  
  private void initDefalutDeviceList()
  {
    deviceList.add(new Sensor());
    deviceList.add(new Motion());
    deviceList.add(new Battery());
    deviceList.add(new EarJack());
    deviceList.add(new USBDevice());
    deviceList.add(new RSSI());
    deviceList.add(new SDCard());
    deviceList.add(new Location());
    deviceList.add(new SMS());
    deviceList.add(new Call());
    deviceList.add(nfc);
  }
  
  public Device findDevice(String name)
  {
    for (Device d : deviceList) {
      if (d.getName().equals(name)) {
        return d;
      }
    }
    return null;
  }
  
  public ArrayList<Device> getDeviceList()
  {
    return deviceList;
  }
  
  public void startSession()
  {
    nfc.initSessionMode();
    
    deviceList.add(new Record(EventInjector.getInstance().getRecorder()));
    deviceList.add(new EmulatorDevice());
    deviceList.add(new HelpDevice());
    deviceList.add(new ExitDevice());
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.DeviceList
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector;

import java.io.IOException;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.List;
import jline.ArgumentCompletor;
import jline.Completor;
import jline.ConsoleReader;
import jline.NullCompletor;
import org.tizen.eilib.connection.ConnectionToEmulator;
import org.tizen.eilib.connection.Emulator;
import org.tizen.eilib.events.EventInjectorCreator;
import org.tizen.eilib.exception.ConnectionException;
import org.tizen.eilib.exception.EILibError;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.device.Command;
import org.tizen.injector.device.Device;
import org.tizen.injector.exception.ConsoleException;
import org.tizen.injector.parser.ArgCompletor;
import org.tizen.injector.parser.Args;
import org.tizen.injector.parser.CommandCompletor;
import org.tizen.injector.parser.CommandParser;
import org.tizen.injector.parser.DeviceCompletor;
import org.tizen.injector.parser.HelpMessage;

public class EventInjector
{
  private static ConnectionToEmulator connector = null;
  private static EventInjectorCreator creator = null;
  private static Emulator currentEmulator = null;
  private static CommandParser parser = null;
  private GlobalOption options = null;
  private DeviceList deviceList = null;
  private Args argsList = null;
  private static boolean isSession = false;
  private static EventInjector injector = null;
  
  public static EventInjector getInstance()
  {
    return injector;
  }
  
  private EventInjector()
  {
    options = new GlobalOption();
    deviceList = new DeviceList();
    parser = new CommandParser(this);
    HelpMessage.setting(options, deviceList);
  }
  
  public static void main(String[] args)
  {
    try
    {
      connector = new ConnectionToEmulator();
      creator = new EventInjectorCreator(connector);
      
      connector.addDeviceChangeListener(new MonitorEmulator());
      
      injector = new EventInjector();
      
      injectorargsList = new Args(args);
      injectorargsList = parser.parseOptions(injectorargsList);
      if (parser.isHasOptions()) {
        parser.getOptions().process();
      }
      if ((!parser.isHasOptions()) || ((parser.isHasOptions()) && (parser.getOptions().isHasSessionOption()))) {
        if (injectorargsList != null) {
          injector.OnceSession();
        } else {
          injector.Session();
        }
      }
    }
    catch (ConsoleException ce)
    {
      exitEventInjector(ce.getErrorNumber());
    }
    catch (InjectorLibraryException ie)
    {
      System.out.println("Error:" + ie.getMessage());
      if (ie.getError() == EILibError.EmulatorNotOne) {
        System.out.println("Use --connect | -c option to select emulator.");
      }
      exitEventInjector(ie.getErrorNumber());
    }
    catch (Throwable t)
    {
      System.out.println("Error:" + t.getMessage());
      exitEventInjector(1);
    }
    exitEventInjector(0);
  }
  
  public int process(Args args)
  {
    Device device = null;
    try
    {
      device = parser.parseDevice(args);
    }
    catch (ConsoleException e)
    {
      HelpMessage.printHelp(e, isSession);
      return e.getErrorNumber();
    }
    Command command = null;
    try
    {
      command = parser.parseCommand(device, args);
    }
    catch (ConsoleException e)
    {
      HelpMessage.printHelp(device, e);
      return e.getErrorNumber();
    }
    if (command != null)
    {
      int re = 0;
      try
      {
        re = parser.parseArgument(command, args);
        if (re != 0) {
          return re;
        }
        re = command.process();
      }
      catch (ConnectionException e)
      {
        re = e.getErrorNumber();
      }
      catch (ConsoleException e)
      {
        re = e.getErrorNumber();
      }
      if (re != 0) {
        return re;
      }
      System.out.println("OK");
    }
    else
    {
      HelpMessage.printHelp(device, null);
      return 1;
    }
    return 0;
  }
  
  private void OnceSession()
    throws IOException, InjectorLibraryException
  {
    try
    {
      connector.connect();
    }
    catch (InjectorLibraryException e)
    {
      if (e.getError() == EILibError.EmuldVersionOld)
      {
        System.out.println("Error: " + e.getMessage());
        System.out.println("Some command does not work...!");
        System.out.println("Please update emulator that has emuld over " + connector.getEmuldVersion() + " version");
      }
      else
      {
        throw e;
      }
    }
    currentEmulator = connector.getCurrentEmulator();
    
    int exitValue = process(argsList);
    if (exitValue != 0) {
      exitEventInjector(exitValue);
    }
  }
  
  private static boolean isRecordMode = false;
  private static EventRecorder recorder = new EventRecorder();
  
  private void Session()
    throws ConsoleException, InjectorLibraryException, IOException
  {
    isSession = true;
    deviceList.startSession();
    HelpMessage.setting(options, deviceList);
    try
    {
      connector.connect();
    }
    catch (InjectorLibraryException e)
    {
      if (e.getError() == EILibError.EmuldVersionOld)
      {
        System.out.println("Error: " + e.getMessage());
        System.out.println("Some command does not work...!");
        System.out.println("Please update emulator that has emuld over " + connector.getEmuldVersion() + " version");
      }
      else
      {
        throw e;
      }
    }
    currentEmulator = connector.getCurrentEmulator();
    
    System.out.println("Start event injector..");
    
    ConsoleReader reader = new ConsoleReader();
    reader.setBellEnabled(false);
    
    List<Completor> completors = new LinkedList();
    
    DeviceCompletor dCompletor = new DeviceCompletor();
    completors.add(dCompletor);
    CommandCompletor cCompletor = new CommandCompletor(dCompletor);
    completors.add(cCompletor);
    completors.add(new ArgCompletor(cCompletor, 1));
    completors.add(new ArgCompletor(cCompletor, 2));
    completors.add(new NullCompletor());
    
    reader.addCompletor(new ArgumentCompletor(completors));
    String line;
    while ((line = reader.readLine(">> ")) != null)
    {
      Args args = new Args(line.split(" "));
      if ((process(args) == 0) && 
        (isRecordMode())) {
        recorder.addCommand(line);
      }
    }
  }
  
  public static void exitEventInjector(int exitValue)
  {
    if (connector != null) {
      connector.terminate();
    }
    if (injector.isRecordMode()) {
      try
      {
        recorder.endRecord();
      }
      catch (ConsoleException e)
      {
        System.out.println(e.getMessage());
      }
    }
    System.exit(exitValue);
  }
  
  public static ConnectionToEmulator getConnector()
  {
    return connector;
  }
  
  public static EventInjectorCreator getCreator()
  {
    return creator;
  }
  
  public static Emulator getCurrentEmulator()
  {
    return currentEmulator;
  }
  
  public static CommandParser getParser()
  {
    return parser;
  }
  
  public GlobalOption getOptions()
  {
    return options;
  }
  
  public DeviceList getDeviceList()
  {
    return deviceList;
  }
  
  public boolean isRecordMode()
  {
    return isRecordMode;
  }
  
  public void setRecordMode(boolean isRecordMode)
  {
    isRecordMode = isRecordMode;
  }
  
  public EventRecorder getRecorder()
  {
    return recorder;
  }
  
  public static boolean isSessionMode()
  {
    return isSession;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.EventInjector
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import org.tizen.injector.exception.ConsoleError;
import org.tizen.injector.exception.ConsoleException;

public class EventRecorder
{
  private ArrayList<String> commands = null;
  private PrintWriter output = null;
  private int maxSize = 1000;
  private String fileName = "";
  private String filePath = "";
  private File recordFile = null;
  private boolean isRecording = false;
  
  public EventRecorder()
  {
    commands = new ArrayList();
  }
  
  public String getFileName()
  {
    return fileName;
  }
  
  public void setFileName(String fileName)
  {
    this.fileName = fileName;
  }
  
  public String getFilePath()
  {
    return filePath;
  }
  
  public void setFilePath(String filePath)
  {
    this.filePath = filePath;
  }
  
  public boolean isRecording()
  {
    return isRecording;
  }
  
  public void addCommand(String command)
    throws ConsoleException
  {
    if (commands.size() == maxSize) {
      throw new ConsoleException(ConsoleError.FullCommandBuffer);
    }
    if (!command.startsWith("record")) {
      commands.add(command);
    }
  }
  
  private SimpleDateFormat dayTime = new SimpleDateFormat("yyMMdd-HHmmss");
  
  public String startRecord()
    throws ConsoleException, IOException
  {
    if (isRecording) {
      throw new ConsoleException(ConsoleError.AlreadyStartRecording);
    }
    String name = "";
    if (fileName.isEmpty())
    {
      String str = dayTime.format(new Date(System.currentTimeMillis()));
      name = "record" + str + ".txt";
    }
    else
    {
      name = fileName;
    }
    if (filePath.isEmpty()) {
      recordFile = new File(name);
    } else {
      recordFile = new File(filePath + File.separator + name);
    }
    try
    {
      recordFile = recordFile.getCanonicalFile();
      if (!recordFile.exists()) {
        recordFile.createNewFile();
      }
      output = new PrintWriter(new FileWriter(recordFile), true);
    }
    catch (IOException e)
    {
      fileName = "";
      filePath = "";
      throw e;
    }
    isRecording = true;
    return recordFile.getPath();
  }
  
  public String endRecord()
    throws ConsoleException
  {
    if (!isRecording) {
      throw new ConsoleException(ConsoleError.AlreadyStopRecording);
    }
    if (output != null)
    {
      for (Iterator<String> i = commands.iterator(); i.hasNext();) {
        output.println((String)i.next());
      }
      output.flush();
      output.close();
    }
    commands.clear();
    isRecording = false;
    fileName = "";
    filePath = "";
    return recordFile.getPath();
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.EventRecorder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector;

import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.eilib.connection.ConnectionToEmulator;
import org.tizen.eilib.connection.Emulator;
import org.tizen.eilib.exception.EILibError;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.device.Option;
import org.tizen.injector.exception.ConsoleError;
import org.tizen.injector.exception.ConsoleException;
import org.tizen.injector.parser.HelpMessage;

public class GlobalOption
{
  private ArrayList<Option> options;
  private boolean hasSessionOption = false;
  
  public GlobalOption()
  {
    options = new ArrayList();
    
    options.add(new Option("help", "h", "Pirnt help message", false, true));
    
    options.add(new Option("emulator", "e", "Display running emulator list", false, true));
    
    options.add(new Option("connect", "c", "Select emulator.", true, false));
  }
  
  public Option findShortNameOption(String option)
  {
    for (Option o : options) {
      if (o.getShortName().equals(option)) {
        return o;
      }
    }
    return null;
  }
  
  public Option findLongNameOption(String option)
  {
    for (Option o : options) {
      if (o.getLongName().equals(option)) {
        return o;
      }
    }
    return null;
  }
  
  public void process()
    throws InjectorLibraryException, ConsoleException
  {
    for (Option o : options) {
      if (o.isInCommandLine())
      {
        hasSessionOption |= !o.isExitOption();
        switch (o.getShortName().charAt(0))
        {
        case 'h': 
          printHelpMessage();
          break;
        case 'e': 
          displayEmualtorList();
          break;
        case 'c': 
          setPortInfomation(o);
          break;
        default: 
          return;
        }
      }
    }
  }
  
  private void printHelpMessage()
  {
    HelpMessage.printHelp(null, false);
  }
  
  private void displayEmualtorList()
    throws InjectorLibraryException
  {
    ArrayList<Emulator> list = EventInjector.getConnector().getEmulatorList();
    if (list.isEmpty()) {
      throw new InjectorLibraryException(EILibError.EmulatorNotExist);
    }
    for (Emulator e : list) {
      System.out.println(e.toString());
    }
  }
  
  private void setPortInfomation(Option o)
    throws ConsoleException
  {
    String value = o.getCurrentValue();
    int port = 0;
    String em = "";
    try
    {
      port = Integer.parseInt(value);
    }
    catch (NumberFormatException t)
    {
      port = 0;
    }
    for (Emulator e : EventInjector.getConnector().getEmulatorList()) {
      if ((port != 0) && (port == e.getPort()))
      {
        em = e.getDeviceName();
      }
      else if (e.getDeviceName().equals(value))
      {
        em = value;
        port = e.getPort();
      }
    }
    if (em.isEmpty()) {
      throw new ConsoleException(ConsoleError.NotAvaliableEM);
    }
    EventInjector.getConnector().setPort(port);
  }
  
  public boolean isHasSessionOption()
  {
    return hasSessionOption;
  }
  
  public ArrayList<Option> getOptionList()
  {
    return options;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.GlobalOption
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector;

import org.tizen.eilib.connection.Emulator;
import org.tizen.eilib.connection.IEmulatorChangeListener;

class MonitorEmulator
  extends IEmulatorChangeListener
{
  public void deviceConnected(Emulator device) {}
  
  public void deviceDisconnected(Emulator device)
  {
    if ((EventInjector.getCurrentEmulator() != null) && 
      (device.equals(EventInjector.getCurrentEmulator()))) {
      EventInjector.exitEventInjector(0);
    }
  }
  
  public void deviceChanged(Emulator device, int changeMask) {}
}

/* Location:
 * Qualified Name:     org.tizen.injector.MonitorEmulator
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector;

public class StringResource
{
  public static String AvailableState = "This device is avaliable.";
  public static String NotAvailableState = "This device is not available.";
  public static String NotAvaliableGettingStatus = "Getting the value from emulator is not supported.";
  public static String FailedGetValue = "Failed to get the value of device from emulator.";
  public static String EmulatorDesc = "Display running emulator list.";
  public static String ExitDesc = "Terminate event injector.";
  public static String HelpDesc = "Print help message about event injector or selected device";
  public static String Command = " command [command args]";
  public static String Usage = "Usage: ";
  public static String CommandSyntax = "Command syntax:";
  public static String CommandArgument = "Command argument:";
  public static String RecordDesc = "Record commands to the file.";
  public static String RecordStopDesc = "Stop to record commands.";
  public static String RecordStartDesc = "Start to record commands.";
  public static String StopSuccess = "Recording commands is complete : ";
  public static String StopFailed = "Failed to be complete recording commands.";
  public static String StartFileDesc = "is address of file recorded commands.\n\tDefalut path is current directory and defalut file name is recordYYMMDD-HHMMSS.\n\tIf input only file name, file path is current directory + file name.\n\tIf input only directory path, file path is directory path + default name";
  public static String StartSuccess = "Start to record commands to the file: ";
  public static String StartFailed = "Failed to start recording command.";
  public static String RecordPlayDesc = "Play events from the file that has commamds.";
  public static String PlayFileDesc = "is address of event log file.";
  public static String BatteryDesc = "Set level or charger state of battery.";
  public static String BatteryStatusDesc = "is to display status of battery device";
  public static String BatteryLevelDesc = "is setting battery level.";
  public static String BatteryChargerDesc = "is setting state of charger.";
  public static String ArgChargerDesc = "is state of battery charger.";
  public static String ArgLevelDesc = "is battery level.";
  public static String EarJackDesc = "Set status of ear jack.";
  public static String EarJackStatusDesc = "is to display status of ear jack device";
  public static String EarJackSetDesc = "is setting state of ear jack.";
  public static String ArgEarJackDesc = "is current state of ear jack.";
  public static String RssiDesc = "Set rssi information.";
  public static String RssiStatusDesc = "is to display status of rssi.";
  public static String RssiSetDesc = "is setting rssi level.";
  public static String ArgRssiDesc = "is rssi level.";
  public static String SdcardDesc = "Mount or unmount sd card.";
  public static String SdcardStatusDesc = "is to display status of sdcard device.";
  public static String SdcardMountDesc = "is to mount sd card to the emulator.";
  public static String ArgSdcardNameDesc = "is name of sdcard image";
  public static String SdcardUmountDesc = "is to unmount sd card to the emulator.";
  public static String UsbDesc = "Send usb status.";
  public static String UsbStatusDesc = "is to display status of usb device.";
  public static String UsbSetDesc = "is setting usb status.";
  public static String ArgUsbDesc = "is current state of USB.";
  public static String LocationDesc = "Send location information.";
  public static String LocationStatusDesc = "is to display status of location";
  public static String LocaiontCodiDesc = "is setting location information.";
  public static String ArgLatitudeDesc = "'latitude' of a place is its distance from the equator.";
  public static String ArgLongitudeDesc = "'longitude' of a place is its distance to the west or eastof a line passing through Greenwich.";
  public static String LocationFileDesc = "is setting location value of emulator using log file.(NMEA type file)";
  public static String ArgLocationFileDesc = "is address of log file.\n\tThis file will be sent to emulator and used to event injector.";
  public static String LocationStopDesc = "is to stop location event.";
  public static String CallDesc = "Handling call event associated the emulator";
  public static String CallStatusDesc = "is to display status of call including call list";
  public static String CallListDesc = "is to display list of call.";
  public static String CallListEmpty = "Call list is empty.";
  public static String CallDialDesc = "is sending phone call event to the emulator.";
  public static String CallHiddenDesc = "is sending phone call event with hidden number.";
  public static String CallAlertDesc = "is to change call state  to the alert state.";
  public static String CallConnectDesc = "is to change call state to the connect state.";
  public static String CallDisconnectDesc = "is to change call state to the disconnect state.";
  public static String ArgCallNumberDesc = "is phone number";
  public static String ArgCallIDDesc = "is id of call event. You can check id using 'call list' command.";
  public static String ArgCallErrorCodeDesc = "is result of call event.";
  public static String SMSDesc = "Send sms message or status to the emulator.";
  public static String SMSStatusDesc = "is to display status of sms.";
  public static String SMSSendDesc = "is sending SMS text message to the emulator.";
  public static String ArgSMSNumberDesc = "is phone number";
  public static String ArgSMSTextDesc = "is contents of sms";
  public static String SMSSetStatusDesc = "is sending status of message(SMS) sent from the emulator.";
  public static String ArgSMSStatusDesc = "is reslut of message sent from emulator.";
  public static String MMSSetStatusDesc = "is sending status of message(MMS) sent from the emulator.";
  public static String ArgMMSStatusDesc = "is reslut of message sent from emulator.";
  public static String NfcDesc = "Send nfc message to the emulator.";
  public static String NfcHelpMessage = "\t'event-type' is event type of each command.\n\tIf you want more detail, enter 'nfc [command]' or 'help nfc [command]'";
  public static String NfcStatusDesc = "is to display status of nfc device";
  public static String NDEFListEmpty = "Message list is empty";
  public static String NfcMessageDesc = "is to create or remove ndef message.\nBefore attaching nfc tag, at least one more message should exist in the list.";
  public static String NfcTagDesc = "send tag event to the emulator. You can attach with one NDEF message.\nIf you want to send more message, use session mode.";
  public static String NfcTagSessionDesc = "send tag event to the emulator.\nBefore attaching nfc tag, at least one more message should exist in the list.";
  public static String NfcP2PDesc = "send p2p event to the emulator. You can send with one NDEF message.\nIf you want to send more message, use session mode.";
  public static String NfcP2PSessionDesc = "send p2p event to the emulator.\nBefore p2p send event, at least one more message shoud exist in the list.";
  public static String ArgNfcTagTypeDesc = "is event type of tag command.";
  public static String ArgP2PTypeDesc = "is event type of p2p command.";
  public static String ArgNDEFMessageDesc = "is ndef message.";
  public static String ArgMessageIndexDesc = "is index of ndef message list.";
  public static String SensorDesc = "Send sensor device's value to the emulator.";
  public static String SensorStatusDesc = "is to display status of sensor device.";
  public static String SensorGetDesc = "is getting sensor value from emulator.";
  public static String SensorSetDesc = "is setting sensor value of emulator.";
  public static String SensorFileDesc = "is setting sensor value of emulator by using log file.";
  public static String ArgSensorNameDesc = "is sensor device of emulator";
  public static String ArgSensorFilePathDesc = "is address of log file.\n\tThis file will be sent to emulator and used to event injection.";
  public static String ArgSensorValueDesc = "is appropriate sensor data for each sensor.";
  public static String ArgAccelValueDesc = "In particular, the force of gravity is always influencing the measured acceleration.";
  public static String ArgMagneticValueDesc = "All values are in micro-Tesla (uT) and measure the ambient magnetic\n\tfield in the X, Y and Z axis.";
  public static String ArgGyroValueDesc = "All values are in radians/second and measure the rate of rotation\n\taround the device's local X, Y and Z axis.";
  public static String ArgLightValueDesc = "Ambient light level.";
  public static String ArgProxiValueDesc = "Proximity sensor only support near or far measurement.\n\tNear is on and far is off.";
  public static String MotionDesc = "Send motion sensor value to the emulator.";
  public static String MotionStatusDesc = "is to display status of motion sensor.";
  public static String MotionSetDesc = "is setting motion sensor value of emulator.";
  public static String ArgMotionDesc = "is name of motion sensor.";
}

/* Location:
 * Qualified Name:     org.tizen.injector.StringResource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.StringResource;
import org.tizen.injector.exception.ConsoleError;
import org.tizen.injector.exception.ConsoleException;
import org.tizen.injector.parser.Args;

class ArgPlayFilePath
  extends Argument
{
  private File logFile = null;
  
  public ArgPlayFilePath()
  {
    setUsingFile(true);
    initialize();
  }
  
  protected void initialize()
  {
    name = "file-path";
    
    description = ("'" + name + "' " + StringResource.PlayFileDesc);
  }
  
  public boolean parseArgs(Args args)
    throws InjectorLibraryException
  {
    if (args.remain() == 1)
    {
      String path = args.pop();
      File f = new File(path);
      if (!f.exists())
      {
        ConsoleException e = new ConsoleException(ConsoleError.NotExistLogFile);
        System.out.println("Error:" + e.getMessage());
        return false;
      }
      logFile = f;
    }
    else
    {
      return false;
    }
    return true;
  }
  
  public ArrayList<String> getPassibleValue()
  {
    if (values == null) {
      values = new ArrayList();
    }
    return values;
  }
  
  public File getLogFile()
  {
    return logFile;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.ArgPlayFilePath
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.EventRecorder;
import org.tizen.injector.StringResource;
import org.tizen.injector.parser.Args;

class ArgRecordFilePath
  extends Argument
{
  private EventRecorder recorder;
  
  public ArgRecordFilePath(EventRecorder recorder)
  {
    this.recorder = recorder;
    setUsingFile(true);
    initialize();
  }
  
  protected void initialize()
  {
    name = "file-path";
    
    description = ("'" + name + "' " + StringResource.StartFileDesc);
  }
  
  public boolean parseArgs(Args args)
    throws InjectorLibraryException
  {
    if (args.remain() == 1)
    {
      String path = args.pop();
      File f = new File(path);
      if (path.contains(File.separator))
      {
        try
        {
          f = f.getCanonicalFile();
        }
        catch (IOException e)
        {
          System.out.println("Error: " + e.getMessage());
          return false;
        }
        if (f.isDirectory())
        {
          recorder.setFilePath(f.getPath());
        }
        else
        {
          recorder.setFilePath(f.getParent());
          recorder.setFileName(f.getName());
        }
      }
      else
      {
        recorder.setFileName(f.getName());
      }
    }
    else
    {
      if (args.peek() == null) {
        return true;
      }
      return false;
    }
    return true;
  }
  
  public ArrayList<String> getPassibleValue()
  {
    if (values == null) {
      values = new ArrayList();
    }
    return values;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.ArgRecordFilePath
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.exception.ConsoleException;
import org.tizen.injector.parser.Args;

public abstract class Argument
{
  protected String name = "";
  protected String description = "";
  private boolean isUsingFile = false;
  
  protected abstract void initialize();
  
  public String getName()
  {
    return name;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public void printHelpMessage(Exception e)
  {
    if (e != null)
    {
      System.out.println("Error:" + e.getMessage());
      System.out.println("Avaliable value:");
    }
    System.out.println("\t" + getDescription());
  }
  
  protected ArrayList<String> values = null;
  
  public abstract boolean parseArgs(Args paramArgs)
    throws InjectorLibraryException, ConsoleException;
  
  public abstract ArrayList<String> getPassibleValue();
  
  public boolean isUsingFile()
  {
    return isUsingFile;
  }
  
  protected void setUsingFile(boolean isUsingFile)
  {
    this.isUsingFile = isUsingFile;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.Argument
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.eilib.exception.ConnectionException;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.StringResource;
import org.tizen.injector.exception.ConsoleError;
import org.tizen.injector.exception.ConsoleException;
import org.tizen.injector.parser.Args;

public abstract class Command
{
  protected Device device = null;
  protected String name = "";
  protected String syntax = "";
  protected String description = "";
  protected boolean isDefault = false;
  protected boolean hasArguments = false;
  protected boolean isStandalone = false;
  protected ArrayList<Argument> argList = null;
  
  public Command(Device device, boolean isDefault, boolean hasArguments)
  {
    this.device = device;
    this.isDefault = isDefault;
    this.hasArguments = hasArguments;
    argList = new ArrayList();
  }
  
  public Device getDevice()
  {
    return device;
  }
  
  public String getName()
  {
    return name;
  }
  
  public String getSyntax()
  {
    return syntax;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public boolean isDefault()
  {
    return isDefault;
  }
  
  public boolean hasArguments()
  {
    return hasArguments;
  }
  
  public boolean isStandalone()
  {
    return isStandalone;
  }
  
  public void addArgument(Argument arg)
  {
    if (argList == null) {
      return;
    }
    argList.add(arg);
  }
  
  public ArrayList<Argument> getArgumentList()
  {
    return argList;
  }
  
  public void printHelpMessage(Exception e)
  {
    if (e != null)
    {
      System.out.println("Error:" + e.getMessage());
      System.out.println();
    }
    System.out.println(getDescription());
    System.out.println();
    System.out.println(StringResource.CommandSyntax);
    System.out.println("\t" + getSyntax());
    System.out.println();
    System.out.println(StringResource.CommandArgument);
    for (Argument a : getArgumentList()) {
      System.out.println("\t" + a.getDescription());
    }
  }
  
  public void printArgumentHelp(Exception e)
  {
    if (e != null)
    {
      System.out.println("Error:" + e.getMessage());
      System.out.println();
    }
    System.out.println(StringResource.Usage + device.getName() + " " + syntax);
    
    System.out.println();
    System.out.println(StringResource.CommandArgument);
    for (Argument a : argList) {
      a.printHelpMessage(null);
    }
  }
  
  public int parseArgs(Args args)
    throws InjectorLibraryException, ConsoleException
  {
    if (!hasArguments) {
      return 1;
    }
    for (Argument a : argList) {
      if (!a.parseArgs(args))
      {
        ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
        printArgumentHelp(e);
        return e.getErrorNumber();
      }
    }
    if (args.peek() != null)
    {
      ConsoleException e = new ConsoleException(ConsoleError.WrongArgument);
      printArgumentHelp(e);
      return e.getErrorNumber();
    }
    return 0;
  }
  
  protected abstract void initialize();
  
  public abstract int process()
    throws ConnectionException;
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.Command
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.injector.StringResource;

public abstract class Device
{
  protected String name = null;
  protected String description = null;
  protected String usage = null;
  protected ArrayList<Command> commandList = null;
  
  public Device()
  {
    commandList = new ArrayList();
  }
  
  public String getName()
  {
    return name;
  }
  
  public String getDescription()
  {
    return description;
  }
  
  public String getUsage()
  {
    return usage;
  }
  
  public void addCommand(Command c)
  {
    commandList.add(c);
  }
  
  public ArrayList<Command> getCommandList()
  {
    return commandList;
  }
  
  public Command findCommand(String name)
  {
    if (name != null) {
      for (Command c : commandList) {
        if (c.getName().equals(name)) {
          return c;
        }
      }
    }
    return null;
  }
  
  public Command getDefalutCommand()
  {
    for (Command c : commandList) {
      if (c.isDefault()) {
        return c;
      }
    }
    return null;
  }
  
  ArrayList<Argument> argsList = null;
  
  public void printHelpMessage()
  {
    System.out.println(StringResource.Usage + getUsage());
    System.out.println();
    System.out.println(StringResource.CommandSyntax);
    for (Command c : commandList) {
      if (!c.getSyntax().isEmpty()) {
        System.out.println("\t" + c.getSyntax());
      }
    }
    System.out.println();
    System.out.println(StringResource.CommandArgument);
    boolean isExist;
    if (argsList == null)
    {
      argsList = new ArrayList();
      isExist = false;
      for (Command c : commandList) {
        for (Argument a : c.getArgumentList())
        {
          for (Argument a2 : argsList) {
            if (a2.getName().equals(a.getName())) {
              isExist = true;
            }
          }
          if (!isExist) {
            argsList.add(a);
          }
          isExist = false;
        }
      }
    }
    for (Argument a : argsList) {
      System.out.println("\t" + a.getDescription());
    }
  }
  
  protected abstract void initialize();
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.Device
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.PrintStream;
import java.util.ArrayList;
import org.tizen.eilib.connection.ConnectionToEmulator;
import org.tizen.eilib.connection.Emulator;
import org.tizen.eilib.exception.EILibError;
import org.tizen.injector.EventInjector;

class EmulatorCommand
  extends Command
{
  public EmulatorCommand(Device device, boolean isDefault)
  {
    super(device, isDefault, false);
    isStandalone = true;
  }
  
  protected void initialize()
  {
    syntax = (name = "");
    description = "";
  }
  
  public int process()
  {
    ArrayList<Emulator> list = EventInjector.getConnector().getEmulatorList();
    Emulator em = EventInjector.getConnector().getCurrentEmulator();
    if (list.isEmpty()) {
      System.out.println(EILibError.EmulatorNotExist.getMessage());
    }
    for (Emulator e : list)
    {
      System.out.print(e.toString());
      if (e.equals(em)) {
        System.out.println(" * ");
      } else {
        System.out.println();
      }
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.EmulatorCommand
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.util.ArrayList;
import org.tizen.injector.StringResource;

public class EmulatorDevice
  extends Device
{
  public EmulatorDevice()
  {
    commandList.add(new EmulatorCommand(this, true));
    initialize();
  }
  
  protected void initialize()
  {
    name = "emulator";
    usage = name;
    description = StringResource.EmulatorDesc;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.EmulatorDevice
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import org.tizen.injector.EventInjector;

class ExitCommand
  extends Command
{
  public ExitCommand(Device device, boolean isDefault)
  {
    super(device, isDefault, false);
    isStandalone = true;
  }
  
  protected void initialize()
  {
    syntax = (name = "");
    description = "";
  }
  
  public int process()
  {
    EventInjector.exitEventInjector(0);
    return 0;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.ExitCommand
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.util.ArrayList;
import org.tizen.injector.StringResource;

public class ExitDevice
  extends Device
{
  public ExitDevice()
  {
    commandList.add(new ExitCommand(this, true));
    initialize();
  }
  
  protected void initialize()
  {
    name = "exit";
    usage = name;
    description = StringResource.ExitDesc;
  }
}

/* Location:
 * Qualified Name:     org.tizen.injector.device.ExitDevice
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.injector.device;

import java.io.PrintStream;
import org.tizen.eilib.exception.InjectorLibraryException;
import org.tizen.injector.EventInjector;
import org.tizen.injector.exception.ConsoleException;
import org.tizen.injector.parser.Args;
import org.tizen.injector.parser.CommandParser;
import org.tizen.injector.parser.HelpMessage;

class HelpCommand
  extends Command
{
  private Device helpDevice = null;
  private Command helpCommand = null;
  
  public HelpCommand(Device device, boolean isDefault)
  {
    super(device, isDefault, true);
    isStandalone = true;
    
    initialize();
  }
  
  protected void initialize()
  {
    syntax = (name = "");
    description = "";
  }
  
  public int parseArgs(Args 
1 2 3 4 5 6

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd