262. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/5/2017 12:06:44 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

262.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCommon\main\src\java\gov\va\med\interactive CommandLineCommandSource.java Mon Dec 4 21:34:26 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCommon\main\src\java\gov\va\med\interactive CommandLineCommandSource.java Mon Dec 4 22:02:07 2017 UTC

262.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 752
Changed 1 2
Inserted 0 0
Removed 0 0

262.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

262.4 Active regular expressions

No regular expressions were active.

262.5 Comparison detail

  1   package go v.va.med.i nteractive ;
  2  
  3  
  4   import jav a.io.*;
  5   import jav a.util.Arr ayList;
  6   import jav a.util.Lis t;
  7   import jav a.util.con current.Bl ockingQueu e;
  8  
  9   import org .apache.lo gging.log4 j.LogManag er;
  10   import org .apache.lo gging.log4 j.Logger;
  11  
  12   /**
  13    * This cl ass:
  14    * 1.) tak es the app lication c ommand lin e args and  parses th em to crea te command s and put
  15    *     the m on the c ommand que ue.
  16    * 2.) con tinuously  reads from  the comma nd line an d put comm ands on th e command  queue.
  17    * 
  18    * If any  commands o n the give n list (th e app comm and line)  are invali d then non e of them  will
  19    * be put  on the com mand queue  and the a pp will ex it immedia tely
  20    * 
  21    * @author         
BECKEC
  22    *
  23    */
  24   public cla ss Command LineComman dSource<M>
  25   implements  CommandSo urce<M>
  26   {
  27           pr ivate fina l Logger l ogger = Lo gManager.g etLogger(t his.getCla ss());
  28           pr ivate Prin tStream pr omptStream ;
  29           pr ivate Inpu tStream in Stream;
  30           pr ivate Comm andFactory <M> comman dFactory;
  31           pr ivate Comm andControl ler<M> com mandContro ller;
  32           pr ivate bool ean exitRe quested;
  33           
  34           /* *
  35            *  Get input  from Syst em.in and  write prom pts to Sys tem.out
  36            * /
  37           pu blic Comma ndLineComm andSource(
  38           { 
  39                    this (System.ou t, System. in);
  40           }
  41  
  42           /* *
  43            *  Set the i nput strea m for comm ands and t he output  stream for  prompts.
  44            *  The promp t stream c an be null  if no pro mpts are n eeded.
  45            *  @param pr omptStream
  46            *  @param in Stream
  47            * /
  48           pu blic Comma ndLineComm andSource( PrintStrea m promptSt ream, Inpu tStream in Stream)
  49           {
  50                    this .promptStr eam = prom ptStream;
  51                    this .inStream  = inStream ;
  52           }
  53  
  54           /* *
  55            *  @return t he promptS tream
  56            * /
  57           pu blic Print Stream get PromptStre am()
  58           {
  59                    retu rn this.pr omptStream ;
  60           }
  61  
  62           /* *
  63            *  @return t he inStrea m
  64            * /
  65           pu blic Input Stream get InStream()
  66           {
  67                    retu rn this.in Stream;
  68           }
  69  
  70           @O verride
  71           pu blic void  commandQue ueAvailabl e()
  72           {
  73                    queu eSavedComm ands();
  74           }
  75  
  76           @O verride
  77           pu blic void  commandQue ueUnavaila ble()
  78           {
  79           }
  80  
  81           @O verride
  82           pu blic void  managedObj ectAvailab le()
  83           {
  84           }
  85  
  86           @O verride
  87           pu blic void  managedObj ectUnavail able()
  88           {
  89           }
  90           
  91           pu blic Block ingQueue<C ommand<M>>  getComman dQueue()
  92           {
  93                    retu rn this.co mmandContr oller.getC ommandQueu e();
  94           }
  95  
  96           /* *
  97            *  @see gov. va.med.int eractive.C ommandSour ce#setComm andControl ler(gov.va .med.inter active.Com mandContro ller)
  98            * /
  99           @O verride
  100           pu blic void  setCommand Controller (CommandCo ntroller<M > commandC ontroller)
  101           {
  102                    this .commandCo ntroller =  commandCo ntroller;
  103           }
  104  
  105           /* *
  106            *  @param co mmandFacto ry the com mandFactor y to set
  107            * /
  108           @O verride
  109           pu blic void  setCommand Factory(Co mmandFacto ry<M> comm andFactory )
  110           {
  111                    this .commandFa ctory = co mmandFacto ry;
  112           }
  113  
  114           @O verride
  115           pu blic Comma ndFactory< M> getComm andFactory ()
  116           {
  117                    retu rn this.co mmandFacto ry;
  118           }
  119           
  120           /* *
  121            *  @param co mmandLine
  122            *  @throws C ommandLine ParseExcep tion
  123            * /
  124           @O verride
  125           pu blic void  pushComman ds(String[ ] commandL ine) 
  126           th rows Comma ndLinePars eException
  127           {
  128                    List <Command<M >> command s = parseC ommandLine (commandLi ne);
  129                    if(c ommands !=  null)
  130                             queueC ommandList (commands) ;
  131           }
  132  
  133           pu blic boole an isExitR equested()
  134           {
  135                    retu rn this.ex itRequeste d;
  136           }
  137  
  138           pr ivate void  setExitRe quested(bo olean exit Requested)
  139           {
  140                    this .exitReque sted = exi tRequested ;
  141           }
  142           
  143           pu blic Logge r getLogge r()
  144           {
  145                    retu rn this.lo gger;
  146           }
  147  
  148           pu blic void  run()
  149           {
  150                    // a s long as  the sky re mains blue  ...
  151                    // o r the user  exits
  152                    whil e(! isExit Requested( ))
  153                    {
  154                             try
  155                             {
  156                                      String[]  commandLi ne = readI nteractive CommandLin e();
  157                                      
  158                                      List<Com mand<M>> c ommands =  parseComma ndLine(com mandLine);
  159                                      if(comma nds != nul l)
  160                                               queueComma ndList(com mands);
  161                             } 
  162                             catch  (CommandLi neParseExc eption x)
  163                             {
  164                                      x.printS tackTrace( );
  165                             } 
  166                             catch  (IOExcepti on x)
  167                             {
  168                                      x.printS tackTrace( );
  169                             }
  170                    }
  171           }
  172  
  173           /* *
  174            *  
  175            *  @param co mmands
  176            * /
  177           pr ivate sync hronized v oid queueC ommandList (List<Comm and<M>> co mmands)
  178           {
  179                    if(g etCommandQ ueue() !=  null)
  180                    {
  181                             for(Co mmand<M> c ommand : c ommands)
  182                             {
  183                                      getComma ndQueue(). add(comman d);
  184                                      if(comma nd.exitAft erProcessi ng())
  185                                               setExitReq uested(tru e);
  186                             }
  187                    }
  188                    else
  189                             saveCo mmandsUnti lQueueIsSe t(commands );
  190           }
  191  
  192           pr ivate List <Command<M >> savedCo mmands = n ew ArrayLi st<Command <M>>(); 
  193           /* *
  194            *  @param co mmands
  195            * /
  196           pr ivate void  saveComma ndsUntilQu eueIsSet(L ist<Comman d<M>> comm ands)
  197           {
  198                    sync hronized ( savedComma nds)
  199                    {
  200                             savedC ommands.ad dAll(comma nds);
  201                    }
  202           }
  203           
  204           pr ivate void  queueSave dCommands( )
  205           {
  206                    sync hronized ( savedComma nds)
  207                    {
  208                             if(get CommandQue ue() != nu ll)
  209                             {
  210                                      queueCom mandList(s avedComman ds);
  211                                      savedCom mands.clea r();
  212                             }
  213                    }
  214           }
  215           
  216           /* *
  217            *  
  218            * /
  219           pr ivate Line NumberRead er reader  = null;
  220           pr ivate sync hronized L ineNumberR eader getL ineReader( )
  221           {
  222                    if(r eader == n ull)
  223                             reader  = new Lin eNumberRea der( new I nputStream Reader(get InStream() ) );
  224                    retu rn reader;
  225           }
  226           
  227           /* *
  228            *  @return
  229            *  @throws I OException  
  230            * /
  231           pr ivate Stri ng[] readI nteractive CommandLin e() 
  232           th rows IOExc eption
  233           {
  234                    if(g etPromptSt ream() !=  null)
  235                             getPro mptStream( ).print("Y our comman d >");
  236                    Stri ng line =  getLineRea der().read Line();
  237                    
  238                    // s plit on wh itespace a nd return  the array
  239                    retu rn line.sp lit("[\\s] ");
  240           }
  241  
  242           /* *
  243            *  Parse the  string ar ray and tr y to make  (a) comman d(s) from  it.
  244            *  If balkin g queue is  true then  do not qu eue any co mmands unt il all hav
  245            *  been crea ted succes sfully (i. e. are val id command s).
  246            *  
  247            *  @param ar gs
  248            *  @param ba lkingQueue
  249            *  @throws C ommandLine ParseExcep tion
  250            * /
  251           pr ivate List <Command<M >> parseCo mmandLine( String[] a rgs) 
  252           th rows Comma ndLinePars eException
  253           {
  254                    List <Command<M >> command s = new Ar rayList<Co mmand<M>>( );
  255                    bool ean allCom mandsValid  = true;
  256                    
  257                    Comm andText ac tiveComman dText = nu ll;
  258                    for( int index= 0; index <  args.leng th; ++inde x)
  259                    {
  260                             String  currentAr g = args[i ndex];
  261                             
  262                             if(cur rentArg.st artsWith(" <") && cur rentArg.en dsWith(">" ))
  263                             {
  264                                      if(activ eCommandTe xt == null )
  265                                               throw new  CommandLin eParseExce ption("Inv alid comma nd line sy ntax near  '" + curre ntArg + "' , no comma nd to asso ciate para meter with .");
  266  
  267                                      currentA rg = curre ntArg.subs tring(1, c urrentArg. length() - 1);
  268                                      activeCo mmandText. parameters .add(curre ntArg);
  269                             }
  270                             else
  271                             {
  272                                      if(activ eCommandTe xt != null )
  273                                      {
  274                                               try
  275                                               {
  276                                                       Co mmand<M> c ommand = g etCommandF actory().c reateComma nd(activeC ommandText .getComman d(), activ eCommandTe xt.getPara metersAsAr ray());
  277                                                       ge tLogger(). debug("Cre ated comma nd of type  '" + comm and.getCla ss().getNa me() + "'. ");
  278                                                       co mmands.add (command);
  279                                               }
  280                                               catch (Exc eption x)
  281                                               {
  282                                                       Sy stem.err.p rintln("Un able to cr eate a val id command  from: " +  activeCom mandText.t oString()) ;
  283                                                       al lCommandsV alid = fal se;
  284                                               }
  285                                      }
  286                                      
  287                                      activeCo mmandText  = new Comm andText(cu rrentArg);
  288                             }
  289                    }
  290                    
  291                    if(a ctiveComma ndText !=  null)
  292                    {
  293                             try
  294                             {
  295                                      Command< M> command  = getComm andFactory ().createC ommand(act iveCommand Text.getCo mmand(), a ctiveComma ndText.get Parameters AsArray()) ;
  296                                      if(comma nd != null )
  297                                      {
  298                                               getLogger( ).debug("C reated com mand of ty pe '" + co mmand.getC lass().get Name() + " '.");
  299                                               commands.a dd(command );
  300                                      }
  301                                      else
  302                                      {
  303  
  304                                               allCommand sValid = f alse;
  305                                      }
  306                             }
  307                             catch  (Exception  x)
  308                             {
  309                                      getLogge r().error( "Exception  raised cr eating com mand from:  " + activ eCommandTe xt.toStrin g(), x);
  310                                      allComma ndsValid =  false;
  311                             }
  312                    }
  313                    
  314                    if(!  allComman dsValid)
  315                    {
  316                             printC ommandMenu ();
  317                             return  null;
  318                    }
  319                    
  320                    retu rn command s;
  321           }
  322           
  323           pr ivate void  printComm andMenu()
  324           {
  325                    if(g etPromptSt ream() !=  null)
  326                    {
  327                             getPro mptStream( ).println(  getComman dFactory() .getHelpMe ssage() );
  328                             getPro mptStream( ).println( "Command p arameters  must be de limited wi th '<' and  '>'.");
  329                             getPro mptStream( ).println( "Multiple  commands m ay be give n on one l ine (e.g.  create <Ju nkCache> < file:///ju nk/cache>  <TestWithE victionPro totype> in itialize e nable stor e stop exi t"); 
  330                             getPro mptStream( ).println( "                                               (creat e a cache,  initializ e it, enab le it, sto re the con figuration , stop the  cache and  exit"); 
  331                    }
  332           }
  333           
  334           /* *
  335            *  A simple  value obje ct for col lecting th e command  and its ar guments to gether
  336            *  while we  parse the  command li ne.
  337            * /
  338           pu blic class  CommandTe xt
  339           {
  340                    priv ate final  String com mand;
  341                    priv ate final  List<Strin g> paramet ers;
  342                    
  343                    publ ic Command Text(Strin g command)
  344                    {
  345                             super( );
  346                             this.c ommand = c ommand;
  347                             this.p arameters  = new Arra yList<Stri ng>();
  348                    }
  349  
  350                    publ ic String  getCommand ()
  351                    {
  352                             return  this.comm and;
  353                    }
  354  
  355                    publ ic void ad dParameter (String pa rameter)
  356                    {
  357                             parame ters.add(p arameter);
  358                    }
  359  
  360                    publ ic String[ ] getParam etersAsArr ay()
  361                    {
  362                             return  parameter s.toArray( new String [parameter s.size()]) ;
  363                    }
  364  
  365                    @Ove rride
  366                    publ ic String  toString()
  367                    {
  368                             String Builder sb  = new Str ingBuilder ();
  369                             
  370                             sb.app end(getCom mand());
  371                             for(St ring param eter : thi s.paramete rs)
  372                                      sb.appen d(" " + pa rameter);
  373                             
  374                             return  sb.toStri ng();
  375                    }
  376           }
  377   }