793. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/18/2018 2:02:20 PM Central Daylight 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.

793.1 Files compared

# Location File Last Modified
1 VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\MockDataGenerationImpl\main\src\java\gov\va\med GenericDataGenerator.java Thu Oct 11 13:30:12 2018 UTC
2 VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\MockDataGenerationImpl\main\src\java\gov\va\med GenericDataGenerator.java Wed Oct 17 19:01:37 2018 UTC

793.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 4666
Changed 2 4
Inserted 0 0
Removed 0 0

793.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

793.4 Active regular expressions

No regular expressions were active.

793.5 Comparison detail

  1   /**
  2    * 
  3    */
  4   package go v.va.med;
  5  
  6   import jav a.io.IOExc eption;
  7   import jav a.io.Input Stream;
  8   import jav a.lang.ref lect.Array ;
  9   import jav a.lang.ref lect.Field ;
  10   import jav a.lang.ref lect.Metho d;
  11   import jav a.lang.ref lect.Modif ier;
  12   import jav a.net.URL;
  13   import jav a.net.URLC onnection;
  14   import jav a.nio.Byte Buffer;
  15   import jav a.nio.chan nels.Writa bleByteCha nnel;
  16   import jav a.text.Dat eFormat;
  17   import jav a.text.Par seExceptio n;
  18   import jav a.text.Sim pleDateFor mat;
  19   import jav a.util.*;
  20   import jav a.util.reg ex.Matcher ;
  21   import jav a.util.reg ex.Pattern ;
  22   import org .apache.lo gging.log4 j.LogManag er;
  23   import org .apache.lo gging.log4 j.Logger;
  24  
  25   /**
  26    * Package : MAG - Vi stA Imagin g
  27    * WARNING : Per VHA  Directive  2004-038,  this routi ne should  not be mod ified.
  28    * Date Cr eated: Oct  1, 2008
  29    * Site Na me:  Washi ngton OI F ield Offic e, Silver  Spring, MD
  30    * @author   PI I
  31    * @versio n 1.0
  32    *
  33    * ------- ---------- ---------- ---------- ---------- ---------- -------
  34    * Propert y of the U S Governme nt.
  35    * No perm ission to  copy or re distribute  this soft ware is gi ven.
  36    * Use of  unreleased  versions  of this so ftware req uires the  user
  37    * to exec ute a writ ten test a greement w ith the Vi stA Imagin g
  38    * Develop ment Offic e of the D epartment  of Veteran s Affairs,
  39    * telepho ne (301) 7 34-0100.
  40    * 
  41    * The Foo d and Drug  Administr ation clas sifies thi s software  as
  42    * a Class  II medica l device.   As such,  it may not  be change d
  43    * in any  way.  Modi fications  to this so ftware may  result in  an
  44    * adulter ated medic al device  under 21CF R820, the  use of whi ch
  45    * is cons idered to  be a viola tion of US  Federal S tatutes.
  46    * ------- ---------- ---------- ---------- ---------- ---------- -------
  47    * 
  48    * @author   PII
  49    *
  50    */
  51   public cla ss Generic DataGenera tor
  52   implements  Observer
  53   {
  54           pu blic stati c String D EFAULT_STR ING_VALUE  = Messages .getString ("GenericD ataGenerat or.Default StringValu e"); //$NO N-NLS-1$
  55           pu blic stati c String D EFAULT_BOO LEAN_VALUE  = Message s.getStrin g("Generic DataGenera tor.Defaul tBooleanVa lue"); //$ NON-NLS-1$
  56           pu blic stati c String D EFAULT_CHA R_VALUE =  Messages.g etString(" GenericDat aGenerator .DefaultCh arValue");  //$NON-NL S-1$
  57           pu blic stati c String D EFAULT_BYT E_VALUE =  Messages.g etString(" GenericDat aGenerator .DefaultBy teValue");  //$NON-NL S-1$
  58           pu blic stati c String D EFAULT_SHO RT_VALUE =  Messages. getString( "GenericDa taGenerato r.DefaultS hortValue" ); //$NON- NLS-1$
  59           pu blic stati c String D EFAULT_INT _VALUE = M essages.ge tString("G enericData Generator. DefaultInt Value"); / /$NON-NLS- 1$
  60           pu blic stati c String D EFAULT_LON G_VALUE =  Messages.g etString(" GenericDat aGenerator .DefaultLO ngValue");  //$NON-NL S-1$
  61           pu blic stati c String D EFAULT_FLO AT_VALUE =  Messages. getString( "GenericDa taGenerato r.DefaultF loatValue" ); //$NON- NLS-1$
  62           pu blic stati c String D EFAULT_DOU BLE_VALUE  = Messages .getString ("GenericD ataGenerat or.Default DoubleValu e"); //$NO N-NLS-1$
  63           pu blic stati c Date DEF AULT_DATE_ VALUE = ne w Date();
  64  
  65           //  a regex u sed to gen erate Stri ng values  where no p attern is  specified
  66           pu blic stati c String D EFAULT_STR ING_PATTER N = "[A-Z] [a-z]{2,8} "; //$NON- NLS-1$
  67           
  68           pu blic DateF ormat DEFA ULT_DATE_F ORMAT = ne w SimpleDa teFormat(" dd-MM-yyyy "); //$NON -NLS-1$
  69           pu blic DateF ormat DEFA ULT_DATETI ME_FORMAT  = new Simp leDateForm at("dd-MM- yyyy:hh:mm :ss"); //$ NON-NLS-1$
  70           
  71           pr ivate fina l static S tring RAND OM_STRING_ CHARACTER_ CLASS = "[ A-Za-z0-9] "; //$NON- NLS-1$
  72           pr ivate fina l static S tring STRI NG_MAXIMUM _REPEATER  = "{32}";  //$NON-NLS -1$
  73           pr ivate fina l static S tring STRI NG_MINIMUM _REPEATER  = "{3}"; / /$NON-NLS- 1$
  74           pr ivate fina l static S tring STRI NG_RANDOM_ REPEATER =  "{3,32}";  //$NON-NL S-1$
  75           
  76           pr ivate fina l static S tring RAND OM_CHAR_PA TTERN = "[ a-zA-Z0-9_ !@#$%^&*() +]"; //$NO N-NLS-1$
  77           pr ivate fina l static S tring RAND OM_BYTE_PA TTERN = "[ +-][0-9]{1 ,2}"; //$N ON-NLS-1$
  78           pr ivate fina l static S tring RAND OM_SHORT_P ATTERN = " [+-][0-9]{ 1,4}"; //$ NON-NLS-1$
  79           pr ivate fina l static S tring RAND OM_INT_PAT TERN = "[+ -][0-9]{1, 8}"; //$NO N-NLS-1$
  80           pr ivate fina l static S tring RAND OM_LONG_PA TTERN = "[ +-][0-9]{1 ,16}"; //$ NON-NLS-1$
  81           pr ivate fina l static S tring RAND OM_FLOAT_P ATTERN = " [+-][0-9]{ 1,8}.[0-9] {1,8}"; // $NON-NLS-1 $
  82           pr ivate fina l static S tring RAND OM_DOUBLE_ PATTERN =  "[+-][0-9] {1,16}.[0- 9]{1,16}";  //$NON-NL S-1$
  83           
  84           pr ivate fina l static S tring RAND OM_PHONE_P ATTERN = " [1-9][0-9] {2}-[0-9]{ 2}-[0-9]{4 }"; //$NON -NLS-1$
  85           pr ivate fina l static S tring RAND OM_NAME_PA TTERN = "[ A-Z][a-z]{ 3,9} [A-Z]  [A-Z][a-z ]{3,12}";  //$NON-NLS -1$
  86           pr ivate fina l static S tring RAND OM_SURNAME _PATTERN =  "[[A-Z][a -z]{3,12}" ; //$NON-N LS-1$
  87           pr ivate fina l static S tring RAND OM_GIVENNA ME_PATTERN  = "[A-Z][ a-z]{3,9}" ; //$NON-N LS-1$
  88           pr ivate fina l static S tring RAND OM_SSN_PAT TERN = "[1 -9][0-9]{2 }-[0-9]{2} -[0-9]{4}" ; //$NON-N LS-1$
  89  
  90           pr ivate fina l static S tring RAND OM_STREETA DDRESS_PAT TERN = "[1 -9][0-9]{1 ,4} [A-Z][ a-z]{3,14}  [A-Z][a-z ]"; //$NON -NLS-1$
  91           pr ivate fina l static S tring RAND OM_APARTME NT_PATTERN  = "[A-Z][ a-z]{1-3}  [1-9][0-9] {1,4}"; // $NON-NLS-1 $
  92           pr ivate fina l static S tring RAND OM_CITY_PA TTERN = "[ A-Z][a-z]{ 1-14}"; // $NON-NLS-1 $
  93           pr ivate fina l static S tring RAND OM_STATE_P ATTERN = " [A-Z][a-z] "; //$NON- NLS-1$
  94           pr ivate fina l static S tring RAND OM_ZIP_PAT TERN = "[1 -9][0-9]{4 }"; //$NON -NLS-1$
  95           pr ivate fina l static S tring RAND OM_ZIP4_PA TTERN = "[ 1-9][0-9]{ 3}"; //$NO N-NLS-1$
  96  
  97           /* *
  98            *  
  99            * /
  100           pu blic enum  Mode
  101           {
  102                    DEFA ULT,                  // use def ault value s
  103                    RAND OMIZE,                // use ran domly gene rated valu es
  104                    MINI MUM,                  // use the  minimum p ermissible  value
  105                    MAXI MUM                   // use the  maximum p ermissible  value
  106           }
  107           
  108           //  The discr iminators  for what c onstitutes  a create  method in  this class
  109           pu blic stati c final St ring CREAT E_METHOD_R EGEX = "(c reate)([A- Z][A-Za-z0 -9_]*)?";  //$NON-NLS -1$
  110           pu blic stati c final Pa ttern CREA TE_METHOD_ PATTERN =  Pattern.co mpile(CREA TE_METHOD_ REGEX);
  111           pu blic stati c final Cl ass<?>[] C OMPLEX_CRE ATE_METHOD _PARAMETER S = new Cl ass<?>[]
  112           {
  113                    Inst ancePopula tion.class , Aggregat ionPopulat ion.class,  Compositi onPopulati on.class,  ReferenceM ap.class
  114           };
  115           pu blic stati c final Cl ass<?>[] R EFERENCE_C REATE_METH OD_PARAMET ERS = new  Class<?>[]
  116           {
  117                    Refe renceMap.c lass
  118           };
  119           pu blic stati c final Cl ass<?>[] S IMPLE_CREA TE_METHOD_ PARAMETERS  = new Cla ss<?>[]
  120           {
  121           };
  122           pu blic stati c final St ring POSTP OPULATE_ME THOD_REGEX  = "(postP opulate)([ A-Z][A-Za- z0-9_]*)?" ; //$NON-N LS-1$
  123           pu blic stati c final Pa ttern POST POPULATE_M ETHOD_PATT ERN = Patt ern.compil e(POSTPOPU LATE_METHO D_REGEX);
  124  
  125           //  ========= ========== ========== ========== ========== ========== ========== ========== =====
  126           //
  127           //  ========= ========== ========== ========== ========== ========== ========== ========== =====
  128           pr ivate List <GenericDa taGenerato r> registe redDataGen erators = 
  129                    Coll ections.sy nchronized List( new  ArrayList< GenericDat aGenerator >() );
  130           
  131           pu blic void  registerDa taGenerato r(GenericD ataGenerat or dataGen erator)
  132           {
  133                    regi steredData Generators .add(dataG enerator);
  134           }
  135           pu blic void  deRegister DataGenera tor(Generi cDataGener ator dataG enerator)
  136           {
  137                    regi steredData Generators .remove(da taGenerato r);
  138           }
  139           
  140           pu blic List< GenericDat aGenerator > getRegis teredDataG enerator()
  141           {
  142                    retu rn Collect ions.unmod ifiableLis t(register edDataGene rators);
  143           }
  144           
  145           //  ========= ========== ========== ========== ========== ========== ========== ========== =====
  146           //
  147           //  ========= ========== ========== ========== ========== ========== ========== ========== =====
  148           pr ivate fina l DataGene rationConf iguration  configurat ion;
  149           pr ivate fina l Logger l ogger = Lo gManager.g etLogger(t his.getCla ss());
  150           
  151           pu blic Gener icDataGene rator()
  152           {
  153                    this ( new Data Generation Configurat ion(Mode.R ANDOMIZE,  NetworkSim ulatingInp utStream.E XCEPTION_M ODE.RELIAB LE, Networ kSimulatin gInputStre am.DELAY_M ODE.NONE)  );
  154           }
  155           
  156           pu blic Gener icDataGene rator(Mode  mode)
  157           {
  158                    this ( new Data Generation Configurat ion(mode,  NetworkSim ulatingInp utStream.E XCEPTION_M ODE.RELIAB LE, Networ kSimulatin gInputStre am.DELAY_M ODE.NONE)  );
  159           }
  160           
  161           pu blic Gener icDataGene rator(Data Generation Configurat ion config uration)
  162           {
  163                    this .configura tion = con figuration ;
  164                    conf iguration. addObserve r(this);         // a dd ourselv es as an o bserver of  our confi guration
  165                    regi sterDataGe nerator(th is);             // a lways regi ster ourse lves
  166           }
  167           
  168           //  This meth od gets ca lled to no tify us th at the con figuration  has chang ed.
  169           //  As of now  (4May2010 ) this cla ss does no t keep any  local cop ies of con figuration
  170           //  and does  not need t o be sensi tive to ch anges.  If  that chan ges though  
  171           @O verride
  172           pu blic void  update(Obs ervable o,  Object ar g)
  173           {
  174                    if(o  == this.c onfigurati on)
  175                    {
  176                             Observ ableMap.Ev ent event  = (Observa bleMap.Eve nt)arg;
  177                             //even t.getType( );
  178                             //even t.getOldVa lue();
  179                             //even t.getNewVa lue();
  180                    }
  181           }
  182           
  183           pr otected Da taGenerati onConfigur ation getC onfigurati on()
  184           {
  185                    retu rn this.co nfiguratio n;
  186           }
  187           
  188           pr otected bo olean isRa ndomize()
  189           {
  190                    retu rn Mode.RA NDOMIZE ==  getConfig uration(). getMode();
  191           }
  192           
  193           pr otected Lo gger getLo gger()
  194           {
  195                    retu rn this.lo gger;
  196           }
  197  
  198           /* *
  199            *  Create so me list of  bytes we  can use fo r data
  200            *  the data  should be  re-used if  tests mus t be consi stent.
  201            *  
  202            *  @param te stDataLeng th
  203            *  @return
  204            * /
  205           pu blic byte[ ] createRa ndomByteAr ray(int te stDataLeng th)
  206           {
  207                    byte [] sampleD ata = new  byte[testD ataLength] ;
  208                    for( int index= 0; index<t estDataLen gth; ++ind ex)
  209                             sample Data[index ] = (byte) (index % 2 56);
  210                    
  211                    retu rn sampleD ata;
  212           }
  213  
  214           /* *
  215            *  Create an  instance  of an obje ct of the  class give n by resul tClass, 
  216            *  populatin g it accor ding to th e instance  and child  populatio n enums.
  217            *  
  218            *  @param <T >
  219            *  @param re sultClass
  220            *  @param in stancePopu lation
  221            *  @param ch ildren
  222            *  @param op tionalPara meters
  223            *  @return a n instance  of class  resultClas s or null  if unable  to create  an instanc e
  224            * /
  225           pu blic <T ex tends Obje ct> T crea teInstance (
  226                    Clas s<T> resul tClass, 
  227                    Inst ancePopula tion insta ncePopulat ion, 
  228                    Aggr egationPop ulation ag gregates,
  229                    Comp ositionPop ulation co mponents,
  230                    Obje ct ... opt ionalParam eters )
  231           {
  232                    retu rn createI nstance(
  233                             result Class, 
  234                             instan cePopulati on, aggreg ates, comp onents,
  235                             Refere nceMap.cre ateRoot(),
  236                             option alParamete rs);
  237           }
  238           
  239           /* *
  240            *  Create an  instance  of the req uested typ e with no  context (r eferential
  241            *  integrity ) and no p opulation  of childre n or compo sition ele ments.
  242            *  This meth od require s that a s imple crea teXXX meth od exists  for the 
  243            *  requested  type.
  244            *  
  245            *  @param <T >
  246            *  @param re sultClass
  247            *  @return
  248            * /
  249           pu blic <T ex tends Obje ct> T crea teInstance ( Class<T>  resultCla ss )
  250           {
  251                    retu rn createI nstance(
  252                             result Class, 
  253                             Instan cePopulati on.FULL, 
  254                             Aggreg ationPopul ation.MANY
  255                             Compos itionPopul ation.MANY
  256                             Refere nceMap.cre ateRoot(),  
  257                             (Objec t [])null) ;
  258           }
  259           
  260           /* *
  261            *  Create an  instance  of the req uested col lection ty pe with no  context ( referentia l
  262            *  integrity ) and no p opulation  of childre n or compo sition ele ments.
  263            *  This meth od require s that a s imple crea teXXX meth od exists  for the 
  264            *  requested  type.
  265            *  
  266            *  @param <T >
  267            *  @param <E >
  268            *  @param co llectionTy pe
  269            *  @param el ementType
  270            *  @return
  271            * /
  272           pu blic <T ex tends Coll ection<E>,  E extends  Object> T  createCol lectionIns tance(
  273                    Clas s<T> colle ctionType,  
  274                    Clas s<E> eleme ntType)
  275           {
  276                    retu rn createC ollectionI nstance(
  277                             collec tionType, 
  278                             elemen tType, 
  279                             Instan cePopulati on.FULL, 
  280                             Aggreg ationPopul ation.MANY
  281                             Compos itionPopul ation.MANY
  282                             Refere nceMap.cre ateRoot(),  
  283                             (Objec t [])null
  284                    );
  285           }
  286           
  287           pu blic <T ex tends Map< K, V>, K e xtends Obj ect, V ext ends Objec t> T creat eMapInstan ce(
  288                    Clas s<T> mapTy pe,
  289                    Clas s<K> keyTy pe, 
  290                    Clas s<V> value Type)
  291           {
  292                    retu rn createM apInstance (
  293                             mapTyp e, 
  294                             keyTyp e, 
  295                             valueT ype, 
  296                             Instan cePopulati on.FULL, 
  297                             Aggreg ationPopul ation.MANY
  298                             Compos itionPopul ation.MANY
  299                             Refere nceMap.cre ateRoot(),  
  300                             (Objec t [])null
  301                    );
  302           }
  303           
  304           /* *
  305            *  
  306            *  @param <T >
  307            *  @param re sultClass
  308            *  @param in stancePopu lation
  309            *  @param ag gregates
  310            *  @param co mponents
  311            *  @param re ferences
  312            *  @param op tionalPara meters
  313            *  @return
  314            * /
  315           @S uppressWar nings("unc hecked")
  316           pu blic <T ex tends Obje ct> T crea teInstance (
  317                    Clas s<T> resul tClass, 
  318                    Inst ancePopula tion insta ncePopulat ion, 
  319                    Aggr egationPop ulation ag gregates,
  320                    Comp ositionPop ulation co mponents,
  321                    Refe renceMap r eferences,
  322                    Obje ct ... opt ionalParam eters )
  323           {
  324                    getL ogger().in fo("create Instance("  + resultC lass.getNa me() +  // $NON-NLS-1 $
  325                             ", " +  (instance Population  == null ?  "null ins tances" :  instancePo pulation.t oString())  +  //$NON -NLS-1$ // $NON-NLS-2 $
  326                             ", " +  (aggregat es == null  ? "null a ggregates"  : aggrega tes.toStri ng()) + // $NON-NLS-1 $ //$NON-N LS-2$
  327                             ", " +  (componen ts == null  ? "null c omponents"  : compone nts.toStri ng()) + ") "); //$NON -NLS-1$ // $NON-NLS-2 $ //$NON-N LS-3$
  328                    
  329                    if(  isSimpleTy pe(resultC lass) )
  330                             return  (T)create SimpleData Type(resul tClass);
  331                    
  332                    if(  resultClas s.isEnum()  )
  333                             return  (T)select Enum( (Cla ss<Enum>)r esultClass  );
  334                    
  335                    Meth od complex CreateMeth od = getCo mplexObjec tCreateMet hod(result Class, opt ionalParam eters);
  336                    Meth od referen ceCreateMe thod = get ReferenceO bjectCreat eMethod(re sultClass,  optionalP arameters) ;
  337                    Meth od simpleC reateMetho d = getSim pleObjectC reateMetho d(resultCl ass, optio nalParamet ers);
  338                    Meth od postPop ulateMetho d = getPos tPopulateM ethod(resu ltClass);
  339                    if(c omplexCrea teMethod ! = null && 
  340                             instan cePopulati on != null  &&
  341                             aggreg ates != nu ll &&
  342                             compon ents != nu ll &&
  343                             refere nces != nu ll)
  344                    {
  345                             getLog ger().info ("found me thod '" +  complexCre ateMethod. toGenericS tring() +  "'."); //$ NON-NLS-1$  //$NON-NL S-2$
  346                             try
  347                             {
  348                                      Referenc eMap child References  = referen ces.create Child();
  349                                      Object[]  parameter s = combin eParameter s(instance Population , aggregat es, compon ents, chil dReference s, optiona lParameter s);
  350                                      GenericD ataGenerat or registe redInstanc e = getReg isteredIns tance(comp lexCreateM ethod.getD eclaringCl ass());
  351                                      T instan ce = (T)co mplexCreat eMethod.in voke(regis teredInsta nce, param eters);
  352                                      getLogge r().info(" created in stance usi ng '" + co mplexCreat eMethod.to GenericStr ing() + "' ."); //$NO N-NLS-1$ / /$NON-NLS- 2$
  353  
  354                                      if(compo nents != C omposition Population .NONE)
  355                                               populateCo mposition( instance,  instancePo pulation,  aggregates , componen ts, refere nces);
  356                                      if(insta ncePopulat ion == Ins tancePopul ation.FULL )
  357                                               populateCh ildren(ins tance, ins tancePopul ation, agg regates, c omponents,  reference s);
  358                                      //popula teAnnotate dFields(in stance, in stancePopu lation, ag gregates,  components , referenc es);
  359                                      
  360                                      if(postP opulateMet hod != nul l)
  361                                               postPopula teMethod.i nvoke(regi steredInst ance, inst ance);
  362                                      
  363                                      return i nstance;
  364                             }
  365                             catch  (Exception  x)
  366                             {
  367                                      getLogge r().error( x);
  368                                      x.printS tackTrace( );
  369                             }
  370                    }
  371                    else  if(refere nceCreateM ethod != n ull && ref erences !=  null)
  372                    {
  373                             getLog ger().info ("found me thod '" +  referenceC reateMetho d.toGeneri cString()  + "'."); / /$NON-NLS- 1$ //$NON- NLS-2$
  374                             try
  375                             {
  376                                      Referenc eMap child References  = referen ces.create Child();
  377                                      Object[]  parameter s = combin eParameter s(childRef erences, o ptionalPar ameters);
  378                                      GenericD ataGenerat or registe redInstanc e = getReg isteredIns tance(comp lexCreateM ethod.getD eclaringCl ass());
  379                                      T instan ce = (T)re ferenceCre ateMethod. invoke(reg isteredIns tance, par ameters);
  380                                      getLogge r().info(" created in stance usi ng '" + re ferenceCre ateMethod. toGenericS tring() +  "'."); //$ NON-NLS-1$  //$NON-NL S-2$
  381  
  382                                      return i nstance;
  383                             }
  384                             catch  (Exception  x)
  385                             {
  386                                      getLogge r().error( x);
  387                             }
  388                    }
  389                    else  if(simple CreateMeth od != null )
  390                    {
  391                             getLog ger().info ("found me thod '" +  simpleCrea teMethod.t oGenericSt ring() + " '."); //$N ON-NLS-1$  //$NON-NLS -2$
  392                             try
  393                             {
  394                                      GenericD ataGenerat or registe redInstanc e = getReg isteredIns tance(simp leCreateMe thod.getDe claringCla ss());
  395                                      T instan ce = (T)si mpleCreate Method.inv oke(regist eredInstan ce, option alParamete rs);
  396                                      getLogge r().info(" created in stance usi ng '" + si mpleCreate Method.toG enericStri ng() + "'. "); //$NON -NLS-1$ // $NON-NLS-2 $
  397  
  398                                      return i nstance;
  399                             }
  400                             catch  (Exception  x)
  401                             {
  402                                      getLogge r().error( x);
  403                                      x.printS tackTrace( );
  404                             }
  405                    }
  406                    else
  407                    {
  408                             getLog ger().warn ("No creat e method f ound, crea ting insta nce of '"  + resultCl ass.getSim pleName()  + "' using  default c onstructor ." );
  409                             try
  410                             {
  411                                      T instan ce = resul tClass.new Instance() ;
  412                                      getLogge r().warn(" Created in stance of  '" + resul tClass.get SimpleName () + "' us ing defaul t construc tor." );
  413                                      populate Children(i nstance, i nstancePop ulation, a ggregates,  component s, referen ces);
  414                                      return i nstance;
  415                             }
  416                             catch  (Throwable  x)
  417                             {
  418                                      getLogge r().error( "Unable to  create in stance of  '" + resul tClass.get SimpleName () + "' us ing defaul t construc tor.", x);
  419                                      while((x  = x.getCa use()) !=  null)
  420                                               getLogger( ).error("R OOT CAUSE  of inabili ty to crea te instanc e of '" +  resultClas s.getSimpl eName() +  "' using d efault con structor f ollows.",  x);
  421                                      x.printS tackTrace( );
  422                             }
  423                    }
  424                    
  425                    retu rn null;
  426           }
  427           
  428           /* *
  429            *  
  430            *  @param <T >
  431            *  @param <E >
  432            *  @param co llectionTy pe
  433            *  @param el ementType
  434            *  @param in stancePopu lation
  435            *  @param ag gregates
  436            *  @param co mponents
  437            *  @param re ferences
  438            *  @param op tionalPara meters
  439            *  @return
  440            * /
  441           pu blic <T ex tends Coll ection<E>,  E extends  Object> T  createCol lectionIns tance(
  442                    Clas s<T> colle ctionType,  
  443                    Clas s<E> eleme ntType,
  444                    Inst ancePopula tion insta ncePopulat ion, 
  445                    Aggr egationPop ulation ag gregates,
  446                    Comp ositionPop ulation co mponents,
  447                    Refe renceMap r eferences,
  448                    Obje ct ... opt ionalParam eters )
  449           {
  450                    Coll ection<E>  collection  = null;
  451                    try
  452                    {
  453                             if(col lectionTyp e.isInterf ace())
  454                             {
  455                                      if(Set.c lass.isAss ignableFro m(collecti onType))
  456                                      {
  457                                               if( Sorted Set.class. isAssignab leFrom(col lectionTyp e) && coll ectionType .isAssigna bleFrom(Tr eeSet.clas s) )
  458                                                       co llection =  new TreeS et<E>();
  459                                               else if( H ashSet.cla ss.isAssig nableFrom( collection Type) )
  460                                                       co llection =  new HashS et<E>();
  461                                      }
  462                                      else if(  List.clas s.isAssign ableFrom(c ollectionT ype) && co llectionTy pe.isAssig nableFrom( ArrayList. class) )
  463                                               collection  = new Arr ayList<E>( );
  464                                      else if(  Queue.cla ss.isAssig nableFrom( collection Type) && c ollectionT ype.isAssi gnableFrom (LinkedLis t.class) )
  465                                               collection  = new Lin kedList<E> ();
  466                             }
  467                             else
  468                                      collecti on = colle ctionType. newInstanc e();
  469                             
  470                             if(col lection ==  null)
  471                             {
  472                                      getLogge r().error( "Unable to  create co llection o f type " +  collectio nType.getN ame() + ". "); //$NON -NLS-1$ // $NON-NLS-2 $
  473                                      return n ull;
  474                             }
  475                             
  476                             for(in t elementC ount=0; el ementCount <component s.getCount (); ++elem entCount)
  477                                      collecti on.add( cr eateInstan ce(element Type, inst ancePopula tion, aggr egates, co mponents,  references , optional Parameters ) );
  478                             
  479                             return  (T)collec tion;
  480                    }
  481                    catc h (Excepti on x)
  482                    {
  483                             getLog ger().erro r(x);
  484                             x.prin tStackTrac e();
  485                             return  null;
  486                    }
  487           }
  488           
  489           /* *
  490            *  
  491            *  @param <T >   A Map  realizatio n
  492            *  @param <K >   The ke y type of  the Map
  493            *  @param <V >   The va lue type o f the Map
  494            *  @param ke yType
  495            *  @param va lueType
  496            *  @param in stancePopu lation
  497            *  @param ag gregates
  498            *  @param co mponents
  499            *  @param re ferences
  500            *  @param op tionalPara meters
  501            *  @return
  502            * /
  503           pu blic <T ex tends Map< K,V>, K ex tends Obje ct,V exten ds Object>  T createM apInstance (
  504                    Clas s<T> mapTy pe,
  505                    Clas s<K> keyTy pe, 
  506                    Clas s<V> value Type,
  507                    Inst ancePopula tion insta ncePopulat ion, 
  508                    Aggr egationPop ulation ag gregates,
  509                    Comp ositionPop ulation co mponents,
  510                    Refe renceMap r eferences,
  511                    Obje ct ... opt ionalParam eters )
  512           {
  513                    Map< K,V> map =  null;
  514                    try
  515                    {
  516                             if( ma pType.isIn terface()  && mapType .isAssigna bleFrom(Tr eeMap.clas s) )
  517                                      map = ne w TreeMap< K,V>();                 // use a  TreeMap b ecause it  implements  Map, Sort edMap and  NavigableM ap
  518                             else
  519                                      map = ma pType.newI nstance();
  520                             
  521                             if(map  == null)
  522                             {
  523                                      getLogge r().error( "Unable to  create ma p of type  " + mapTyp e.getName( ) + ".");  //$NON-NLS -1$ //$NON -NLS-2$
  524                                      return n ull;
  525                             }
  526                             
  527                             for(in t elementC ount=0; el ementCount <component s.getCount (); ++elem entCount)
  528                             {
  529                                      K key =  (K)createI nstance(ke yType, ins tancePopul ation, agg regates, c omponents,  reference s, optiona lParameter s);
  530                                      V value  = (V)creat eInstance( valueType,  instanceP opulation,  aggregate s, compone nts, refer ences, opt ionalParam eters);
  531  
  532                                      if(key = = null)
  533                                               logger.war n("Failed  to create  key, insta nce of " +  keyType.t oString()  + ".");
  534                                      if(value  == null)
  535                                               logger.war n("Failed  to create  value, ins tance of "  + valueTy pe.toStrin g() + ".") ;
  536                                      
  537                                      map.put(  key, valu e );
  538                             }
  539                             
  540                             return  (T)map;
  541                    }
  542                    catc h (Excepti on x)
  543                    {
  544                             getLog ger().erro r(x);
  545                             x.prin tStackTrac e();
  546                             return  null;
  547                    }
  548           }
  549           
  550           /* *
  551            *  @param de claringCla ss
  552            *  @return
  553            * /
  554           pr ivate Gene ricDataGen erator get Registered Instance(C lass<?> de claringCla ss)
  555           {
  556                    if(d eclaringCl ass == nul l)
  557                             return  null;
  558                    
  559                    for( GenericDat aGenerator  dataGener ator : get Registered DataGenera tor())
  560                             if(dat aGenerator .getClass( ) == decla ringClass)
  561                                      return d ataGenerat or;
  562                    
  563                    retu rn null;
  564           }
  565  
  566           /* *
  567            *  @param in stancePopu lation
  568            *  @param ag gregates
  569            *  @param co mponents
  570            *  @param op tionalPara meters
  571            *  @return
  572            * /
  573           pr ivate stat ic final i nt COMPLEX _CREATE_KN OWN_PARAME TER_COUNT  = 4;
  574           
  575           pr ivate Obje ct[] combi neParamete rs(
  576                    Inst ancePopula tion insta ncePopulat ion, 
  577                    Aggr egationPop ulation ag gregates,
  578                    Comp ositionPop ulation co mponents, 
  579                    Refe renceMap r eferences,
  580                    Obje ct[] optio nalParamet ers)
  581           {
  582                    Obje ct[] resul t = new Ob ject[
  583                               COMP LEX_CREATE _KNOWN_PAR AMETER_COU NT + 
  584                               (opt ionalParam eters == n ull ? 0 :  optionalPa rameters.l ength)
  585                             ];
  586                    
  587                    resu lt[0] = in stancePopu lation;
  588                    resu lt[1] = ag gregates;
  589                    resu lt[2] = co mponents;
  590                    resu lt[3] = re ferences;
  591                    
  592                    for(
  593                    int  index=COMP LEX_CREATE _KNOWN_PAR AMETER_COU NT; 
  594                    opti onalParame ters != nu ll && opti onalParame ters.lengt h > 0 && i ndex <= CO MPLEX_CREA TE_KNOWN_P ARAMETER_C OUNT + opt ionalParam eters.leng th; 
  595                    ++in dex)
  596                             result [index] =  optionalPa rameters[i ndex - COM PLEX_CREAT E_KNOWN_PA RAMETER_CO UNT];
  597                    
  598                    retu rn result;
  599           }
  600           
  601           pr ivate stat ic final i nt REFEREN CE_CREATE_ KNOWN_PARA METER_COUN T = 1;
  602           pr ivate Obje ct[] combi neParamete rs(
  603                    Refe renceMap r eferences,
  604                    Obje ct[] optio nalParamet ers)
  605           {
  606                    Obje ct[] resul t = new Ob ject[REFER ENCE_CREAT E_KNOWN_PA RAMETER_CO UNT + (opt ionalParam eters == n ull ? 0 :  optionalPa rameters.l ength)];
  607                    
  608                    resu lt[0] = re ferences;
  609                    
  610                    for(
  611                    int  index=REFE RENCE_CREA TE_KNOWN_P ARAMETER_C OUNT; 
  612                    opti onalParame ters != nu ll && inde x <= optio nalParamet ers.length  + REFEREN CE_CREATE_ KNOWN_PARA METER_COUN T; 
  613                    ++in dex)
  614                             result [index] =  optionalPa rameters[i ndex - REF ERENCE_CRE ATE_KNOWN_ PARAMETER_ COUNT];
  615                    
  616                    retu rn result;
  617           }
  618  
  619           /* *
  620            *  Find a me thod in th is class t hat is:
  621            *  1.) stati c
  622            *  2.) named  according  to the re gex "creat e[A-Z][A=Z a-z0-9_]"
  623            *  3.) publi c
  624            *  4.) retur ns an inst ance of ty pe resultC lass
  625            *  5.) has a  parameter  list equa l to 
  626            *  
  627            *  @param <T >
  628            *  @param re sultClass
  629            *  @return
  630            * /
  631           pr otected <T  extends O bject> Met hod getCom plexObject CreateMeth od(
  632                    Clas s<T> resul tClass, 
  633                    Obje ct ... opt ionalParam eters)
  634           {
  635                    if(r esultClass  == null)
  636                             return  null;
  637                    
  638                    Clas s<?>[] par ameterList  = combine ParameterL ists(COMPL EX_CREATE_ METHOD_PAR AMETERS, o ptionalPar ameters); 
  639                    
  640                    for( GenericDat aGenerator  dataGener ator : thi s.getRegis teredDataG enerator() )
  641                    {
  642                             Class< ? extends  GenericDat aGenerator > dataGene ratorClass  = dataGen erator.get Class();
  643                             
  644                             for(Me thod metho d : dataGe neratorCla ss.getDecl aredMethod s())
  645                             {
  646                                      int meth odModifier s = method .getModifi ers();
  647                                      if( Modi fier.isPub lic(method Modifiers)  && 
  648                                               method.get ReturnType () == resu ltClass &&  
  649                                               Pattern.ma tches(CREA TE_METHOD_ REGEX, met hod.getNam e()) &&
  650                                               parameterL istEqual(p arameterLi st, method .getParame terTypes() ))
  651                                                       re turn metho d;
  652                             }
  653                    }                 
  654                    retu rn null;
  655           }
  656  
  657           /* *
  658            *  Get a cre ateXXX met hod that c reates an  object and  takes a
  659            *  Reference Map parame ter.
  660            *  
  661            *  @param <T >
  662            *  @param re sultClass
  663            *  @param op tionalPara meters
  664            *  @return
  665            * /
  666           pr otected <T  extends O bject> Met hod getRef erenceObje ctCreateMe thod(
  667                    Clas s<T> resul tClass, 
  668                    Obje ct ... opt ionalParam eters)
  669           {
  670                    if(r esultClass  == null)
  671                             return  null;
  672                    
  673                    Clas s<?>[] par ameterList  = combine ParameterL ists(REFER ENCE_CREAT E_METHOD_P ARAMETERS,  optionalP arameters)
  674                    
  675                    for( GenericDat aGenerator  dataGener ator : thi s.getRegis teredDataG enerator() )
  676                    {
  677                             Class< ? extends  GenericDat aGenerator > dataGene ratorClass  = dataGen erator.get Class();
  678                             
  679                             for(Me thod metho d : dataGe neratorCla ss.getDecl aredMethod s())
  680                             {
  681                                      int meth odModifier s = method .getModifi ers();
  682                                      if( Modi fier.isPub lic(method Modifiers)  && 
  683                                               method.get ReturnType () == resu ltClass &&  
  684                                               Pattern.ma tches(CREA TE_METHOD_ REGEX, met hod.getNam e()) &&
  685                                               parameterL istEqual(p arameterLi st, method .getParame terTypes() ))
  686                                                       re turn metho d;
  687                             }
  688                    }
  689                    
  690                    retu rn null;
  691           }
  692           
  693           /* *
  694            *  Find a cr eateXXX me thod that  creates an  object an d takes no
  695            *  environme nt paramet ers.
  696            *  
  697            *  @param <T >
  698            *  @param re sultClass
  699            *  @param op tionalPara meters
  700            *  @return
  701            * /
  702           pr otected <T  extends O bject> Met hod getSim pleObjectC reateMetho d(
  703                    Clas s<T> resul tClass, 
  704                    Obje ct ... opt ionalParam eters)
  705           {
  706                    if(r esultClass  == null)
  707                             return  null;
  708                    
  709                    Clas s<?>[] par ameterList  = combine ParameterL ists(SIMPL E_CREATE_M ETHOD_PARA METERS, op tionalPara meters); 
  710                    
  711                    for( GenericDat aGenerator  dataGener ator : thi s.getRegis teredDataG enerator() )
  712                    {
  713                             Class< ? extends  GenericDat aGenerator > dataGene ratorClass  = dataGen erator.get Class();
  714                             
  715                             for(Me thod metho d : dataGe neratorCla ss.getDecl aredMethod s())
  716                             {
  717                                      int meth odModifier s = method .getModifi ers();
  718                                      if( Modi fier.isPub lic(method Modifiers)  && 
  719                                               method.get ReturnType () == resu ltClass &&  
  720                                               Pattern.ma tches(CREA TE_METHOD_ REGEX, met hod.getNam e()) &&
  721                                               parameterL istEqual(p arameterLi st, method .getParame terTypes() ))
  722                                                       re turn metho d;
  723                             }
  724                    }
  725                    
  726                    retu rn null;
  727           }
  728           
  729           /* *
  730            *  Find a me thod that  will be ca lled after  an object  is create d
  731            *  but befor e the resu lt is retu rned to th e calling  client. 
  732            *  
  733            *  @param <T >
  734            *  @param re sultClass
  735            *  @return
  736            * /
  737           pr ivate fina l <T exten ds Object>  Method ge tPostPopul ateMethod( Class<T> r esultClass )
  738           {
  739                    if(r esultClass  == null)
  740                             return  null;
  741                    
  742                    Clas s<?>[] par ameterList  = new Cla ss<?>[]{re sultClass} ;
  743                    for( GenericDat aGenerator  dataGener ator : thi s.getRegis teredDataG enerator() )
  744                    {
  745                             Class< ? extends  GenericDat aGenerator > dataGene ratorClass  = dataGen erator.get Class();
  746                             
  747                             for(Me thod metho d : dataGe neratorCla ss.getDecl aredMethod s())
  748                             {
  749                                      int meth odModifier s = method .getModifi ers();
  750                                      if( Modi fier.isPub lic(method Modifiers)  && 
  751                                               (Void.clas s == metho d.getRetur nType() ||  void.clas s == metho d.getRetur nType()) &
  752                                               Pattern.ma tches(POST POPULATE_M ETHOD_REGE X, method. getName())  &&
  753                                               parameterL istEqual(p arameterLi st, method .getParame terTypes() ))
  754                                                       re turn metho d;
  755                             }
  756                    }
  757                    
  758                    retu rn null;
  759           }
  760           
  761           /* *
  762            *  @param si mpleCreate MethodPara meters
  763            *  @param op tionalPara meters
  764            *  @return
  765            * /
  766           pr ivate Clas s<?>[] com bineParame terLists(C lass<?>[]  createMeth odParamete rs, Object [] optiona lParameter s)
  767           {
  768                    Clas s<?>[] res ult = new  Class[
  769                       ( createMeth odParamete rs == null  ? 0 : cre ateMethodP arameters. length) +
  770                       ( optionalPa rameters = = null ? 0  : optiona lParameter s.length)
  771                    ];
  772                    
  773                    int  resultInde x = 0;
  774                    for( int index= 0; createM ethodParam eters != n ull && ind ex < creat eMethodPar ameters.le ngth; ++in dex)
  775                             result [resultInd ex++] = cr eateMethod Parameters [index];
  776                    
  777                    for( int index= 0; optiona lParameter s != null  && index <  optionalP arameters. length; ++ index)
  778                             result [resultInd ex++] = op tionalPara meters[ind ex].getCla ss();
  779                    
  780                    retu rn result;
  781           }
  782  
  783           /* *
  784            *  @param cr eateMethod Parameters
  785            *  @param pa rameterTyp es
  786            *  @return
  787            * /
  788           pr otected bo olean para meterListE qual(Class <?>[] expe ctedParame terTypes,  Class<?>[]  actualPar ameterType s)
  789           {
  790                    if(  expectedPa rameterTyp es == null  && actual ParameterT ypes == nu ll )
  791                             return  true;
  792                    
  793                    if(  (expectedP arameterTy pes == nul l && actua lParameter Types != n ull) || 
  794                             (expec tedParamet erTypes !=  null && a ctualParam eterTypes  == null))
  795                                      return f alse;
  796                    
  797                    if(e xpectedPar ameterType s.length ! = actualPa rameterTyp es.length)
  798                             return  false;
  799                    
  800                    for( int index  = 0; index  < expecte dParameter Types.leng th; ++inde x)
  801                             if(exp ectedParam eterTypes[ index] !=  actualPara meterTypes [index])
  802                                      return f alse;
  803                    
  804                    retu rn true;
  805           }
  806  
  807           /* *
  808            *  
  809            *  @param in stance
  810            *  @param in stancePopu lation
  811            *  @param ag gregates
  812            *  @param co mponents
  813            *  @param re ferences
  814            * /
  815           pr otected vo id populat eChildren(
  816                    Obje ct instanc e, 
  817                    Inst ancePopula tion insta ncePopulat ion, 
  818                    Aggr egationPop ulation ag gregates,
  819                    Comp ositionPop ulation co mponents,
  820                    Refe renceMap r eferences)
  821           {
  822                    if(  InstancePo pulation.F ULL == ins tancePopul ation || 
  823                             Instan cePopulati on.REQUIRE D == insta ncePopulat ion ||
  824                             Instan cePopulati on.DEFAULT  == instan cePopulati on)
  825                                      populate AnnotatedF ields(inst ance, inst ancePopula tion, aggr egates, co mponents,  references );
  826           }
  827           
  828           /* *
  829            *  
  830            *  @param in stance
  831            *  @param in stancePopu lation
  832            *  @param ag gregates
  833            *  @param co mponents
  834            * /
  835           pr otected vo id populat eComponent Instances(
  836                    Clas s<?> resul tClass, 
  837                    Obje ct instanc e, 
  838                    Inst ancePopula tion insta ncePopulat ion,
  839                    Aggr egationPop ulation ag gregates,
  840                    Comp ositionPop ulation co mponents,
  841                    Refe renceMap r eferences)
  842           {
  843                    if(M ap.class.i sAssignabl eFrom(resu ltClass))
  844                             popula teMapCompo nentInstan ces(result Class, ins tance, ins tancePopul ation, agg regates, c omponents,  reference s);
  845                    else  if(Collec tion.class .isAssigna bleFrom(re sultClass) )
  846                             popula teCollecti onComponen tInstances (resultCla ss, instan ce, instan cePopulati on, aggreg ates, comp onents, re ferences);
  847                    else
  848                             return ;
  849           }
  850           
  851           /* *
  852            *  @param re sultClass
  853            *  @param in stance
  854            *  @param in stancePopu lation
  855            *  @param ag gregates
  856            *  @param co mponents
  857            * /
  858           @S uppressWar nings("unc hecked")
  859           pr ivate void  populateC ollectionC omponentIn stances(
  860                    Clas s resultCl ass, 
  861                    Obje ct instanc e,
  862                    Inst ancePopula tion insta ncePopulat ion, 
  863                    Aggr egationPop ulation ag gregates, 
  864                    Comp ositionPop ulation co mponents,
  865                    Refe renceMap r eferences
  866                    )
  867           {
  868                    Mock DataGenera tionType d ataGenerat ionAnnotat ion = 
  869                             (MockD ataGenerat ionType)re sultClass. getAnnotat ion(MockDa taGenerati onType.cla ss);
  870                    
  871                    if(d ataGenerat ionAnnotat ion != nul l)
  872                    {
  873                             String  valueType  = dataGen erationAnn otation.co mponentVal ueType();
  874                             if(val ueType ==  null)
  875                             {
  876                                      getLogge r().error( "Collectio n derived  class '" +  resultCla ss.getName () + "' mu st specify  a compone ntValueTyp e in the a nnotation. "); //$NON -NLS-1$ // $NON-NLS-2 $
  877                                      return;
  878                             }
  879                                      
  880                             Collec tion insta nceAsMap =  (Collecti on)instanc e;
  881                             try
  882                             {
  883                                      Class va lueClass =  Class.for Name(value Type);
  884                                      
  885                                      for(int  componentI ndex=0; co mponentInd ex < compo nents.getC ount(); ++ componentI ndex)
  886                                      {
  887                                               Object val ue = creat eInstance( valueClass , instance Population , aggregat es, compon ents, refe rences);
  888                                              
  889                                               instanceAs Map.add(va lue);
  890                                      }
  891                             }
  892                             catch  (ClassNotF oundExcept ion x)
  893                             {
  894                                      x.printS tackTrace( );
  895                             } 
  896                    }
  897           }
  898  
  899           /* *
  900            *  @param re sultClass
  901            *  @param in stance
  902            *  @param in stancePopu lation
  903            *  @param ag gregates
  904            *  @param co mponents
  905            * /
  906           @S uppressWar nings("unc hecked")
  907           pr ivate void  populateM apComponen tInstances (
  908                    Clas s resultCl ass, 
  909                    Obje ct instanc e,
  910                    Inst ancePopula tion insta ncePopulat ion, 
  911                    Aggr egationPop ulation ag gregates, 
  912                    Comp ositionPop ulation co mponents,
  913                    Refe renceMap r eferences)
  914           {
  915                    Mock DataGenera tionType d ataGenerat ionAnnotat ion = 
  916                             (MockD ataGenerat ionType)re sultClass. getAnnotat ion(MockDa taGenerati onType.cla ss);
  917                    
  918                    Stri ng keyType  = dataGen erationAnn otation.co mponentKey Type();
  919                    if(k eyType ==  null)
  920                    {
  921                             getLog ger().erro r("Map der ived field  '" + resu ltClass.ge tName() +  "' must sp ecify a co mponentKey Type in th e annotati on."); //$ NON-NLS-1$  //$NON-NL S-2$
  922                             return ;
  923                    }
  924                    
  925                    Stri ng valueTy pe = dataG enerationA nnotation. componentV alueType() ;
  926                    if(v alueType = = null)
  927                    {
  928                             getLog ger().erro r("Map der ived class  '" + resu ltClass.ge tName() +  "' must sp ecify a co mponentVal ueType in  the annota tion."); / /$NON-NLS- 1$ //$NON- NLS-2$
  929                             return ;
  930                    }
  931                             
  932                    Map  instanceAs Map = (Map )instance;
  933                    try
  934                    {
  935                             Class  keyClass =  Class.for Name(keyTy pe);
  936                             Class  valueClass  = Class.f orName(val ueType);
  937                             
  938                             for(in t componen tIndex=0;  componentI ndex < com ponents.ge tCount();  ++componen tIndex)
  939                             {
  940                                      Object k ey = creat eInstance( keyClass,  instancePo pulation,  aggregates , componen ts, refere nces);
  941                                      Object v alue = cre ateInstanc e(valueCla ss, instan cePopulati on, aggreg ates, comp onents, re ferences);
  942                                      
  943                                      instance AsMap.put( key, value );
  944                             }
  945                    }
  946                    catc h (ClassNo tFoundExce ption x)
  947                    {
  948                             x.prin tStackTrac e();
  949                    } 
  950           }
  951  
  952           /* *
  953            *  Populate  an instanc e of a typ e that is  annotated  with a Moc kDataGener ationType
  954            *  annotatio n.
  955            *  
  956            *  @param in stance
  957            *  @param in stancePopu lation
  958            *  @param ag gregates
  959            *  @param co mponents
  960            *  @throws I llegalAcce ssExceptio
  961            * /
  962           pr otected vo id populat eCompositi on(
  963                    Obje ct instanc e, 
  964                    Inst ancePopula tion insta ncePopulat ion,
  965                    Aggr egationPop ulation ag gregates,
  966                    Comp ositionPop ulation co mponents,
  967                    Refe renceMap r eferences)  
  968           th rows Illeg alAccessEx ception
  969           {
  970                    Clas s<?> insta nceClass =  instance. getClass() ;
  971                    Mock DataGenera tionType t ypeAnnotat ion = inst anceClass. getAnnotat ion(MockDa taGenerati onType.cla ss);
  972                    if(t ypeAnnotat ion != nul l)
  973                    {
  974                             if( Ma p.class.is Instance(i nstance) )
  975                             {
  976                                      populate MapField(
  977                                               (Map)insta nce,
  978                                               typeAnnota tion.compo nentKeyTyp e(), typeA nnotation. componentV alueType() ,
  979                                               instance.g etClass(). getSimpleN ame(), com ponents.ge tCount(), 
  980                                               instancePo pulation,  aggregates , componen ts, refere nces);
  981                             }
  982                             else i f( Collect ion.class. isInstance (instance)  )
  983                             {
  984                                      populate Collection Field(
  985                                               (Collectio n)instance ,
  986                                               typeAnnota tion.compo nentValueT ype(),
  987                                               instance.g etClass(). getSimpleN ame(), com ponents.ge tCount(), 
  988                                               instancePo pulation,  aggregates , componen ts, refere nces);
  989                             }
  990                    }
  991           }
  992           
  993           /* *
  994            *  Populate  the 'simpl e' fields  that are a nnotated w ith the
  995            *  MockDataG enerationF ield annot ation.
  996            *  
  997            *  @param in stance
  998            *  @param in stancePopu lation
  999            *  @param ch ildren
  1000            * /
  1001           pr otected vo id populat eAnnotated Fields(
  1002                    Obje ct instanc e, 
  1003                    Inst ancePopula tion insta ncePopulat ion,
  1004                    Aggr egationPop ulation ag gregates,
  1005                    Comp ositionPop ulation co mponents,
  1006                    Refe renceMap r eferences)
  1007           {
  1008                    Fiel d[] fields  = instanc e.getClass ().getDecl aredFields ();
  1009                    
  1010                    for( Field fiel d : fields )
  1011                    {
  1012                             MockDa taGenerati onField da taGenerati onAnnotati on = field .getAnnota tion(MockD ataGenerat ionField.c lass);
  1013                             
  1014                             // if  the field  is annotat ed and the  annotatio n specifie s required  or
  1015                             // thi s generato r is set t o ALL mode  then popu late the f ield
  1016                             if( da taGenerati onAnnotati on != null  )
  1017                                      populate AnnotatedF ield(
  1018                                               instance, 
  1019                                               instancePo pulation, 
  1020                                               aggregates
  1021                                               components
  1022                                               references
  1023                                               field,
  1024                                               dataGenera tionAnnota tion);
  1025                    }
  1026           }
  1027           /* *
  1028            *  @param in stance
  1029            *  @param in stancePopu lation
  1030            *  @param ag gregates
  1031            *  @param co mponents
  1032            *  @param re ferences
  1033            *  @param fi eld
  1034            *  @param da taGenerati onAnnotati on
  1035            * /
  1036           pr ivate void  populateA nnotatedFi eld(
  1037                    Obje ct instanc e, 
  1038                    Inst ancePopula tion insta ncePopulat ion,
  1039                    Aggr egationPop ulation ag gregates, 
  1040                    Comp ositionPop ulation co mponents, 
  1041                    Refe renceMap r eferences,  
  1042                    Fiel d field,
  1043                    Mock DataGenera tionField  dataGenera tionAnnota tion)
  1044           {
  1045                    // i f the fiel d is not r equired or  the data  generation  mode is n ot FULL th e field do es not nee d
  1046                    // t o be popul ated
  1047                    if(  !(dataGene rationAnno tation.req uired() ||  InstanceP opulation. FULL == in stancePopu lation) )
  1048                             return ;
  1049                    
  1050                    Clas s<?> field Type = fie ld.getType ();
  1051                    
  1052                    try
  1053                    {
  1054                             if( is SimpleType (fieldType ) )
  1055                             {
  1056                                      String m ockData = 
  1057                                               String.cla ss == fiel d.getType( ) ?
  1058                                                       cr eateString Data(                         //  creates t he data as  a string  according  to the ann otation
  1059                                                                data Generation Annotation .pattern() ,
  1060                                                                data Generation Annotation .defaultVa lue(),
  1061                                                                data Generation Annotation .minimumSt ringLength (),
  1062                                                                data Generation Annotation .maximumSt ringLength () ) :
  1063                                               Date.class  == field. getType()  ?
  1064                                                       cr eateDateDa ta(                   // creates  the data  as a strin g accordin g to the a nnotation
  1065                                                                data Generation Annotation .defaultVa lue(),
  1066                                                                data Generation Annotation .minimumDa te(),
  1067                                                                data Generation Annotation .maximumDa te() ) :
  1068                                                       cr eateNumeri cData(                        //  creates t he data as  a string  according  to the ann otation
  1069                                                                fiel d.getType( ),
  1070                                                                data Generation Annotation .pattern() ,
  1071                                                                data Generation Annotation .defaultVa lue(),
  1072                                                                data Generation Annotation .minimum() ,
  1073                                                                data Generation Annotation .maximum()  );
  1074                                      
  1075                                      try
  1076                                      {
  1077                                               if( ! setS impleField (instance,  field, mo ckData) )
  1078                                                       ge tLogger(). error( "Un able to se t " + inst ance.getCl ass().getS impleName( ) +  //$NO N-NLS-1$
  1079                                                                "."  + field.ge tName() +  ", type mu st be a si mple type. " ); //$NO N-NLS-1$ / /$NON-NLS- 2$
  1080                                      }
  1081                                      catch (E xception x )
  1082                                      {
  1083                                               getLogger( ).error( " Unable to  set " + in stance.get Class().ge tSimpleNam e() +  //$ NON-NLS-1$
  1084                                                       ". " + field. getName()  +  //$NON- NLS-1$
  1085                                                       ",  exception  of type "  + x.getCl ass().getS impleName( ) + "(" +  x.getMessa ge() + ")" ); //$NON- NLS-1$ //$ NON-NLS-2$  //$NON-NL S-3$
  1086                                      }
  1087                             }
  1088                             else i f( fieldTy pe.isArray () && isSi mpleType(f ieldType.g etComponen tType()) )
  1089                             {
  1090                                      Class<?>  component Type = fie ldType.get ComponentT ype();
  1091                                      // creat es an arra y of the c omponent t ype
  1092                                      Object v alueArray  = Array.ne wInstance( componentT ype, 3);
  1093                                      for(int  index=0; i ndex < agg regates.ge tCount();  ++index)
  1094                                      {
  1095                                               String moc kData = cr eateNumeri cData(                      // c reates the  data as a  string ac cording to  the annot ation
  1096                                                       co mponentTyp e,
  1097                                                       da taGenerati onAnnotati on.pattern (),
  1098                                                       da taGenerati onAnnotati on.default Value(),
  1099                                                       da taGenerati onAnnotati on.minimum (),
  1100                                                       da taGenerati onAnnotati on.maximum () );
  1101                                              
  1102                                               setArrayVa lue(valueA rray, inde x, mockDat a);
  1103                                      }
  1104                             }
  1105                             else i f( fieldTy pe.isArray () && !isS impleType( fieldType. getCompone ntType())  )
  1106                             {
  1107                                      Class<?>  component Type = fie ldType.get ComponentT ype();
  1108                                      // creat es an arra y of the c omponent t ype
  1109                                      Object v alueArray  = Array.ne wInstance( componentT ype, 3);
  1110                                      for(int  index=0; i ndex < agg regates.ge tCount();  ++index)
  1111                                      {
  1112                                               Object obj  = createI nstance(fi eldType, i nstancePop ulation, a ggregates,  component s, referen ces);
  1113                                              
  1114                                               Array.set( valueArray , index, o bj);
  1115                                      }
  1116                             }
  1117                             else i f( InputSt ream.class  == fieldT ype )
  1118                             {
  1119                                      boolean  accessible Field = fi eld.isAcce ssible();
  1120                                      field.se tAccessibl e(true);
  1121  
  1122                                      try
  1123                                      {
  1124                                               MockSizedI nputStream  inStream  = createIn putStream(
  1125                                                       in stancePopu lation,
  1126                                                       da taGenerati onAnnotati on.mediaTy pes(),
  1127                                                       da taGenerati onAnnotati on.default MediaType( ));
  1128                                              
  1129                                               field.set( instance,  inStream);
  1130                                      }
  1131                                      finally
  1132                                      {
  1133                                               field.setA ccessible( accessible Field);
  1134                                      }
  1135                             }
  1136                             else
  1137                             {
  1138                                      boolean  accessible Field = fi eld.isAcce ssible();
  1139                                      field.se tAccessibl e(true);
  1140  
  1141                                      try
  1142                                      {
  1143                                               if( Map.cl ass.isAssi gnableFrom (fieldType ) )
  1144                                               {
  1145                                                       Ma p map = (M ap)field.g et(instanc e);
  1146                                                       St ring name  = field.ge tName();
  1147                                                       if (map == nu ll)
  1148                                                                getL ogger().er ror("Map d erived fie ld '" + na me + "' mu st be init ialized to  an empty  instance." ); //$NON- NLS-1$ //$ NON-NLS-2$
  1149                                                       el se if(map. size() > 0 )
  1150                                                                getL ogger().er ror("Map d erived fie ld '" + na me + "' mu st be empt y."); //$N ON-NLS-1$  //$NON-NLS -2$
  1151                                                       
  1152                                                       po pulateMapF ield(
  1153                                                                map,  
  1154                                                                data Generation Annotation .component KeyType(),  dataGener ationAnnot ation.comp onentValue Type(), 
  1155                                                                name , componen ts.getCoun t(),
  1156                                                                inst ancePopula tion, aggr egates, co mponents,  references );
  1157                                               }
  1158                                               else if( C ollection. class.isAs signableFr om(fieldTy pe) )
  1159                                               {
  1160                                                       Co llection<? > collecti on = (Coll ection<?>) field.get( instance);
  1161                                                       St ring name  = field.ge tName();
  1162                                                       if (collectio n == null)
  1163                                                                getL ogger().er ror("Colle ction deri ved field  '" + name  + "' must  be initial ized to an  empty ins tance.");  //$NON-NLS -1$ //$NON -NLS-2$
  1164                                                       el se if(coll ection.siz e() > 0)
  1165                                                                getL ogger().er ror("Colle ction deri ved field  '" + name  + "' must  be empty." ); //$NON- NLS-1$ //$ NON-NLS-2$
  1166                                                       
  1167                                                       po pulateColl ectionFiel d(
  1168                                                                coll ection, da taGenerati onAnnotati on.compone ntValueTyp e(), 
  1169                                                                name , componen ts.getCoun t(),
  1170                                                                inst ancePopula tion, aggr egates, co mponents,  references );
  1171                                               }
  1172                                               else
  1173                                               {
  1174                                                       //  the creat eInstance( ) will ret urn true i f it can
  1175                                                       //  create th e instance .  This gi ves applic ation code
  1176                                                       //  an opport unity to c reate inst ances.
  1177                                                       Ob ject obj =  createIns tance(fiel dType, ins tancePopul ation, agg regates, c omponents,  reference s);
  1178                                                       if (obj != nu ll)
  1179                                                                setR eferenceFi eld(instan ce, field,  obj);
  1180                                               }
  1181                                      }
  1182                                      finally
  1183                                      {
  1184                                               field.setA ccessible( accessible Field);
  1185                                      }
  1186                             }
  1187                    }
  1188                    catc h (Illegal ArgumentEx ception x)
  1189                    {
  1190                             x.prin tStackTrac e();
  1191                    }
  1192                    catc h (Illegal AccessExce ption x)
  1193                    {
  1194                             x.prin tStackTrac e();
  1195                    }
  1196                    fina lly
  1197                    {
  1198                             
  1199                    }
  1200           }
  1201  
  1202           /* *
  1203            *  @param in stancePopu lation
  1204            *  @param me diaTypes
  1205            *  @param de faultMedia Type
  1206            *  @return
  1207            * /
  1208           pr ivate Mock SizedInput Stream cre ateInputSt ream(
  1209                    Inst ancePopula tion insta ncePopulat ion, 
  1210                    Stri ng mediaTy pes,
  1211                    Stri ng default MediaType)
  1212           {
  1213                    Stri ng[] split MediaTypes  = ( media Types == n ull || med iaTypes.le ngth() ==  0 ? null :  mediaType s.split(", ") );
  1214                    
  1215                    Stri ng mediaTy pe = null;
  1216                    
  1217                    if(M ode.DEFAUL T == getCo nfiguratio n().getMod e())
  1218                             mediaT ype = defa ultMediaTy pe;
  1219                    if(m ediaType = = null &&  Mode.MINIM UM == getC onfigurati on().getMo de() && sp litMediaTy pes != nul l)
  1220                             mediaT ype = spli tMediaType s[0];
  1221                    if(m ediaType = = null &&  Mode.MAXIM UM == getC onfigurati on().getMo de() && sp litMediaTy pes != nul l)
  1222                             mediaT ype = spli tMediaType s[splitMed iaTypes.le ngth-1];
  1223                    if(m ediaType = = null &&  splitMedia Types != n ull)
  1224                             mediaT ype = spli tMediaType s[createRa ndomInt(0,  splitMedi aTypes.len gth-1)];
  1225                    
  1226                    retu rn mediaTy pe == null  ? null :  getInputSt ream(media Type);
  1227           }
  1228           
  1229           /* *
  1230            *  
  1231            *  @param ma p
  1232            *  @param ke yType
  1233            *  @param va lueType
  1234            *  @param na me
  1235            *  @param de siredInsta nceCount
  1236            *  @param in stancePopu lation
  1237            *  @param ag gregates
  1238            *  @param co mponents
  1239            *  @param re ferences
  1240            *  @throws I llegalAcce ssExceptio n
  1241            * /
  1242           pr ivate void  populateM apField(
  1243                    Map  map, 
  1244                    Stri ng keyType ,
  1245                    Stri ng valueTy pe,
  1246                    Stri ng name,
  1247                    int  desiredIns tanceCount ,
  1248                    Inst ancePopula tion insta ncePopulat ion,
  1249                    Aggr egationPop ulation ag gregates, 
  1250                    Comp ositionPop ulation co mponents,
  1251                    Refe renceMap r eferences)  
  1252           th rows Illeg alAccessEx ception
  1253           {
  1254                    if(k eyType ==  null)
  1255                             getLog ger().erro r("Map der ived field  '" + name  + "' must  specify a  component KeyType in  the annot ation.");  //$NON-NLS -1$ //$NON -NLS-2$
  1256                    if(v alueType = = null)
  1257                             getLog ger().erro r("Map der ived field  '" + name  + "' must  specify a  component ValueType  in the ann otation.") ; //$NON-N LS-1$ //$N ON-NLS-2$
  1258                    
  1259                    if(m ap == null )
  1260                             getLog ger().erro r("Collect ion derive d field '"  + name +  "' must be  initializ ed to an e mpty insta nce."); // $NON-NLS-1 $ //$NON-N LS-2$
  1261                    else  if(map.si ze() > 0)
  1262                             getLog ger().erro r("Collect ion derive d field '"  + name +  "' has " +  map.size( ) + " cont ained inst ances and  must be em pty."); // $NON-NLS-1 $ //$NON-N LS-2$ //$N ON-NLS-3$
  1263                    
  1264                    //Ma p currentV alue = (Ma p)field.ge t(instance );
  1265                    try
  1266                    {
  1267                             Class< ?> keyType Class = Cl ass.forNam e(keyType) ;
  1268                             Class< ?> valueTy peClass =  Class.forN ame(valueT ype);
  1269                    
  1270                             for(in t index =  0; index <  desiredIn stanceCoun t; ++index )
  1271                             {
  1272                                      Object k ey = creat eInstance( keyTypeCla ss, instan cePopulati on, aggreg ates, comp onents, re ferences);
  1273                                      Object v alue = cre ateInstanc e(valueTyp eClass, in stancePopu lation, ag gregates,  components , referenc es);
  1274                                      
  1275                                      map.put( key, value );
  1276                             }
  1277                    }
  1278                    catc h (ClassNo tFoundExce ption x)
  1279                    {
  1280                             // TOD O Auto-gen erated cat ch block
  1281                             x.prin tStackTrac e();
  1282                    }
  1283           }
  1284  
  1285           pr ivate void  populateC ollectionF ield(
  1286                    Coll ection col lection, 
  1287                    Stri ng valueTy pe,  
  1288                    Stri ng name, 
  1289                    int  desiredIns tanceCount ,
  1290                    Inst ancePopula tion insta ncePopulat ion,
  1291                    Aggr egationPop ulation ag gregates, 
  1292                    Comp ositionPop ulation co mponents,
  1293                    Refe renceMap r eferences)  
  1294           th rows Illeg alAccessEx ception
  1295           {
  1296                    if(v alueType = = null ||  valueType. length() = = 0)
  1297                             getLog ger().erro r("Collect ion derive d field '"  + name +  "' must sp ecify a co mponentVal ueType in  the annota tion."); / /$NON-NLS- 1$ //$NON- NLS-2$
  1298                    
  1299                    if(c ollection  == null)
  1300                             getLog ger().erro r("Collect ion derive d field '"  + name +  "' must be  initializ ed to an e mpty insta nce."); // $NON-NLS-1 $ //$NON-N LS-2$
  1301                    else  if(collec tion.size( ) > 0)
  1302                             getLog ger().erro r("Collect ion derive d field '"  + name +  "' has " +  collectio n.size() +  " contain ed instanc es and mus t be empty ."); //$NO N-NLS-1$ / /$NON-NLS- 2$ //$NON- NLS-3$
  1303                    else
  1304                    {
  1305                             for(in t index =  0; index <  desiredIn stanceCoun t; ++index )
  1306                             {
  1307                                      Class<?>  valueType Class;
  1308                                      try
  1309                                      {
  1310                                               valueTypeC lass = Cla ss.forName (valueType );
  1311                                               Object val ue = creat eInstance( valueTypeC lass, inst ancePopula tion, aggr egates, co mponents,  references );
  1312                                               if(value ! = null)
  1313                                                       co llection.a dd(value);
  1314                                               else
  1315                                                       ge tLogger(). error("Una ble to cre ate collec tion insta nce of typ e '" + val ueType + " '."); //$N ON-NLS-1$  //$NON-NLS -2$
  1316                                              
  1317                                      }
  1318                                      catch (C lassNotFou ndExceptio n x)
  1319                                      {
  1320                                               getLogger( ).error("N o class na med '" + v alueType +  "' found. "); //$NON -NLS-1$ // $NON-NLS-2 $
  1321                                      }
  1322                             }
  1323                    }
  1324           }
  1325           
  1326           /* *
  1327            *  
  1328            *  @param va lueArray
  1329            *  @param in dex
  1330            *  @param st ringValue
  1331            *  @return
  1332            *  @throws I llegalArgu mentExcept ion
  1333            *  @throws I llegalAcce ssExceptio n
  1334            * /
  1335           pr ivate bool ean setArr ayValue(Ob ject value Array, int  index, St ring strin gValue) 
  1336           th rows Illeg alArgument Exception,  IllegalAc cessExcept ion
  1337           {
  1338                    Clas s<?> field Type = val ueArray.ge tClass().g etComponen tType();
  1339                    Obje ct value =  null;
  1340                    
  1341                    if(S tring.clas s == field Type)
  1342                             value  = stringVa lue;
  1343                    
  1344                    else  if(Boolea n.class ==  fieldType )
  1345                             value  = new Bool ean(string Value);
  1346                    else  if(Charac ter.class  == fieldTy pe)
  1347                             value  = new Char acter(stri ngValue.ch arAt(0));
  1348                    else  if(Byte.c lass == fi eldType)
  1349                             value  = new Byte (stringVal ue);
  1350                    else  if(Short. class == f ieldType)
  1351                             value  = new Shor t(stringVa lue);
  1352                    else  if(Intege r.class ==  fieldType )
  1353                             value  = new Inte ger(string Value);
  1354                    else  if(Long.c lass == fi eldType)
  1355                             value  = new Long (stringVal ue);
  1356                    else  if(Float. class == f ieldType)
  1357                             value  = new Floa t(stringVa lue);
  1358                    else  if(Double .class ==  fieldType)
  1359                             value  = new Doub le(stringV alue);
  1360                    
  1361                    if(v alue != nu ll)
  1362                    {
  1363                             Array. set(valueA rray, inde x, value);
  1364                             return  true;
  1365                    }
  1366                    
  1367                    retu rn false;
  1368           }
  1369           
  1370           /* *
  1371            *  @param fi eld
  1372            *  @param mo ckData
  1373            *  @throws I llegalAcce ssExceptio
  1374            *  @throws I llegalArgu mentExcept ion 
  1375            *  @throws P arseExcept ion 
  1376            * /
  1377           pr ivate bool ean setSim pleField(O bject inst ance, Fiel d field, S tring valu e) 
  1378           th rows Illeg alArgument Exception,  IllegalAc cessExcept ion, Parse Exception
  1379           {
  1380                    Clas s<?> field Type = fie ld.getType ();
  1381                    
  1382                    if(S tring.clas s == field Type)
  1383                             setRef erenceFiel d(instance , field, v alue);
  1384                    
  1385                    else  if(Date.c lass == fi eldType)
  1386                             setRef erenceFiel d(instance , field, p arseDateVa lue(value) );
  1387                    
  1388                    else  if(Boolea n.class ==  fieldType )
  1389                             setRef erenceFiel d(instance , field, n ew Boolean (value) );
  1390                    else  if(Charac ter.class  == fieldTy pe)
  1391                             setRef erenceFiel d(instance , field, n ew Charact er(value.c harAt(0))  );
  1392                    else  if(Byte.c lass == fi eldType)
  1393                             setRef erenceFiel d(instance , field, n ew Byte(va lue) );
  1394                    else  if(Short. class == f ieldType)
  1395                             setRef erenceFiel d(instance , field, n ew Short(v alue) );
  1396                    else  if(Intege r.class ==  fieldType )
  1397                             setRef erenceFiel d(instance , field, n ew Integer (value) );
  1398                    else  if(Long.c lass == fi eldType)
  1399                             setRef erenceFiel d(instance , field, n ew Long(va lue) );
  1400                    else  if(Float. class == f ieldType)
  1401                             setRef erenceFiel d(instance , field, n ew Float(v alue) );
  1402                    else  if(Double .class ==  fieldType)
  1403                             setRef erenceFiel d(instance , field, n ew Double( value) );
  1404                    
  1405                    else  if(boolea n.class ==  fieldType )
  1406                             field. set( insta nce, Boole an.parseBo olean(valu e) );
  1407                    else  if(char.c lass == fi eldType)
  1408                             field. set( insta nce, value .charAt(0)  );
  1409                    else  if(byte.c lass == fi eldType)
  1410                             field. set( insta nce, Byte. parseByte( value) );
  1411                    else  if(short. class == f ieldType)
  1412                             field. set( insta nce, Short .parseShor t(value) ) ;
  1413                    else  if(int.cl ass == fie ldType)
  1414                             field. set( insta nce, Integ er.parseIn t(value) ) ;
  1415                    else  if(long.c lass == fi eldType)
  1416                             field. set( insta nce, Long. parseLong( value) );
  1417                    else  if(float. class == f ieldType)
  1418                             field. set( insta nce, Float .parseFloa t(value) ) ;
  1419                    else  if(double .class ==  fieldType)
  1420                             field. set( insta nce, Doubl e.parseDou ble(value)  );
  1421                    else
  1422                             return  false;
  1423                    
  1424                    retu rn true;
  1425           }
  1426  
  1427           /* *
  1428            *  
  1429            *  @param in stance
  1430            *  @param fi eld
  1431            *  @param va lue
  1432            *  @return
  1433            *  @throws I llegalAcce ssExceptio
  1434            *  @throws I llegalArgu mentExcept ion 
  1435            * /
  1436           pr otected vo id setRefe renceField (Object in stance, Fi eld field,  Object va lue) 
  1437           th rows Illeg alArgument Exception,  IllegalAc cessExcept ion
  1438           {
  1439                    bool ean access ible = fie ld.isAcces sible();
  1440                    try
  1441                    {
  1442                             field. setAccessi ble(true);
  1443                             field. set( insta nce, value  );
  1444                    }
  1445                    fina lly
  1446                    {
  1447                             field. setAccessi ble(access ible);
  1448                    }
  1449           }
  1450           
  1451           /* *
  1452            *  @param ty pe
  1453            *  @param pa ttern
  1454            *  @param de faultValue
  1455            *  @param mi nimum
  1456            *  @param ma ximum
  1457            *  @return
  1458            * /
  1459           pr ivate <T e xtends Obj ect> Strin g createNu mericData(
  1460                    Clas s<T> type,  
  1461                    Stri ng pattern
  1462                    Stri ng default Value, 
  1463                    doub le minimum
  1464                    doub le maximum )
  1465           {
  1466                    if(M ode.DEFAUL T == getCo nfiguratio n().getMod e())
  1467                             return  defaultVa lue != nul l ? defaul tValue : g etDefaultF ieldValue( type);
  1468                    
  1469                    // i f the patt ern is spe cified the n minimum,  maximum a re ignored
  1470                    // D ates do no t use the  pattern, t hey must s pecify min imum and m aximum 
  1471                    if(p attern !=  null && Da te.class ! = type)
  1472                             return  createRan domString( pattern);
  1473                    
  1474                    retu rn createR andomStrin g(type, mi nimum, max imum);
  1475           }
  1476  
  1477           /* *
  1478            *  @param pa ttern
  1479            *  @param de faultValue
  1480            *  @param mi nimumStrin gLength
  1481            *  @param ma ximumStrin gLength
  1482            *  @return
  1483            * /
  1484           pr ivate Stri ng createS tringData(
  1485                    Stri ng pattern
  1486                    Stri ng default Value, 
  1487                    int  minimumStr ingLength,
  1488                    int  maximumStr ingLength)
  1489           {
  1490                    if(M ode.DEFAUL T == getCo nfiguratio n().getMod e())
  1491                             return  defaultVa lue != nul l && defau ltValue.le ngth() > 0  ? default Value : DE FAULT_STRI NG_VALUE;
  1492                    
  1493                    // i f the patt ern is spe cified the n minimum,  maximum a re ignored
  1494                    // D ates do no t use the  pattern, t hey must s pecify min imum and m aximum 
  1495                    if(p attern !=  null && pa ttern.leng th() > 0)
  1496                             return  createRan domString( pattern);
  1497                    
  1498                    retu rn createR andomStrin g(String.c lass, mini mumStringL ength, max imumString Length);
  1499           }
  1500  
  1501           /* *
  1502            *  @param de faultValue
  1503            *  @param mi nimumStrin gLength
  1504            *  @param ma ximumStrin gLength
  1505            *  @return
  1506            * /
  1507           pr ivate Stri ng createD ateData(
  1508                    Stri ng default Value, 
  1509                    Stri ng minimum Value, 
  1510                    Stri ng maximum Value)
  1511           {
  1512                    try
  1513                    {
  1514                             Date m inimumDate  = parseDa teValue(mi nimumValue );
  1515                             Date m aximumDate  = parseDa teValue(ma ximumValue );
  1516                             
  1517                             Date r andomDate  = new Date
  1518                                      (long)(M ath.random () * (maxi mumDate.ge tTime() -  minimumDat e.getTime( )) ) + min imumDate.g etTime()
  1519                             );
  1520                             
  1521                             return  DEFAULT_D ATE_FORMAT .format(ra ndomDate);
  1522                    }
  1523                    catc h (ParseEx ception x)
  1524                    {
  1525                             x.prin tStackTrac e();
  1526                             return  null;
  1527                    }
  1528           }
  1529  
  1530           pr ivate Date  parseDate Value(Stri ng minimum Value) 
  1531           th rows Parse Exception
  1532           {
  1533                    Date  date;
  1534                    
  1535                    try{ date = DEF AULT_DATET IME_FORMAT .parse(min imumValue) ;}
  1536                    catc h (ParseEx ception x)
  1537                    {dat e = DEFAUL T_DATE_FOR MAT.parse( minimumVal ue);}
  1538                    retu rn date;
  1539           }
  1540  
  1541           
  1542           /* *
  1543            *  
  1544            *  @param <T >
  1545            *  @param ty pe
  1546            *  @return
  1547            * /
  1548           pu blic <T ex tends Obje ct> Object  createSim pleDataTyp e(Class<T>  type)
  1549           {
  1550                    if(  ! isSimple Type(type)  )
  1551                             return  null;
  1552                    if(M ode.DEFAUL T == getCo nfiguratio n().getMod e())
  1553                             return  getDefaul tFieldValu e(type);
  1554  
  1555                    if(S tring.clas s == type)
  1556                             return  createStr ing();
  1557                    if(D ate.class  == type)
  1558                             return  createRan domDate();
  1559                    if(B oolean.cla ss == type  || boolea n.class ==  type)
  1560                             return  createRan domBoolean ();
  1561                    if(C haracter.c lass == ty pe || char .class ==  type)
  1562                             return  createRan domChar(RA NDOM_CHAR_ PATTERN);
  1563                    if(B yte.class  == type ||  byte.clas s == type)
  1564                             return  createRan domByte(RA NDOM_BYTE_ PATTERN);
  1565                    if(S hort.class  == type | | short.cl ass == typ e)
  1566                             return  createRan domShort(R ANDOM_SHOR T_PATTERN) ;
  1567                    if(I nteger.cla ss == type  || int.cl ass == typ e)
  1568                             return  createRan domInt(RAN DOM_INT_PA TTERN);
  1569                    if(L ong.class  == type ||  long.clas s == type)
  1570                             return  createRan domLong(RA NDOM_LONG_ PATTERN);
  1571                    if(F loat.class  == type | | float.cl ass == typ e)
  1572                             return  createRan domFloat(R ANDOM_FLOA T_PATTERN) ;
  1573                    if(D ouble.clas s == type  || double. class == t ype)
  1574                             return  createRan domDouble( RANDOM_DOU BLE_PATTER N);
  1575  
  1576                    retu rn null;
  1577           }
  1578           
  1579           /* *
  1580            *  
  1581            *  @param me diaType -  formatted  as type/su btype
  1582            *  @return
  1583            * /
  1584           pu blic MockS izedInputS tream getI nputStream (String me diaType)
  1585           {
  1586                    Stri ng[] media TypeCompon ents = med iaType.spl it("/");
  1587                    if(m ediaTypeCo mponents.l ength != 2 )
  1588                    {
  1589                             logger .error("Me dia type ' " + mediaT ype + "' i s not vali d when cre ating an i nput strea m.");
  1590                             return  null;
  1591                    }
  1592                    Stri ng resourc eName = "g ov/va/med/ streamdata /" + media TypeCompon ents[0] +  "." + medi aTypeCompo nents[1];
  1593  
  1594                    URL  resourceUr l = this.g etClass(). getClassLo ader().get Resource(r esourceNam e);
  1595                    Inpu tStream wr appedStrea m = null;
  1596                    long  size = 0L ;
  1597                    
  1598                    try
  1599                    {
  1600                             URLCon nection co nn = resou rceUrl.ope nConnectio n();
  1601                             size =  conn.getC ontentLeng th();
  1602                             wrappe dStream =  conn.getIn putStream( );
  1603                    }
  1604                    catc h (IOExcep tion x)
  1605                    {
  1606                             x.prin tStackTrac e();
  1607                    }
  1608                    
  1609                    retu rn wrapped Stream ==  null ? 
  1610                             null :  
  1611                             new Mo ckSizedInp utStream(
  1612                                      new Netw orkSimulat ingInputSt ream(wrapp edStream,  getConfigu ration().g etDelayMod e(), getCo nfiguratio n().getExc eptionMode ()),
  1613                                      size,
  1614                                      mediaTyp e );
  1615           }
  1616           
  1617           /* *
  1618            *  
  1619            *  @param <T >
  1620            *  @param ty pe
  1621            *  @return
  1622            * /
  1623           pr ivate <T e xtends Obj ect> Strin g getDefau ltFieldVal ue(Class<T > type)
  1624           {
  1625                    if(S tring.clas s == type)
  1626                             return  DEFAULT_S TRING_VALU E;
  1627                    if(D ate.class  == type)
  1628                             return  DEFAULT_D ATE_FORMAT .format( D EFAULT_DAT E_VALUE );
  1629                    if(B oolean.cla ss == type  || boolea n.class ==  type)
  1630                             return  DEFAULT_B OOLEAN_VAL UE;
  1631                    if(C haracter.c lass == ty pe || char .class ==  type)
  1632                             return  DEFAULT_C HAR_VALUE;
  1633                    if(B yte.class  == type ||  byte.clas s == type)
  1634                             return  DEFAULT_B YTE_VALUE;
  1635                    if(S hort.class  == type | | short.cl ass == typ e)
  1636                             return  DEFAULT_S HORT_VALUE ;
  1637                    if(I nteger.cla ss == type  || int.cl ass == typ e)
  1638                             return  DEFAULT_I NT_VALUE;
  1639                    if(L ong.class  == type ||  long.clas s == type)
  1640                             return  DEFAULT_L ONG_VALUE;
  1641                    if(F loat.class  == type | | float.cl ass == typ e)
  1642                             return  DEFAULT_F LOAT_VALUE ;
  1643                    if(D ouble.clas s == type  || double. class == t ype)
  1644                             return  DEFAULT_D OUBLE_VALU E;
  1645  
  1646                    retu rn null;
  1647           }
  1648           
  1649           /* *
  1650            *  
  1651            *  @param cl azz
  1652            *  @return
  1653            * /
  1654           pr otected bo olean isSi mpleType(C lass<?> cl azz)
  1655           {
  1656                    retu rn 
  1657                             String .class ==  clazz ||
  1658                             Date.c lass == cl azz ||
  1659                             Boolea n.class ==  clazz ||  boolean.cl ass == cla zz ||
  1660                             Charac ter.class  == clazz | | char.cla ss == claz z ||
  1661                             Byte.c lass == cl azz || byt e.class ==  clazz ||
  1662                             Intege r.class ==  clazz ||  int.class  == clazz | |
  1663                             Long.c lass == cl azz || lon g.class ==  clazz ||
  1664                             Float. class == c lazz || fl oat.class  == clazz | |
  1665                             Double .class ==  clazz || d ouble.clas s == clazz  ||
  1666                             Void.c lass == cl azz || voi d.class ==  clazz;
  1667           }
  1668           
  1669           pr otected bo olean setS implePrope rtyValue(O bject inst ance, Meth od setter,  Class<?>  type)
  1670           {
  1671                    Stri ng default Value = ge tDefaultFi eldValue(t ype);
  1672  
  1673                    try
  1674                    {
  1675                             if(Str ing.class  == type)
  1676                                      setter.i nvoke(inst ance, defa ultValue ) ;
  1677                             else i f(byte.cla ss == type )
  1678                                      setter.i nvoke(inst ance, Byte .parseByte (defaultVa lue) );
  1679                             else i f(char.cla ss == type )
  1680                                      setter.i nvoke(inst ance, defa ultValue.c harAt(0) ) ;
  1681                             else i f(short.cl ass == typ e)
  1682                                      setter.i nvoke(inst ance, Shor t.parseSho rt(default Value) );
  1683                             else i f(int.clas s == type)
  1684                                      setter.i nvoke(inst ance, Inte ger.parseI nt(default Value) );
  1685                             else i f(long.cla ss == type )
  1686                                      setter.i nvoke(inst ance, Long .parseLong (defaultVa lue) );
  1687                             else i f(float.cl ass == typ e)
  1688                                      setter.i nvoke(inst ance, Floa t.parseFlo at(default Value) );
  1689                             else i f(double.c lass == ty pe)
  1690                                      setter.i nvoke(inst ance, Doub le.parseDo uble(defau ltValue) ) ;
  1691                             return  true;
  1692                    }
  1693                    catc h (Excepti on x)
  1694                    {
  1695                             x.prin tStackTrac e();
  1696                    }
  1697                    retu rn false;
  1698           }
  1699           
  1700           //  0x5b is l eft square  bracket ' ['
  1701           //  0x5d is r ight squar e bracket  ']'
  1702           //  0x7b is l eft curly  bracket '{ '
  1703           //  0x7d is r ight curly  bracket ' }'
  1704           //  reads as:
  1705           //  (\\x5b[^\ \x5d]*\\x5 d) - left  square bra cket, foll owed by an y number o f anything  but 
  1706           //                            right  square br acket foll owed by ri ght square  bracket
  1707           //  (?:\\x7b( [0-9]+)(?: ,([0-9]+)) ?\\x7d)? -  optionall y followed  by a left  curly bra cket
  1708           //                                              at least  one digit,  optionall y followed  by a comm a
  1709           //                                              and at le ast one di git, follo wed by a r ight curly
  1710           //                                              bracket
  1711           //  -or-
  1712           //  [^\\x5b]*  - anythin g but a le ft square  bracket
  1713           //  
  1714           pu blic stati c final St ring SIMPL E_REGEX = 
  1715                    "(\\ x5b[^\\x5d ]*\\x5d)(? :\\x7b([0- 9]+)(?:,([ 0-9]+))?\\ x7d)?|[^\\ x5b]*"; // $NON-NLS-1 $
  1716           pu blic stati c final St ring DEFAU LT_MIN = " 1"; //$NON -NLS-1$
  1717           pu blic stati c final St ring DEFAU LT_MAX = " 1"; //$NON -NLS-1$
  1718           pu blic final  static Pa ttern simp leRegexPat tern = Pat tern.compi le(SIMPLE_ REGEX);
  1719  
  1720           
  1721           pu blic stati c final in t MINIMUM_ MANY_CHILD _COUNT = 2 ;
  1722           pu blic stati c final in t DEFAULT_ MANY_CHILD _COUNT = 3 ;
  1723           pu blic stati c final in t MAXIMUM_ MANY_CHILD _COUNT = 1 6;
  1724           pr otected in t createMa nyChildCou nt()
  1725           {
  1726                    swit ch( getCon figuration ().getMode () )
  1727                    {
  1728                    case  MAXIMUM:
  1729                             return  MAXIMUM_M ANY_CHILD_ COUNT;
  1730                    case  MINIMUM:
  1731                             return  MINIMUM_M ANY_CHILD_ COUNT;
  1732                    case  RANDOMIZE :
  1733                             return  (int)( (M ath.random () * (MAXI MUM_MANY_C HILD_COUNT  - MINIMUM _MANY_CHIL D_COUNT))  + MINIMUM_ MANY_CHILD _COUNT );
  1734                    case  DEFAULT:
  1735                    defa ult:
  1736                             return  DEFAULT_M ANY_CHILD_ COUNT;
  1737                    }
  1738           }
  1739           
  1740           /* *
  1741            *  Used to c reate a te st string  when the c ontent and  size are  not import ant.
  1742            *  if random ize is tru e then the  returned  String wil l be an al phanumeric  string
  1743            *  between 3  and 32 ch aracters l ong.
  1744            *  else the  returned v alue will  be "Defaul tValue"
  1745            *  
  1746            *  @return
  1747            * /
  1748           pu blic Strin g createSt ring()
  1749           {
  1750                    swit ch( getCon figuration ().getMode () )
  1751                    {
  1752                    case  MAXIMUM:
  1753                             return  createRan domString( RANDOM_STR ING_CHARAC TER_CLASS  + STRING_M AXIMUM_REP EATER);
  1754                    case  MINIMUM:
  1755                             return  createRan domString( RANDOM_STR ING_CHARAC TER_CLASS  + STRING_M INIMUM_REP EATER);
  1756                    case  RANDOMIZE :
  1757                             return  createRan domString( RANDOM_STR ING_CHARAC TER_CLASS  + STRING_R ANDOM_REPE ATER);
  1758                    case  DEFAULT:
  1759                    defa ult:
  1760                             return  DEFAULT_S TRING_VALU E;
  1761                    }
  1762           }
  1763           
  1764           pu blic Date  createRand omDate()
  1765           {
  1766                    retu rn new Dat e(createRa ndomLong(R ANDOM_LONG _PATTERN)) ;
  1767           }
  1768           
  1769           pu blic Date  createRand omDate(Dat e minimum,  Date maxi mum)
  1770           {
  1771                    long  timestamp  = createR andomLong( minimum.ge tTime(), m aximum.get Time());
  1772                    retu rn new Dat e(timestam p);
  1773           }
  1774           
  1775           /* *
  1776            *  
  1777            *  @return
  1778            * /
  1779           pu blic boole an createR andomBoole an()
  1780           {
  1781                    retu rn Math.ra ndom() >=  .5;
  1782           }
  1783           
  1784           /* *
  1785            *  Create a  random byt e value us ing the gi ven patter n.
  1786            *  The patte rn may inc lude a [+- ] at the b eginning t o specify
  1787            *  that both  negative  and positi ve numbers  may be ge nerated.
  1788            *  This is n onstandard  regex but  makes the  internal  parsing mu ch
  1789            *  easier.
  1790            * /
  1791           pu blic byte  createRand omByte(Str ing regex)
  1792           th rows Numbe rFormatExc eption
  1793           {
  1794                    Stri ng s = cre ateRandomS tring(rege x);
  1795                    if(s .startsWit h("+")) // $NON-NLS-1 $
  1796                             s = s. substring( 1);
  1797                    retu rn Byte.pa rseByte(s) ;
  1798           }
  1799           
  1800           /* *
  1801            *  Create a  random sho rt value u sing the g iven patte rn.
  1802            *  The patte rn may inc lude a [+- ] at the b eginning t o specify
  1803            *  that both  negative  and positi ve numbers  may be ge nerated.
  1804            *  This is n onstandard  regex but  makes the  internal  parsing mu ch
  1805            *  easier.
  1806            *  
  1807            *  @param re gex
  1808            *  @return
  1809            *  @throws N umberForma tException
  1810            * /
  1811           pu blic short  createRan domShort(S tring rege x)
  1812           th rows Numbe rFormatExc eption
  1813           {
  1814                    Stri ng s = cre ateRandomS tring(rege x);
  1815                    if(s .startsWit h("+")) // $NON-NLS-1 $
  1816                             s = s. substring( 1);
  1817                    retu rn Short.p arseShort( s);
  1818           }
  1819           
  1820           /* *
  1821            *  Create a  random int  value usi ng the giv en pattern .
  1822            *  The patte rn may inc lude a [+- ] at the b eginning t o specify
  1823            *  that both  negative  and positi ve numbers  may be ge nerated.
  1824            *  This is n onstandard  regex but  makes the  internal  parsing mu ch
  1825            *  easier.
  1826            *  
  1827            *  @param re gex
  1828            *  @return
  1829            *  @throws N umberForma tException
  1830            * /
  1831           pu blic int c reateRando mInt(Strin g regex)
  1832           th rows Numbe rFormatExc eption
  1833           {
  1834                    Stri ng s = cre ateRandomS tring(rege x);
  1835                    if(s .startsWit h("+")) // $NON-NLS-1 $
  1836                             s = s. substring( 1);
  1837                    retu rn Integer .parseInt( s);
  1838           }
  1839           
  1840           /* *
  1841            *  Create a  random lon g value us ing the gi ven patter n.
  1842            *  The patte rn may inc lude a [+- ] at the b eginning t o specify
  1843            *  that both  negative  and positi ve numbers  may be ge nerated.
  1844            *  This is n onstandard  regex but  makes the  internal  parsing mu ch
  1845            *  easier.
  1846            *  
  1847            *  @param re gex
  1848            *  @return
  1849            *  @throws N umberForma tException
  1850            * /
  1851           pu blic long  createRand omLong(Str ing regex)
  1852           th rows Numbe rFormatExc eption
  1853           {
  1854                    Stri ng s = cre ateRandomS tring(rege x);
  1855                    if(s .startsWit h("+")) // $NON-NLS-1 $
  1856                             s = s. substring( 1);
  1857                    retu rn Long.pa rseLong(s) ;
  1858           }
  1859  
  1860           /* *
  1861            *  Create a  random flo at value u sing the g iven patte rn.
  1862            *  The patte rn may inc lude a [+- ] at the b eginning t o specify
  1863            *  that both  negative  and positi ve numbers  may be ge nerated.
  1864            *  This is n onstandard  regex but  makes the  internal  parsing mu ch
  1865            *  easier.
  1866            *  
  1867            *  @param re gex
  1868            *  @return
  1869            *  @throws N umberForma tException
  1870            * /
  1871           pu blic float  createRan domFloat(S tring rege x)
  1872           th rows Numbe rFormatExc eption
  1873           {
  1874                    Stri ng s = cre ateRandomS tring(rege x);
  1875                    if(s .startsWit h("+")) // $NON-NLS-1 $
  1876                             s = s. substring( 1);
  1877                    retu rn Float.p arseFloat( s);
  1878           }
  1879           
  1880           /* *
  1881            *  Create a  random dou ble value  using the  given patt ern.
  1882            *  The patte rn may inc lude a [+- ] at the b eginning t o specify
  1883            *  that both  negative  and positi ve numbers  may be ge nerated.
  1884            *  This is n onstandard  regex but  makes the  internal  parsing mu ch
  1885            *  easier.
  1886            *  
  1887            *  @param re gex
  1888            *  @return
  1889            *  @throws N umberForma tException
  1890            * /
  1891           pu blic doubl e createRa ndomDouble (String re gex)
  1892           th rows Numbe rFormatExc eption
  1893           {
  1894                    Stri ng s = cre ateRandomS tring(rege x);
  1895                    if(s .startsWit h("+")) // $NON-NLS-1 $
  1896                             s = s. substring( 1);
  1897                    retu rn Double. parseDoubl e(s);
  1898           }
  1899           
  1900           @S uppressWar nings("unc hecked")
  1901           pu blic <T ex tends Obje ct> T crea teRandomNu mber(Class <T> type,  double min imum, doub le maximum )
  1902           {
  1903                    if(B yte.class  == type)
  1904                    {
  1905                             byte v alue = cre ateRandomB yte((byte) minimum, ( byte)maxim um);
  1906                             return  (T)new By te(value);
  1907                    }
  1908                    else  if(Charac ter.class  == type)
  1909                    {
  1910                             char v alue = cre ateRandomC har((char) minimum, ( char)maxim um);
  1911                             return  (T)new Ch aracter(va lue);
  1912                    }
  1913                    else  if(Short. class == t ype)
  1914                    {
  1915                             short  value = cr eateRandom Short((sho rt)minimum , (short)m aximum);
  1916                             return  (T)new Sh ort(value) ;
  1917                    }
  1918                    else  if(Intege r.class ==  type)
  1919                    {
  1920                             int va lue = crea teRandomIn t((int)min imum, (int )maximum);
  1921                             return  (T)new In teger(valu e);
  1922                    }
  1923                    else  if(long.c lass == ty pe || Long .class ==  type)
  1924                    {
  1925                             long v alue = cre ateRandomL ong((long) minimum, ( long)maxim um);
  1926                             return  (T)new Lo ng(value);
  1927                    }
  1928                    else  if(float. class == t ype || Flo at.class = = type)
  1929                    {
  1930                             float  value = cr eateRandom Float((flo at)minimum , (float)m aximum);
  1931                             return  (T)new Fl oat(value) ;
  1932                    }
  1933                    else  if(double .class ==  type || Do uble.class  == type)
  1934                    {
  1935                             double  value = c reateRando mDouble((d ouble)mini mum, (doub le)maximum );
  1936                             return  (T)new Do uble(value );
  1937                    }
  1938                    
  1939                    retu rn null;
  1940           }
  1941           
  1942           pu blic char  createRand omChar(cha r minimum,  char maxi mum)
  1943           th rows Numbe rFormatExc eption
  1944           {
  1945                    retu rn (char)( ((double)( maximum-mi nimum)) *  Math.rando m() + (dou ble)minimu m);
  1946           }
  1947           
  1948           pu blic byte  createRand omByte(byt e minimum,  byte maxi mum)
  1949           th rows Numbe rFormatExc eption
  1950           {
  1951                    retu rn (byte)( ((double)( maximum-mi nimum)) *  Math.rando m() + (dou ble)minimu m);
  1952           }
  1953           
  1954           pu blic short  createRan domShort(s hort minim um, short  maximum)
  1955           th rows Numbe rFormatExc eption
  1956           {
  1957                    retu rn (short) (((double) (maximum-m inimum)) *  Math.rand om() + (do uble)minim um);
  1958           }
  1959           
  1960           pu blic int c reateRando mInt(int m inimum, in t maximum)
  1961           th rows Numbe rFormatExc eption
  1962           {
  1963                    retu rn (int)(( (double)(m aximum-min imum)) * M ath.random () + (doub le)minimum );
  1964           }
  1965           
  1966           pu blic long  createRand omLong(lon g minimum,  long maxi mum)
  1967           th rows Numbe rFormatExc eption
  1968           {
  1969                    retu rn (long)( ((double)( maximum-mi nimum)) *  Math.rando m() + (dou ble)minimu m);
  1970           }
  1971           
  1972           pu blic float  createRan domFloat(f loat minim um, float  maximum)
  1973           th rows Numbe rFormatExc eption
  1974           {
  1975                    retu rn (float) (((double) (maximum-m inimum)) *  Math.rand om() + (do uble)minim um);
  1976           }
  1977           
  1978           pu blic doubl e createRa ndomDouble (double mi nimum, dou ble maximu m)
  1979           th rows Numbe rFormatExc eption
  1980           {
  1981                    retu rn ((doubl e)(maximum -minimum))  * Math.ra ndom() + ( double)min imum;
  1982           }
  1983           
  1984           pu blic Strin g createRa ndomPhoneN umber()
  1985           {
  1986                    retu rn createR andomStrin g(RANDOM_P HONE_PATTE RN);
  1987           }
  1988           pu blic Strin g createRa ndomName()
  1989           {
  1990                    retu rn createR andomStrin g(RANDOM_N AME_PATTER N);
  1991           }
  1992           pu blic Strin g createRa ndomSurnam e()
  1993           {
  1994                    retu rn createR andomStrin g(RANDOM_S URNAME_PAT TERN);
  1995           }
  1996           pu blic Strin g createRa ndomGivenN ame()
  1997           {
  1998                    retu rn createR andomStrin g(RANDOM_G IVENNAME_P ATTERN);
  1999           }
  2000           pu blic Strin g createRa ndomSSN()
  2001           {
  2002                    retu rn createR andomStrin g(RANDOM_S SN_PATTERN );
  2003           }
  2004           
  2005           pu blic Strin g createRa ndomStreet Address()
  2006           {
  2007                    retu rn createR andomStrin g(RANDOM_S TREETADDRE SS_PATTERN );
  2008           }
  2009           pu blic Strin g createRa ndomApartm ent()
  2010           {
  2011                    retu rn createR andomStrin g(RANDOM_A PARTMENT_P ATTERN);
  2012           }
  2013           pu blic Strin g createRa ndomCity()
  2014           {
  2015                    retu rn createR andomStrin g(RANDOM_C ITY_PATTER N);
  2016           }
  2017           pu blic Strin g createRa ndomState( )
  2018           {
  2019                    retu rn createR andomStrin g(RANDOM_S TATE_PATTE RN);
  2020           }
  2021           pu blic Strin g createRa ndomZip()
  2022           {
  2023                    retu rn createR andomStrin g(RANDOM_Z IP_PATTERN );
  2024           }
  2025           pu blic Strin g createRa ndomZip4()
  2026           {
  2027                    retu rn createR andomStrin g(RANDOM_Z IP4_PATTER N);
  2028           }
  2029           
  2030           /* *
  2031            *  
  2032            *  @param <T >
  2033            *  @param en umerationC lass
  2034            *  @return
  2035            * /
  2036           @S uppressWar nings("unc hecked")
  2037           pu blic <T ex tends Enum > T select Enum(Class <T> enumer ationClass )
  2038           {
  2039                    try
  2040                    {
  2041                             Method  valuesMet hod = enum erationCla ss.getMeth od("values ", (Class< ?>[])null) ; //$NON-N LS-1$
  2042                             Enum[]  values =  (Enum[])(  valuesMeth od.invoke( null, (Obj ect[])null ) );
  2043                             int in dex = (Mod e.DEFAULT  == getConf iguration( ).getMode( )) ? 0 :
  2044                                      (Mode.MI NIMUM == g etConfigur ation().ge tMode()) ?  0 :
  2045                                      (Mode.MA XIMUM == g etConfigur ation().ge tMode()) ?  values.le ngth-1 :
  2046                                      (int)(Ma th.random( ) * values .length);
  2047                             String  name = va lues[index ].name();
  2048                             return  (T)Enum.v alueOf(enu merationCl ass, name) ;
  2049                    }
  2050                    catc h (Excepti on x)
  2051                    {
  2052                             x.prin tStackTrac e();
  2053                             return  null;
  2054                    }
  2055           }
  2056           
  2057           /* *
  2058            *  Given a s imple regu lar expres sion, buil d a string  in
  2059            *  the given  pattern.
  2060            *  The allow able chara cters are:
  2061            *  0-9 a-z A -Z
  2062            *  []{}
  2063            *  
  2064            *  eg: regex ="Hello[A- Z][a-z]{3} " may gene rate
  2065            *  "HelloAbg t" or "Hel loNjhs"
  2066            *  
  2067            *  @param re gex
  2068            *  @return
  2069            * /
  2070           pu blic Strin g createRa ndomString (String re gex)
  2071           {
  2072                    Stri ngBuilder  sb = new S tringBuild er();
  2073                    
  2074                    Matc her matche r = simple RegexPatte rn.matcher (regex);
  2075                    
  2076                    whil e( matcher .find() )
  2077                    {
  2078                             String  group = m atcher.gro up();
  2079                             // if  group coun t is 1 the n this is  a literal  string
  2080                             if( ma tcher.grou p(1) == nu ll)
  2081                                      sb.appen d(group);
  2082                             else                      //  not a lit eral group , need to  generate a  string by  pattern
  2083                             {
  2084                                      String p attern = m atcher.gro up(1);
  2085                                      pattern  = pattern. substring( 1, pattern .length()- 1);
  2086                                      int minC harCount =  Integer.p arseInt( 
  2087                                               matcher.gr oup(2) !=  null ? 
  2088                                                       ma tcher.grou p(2) : 
  2089                                                       DE FAULT_MIN  );
  2090                                      int maxC harCount =  Integer.p arseInt( 
  2091                                               matcher.gr oup(3) !=  null ? 
  2092                                                       ma tcher.grou p(3) :
  2093                                                       ma tcher.grou p(2) != nu ll ? 
  2094                                                                matc her.group( 2) : 
  2095                                                                DEFA ULT_MAX );
  2096                                      
  2097                                      int actu alCharCoun t = (int)(  (Math.ran dom() * (m axCharCoun t - minCha rCount)) +  minCharCo unt ); 
  2098                                      for(int  index=0; i ndex < act ualCharCou nt; ++inde x)
  2099                                               sb.append(  createRan domChar(pa ttern) );
  2100                             }
  2101                    }
  2102                    
  2103                    retu rn sb.toSt ring();
  2104           }
  2105  
  2106           /* *
  2107            *  
  2108            *  @param ty pe
  2109            *  @param mi nimum
  2110            *  @param ma ximum
  2111            *  @return
  2112            * /
  2113           pu blic <T ex tends Obje ct> String  createRan domString( Class<T> t ype, doubl e minimum,  double ma ximum)
  2114           {
  2115                    if(S tring.clas s == type)
  2116                             return  createRan domString( "[a-zA-Z0- 9]{" + (in t)minimum  + "," + (i nt)maximum  + "}" );  //$NON-NLS -1$ //$NON -NLS-2$ // $NON-NLS-3 $
  2117                    else  if(Date.c lass == ty pe)
  2118                    {
  2119                             return  null;
  2120                    }
  2121                    else
  2122                             return  "" + crea teRandomNu mber(type,  minimum,  maximum);  //$NON-NLS -1$
  2123           }
  2124           
  2125           pu blic final  static St ring CHARA CTER_CLASS _REGEX = " ([^\\x2d\\ x26])([\\x 2d\\x26])( [^\\x2d\\x 26])|(.)";  //$NON-NL S-1$
  2126           pu blic final  static Pa ttern char acterClass Pattern =  Pattern.co mpile(CHAR ACTER_CLAS S_REGEX);
  2127           
  2128           pu blic final  static in t LEFT_OPE RAND_GROUP  = 1;
  2129           pu blic final  static in t OPERATOR _GROUP = 2 ;
  2130           pu blic final  static in t RIGHT_OP ERAND_GROU P = 3;
  2131           pu blic final  static in t LITERAL_ GROUP = 4;
  2132           
  2133           /* *
  2134            *  This will  take a St ring meeti ng the reg ular expre ssion defi ned above
  2135            *  and parse  it to det ermine the  acceptabl e characte r ranges a nd then
  2136            *  randomly  pick a cha racter in  that range .
  2137            *  The regex  results i n somethin g like:
  2138            *  "a" => gr oup(0)="a" , group(1) =null, gro up(2)=null , group(3) ="a"
  2139            *  "a-b" =>  group(0)=" a-b", grou p(1)="a",  group(2)=" b", group( 3)=null
  2140            *  "cd-vf" ( requires m ultiple "f ind()" cal ls) =>
  2141            *  1.) group (0)="c",    group(1)= null, grou p(2)=null,  group(3)= null, grou p(4)="c"
  2142            *  2.) group (0)="d-v",  group(1)= "d",  grou p(2)="-",   group(3)= "v", group (4)=null
  2143            *  3.) group (0)="f",    group(1)= null, grou p(2)=null,  group(3)= null, grou p(4)="f"
  2144            *  2.) group (0)="d|v",  group(1)= "d",  grou p(2)="|",   group(3)= "v", group (4)=null
  2145            *  
  2146            *  @param pa ttern - sh ould be in  the form  '[' + some  character s + ']'
  2147            *  @return
  2148            * /
  2149           pr otected ch ar createR andomChar( String pat tern)
  2150           {
  2151                    Stri ngBuilder  sb = new S tringBuild er();
  2152                    Matc her charac terClassMa tcher = ch aracterCla ssPattern. matcher(pa ttern);
  2153                    
  2154                    whil e(characte rClassMatc her.find() )
  2155                    {
  2156                             if( ch aracterCla ssMatcher. group(LITE RAL_GROUP)  != null )
  2157                                      sb.appen d(characte rClassMatc her.group( LITERAL_GR OUP));
  2158                             else
  2159                             {
  2160                                      char lef tOperand=c haracterCl assMatcher .group(LEF T_OPERAND_ GROUP).cha rAt(0);
  2161                                      char rig htOperand= characterC lassMatche r.group(RI GHT_OPERAN D_GROUP).c harAt(0);
  2162                                      String o perator=ch aracterCla ssMatcher. group(OPER ATOR_GROUP );
  2163                                      
  2164                                      if( "-". equals(ope rator) ) / /$NON-NLS- 1$
  2165                                               for(char c h=leftOper and; ch <=  rightOper and; ++ch)
  2166                                                       sb .append(ch );
  2167                                      else if(  "&".equal s(operator ) ) //$NON -NLS-1$
  2168                                               if(leftOpe rand == ri ghtOperand )
  2169                                                       sb .append(le ftOperand) ;
  2170                             }
  2171                    }
  2172                    
  2173                    int  random = ( int)(Math. random() *  sb.length ());
  2174                    retu rn sb.char At(random) ;
  2175           }
  2176           
  2177           /* *
  2178            *  Write fro m minSize  to maxSize  random by tes to the  given cha nnel
  2179            *  
  2180            *  @param wr itableChan nel
  2181            *  @param mi nSize
  2182            *  @param ma xSize
  2183            *  @throws I OException  
  2184            * /
  2185           pu blic void  writeRando mBytes(Wri tableByteC hannel wri tableChann el, int mi nSize, int  maxSize) 
  2186           th rows IOExc eption
  2187           {
  2188                    int  size = Mat h.abs( cre ateRandomI nt(minSize , maxSize)  );
  2189                    Byte Buffer buf fer = Byte Buffer.all ocateDirec t(size);
  2190                    for( int index= 0; index <  size; ++i ndex)
  2191                             buffer .put(creat eRandomByt e((byte)0,  (byte)255 ));
  2192                    buff er.flip();
  2193                    writ ableChanne l.write(bu ffer);
  2194           }
  2195           
  2196           /* *
  2197            *  
  2198            *  @param in stance
  2199            *  @param in stancePopu lation
  2200            *  @param ch ildren
  2201            * /
  2202           pr otected vo id populat eChildrenT hroughSett ers(
  2203                    Obje ct instanc e, 
  2204                    Inst ancePopula tion insta ncePopulat ion, 
  2205                    Aggr egationPop ulation ch ildren,
  2206                    Comp ositionPop ulation co mponents,
  2207                    Refe renceMap r eferences)
  2208           {
  2209                    if(A ggregation Population .NONE == c hildren)
  2210                             return ;
  2211                    
  2212                    for( Iterator<M ethod> set terIterato r=declared SetterMeth ods(instan ce); sette rIterator. hasNext();  )
  2213                    {
  2214                             Method  setter =  setterIter ator.next( );
  2215                             Class< ?> resultT ype = sett er.getPara meterTypes ()[0];
  2216                             if( is SimpleType (resultTyp e) )
  2217                                      setSimpl ePropertyV alue(insta nce, sette r, resultT ype);
  2218                             
  2219                             else i f( resultT ype.isArra y() )
  2220                             {
  2221                                      Class<?>  component Type = res ultType.ge tComponent Type();
  2222                                      Object[]  value = n ew Object[ Aggregatio nPopulatio n.ONE == c hildren ?  1 : 3];
  2223                                      for( int  index=0;  index < ch ildren.get Count(); + +index )
  2224                                               value[inde x] = creat eInstance( componentT ype, insta ncePopulat ion, child ren, compo nents, ref erences);
  2225  
  2226                                      try
  2227                                      {
  2228                                               setter.inv oke(instan ce, result Type.cast( value));
  2229                                      }
  2230                                      catch (E xception x )
  2231                                      {
  2232                                               x.printSta ckTrace();
  2233                                      }
  2234                             }
  2235                             // all  reference  types, in cluding co llections
  2236                             else
  2237                             {
  2238                                      try
  2239                                      {
  2240                                               Object val ue = creat eInstance( resultType , instance Population , children , componen ts, refere nces);
  2241                                               if(value ! = null)
  2242                                                       se tter.invok e(instance , resultTy pe.cast(va lue));
  2243                                      }
  2244                                      catch (E xception x )
  2245                                      {
  2246                                               x.printSta ckTrace();
  2247                                      }
  2248                             }
  2249                    }
  2250           }
  2251           
  2252           pr ivate stat ic final S tring GETT ER_REGEX =  "(is|get) ([A-Z][A-Z a-z0-9_]*) "; //$NON- NLS-1$
  2253           pr otected st atic Itera tor<Method > declared GetterMeth ods(Object  instance)
  2254           {
  2255                    List <Method> d eclaredGet terList =  new ArrayL ist<Method >();
  2256                    Clas s<?> insta nceClass =  instance. getClass() ;
  2257                    Meth od[] decla redMethods  = instanc eClass.get DeclaredMe thods();
  2258                    for( Method met hod : decl aredMethod s)
  2259                             if( Pa ttern.matc hes(GETTER _REGEX, me thod.getNa me()) && 
  2260                                      method.g etReturnTy pe() != Vo id.class & &
  2261                                      (method. getParamet erTypes()  == null ||  method.ge tParameter Types().le ngth == 0)  )
  2262                                               declaredGe tterList.a dd(method) ;
  2263                    
  2264                    retu rn declare dGetterLis t.iterator ();
  2265           }
  2266           
  2267           pr ivate stat ic final S tring SETT ER_REGEX =  "(set)([A -Z][A-Za-z 0-9_]*)";  //$NON-NLS -1$
  2268           pr otected st atic Itera tor<Method > declared SetterMeth ods(Object  instance)
  2269           {
  2270                    List <Method> d eclaredSet terList =  new ArrayL ist<Method >();
  2271                    Clas s<?> insta nceClass =  instance. getClass() ;
  2272                    Meth od[] decla redMethods  = instanc eClass.get DeclaredMe thods();
  2273                    for( Method met hod : decl aredMethod s)
  2274                             if( Pa ttern.matc hes(SETTER _REGEX, me thod.getNa me()) && 
  2275                                      method.g etReturnTy pe() == Vo id.class & &
  2276                                      method.g etParamete rTypes().l ength == 1 )
  2277                                               declaredSe tterList.a dd(method) ;
  2278                    
  2279                    retu rn declare dSetterLis t.iterator ();
  2280           }
  2281           
  2282           /* *
  2283            *  a test dr iver of th e random s tring gene rator
  2284            *  @param ar gv
  2285            * /
  2286           pu blic stati c void mai n(String[]  argv)
  2287           {
  2288                    Gene ricDataGen erator gen erator = n ew Generic DataGenera tor(Mode.R ANDOMIZE);
  2289                    //Sy stem.out.p rintln( ge nerator.cr eateExamIn stance(Ins tancePopul ation.FULL , ChildIns tancesPopu lation.MAN Y).toStrin g() );
  2290                    //Sy stem.out.p rintln( ge nerator.cr eateExamSi teInstance (InstanceP opulation. FULL, Chil dInstances Population .MANY).toS tring() );
  2291                    
  2292                    Syst em.out.pri ntln("Rand om byte "  + generato r.createRa ndomByte(  (byte)-32,  (byte)32)  ); //$NON -NLS-1$
  2293                    Syst em.out.pri ntln("Rand om byte "  + generato r.createRa ndomByte(  (byte)-32,  (byte)32)  ); //$NON -NLS-1$
  2294                    
  2295                    Syst em.out.pri ntln("Rand om char "  + generato r.createRa ndomChar(" [a-z]") );  //$NON-NL S-1$ //$NO N-NLS-2$
  2296                    Syst em.out.pri ntln("Rand om char "  + generato r.createRa ndomChar(  (char)0x60 , (char)0x 72) ); //$ NON-NLS-1$
  2297                    
  2298                    Syst em.out.pri ntln("Rand om short "  + generat or.createR andomShort ("[+-][1-9 ][0-9]{0,4 }") ); //$ NON-NLS-1$  //$NON-NL S-2$
  2299                    Syst em.out.pri ntln("Rand om short "  + generat or.createR andomShort ( (short)- 128, (shor t)128) );  //$NON-NLS -1$
  2300                    
  2301                    Syst em.out.pri ntln("Rand om int " +  generator .createRan domInt("[+ -][1-9][0- 9]{0,6}")  ); //$NON- NLS-1$ //$ NON-NLS-2$
  2302                    Syst em.out.pri ntln("Rand om int " +  generator .createRan domInt( (i nt)-1024,  (int)1024)  ); //$NON -NLS-1$
  2303                    
  2304                    Syst em.out.pri ntln("Rand om long "  + generato r.createRa ndomLong(" [+-][1-9][ 0-9]{0,8}" ) ); //$NO N-NLS-1$ / /$NON-NLS- 2$
  2305                    Syst em.out.pri ntln("Rand om long "  + generato r.createRa ndomLong(  (long)-102 4, (long)1 024) ); // $NON-NLS-1 $
  2306                    
  2307                    Syst em.out.pri ntln("Rand om float "  + generat or.createR andomFloat ("[+-][1-9 ][0-9]{0,8 }.[0-9]{3, 4}") ); // $NON-NLS-1 $ //$NON-N LS-2$
  2308                    Syst em.out.pri ntln("Rand om float "  + generat or.createR andomFloat ( (float)- 1024.0001,  (float)10 24.9999) ) ; //$NON-N LS-1$
  2309                    
  2310                    Syst em.out.pri ntln("Rand om double  " + genera tor.create RandomDoub le("[+-][1 -9][0-9]{0 ,8}.[0-9]{ 3,4}") );  //$NON-NLS -1$ //$NON -NLS-2$
  2311                    Syst em.out.pri ntln("Rand om double  " + genera tor.create RandomDoub le( (doubl e)-2048.00 01, (float )2048.9999 ) ); //$NO N-NLS-1$
  2312                    
  2313                    for( int index= 0; index<1 0; ++index )
  2314                             System .out.print ln("Random  String (l ooks like  a float)"  + generato r.createRa ndomString ("[+-][1-9 ].[0-9]{2} ")); //$NO N-NLS-1$ / /$NON-NLS- 2$
  2315                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("HelloW orld")); / /$NON-NLS- 1$ //$NON- NLS-2$
  2316                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("HelloW orld[a-z]" )); //$NON -NLS-1$ // $NON-NLS-2 $
  2317                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("HelloW orld[a-z]{ 3,4}")); / /$NON-NLS- 1$ //$NON- NLS-2$
  2318                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("HelloW orld[abcde f]{3,3}")) ; //$NON-N LS-1$ //$N ON-NLS-2$
  2319                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("HelloW orld[abc12 3]{3,3}")) ; //$NON-N LS-1$ //$N ON-NLS-2$
  2320                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("HelloW orld[A-Z][ a-z0-9]{3, 3}")); //$ NON-NLS-1$  //$NON-NL S-2$
  2321                    Syst em.out.pri ntln("Rand om String  (looks lik e a name)"  + generat or.createR andomStrin g("[A-Z][a -z]{3,9} [ A-Z] [A-Z] [a-z]{3,12 }")); //$N ON-NLS-1$  //$NON-NLS -2$
  2322                    Syst em.out.pri ntln("Rand om String  (3 digits) " + genera tor.create RandomStri ng("[1-9][ 0-9]{2}")) ; //$NON-N LS-1$ //$N ON-NLS-2$
  2323                    Syst em.out.pri ntln("Rand om String  " + genera tor.create RandomStri ng("[1-9][ 0-9]{9}V[1 -9][0-9]{5 }")); //$N ON-NLS-1$  //$NON-NLS -2$
  2324                    for( int index= 0; index<1 0; ++index )
  2325                             System .out.print ln( "Rando m String   (looks lik e a SSN)"  + generato r.createRa ndomString ("[1-9][0- 9]{2}-[0-9 ]{2}-[0-9] {4}") ); / /$NON-NLS- 1$ //$NON- NLS-2$
  2326                    for( int index= 0; index<1 0; ++index )
  2327                             System .out.print ln( "Rando m String   (looks lik e a phone  number)" +  generator .createRan domString( "([1-9][0- 9]{2})[1-9 ][0-9]{2}- [0-9]{4}")  ); //$NON -NLS-1$ // $NON-NLS-2 $
  2328                    
  2329                    for( int index= 0; index<1 0; ++index )
  2330                             System .out.print ln( "Rando mly select ed enum "  + generato r.selectEn um(Mode.cl ass) + "."  ); //$NON -NLS-1$ // $NON-NLS-2 $
  2331                    
  2332                    for( int index= 0; index<1 0; ++index )
  2333                             System .out.print ln( "Rando mly create d String{3 2,1024} "  + generato r.createSt ringData(n ull, null,  32, 1024)  + "." );  //$NON-NLS -1$ //$NON -NLS-2$
  2334           }
  2335   }