377. EPMO Open Source Coordination Office Redaction File Detail Report

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

377.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionContext\main\src\java\gov\va\med\imaging\transactioncontext TransactionContextProxyInvocationHandler.java Mon Dec 4 21:34:48 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\TransactionContext\main\src\java\gov\va\med\imaging\transactioncontext TransactionContextProxyInvocationHandler.java Mon Dec 4 22:06:05 2017 UTC

377.2 Comparison summary

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

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

377.4 Active regular expressions

No regular expressions were active.

377.5 Comparison detail

  1   /**
  2    * 
  3    */
  4   package go v.va.med.i maging.tra nsactionco ntext;
  5  
  6   import gov .va.med.Ap plicationP ropertyAcc essor;
  7   import gov .va.med.im aging.Stac kTraceAnal yzer;
  8   import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmPrinci pal;
  9   import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmSecuri tyContext;
  10   import gov .va.med.im aging.tomc at.vistare alm.VistaR ealmPrinci pal.Authen ticationCr edentialsT ype;
  11   import jav a.io.IOExc eption;
  12   import jav a.lang.ref lect.Invoc ationHandl er;
  13   import jav a.lang.ref lect.Metho d;
  14   import org .apache.lo gging.log4 j.LogManag er;
  15   import org .apache.lo gging.log4 j.Logger;
  16  
  17   /**
  18    * @author         
BECKEC
  19    *
  20    */
  21   public cla ss Transac tionContex tProxyInvo cationHand ler
  22   implements  Invocatio nHandler
  23   {
  24           /* *
  25            *  Meta Meth od method  name const ants
  26            * /
  27           pr ivate stat ic final S tring SET_ MEMENTO =  "setMement o";
  28           pr ivate stat ic final S tring GET_ CONTEXT_DE BUG_STATE  = "getCont extDebugSt ate";
  29           pr ivate stat ic final S tring IS_C LIENT_PRIN CIPAL = "i sClientPri ncipal";
  30           pr ivate stat ic final S tring GET_ DISPLAY_ID ENTITY = " getDisplay Identity";
  31           pr ivate stat ic final S tring CLEA R = "clear ";
  32           pr ivate stat ic final S tring GET_ MEMENTO =  "getMement o";
  33           pr ivate stat ic final S tring GET_ IDENTITY =  "getIdent ity";
  34           pr ivate stat ic final S tring CREA TE_CHILD_C LONE = "cr eateChildC lone";
  35           pr ivate stat ic final S tring GET_ ADDITIONAL _DEBUG_INF ORMATION =  "getAddit ionalDebug Informatio n";
  36           
  37           /* *
  38            *  The stand ard prefix  for a GET  accessor.
  39            *  Note we o nly do Str ing proper ties so no  "is" meth ods but we  have
  40            *  some spec ial cases  with boole n types in  VistaReal mPrincipal
  41            * /
  42           pr ivate stat ic final S tring GET_ ACCESSOR_P REFIX = "g et";
  43           pr ivate stat ic final S tring IS_A CCESSOR_PR EFIX = "is ";
  44           
  45           /* *
  46            *  The stand ard prefix  for a SET  accessor.
  47            * /
  48           pr ivate stat ic final S tring SET_ ACCESSOR_P REFIX = "s et";
  49           
  50           pr ivate stat ic final S tring ADD_ ACCESSOR_P REFIX = "a dd";
  51           
  52           /* *
  53            *  Logger ac cessor met hods get t heir value s from app lication p roperties
  54            *  preferent ially over  "real" pr operties. 
  55            * /
  56           pr ivate stat ic final S tring LOGG ER_ACCESSO R_PREFIX =  "Logger";            // i.e. as  in getLog gerSiteNam e()
  57           pr ivate stat ic final S tring LOGG ER_PROPERT Y_PREFIX =  "logger";            // i.e. lo ggerSiteNa me
  58           
  59           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ====
  60           //  Known Pro perties by  the type  of access  granted
  61           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ====
  62           
  63           //  Immutable  Propertie s
  64           pr ivate stat ic final S tring ACCE SS_CODE_PR OPERTY = " accessCode ";         // mutable  if princi pal is cli ent type 
  65           pr ivate stat ic final S tring VERI FY_CODE_PR OPERTY = " verifyCode ";         // mutable  if princi pal is cli ent type 
  66           pr ivate stat ic final S tring NAME _PROPERTY  = "name";
  67           pr ivate stat ic final S tring REAL M_PROPERTY  = "realm" ;
  68           pr ivate stat ic final S tring AUTH ENTICATED_ BY_DELEGAT E_PROPERTY  = "authen ticatedByD elegate";
  69           pr ivate stat ic final S tring CRED ENTIALS_TY PE_PROPERT Y = "crede ntialsType ";
  70           pr ivate stat ic final S tring SECU RITY_HASHC ODE_PROPER TY = "secu rityHashCo de";
  71           pr ivate stat ic final S tring AUTH ENTICATED_ BY_VISTA_P ROPERTY =  "authentic atedByVist a";
  72  
  73           pr ivate stat ic boolean  isImmutab leProperty (String pr opertyName )
  74           {
  75                    retu rn 
  76                             ACCESS _CODE_PROP ERTY.equal s(property Name) ||
  77                             VERIFY _CODE_PROP ERTY.equal s(property Name) ||
  78                             NAME_P ROPERTY.eq uals(prope rtyName) | |
  79                             REALM_ PROPERTY.e quals(prop ertyName)  ||
  80                             AUTHEN TICATED_BY _DELEGATE_ PROPERTY.e quals(prop ertyName)  ||
  81                             CREDEN TIALS_TYPE _PROPERTY. equals(pro pertyName)  ||
  82                             SECURI TY_HASHCOD E_PROPERTY .equals(pr opertyName ) ||
  83                             AUTHEN TICATED_BY _VISTA_PRO PERTY.equa ls(propert yName);
  84           }
  85           
  86           //  Requestor  Propertie s
  87           pr ivate stat ic final S tring SITE _NAME_PROP ERTY = "si teName";
  88           pr ivate stat ic final S tring SITE _NUMBER_PR OPERTY = " siteNumber ";
  89           pr ivate fina l static S tring SSN_ PROPERTY =  "ssn";
  90           pr ivate stat ic final S tring DUZ_ PROPERTY =  "duz";
  91           pr ivate stat ic final S tring FULL NAME_PROPE RTY = "ful lName";
  92           pr ivate stat ic final S tring SECU RITY_TOKEN _PROPERTY  = "brokerS ecurityTok en";
  93           pr ivate stat ic final S tring CACH E_LOCATION _ID_PROPER TY = "cach eLocationI d";
  94           pr ivate stat ic final S tring USER _DIVISION_ PROPERTY =  "userDivi sion";
  95  
  96           pr ivate stat ic boolean  isRequest orProperty (String pr opertyName )
  97           {
  98                    retu rn  
  99                             SITE_N AME_PROPER TY.equals( propertyNa me) ||
  100                             SITE_N UMBER_PROP ERTY.equal s(property Name) ||
  101                             SSN_PR OPERTY.equ als(proper tyName) ||
  102                             DUZ_PR OPERTY.equ als(proper tyName) ||
  103                             FULLNA ME_PROPERT Y.equals(p ropertyNam e) ||
  104                             SECURI TY_TOKEN_P ROPERTY.eq uals(prope rtyName) |
  105                             CACHE_ LOCATION_I D_PROPERTY .equals(pr opertyName ) ||
  106                             USER_D IVISION_PR OPERTY.equ als(proper tyName);
  107           }
  108           
  109           pr ivate fina l static S tring DEBU G_PROPERTY  = "debugI nformation ";
  110           
  111           pr ivate stat ic boolean  isDebugPr operty(Str ing proper tyName)
  112           {
  113                    retu rn DEBUG_P ROPERTY.eq uals(prope rtyName);
  114           }
  115           
  116           //  Applicati onProperty Accessor i nstances w ill take a ny Object  instance a nd try to
  117           // extract a  value in t he desired  type.  If  they cann ot do the  type conve rsion then
  118           //  they retu rn null.
  119           pr ivate stat ic Applica tionProper tyAccessor <String> s tringPrope rtyAccesso r;
  120           
  121           pr ivate stat ic Applica tionProper tyAccessor <Boolean>  booleanPro pertyAcces sor;
  122           
  123           pr ivate stat ic Applica tionProper tyAccessor <Character > characte rPropertyA ccessor;
  124           
  125           pr ivate stat ic Applica tionProper tyAccessor <Byte> byt ePropertyA ccessor;
  126           pr ivate stat ic Applica tionProper tyAccessor <Short> sh ortPropert yAccessor;
  127           
  128           pr ivate stat ic Applica tionProper tyAccessor <Integer>  integerPro pertyAcces sor;
  129           pr ivate stat ic Applica tionProper tyAccessor <Long> lon gPropertyA ccessor;
  130  
  131           pr ivate stat ic Applica tionProper tyAccessor <Float> fl oatPropert yAccessor;
  132           pr ivate stat ic Applica tionProper tyAccessor <Double> d oublePrope rtyAccesso r;
  133           
  134           pr ivate stat ic Applica tionProper tyAccessor <Object> o bjectPrope rtyAccesso r;
  135           
  136           pr ivate stat ic boolean  warnOnPro pertOverwr ite = fals e;
  137           
  138           st atic
  139       {
  140                    stri ngProperty Accessor =  
  141                             new Ap plicationP ropertyAcc essor<Stri ng>("toStr ing", null );
  142                    
  143                    try
  144           {
  145                    bool eanPropert yAccessor 
  146                             new Ap plicationP ropertyAcc essor<Bool ean>("bool eanValue",  
  147                                      Boolean. class.getM ethod("par seBoolean" , new Clas s[]{String .class})
  148                             );
  149           } 
  150                    catc h (Excepti on e)
  151           {
  152                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating b oolean pro perty acce ssor", e);
  153           } 
  154                    
  155                    char acterPrope rtyAccesso r = 
  156                             new Ap plicationP ropertyAcc essor<Char acter>("ch arValue",  null);
  157  
  158                    try
  159                    {
  160                             bytePr opertyAcce ssor = 
  161                                      new Appl icationPro pertyAcces sor<Byte>( "byteValue ", 
  162                                               Byte.class .getMethod ("parseByt e", new Cl ass[]{Stri ng.class})
  163                                      );
  164           } 
  165                    catc h (Excepti on e)
  166           {
  167                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating b yte proper ty accesso r", e);
  168           } 
  169  
  170                    try
  171                    {
  172                             shortP ropertyAcc essor = 
  173                                      new Appl icationPro pertyAcces sor<Short> ("shortVal ue", 
  174                                               Short.clas s.getMetho d("parseSh ort", new  Class[]{St ring.class })
  175                                      );
  176           } 
  177                    catc h (Excepti on e)
  178           {
  179                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating s hort prope rty access or", e);
  180           } 
  181                    
  182                    try
  183                    {
  184                             intege rPropertyA ccessor = 
  185                                      new Appl icationPro pertyAcces sor<Intege r>("intVal ue", 
  186                                               Integer.cl ass.getMet hod("parse Int", new  Class[]{St ring.class })
  187                                      );
  188           } 
  189                    catc h (Excepti on e)
  190           {
  191                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating i nteger pro perty acce ssor", e);
  192           } 
  193                    
  194                    try
  195                    {
  196                             longPr opertyAcce ssor = 
  197                                      new Appl icationPro pertyAcces sor<Long>( "longValue ", 
  198                                               Long.class .getMethod ("parseLon g", new Cl ass[]{Stri ng.class})
  199                                      );
  200           } 
  201                    catc h (Excepti on e)
  202           {
  203                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating l ong proper ty accesso r", e);
  204           } 
  205  
  206                    try
  207                    {
  208                             floatP ropertyAcc essor = 
  209                                      new Appl icationPro pertyAcces sor<Float> ("floatVal ue", 
  210                                               Float.clas s.getMetho d("parseFl oat", new  Class[]{St ring.class })
  211                                      );
  212           } 
  213                    catc h (Excepti on e)
  214           {
  215                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating f loat prope rty access or", e);
  216           } 
  217                    
  218                    try
  219                    {
  220                             double PropertyAc cessor = 
  221                                      new Appl icationPro pertyAcces sor<Double >("doubleV alue", 
  222                                               Double.cla ss.getMeth od("parseD ouble", ne w Class[]{ String.cla ss})
  223                                      );
  224           } 
  225                    catc h (Excepti on e)
  226           {
  227                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating d ouble prop erty acces sor", e);
  228           } 
  229                    
  230                    try
  231                    {
  232                             object PropertyAc cessor = n ew Applica tionProper tyAccessor <Object>(n ull, null) ;
  233           } 
  234                    catc h (Excepti on e)
  235           {
  236                             LogMan ager.getLo gger(Trans actionCont extProxyIn vocationHa ndler.clas s).error(" Exception  creating d ouble prop erty acces sor", e);
  237           } 
  238       }
  239           
  240           pr ivate stat ic Applica tionProper tyAccessor <?> getPro pertyAcces sorForType (Class<?>  clazz)
  241           {
  242                    if(B oolean.cla ss.isAssig nableFrom( clazz) ||  Boolean.TY PE == claz z )
  243                             return  booleanPr opertyAcce ssor;
  244                    if(B yte.class. isAssignab leFrom(cla zz) || Byt e.TYPE ==  clazz)
  245                             return  bytePrope rtyAccesso r;
  246                    if(C haracter.c lass.isAss ignableFro m(clazz) | | Characte r.TYPE ==  clazz )
  247                             return  character PropertyAc cessor;
  248                    if(S hort.class .isAssigna bleFrom(cl azz) || Sh ort.TYPE = = clazz )
  249                             return  shortProp ertyAccess or;
  250                    if(I nteger.cla ss.isAssig nableFrom( clazz) ||  Integer.TY PE == claz z )
  251                             return  integerPr opertyAcce ssor;
  252                    if(L ong.class. isAssignab leFrom(cla zz) || Lon g.TYPE ==  clazz )
  253                             return  longPrope rtyAccesso r;
  254                    if(F loat.class .isAssigna bleFrom(cl azz) || Fl oat.TYPE = = clazz )
  255                             return  floatProp ertyAccess or;
  256                    if(D ouble.clas s.isAssign ableFrom(c lazz) || D ouble.TYPE  == clazz  )
  257                             return  doublePro pertyAcces sor;
  258                    if(S tring.clas s == clazz  )
  259                             return  stringPro pertyAcces sor;
  260                    
  261                    retu rn objectP ropertyAcc essor;
  262           }
  263  
  264           /* *
  265            *  if true t hen a warn ing will b e logged w hen a prop erty value  is overwr itten
  266            *  this shou ld usually  be false  because it  can produ ce so much  log outpu t that
  267            *  it signif icantly sl ows unit t esting
  268            *  @return
  269            * /
  270           pu blic stati c boolean  isWarnOnPr opertOverw rite()
  271           {
  272                    retu rn warnOnP ropertOver write;
  273           }
  274  
  275           pu blic stati c void set WarnOnProp ertOverwri te(boolean  warnOnPro pertOverwr ite)
  276           {
  277                    Tran sactionCon textProxyI nvocationH andler.war nOnPropert Overwrite  = warnOnPr opertOverw rite;
  278           }
  279  
  280           /* *
  281            *  Return a  boolean in dicating i f a transa ction cont ext has be en establi shed.
  282            *  Returns t rue if a c all to cre ate a Tran sactionCon textProxyI nvocationH andler wou ld
  283            *  result in  a valid t ransaction  context.   If the un derlying s ecurity co ntext does  not
  284            *  exist the n this wil l return f alse and a  new insta nce of Tra nsactionCo ntextProxy Invocation Handler
  285            *  will be r unning aga inst a "cl ient" inst ance of Pr incipal wi th no real  security  context.
  286            *  Note that  this diff ers from t esting the  get() met hod result  for null,  which 
  287            *  will crea te a trans action con text.
  288            *  
  289            *  @return
  290            * /
  291           pu blic stati c boolean  isTransact ionContext Establishe d()
  292           {
  293                    retu rn VistaRe almSecurit yContext.g et() != nu ll;
  294           }
  295           
  296           //  the insta nce logger  
  297           Lo gger logge r = LogMan ager.getLo gger(this. getClass() );
  298  
  299           //  the Vista RealmPrinc ipal insta nce that t his transa ction cont ext wraps
  300           pr ivate fina l VistaRea lmPrincipa l principa l;
  301  
  302           /* *
  303            *  Construct  a new Tra nsactionCo ntextProxy Invocation Handler us ing the cu rrent
  304            *  threads V istaRealmP rincipal a s the back ing store.
  305            *
  306            * /
  307           pu blic Trans actionCont extProxyIn vocationHa ndler()
  308           {
  309                    supe r();
  310                    
  311                    Vist aRealmPrin cipal temp Principal  = VistaRea lmSecurity Context.ge t();
  312                    if(t empPrincip al == null )
  313                    {
  314                             Throwa ble t = ne w Throwabl e();
  315                             StackT raceAnalyz er analyze r = new St ackTraceAn alyzer( t. getStackTr ace() );
  316                             StackT raceElemen t culprit  = analyzer .getFirstE lementNotI nPackage(" gov.va.med .imaging.t ransaction context");
  317                             //t.pr intStackTr ace();
  318                             
  319                             // JMW  1/26/2012  - we neve r pay atte ntion to t his warnin g message  so I'm dow n grading  the log le vel so it  doesn't sh ow up as m uch
  320                             logger .debug(
  321                                      "VistaRe almSecurit yContext p rincipal h as not bee n created  on thread  '" + Threa d.currentT hread().ge tName() +  "' before  instantiat ing Transa ctionConte xt. \n" + 
  322                                      "A null  security c ontext wil l be creat ed.\n" + 
  323                                      "If this  occurs wh ile runnin g in a ser ver enviro nment then  \n" + 
  324                                      "\tthe t hread is c urrently o perating w ith no rea l security  context\n " + 
  325                                      "\tasycn chronous p roxy threa ds will ha ve a secur ity contex t assigned  when they  are used. \n" + 
  326                                      "If this  occurs wh ile runnin g in a cli ent enviro nment then  \n" + 
  327                                      "\tthe a pplication  should se t the secu rity conte xt before  calling pr oxies.\n" 
  328                                      "The mos t likely c alling cod e is '" +  culprit.ge tClassName () + ":" +  + culprit .getLineNu mber() + " '."
  329                             );
  330                             
  331                             tempPr incipal =  new VistaR ealmPrinci pal("clien t", true,  Authentica tionCreden tialsType. Password);
  332                             //temp Principal  = null;
  333                    }
  334                    
  335                    prin cipal = te mpPrincipa l;
  336                    Vist aRealmSecu rityContex t.set(prin cipal);
  337           }
  338  
  339           /* *
  340            *  
  341            *  @param pr incipal
  342            * /
  343           pu blic Trans actionCont extProxyIn vocationHa ndler(fina l VistaRea lmPrincipa l principa l)
  344           {
  345                    supe r();
  346                    Vist aRealmPrin cipal temp Principal  = VistaRea lmSecurity Context.ge t();
  347                    if(t empPrincip al == null )
  348                    {
  349                             this.p rincipal =  principal ;
  350                             VistaR ealmSecuri tyContext. set(princi pal);
  351                    }
  352                    else
  353                    {
  354                             logger .warn("Att empt to se t Principa l instance  in Transa ctionConte xt after t ransaction  context h as been es tablished. ");
  355                             this.p rincipal =  tempPrinc ipal;
  356                    }
  357           }
  358  
  359           /* *
  360            *  
  361            *  @param se curityCont extMemento
  362            *  @throws I llegalArgu mentExcept ion
  363            * /
  364           pu blic Trans actionCont extProxyIn vocationHa ndler(fina l Object s ecurityCon textMement o)
  365           th rows Illeg alArgument Exception
  366           {
  367                    supe r();
  368                    if(s ecurityCon textMement o instance of VistaRe almPrincip al)
  369                             this.p rincipal =  (VistaRea lmPrincipa l)security ContextMem ento;
  370                    else
  371                             throw  new Illega lArgumentE xception(" Security C ontext Mem ento is of  an unknow n type");
  372           }
  373           
  374           /* *
  375            *  @return t he princip al
  376            * /
  377           pr ivate Vist aRealmPrin cipal getP rincipal()
  378           {
  379                    retu rn this.pr incipal;
  380           }
  381  
  382           pr ivate Bool ean isClie ntPrincipa l()
  383           {
  384                    Vist aRealmPrin cipal p =  getPrincip al();
  385                    retu rn p != nu ll && p in stanceof C lientPrinc ipal;
  386           }
  387           
  388           /* *
  389            *  All invoc ations sho uld come t hrough the  Transacti onContext  interface.   We do on e of two t hings
  390            *  with the  invoke(): 
  391            *  first, if  it is a k nown acces sor method  being cal led we sim ply pass t he
  392            *  call to t he known m ethod,  
  393            *  second: i f the meth od is not  one of the  known met hods and i t is a Str ing access or (i.e.
  394            *  String ge tX(){} or  void setX( String val ue)) then  we get or  set the va lue from a
  395            *  Map<Strin g,String>  that is ma intained b y the Vist aRealmPrin cipal inst ance.
  396            *  
  397            *  @see java .lang.refl ect.Invoca tionHandle r#invoke(j ava.lang.O bject, jav a.lang.ref lect.Metho d, java.la ng.Object[ ])
  398            * /
  399           pu blic synch ronized Ob ject invok e(Object p roxy, Meth od method,  Object[]  args) 
  400           th rows Throw able
  401           {
  402                    try
  403                    {
  404                             // met a-methods  are method s that ret urn info a bout the t ransaction
  405                             // con text and n ot necessa rily the t ransaction  context p roperties
  406                             // for  example:  getting a  memento (s erializabl e represen tation)
  407                             return  invokeMet aMethods(g etPrincipa l(), proxy , method,  args);
  408                    }
  409                    catc h(NoSuchMe thodExcept ion nsmX)
  410                    {
  411                             // if  the securi ty princip al has bee n cleared  then just  return a n ull
  412                             if(pri ncipal ==  null)
  413                             {
  414                                      logger.w arn("Attem pt to call  method "  + method.g etName() +  " after s ecurity co ntext has  been clear ed is bein g ignored. ");
  415                                      return n ull;
  416                             }
  417                             
  418                             try
  419                             {
  420                                      return i nvokeKnown Method(get Principal( ), method,  args);
  421                             } 
  422                             catch  (NoSuchMet hodExcepti on nsmX2)
  423                             {
  424                                      // if th e method i s not one  of the sta tically ma pped metho ds then pa rse the me thod
  425                                      // to ge t the fiel d name des ired.
  426                                      return i nvokeUnkno wnMethod(g etPrincipa l(), metho d, args);
  427                             }
  428                    }
  429                    
  430           }
  431  
  432           /* *
  433            *  MetaMetho ds are tra nsaction c ontext man agement me thods.
  434            *  In genera l, applica tion code  should not  call thes e methods.   These 
  435            *  methods a re used pr edominantl y for tran sferring t ransaction  context
  436            *  between a synchronou s threads  (and for t esting).
  437            *  Mete-meth ods are ca lled befor e checking  that a pr incipal ex ists, meta -methods
  438            *  that rely  on the ex istence of  a Princip al must ch eck that i t exists b efore
  439            *  continuin g.
  440            *  
  441            *  @param pr oxy
  442            *  @param pr oxy2 
  443            *  @param me thod
  444            *  @param ar gs
  445            * /
  446           pr ivate Obje ct invokeM etaMethods (VistaReal mPrincipal  principal , Object p roxy, Meth od method,  Object[]  args)
  447           th rows NoSuc hMethodExc eption
  448           {
  449                    // t he setMeme nto method  may run w ithout a P rincipal i nstance as sociated t o the cont ext,
  450                    // b ecause it  sets one
  451                    if(  SET_MEMENT O.equals(m ethod.getN ame()) &&  (args != n ull && arg s.length = = 1) && ar gs[0] inst anceof Tra nsactionCo ntextMemen to )
  452                    {
  453                             try
  454                             {
  455                                      VistaRea lmPrincipa l principa lClone = T ransaction ContextMem ento.creat e((Transac tionContex tMemento)a rgs[0]);
  456                                      principa l.setAll(p rincipalCl one);
  457                                      
  458                                      return n ull;
  459                             } 
  460                             catch  (Throwable  x)
  461                             {
  462                                      String l ocation;
  463                                      if( x.ge tStackTrac e() != nul l && x.get StackTrace ().length  > 0)
  464                                      {
  465                                               location =  x.getStac kTrace()[0 ].getFileN ame() + ": " + x.getS tackTrace( )[0].getLi neNumber() ;
  466                                      }
  467                                      else
  468                                               location =  "<locatio n unknown> ";
  469                                      
  470                                      logger.e rror(locat ion, x);
  471                                      return n ull;
  472                             }
  473                    }
  474                    
  475                    // A s close to  bulletpro of as we c an make it , return a  useful de scription  of the cur rent conte xt
  476                    // s tate.
  477                    if(G ET_CONTEXT _DEBUG_STA TE.equals( method.get Name()) &&  
  478                             (metho d.getParam eterTypes( ) == null  || method. getParamet erTypes(). length ==  0) && 
  479                             java.l ang.String .class.equ als(method .getReturn Type()) )
  480                    {
  481                             return  buildCont extStateDe bugString( );
  482                    }
  483                    
  484                    // m ethods bel ow this co nditional  may rely o n the Prin cipal exis ting.
  485                    if(p rincipal = = null)
  486                    {
  487                             logger .warn("Att empt to ca ll method  " + method .getName()  + " with  no securit y context  is being i gnored.");
  488                             return  null;
  489                    }
  490                    
  491                    if(  IS_CLIENT_ PRINCIPAL. equals(met hod.getNam e()) && (a rgs == nul l || args. length ==  0) && Bool ean.class. isAssignab leFrom(met hod.getRet urnType())  )
  492                             return  isClientP rincipal() ;
  493                    
  494                    
  495                    if(  GET_DISPLA Y_IDENTITY .equals(me thod.getNa me()) && ( args == nu ll || args .length ==  0) && Str ing.class. isAssignab leFrom(met hod.getRet urnType())  )
  496                             return  principal .getAccess Code() + " , " + prin cipal.getA pplication Property(" transactio nId");
  497                    
  498                    if(  CLEAR.equa ls(method. getName())  && (args  == null ||  args.leng th == 0) )
  499                    {
  500                             VistaR ealmSecuri tyContext. clear();
  501                             princi pal = null ;
  502                             return  null;
  503                    }
  504                    
  505                    if(  GET_MEMENT O.equals(m ethod.getN ame()) &&  (args == n ull || arg s.length = = 0) && Tr ansactionC ontextMeme nto.class. isAssignab leFrom(met hod.getRet urnType())  )
  506                    {
  507                             try
  508                             {
  509                                      Transact ionContext Memento me mento = Tr ansactionC ontextMeme nto.create (principal );
  510                                      return m emento;
  511                             } 
  512                             catch  (IOExcepti on x)
  513                             {
  514                                      logger.e rror(x);
  515                                      return n ull;
  516                             }
  517                    }
  518                    
  519                    if(  GET_IDENTI TY.equals( method.get Name()) &&  (args ==  null || ar gs.length  == 0) )
  520                    {
  521                             return  new Integ er(princip al == null  ? 0 : Sys tem.identi tyHashCode (principal ));
  522                    }
  523                    
  524                    if(  CREATE_CHI LD_CLONE.e quals(meth od.getName ()) && (ar gs == null  || args.l ength == 0 ) )
  525                    {
  526                             return  principal  == null ?  null : pr incipal.cl one();
  527                    }
  528                    
  529                    if(G ET_ADDITIO NAL_DEBUG_ INFORMATIO N.equals(m ethod.getN ame()) && 
  530                                      (method. getParamet erTypes()  == null ||  method.ge tParameter Types().le ngth == 0)  && 
  531                                      java.lan g.String.c lass.equal s(method.g etReturnTy pe()) )
  532                    {
  533                             return  buildAddi tionalDebu gInformati onString() ;
  534                    }
  535  
  536                    thro w new NoSu chMethodEx ception();
  537           }
  538  
  539           /* *
  540            *  @return
  541            * /
  542           pr ivate Obje ct buildCo ntextState DebugStrin g()
  543           {
  544                    if(p rincipal = = null)
  545                             return  "Principa l is not s et, transa ction cont ext unavai lable.";
  546                    
  547                    if(T ransaction Context.de bugPropert ies == nul l)
  548                             return  "No debug  propertie s configur ed.";
  549                    
  550                    Stri ngBuilder  sb = new S tringBuild er();
  551                    
  552                    for( String pro pertyName  : Transact ionContext .debugProp erties)
  553                    {
  554                             sb.app end(proper tyName);
  555                             sb.app end('=');
  556                             sb.app end('\'');
  557                             
  558                             Object  value = n ull;
  559                             if(isI mmutablePr operty(pro pertyName) )
  560                                      value =  invokeImmu tablePrope rtyGetAcce ssor(princ ipal, prop ertyName);
  561                             else i f(isReques torPropert y(property Name))
  562                                      value =  invokeProp ertyGetAcc essor(prin cipal, pro pertyName) ;
  563                             else
  564                                      value =  principal. getApplica tionProper ty(propert yName);
  565                             
  566                             sb.app end(value= =null ? "< null>" : v alue.toStr ing());
  567                             sb.app end('\'');
  568                    }
  569                    
  570                    retu rn sb.toSt ring();
  571           }
  572           
  573           pr ivate Stri ng buildAd ditionalDe bugInforma tionString ()
  574           {
  575                    if(p rincipal = = null)
  576                             return  null;
  577                    
  578                    if(T ransaction Context.ad ditionalDe bugInforma tionProper ties == nu ll)
  579                             return  null;
  580                    
  581                    Stri ngBuilder  sb = new S tringBuild er();
  582                    Stri ng prefix  = "";
  583                    
  584                    for( String pro pertyName  : Transact ionContext .additiona lDebugInfo rmationPro perties)
  585                    {
  586                             Object  value = n ull;
  587                             if(isI mmutablePr operty(pro pertyName) )
  588                                      value =  invokeImmu tablePrope rtyGetAcce ssor(princ ipal, prop ertyName);
  589                             else i f(isReques torPropert y(property Name))
  590                                      value =  invokeProp ertyGetAcc essor(prin cipal, pro pertyName) ;
  591                             else
  592                                      value =  principal. getApplica tionProper ty(propert yName);
  593                             
  594                             if(val ue != null )
  595                             {
  596                                      sb.appen d(prefix);
  597                                      sb.appen d(property Name);
  598                                      sb.appen d('=');
  599                                      sb.appen d(value.to String());
  600                                      prefix =  Transacti onContext. debugInfor mationDeli miter;
  601                             }
  602                    }
  603                    
  604                    // i f none of  the proper ties have  values the n just ret urn null
  605                    if(s b.length()  == 0)
  606                             return  null;
  607                    
  608                    retu rn sb.toSt ring();
  609           }
  610  
  611           /* *
  612            *  Invoke on e of the k nown metho ds, those  that map d irectly to  VistaReal mPrincipal  calls.
  613            *  NOTE: all  of these  methods ar e, and mus t be, Stri ng accesso rs.
  614            *  @param pr incipal
  615            *  @param me thod
  616            *  @param ar gs
  617            *  @return
  618            *  @throws N oSuchMetho dException  - thrown  if the met hod is not  one of th e known ma ppings
  619            * /
  620           pr ivate Obje ct invokeK nownMethod (VistaReal mPrincipal  principal , Method m ethod, Obj ect[] args
  621           th rows NoSuc hMethodExc eption
  622           {
  623                    if(p rincipal ! = null)
  624                    {
  625                             String  methodNam e = method .getName() ;                                                                         //  the acces sor name
  626                             String  propertyN ame = getP ropertyNam e(methodNa me, true);                                    // the p roperty na me for log ger proper ties will  have logge r stripped  off
  627                             boolea n isGetter Args = arg s == null  || args.le ngth == 0;                                    // true  if the arg  list is c ompatible  with a Str ing getter
  628                             boolea n isSetter Args = arg s != null  && args.le ngth == 1  && args[0]  instanceo f String;    // true  if the arg  list is c ompatible  with a Str ing setter
  629                             
  630                             // === ========== ========== ========== ========== ========== ========== ========== ========== =======
  631                             // Imm utable fie lds
  632                             // Vis taRealm se ts these.
  633                             // === ========== ========== ========== ========== ========== ========== ========== ========== =======
  634                             
  635                             if(isI mmutablePr operty(pro pertyName) )
  636                             {
  637                                      if(isGet terAccesso r(methodNa me) && isG etterArgs)
  638                                               return inv okeImmutab leProperty GetAccesso r(principa l, propert yName);
  639                                      else if(  isSetterA ccessor(me thodName)  && isSette rArgs )
  640                                      {
  641                                               // if the  backing Pr incipal in stance is  a ClientPr incipal th en allow c hanges to  UID and PW D
  642                                               if(isClien tPrincipal ())
  643                                               {
  644                                                       if ( ACCESS_C ODE_PROPER TY.equals( propertyNa me) )
  645                                                                prin cipal.setA ccessCode( (String)ar gs[0]);
  646                                                       if ( VERIFY_C ODE_PROPER TY.equals( propertyNa me) )
  647                                                                prin cipal.setV erifyCode( (String)ar gs[0]);
  648                                               }
  649                                               else
  650                                               {
  651                                                       St ackTraceAn alyzer ana lyzer = St ackTraceAn alyzer.cur rentStackA nalyzer();
  652                                                       St ackTraceEl ement elem ent = anal yzer.getFi rstElement NotInPacka ge( this.g etClass(). getPackage ().getName () );
  653                                                       lo gger.warn(
  654                                                                "Att empt to se t transact ion contex t property  '" + prop ertyName +  "', which  is immuta ble in the  current c ontext.\n"  + 
  655                                                                "Lik ely culpri t is [" +  Thread.cur rentThread ().getName () + "]'"  + element. getClassNa me() + "."  + element .getMethod Name() + " :" + eleme nt.getLine Number() +  "'. "
  656                                                       );
  657                                               }
  658                                               return nul l;
  659                                      }
  660                                      else
  661                                      {
  662                                               logger.war n("Attempt  to set im mutable tr ansaction  context pr operty '"  + property Name + "'  or calling  get acces sor with a rguments i s being ig nored.");
  663                                               return nul l;
  664                                      }
  665                             }
  666  
  667                             // === ========== ========== ========== ========== ========== ========== ========== ========== =======
  668                             // Rea l Requesto r Fields a nd Logger  Requestor  Fields
  669                             // Rea l requesto r fields a re always  retreived  from real  properties  though th ey may com e from 
  670                             // HTT P headers  or webserv ice elemen ts.
  671                             // Log ger reques tor fields  may come  from the a pplication  propertie s or the " real" prop erties
  672                             // if  the applic ation prop erties do  not exist.
  673                             // See  the comme nts below  on the set ter method s for more  info.
  674                             // === ========== ========== ========== ========== ========== ========== ========== ========== =======
  675                             else i f(isReques torPropert y(property Name))
  676                             {
  677                                      if( isGe tterAccess or(methodN ame) && is GetterArgs  )
  678                                      {
  679                                               if( isGetL oggerAcces sor(method Name) )
  680                                                       re turn invok eLoggerPro pertyGetAc cessor(pri ncipal, pr opertyName );
  681                                               else
  682                                                       re turn invok ePropertyG etAccessor (principal , property Name);
  683                                      }
  684                                      
  685                                      if( isSe tterAccess or(methodN ame) && is SetterArgs  )
  686                                               return inv okePropert ySetAccess or(princip al, proper tyName, (S tring)args [0]);
  687                                      
  688                                      logger.w arn("Attem pt to acce ss transac tion conte xt propert y '" + pro pertyName 
  689                                                       "'  but eithe r method n aming or a rgument li st is not  correct.   Accessor m ethods mus t follow J avaBean st andards fo r String p roperties" );
  690                                      return n ull;
  691                             }
  692                             else i f(isDebugP roperty(pr opertyName ))
  693                             {
  694                                      if( isGe tterAccess or(methodN ame) && is GetterArgs  )
  695                                      {
  696                                               return inv okeLoggerP ropertyGet Accessor(p rincipal,  propertyNa me);
  697                                      }
  698                                      
  699                                      if( isSe tterAccess or(methodN ame) && is SetterArgs  )
  700                                      {
  701                                               String new Value = (S tring)args [0];
  702                                               setApplica tionProper ty(princip al, proper tyName, ne wValue);
  703                                               return nul l;
  704                                      }
  705                                      if((isAd derAccesso r(methodNa me) && isS etterArgs  ))
  706                                      {
  707                                               String old Value = in vokeLogger PropertyGe tAccessor( principal,  propertyN ame);
  708                                               String new Value = (S tring)args [0];
  709                                               if((oldVal ue != null ) && (oldV alue.lengt h() > 0))
  710                                               {
  711                                                       ne wValue = o ldValue +  Transactio nContext.d ebugInform ationDelim iter + new Value;
  712                                               }
  713                                               setApplica tionProper ty(princip al, proper tyName, ne wValue);
  714                                               return nul l;
  715                                      }
  716                                      
  717                                      logger.w arn("Attem pt to acce ss transac tion conte xt propert y '" + pro pertyName 
  718                                                       "'  but eithe r method n aming or a rgument li st is not  correct.   Accessor m ethods mus t follow J avaBean st andards fo r String p roperties" );
  719                                      return n ull;
  720                             }
  721           
  722                             // we  don't know  what the  method is,  throw a N oSuchMetho dException
  723                             // the  caller sh ould inter pret this  as an unkn own method  not as a  runtime er ror
  724                             else
  725                                      throw ne w NoSuchMe thodExcept ion();
  726                    }
  727                    else
  728                    {
  729                             logger .warn("Att empted to  call Trans actionCont ext method  '" + meth od.getName () + "' an d backing  instance o f VistaRea lmPrincipa l does not  exist.");
  730                             return  null;
  731                    }
  732           }
  733           
  734           /* *
  735            *  Whether a  field may  be set de pends on w hether it  has alread y been set  and wheth er the
  736            *  values we re set by  VistARealm  (not by t he delegat e realm). 
  737            *  VistaReal m sourced  values are  immutable .
  738            *  Requestor  informati on that is  being add ed to a Vi staRealmPr incipal in stance tha t was
  739            *  originall y populate d by Vista Realm will  be stored  as applic ation prop erties
  740            *  and will  be accessi ble as get LoggingXXX  methods.
  741            *  Requestor  informati on that is  being add ed to a Vi staRealmPr incipal in stance tha t was
  742            *  NOT origi nally popu lated by V istaRealm  will be st ored in th e "real" p roperties
  743            *  and will  be accessi ble as eit her getXXX  or getLog gingXXX me thods.
  744            *  The getLo ggingXXX m ethods ret urn the ap plication  properties  if they e xist, else  they retu rn
  745            *  the field s of the s ame names.
  746            *  
  747            *  @param pr incipal
  748            *  @param pr opertyName
  749            *  @param st ring
  750            *  @return
  751            * /
  752           pr ivate Stri ng invokeP ropertySet Accessor(V istaRealmP rincipal p rincipal,  String pro pertyName,  String va lue)
  753           {
  754                    Stri ng oldValu e = invoke PropertyGe tAccessor( principal,  propertyN ame);
  755                    
  756                    if(o ldValue !=  null)
  757                             logger .warn("Ove rwriting k nown prope rty '" + p ropertyNam e + "'; fr om '" + ol dValue + " ' to '" +  value + "' .");
  758                    
  759                    if(p rincipal.i sAuthentic atedByDele gate())
  760                    {
  761                             if( SI TE_NAME_PR OPERTY.equ als(proper tyName) )
  762                                      principa l.setSiteN ame(value) ;
  763                             if( SI TE_NUMBER_ PROPERTY.e quals(prop ertyName)  )
  764                                      principa l.setSiteN umber(valu e);
  765                             if( SS N_PROPERTY .equals(pr opertyName ) )
  766                                      principa l.setSsn(v alue);
  767                             if( DU Z_PROPERTY .equals(pr opertyName ) )
  768                                      principa l.setDuz(v alue);
  769                             if( FU LLNAME_PRO PERTY.equa ls(propert yName) )
  770                                      principa l.setFullN ame(value) ;
  771                             if( SE CURITY_TOK EN_PROPERT Y.equals(p ropertyNam e))
  772                                      principa l.setSecur ityToken(v alue);
  773                             if( CA CHE_LOCATI ON_ID_PROP ERTY.equal s(property Name))
  774                                      principa l.setCache LocationId (value);
  775                             if( US ER_DIVISIO N_PROPERTY .equals(pr opertyName ))
  776                                      principa l.setUserD ivision(va lue);
  777                             
  778                    }
  779                    else
  780                             setApp licationPr operty(pri ncipal, pr opertyName , value);
  781                    
  782                    retu rn null;
  783           }
  784  
  785           /* *
  786            *  Real Requ estor Fiel ds and Log ger Reques tor Fields
  787            *  Real requ estor fiel ds are alw ays retrei ved from r eal proper ties thoug h they may  come from  
  788            *  HTTP head ers or web service el ements.
  789            *  Logger re questor fi elds may c ome from t he applica tion prope rties or t he "real"  properties
  790            *  if the ap plication  properties  do not ex ist.
  791            *  See the c omments be low on the  setter me thods for  more info.
  792            *  
  793            *  This meth od provide s a mappin g from pro perty name  to get ac cessor for  known pro perties
  794            *  
  795            *  @param pr incipal
  796            *  @param pr opertyName
  797            *  @return
  798            * /
  799           pr ivate Stri ng invokeP ropertyGet Accessor(V istaRealmP rincipal p rincipal,  String pro pertyName)
  800           {
  801                    if(  SITE_NAME_ PROPERTY.e quals(prop ertyName)  )
  802                             return  principal .getSiteNa me();
  803                    if(  SITE_NUMBE R_PROPERTY .equals(pr opertyName ) )
  804                             return  principal .getSiteNu mber();
  805                    if(  SSN_PROPER TY.equals( propertyNa me) )
  806                             return  principal .getSsn();
  807                    if(  DUZ_PROPER TY.equals( propertyNa me) )
  808                             return  principal .getDuz();
  809                    if(  FULLNAME_P ROPERTY.eq uals(prope rtyName) )
  810                             return  principal .getFullNa me();
  811                    if(  SECURITY_T OKEN_PROPE RTY.equals (propertyN ame))
  812                             return  principal .getSecuri tyToken();
  813                    if(  CACHE_LOCA TION_ID_PR OPERTY.equ als(proper tyName))
  814                             return  principal .getCacheL ocationId( );
  815                    if(  USER_DIVIS ION_PROPER TY.equals( propertyNa me))
  816                             return  principal .getUserDi vision();
  817                    
  818                    retu rn null;
  819           }
  820  
  821           /* *
  822            *  Real Requ estor Fiel ds and Log ger Reques tor Fields
  823            *  Real requ estor fiel ds are alw ays retrei ved from r eal proper ties thoug h they may  come from  
  824            *  HTTP head ers or web service el ements.
  825            *  Logger re questor fi elds may c ome from t he applica tion prope rties or t he "real"  properties
  826            *  if the ap plication  properties  do not ex ist.
  827            *  See the c omments be low on the  setter me thods for  more info.
  828            *  
  829            *  Get the p roperty va lue from t he applica tion prope rties firs t and then  from the
  830            *  known pro perties if  the prope rtyName is  not set i n the appl ication pr operties
  831            *  
  832            *  @param pr incipal
  833            *  @param pr opertyName
  834            *  @return
  835            * /
  836           pr ivate Stri ng invokeL oggerPrope rtyGetAcce ssor(Vista RealmPrinc ipal princ ipal, Stri ng propert yName)
  837           {
  838                    Obje ct propert yValue = g etApplicat ionPropert y(principa l, propert yName);
  839                    retu rn propert yValue ==  null ? 
  840                             invoke PropertyGe tAccessor( principal,  propertyN ame) : 
  841                             proper tyValue.to String();
  842           }
  843  
  844           /* *
  845            *  @param pr incipal
  846            *  @param pr opertyName
  847            *  @return
  848            * /
  849           pr ivate Obje ct invokeI mmutablePr opertyGetA ccessor(Vi staRealmPr incipal pr incipal, S tring prop ertyName)
  850           {
  851                    // a ccess code  and name  are synono mous
  852                    // n ame is par t of the P rincipal i nterface,  which Tran sactionCon text exten ds
  853                    if(  ACCESS_COD E_PROPERTY .equals(pr opertyName ) || NAME_ PROPERTY.e quals(prop ertyName)  )
  854                             return  principal .getAccess Code();
  855                    
  856                    if(  VERIFY_COD E_PROPERTY .equals(pr opertyName ) )
  857                             return  principal .getVerify Code();
  858                    
  859                    if(  REALM_PROP ERTY.equal s(property Name) )
  860                             return  principal .getRealm( );
  861                    
  862                    if(  AUTHENTICA TED_BY_DEL EGATE_PROP ERTY.equal s(property Name) )
  863                             return  (Boolean) ( principa l.isAuthen ticatedByD elegate()  );
  864  
  865                    if(  CREDENTIAL S_TYPE_PRO PERTY.equa ls(propert yName) )
  866                             return  principal .getCreden tialsType( ).toString ();
  867                    
  868                    if(  SECURITY_H ASHCODE_PR OPERTY.equ als(proper tyName) )
  869                             return  principal .getSecuri tyHashCode ();
  870                    
  871                    if(A UTHENTICAT ED_BY_VIST A_PROPERTY .equals(pr opertyName ))
  872                             return  new Boole an( princi pal.isAuth enticatedB yVista() ) ;       
  873                    
  874                    logg er.warn("A ttempt to  get unknow n immutabl e transact ion contex t properti es '" + pr opertyName  + "' is b eing ignor ed.");
  875                    retu rn null;
  876           }
  877  
  878           /* *
  879            *  @param pr opertyName
  880            *  @return
  881            * /
  882           pr ivate bool ean isLogg erProperty (String pr opertyName )
  883           {
  884                    retu rn propert yName.star tsWith(LOG GER_PROPER TY_PREFIX) ;
  885           }
  886  
  887           /* *
  888            *  Unknown M ethods are  accessors  on applic ation prop erties.  V istaRealm  has nothin g to
  889            *  do with t hese other  than stor ing them i n the thre ad local o n behalf o f the appl ication.
  890            *  
  891            *  Invoke an  unknown a ccessor.   The access or name mu st be enco ded in the  method na me using
  892            *  the JavaB ean standa rd.  The r eturn type  of the me thod must  be a base  java.lang. * for get  methods,
  893            *  or void f or set met hods.  Set  methods m ust take o ne object  argument.
  894            *  The value s are get/ set in the  VistaReal mPrincipal  attribute Map.
  895            *  
  896            *  @param pr incipal
  897            *  @param me thod
  898            *  @param ar gs
  899            *  @return
  900            * /
  901           pr ivate Obje ct invokeU nknownMeth od(VistaRe almPrincip al princip al, Method  method, O bject[] ar gs)
  902           {
  903                    if(p rincipal ! = null)
  904                    {
  905                             String  methodNam e = method .getName() ;
  906                             boolea n isIsGett er = metho dName.star tsWith(IS_ ACCESSOR_P REFIX);
  907                             boolea n isGetter  = methodN ame.starts With(GET_A CCESSOR_PR EFIX);
  908                             boolea n isSetter  = methodN ame.starts With(SET_A CCESSOR_PR EFIX);
  909                             
  910                             // if  the method  name does  not start  with 'get ' or 'set'  then we d on't know  what
  911                             // to  do with it
  912                             if(!is Getter &&  !isSetter  && !isIsGe tter)
  913                                      return n ull;
  914                             
  915                             String  propertyN ame = getP ropertyNam e(methodNa me, false) ;
  916                             Object  currentVa lue = getA pplication Property(p rincipal,  propertyNa me);
  917                             
  918                             // if  it is a pr oper gette r method t hen try to  convert t o the retu rn type of  the
  919                             // met hod
  920                             if( is Getter ||  isIsGetter )
  921                             {
  922                                      Class<?>  getterRet urnType =  method.get ReturnType ();
  923                                      Applicat ionPropert yAccessor< ?> accesso r = getPro pertyAcces sorForType (getterRet urnType);
  924  
  925                                      return a ccessor.ge tValueAs(c urrentValu e);
  926                             }
  927                             
  928                             // if  it is a pr oper sette r then set  the prope rty by nam
  929                             if(isS etter && a rgs != nul l && args. length ==  1)
  930                             {
  931                                      StackTra ceAnalyzer  analyzer  = StackTra ceAnalyzer .currentSt ackAnalyze r();
  932                                      StackTra ceElement  element =  analyzer.g etFirstEle mentNotInP ackage( th is.getClas s().getPac kage().get Name() );
  933                                      
  934                                      if(curre ntValue !=  null)
  935                                      {
  936                                               if( isWarn OnPropertO verwrite()  )
  937                                                       lo gger.warn(  "Transact ionContext [" + princ ipal.hashC ode() + "] " + 
  938                                                                "Ove rwriting a pplication  property  '" + prope rtyName +  "'; from ' " + curren tValue + " ' to '" + 
  939                                                                (arg s[0] == nu ll ? "<nul l>" : args [0].toStri ng()) + "' .\n" +
  940                                                                (ele ment == nu ll ? 
  941                                                                         "Unkno wn offendi ng element " :
  942                                                                         "Offen ding eleme nt may be  '" + eleme nt.getClas sName() +  "." + elem ent.getMet hodName()  + ":" + el ement.getL ineNumber( ) + "'"
  943                                                                )
  944                                                       );
  945                                      }
  946                                      logger.d ebug( (ele ment == nu ll ? "unkn own" : (el ement.getC lassName()  + ":" + e lement.get LineNumber ())) + 
  947                                               " is setti ng propert y name '"  + property Name + "'  from value  '" + curr entValue +  "' to '"  + args[0]  + "'");
  948                                      
  949                                      setAppli cationProp erty(princ ipal, prop ertyName,  args[0]);
  950                             }
  951                             return  null;
  952                    }
  953                    else
  954                    {
  955                             logger .warn("Att empted to  call Trans actionCont ext method  '" + meth od.getName () + "' an d backing  instance o f VistaRea lmPrincipa l does not  exist.");
  956                             return  null;
  957                    }
  958           }
  959  
  960           /* *
  961            *  Semantic  Helper Met hod
  962            *  
  963            *  @param pr incipal
  964            *  @param pr opertyName
  965            *  @param va lue
  966            * /
  967           pr ivate void  setApplic ationPrope rty(VistaR ealmPrinci pal princi pal, Strin g property Name, Obje ct value)
  968           {
  969                    prin cipal.setA pplication Property(p ropertyNam e, value);
  970           }
  971           
  972           /* *
  973            *  Semantic  Helper Met hod
  974            *  
  975            *  @param pr incipal
  976            *  @param pr opertyName
  977            *  @return
  978            * /
  979           pr ivate Obje ct getAppl icationPro perty(Vist aRealmPrin cipal prin cipal, Str ing proper tyName)
  980           {
  981                    retu rn princip al.getAppl icationPro perty(prop ertyName);
  982           }
  983           
  984           /* *
  985            *  If the me thod name  is getXXX  or setXXX  return the  
  986            *  (i.e. fir st char is  lower cas e).
  987            *  
  988            *  e.g. getS iteNumber  => siteNum ber
  989            *       setS umpin => s umpin
  990            *  
  991            *  @param ac cessorMeth odName
  992            *  @return
  993            * /
  994           pr ivate Stri ng getProp ertyName(S tring acce ssorMethod Name, bool ean remove LoggerPref ix)
  995           {
  996                    bool ean isIs =  isIsAcces sor(access orMethodNa me);
  997                    bool ean isGett er = isGet terAccesso r(accessor MethodName );
  998                    bool ean isSett er = isSet terAccesso r(accessor MethodName );
  999                    bool ean isAdde r = isAdde rAccessor( accessorMe thodName);
  1000                    
  1001                    // i f the meth od name do es not sta rt with 'g et' or 'se t' then we  don't kno w what
  1002                    // t o do with  it
  1003                    if(  ! isGetter  && ! isSe tter && !i sAdder)
  1004                             return  null;
  1005                    
  1006                    int  prefixLeng th = 
  1007                             isIs ?  IS_ACCESS OR_PREFIX. length() :
  1008                             isGett er ? GET_A CCESSOR_PR EFIX.lengt h() : 
  1009                             isSett er ? SET_A CCESSOR_PR EFIX.lengt h() :
  1010                             ADD_AC CESSOR_PRE FIX.length ();
  1011                             
  1012                    // t here must  be a field  name to b e a proper  accessor,  i.e. get( ) is not a  proper
  1013                    // a ccessor as  far as we  are conce rned
  1014                    if(  accessorMe thodName.l ength() <=  prefixLen gth )
  1015                             return  null;
  1016                    
  1017                    //       the fi eldname be gins after  the 'is',  'get' or  'set'
  1018                    Stri ng propert yName = ac cessorMeth odName.sub string(pre fixLength) ;
  1019                    
  1020                    // l ower case  the first  char
  1021                    prop ertyName =  propertyN ame.substr ing(0,1).t oLowerCase () + (prop ertyName.l ength()>1  ? property Name.subst ring(1) :  "");
  1022                    
  1023                    if(r emoveLogge rPrefix &&  propertyN ame.starts With(LOGGE R_PROPERTY _PREFIX))
  1024                    {
  1025                             proper tyName = p ropertyNam e.substrin g(LOGGER_P ROPERTY_PR EFIX.lengt h());
  1026                             proper tyName = p ropertyNam e.substrin g(0,1).toL owerCase()  + (proper tyName.len gth()>1 ?  propertyNa me.substri ng(1) : "" );
  1027                    }
  1028                    
  1029                    retu rn propert yName;
  1030           }
  1031           
  1032           /* *
  1033            *  Create a  standard g etter meth od name fr om the pro perty name .
  1034            *  
  1035            *  @param pr opertyName
  1036            *  @return
  1037            * /
  1038           pr ivate Stri ng getGett erName(Str ing proper tyName)
  1039           {
  1040                    retu rn GET_ACC ESSOR_PREF IX + prope rtyName.su bstring(0, 1).toUpper Case() + ( propertyNa me.length( )>1 ? prop ertyName.s ubstring(1 ) : "");
  1041           }
  1042  
  1043           /* *
  1044            *  Create a  standard s etter meth od name fr om the pro perty name .
  1045            *  
  1046            *  @param pr opertyName
  1047            *  @return
  1048            * /
  1049           pr ivate Stri ng getSett erName(Str ing proper tyName)
  1050           {
  1051                    retu rn SET_ACC ESSOR_PREF IX + prope rtyName.su bstring(0, 1).toUpper Case() + ( propertyNa me.length( )>1 ? prop ertyName.s ubstring(1 ) : "");
  1052           }
  1053           
  1054           pr ivate bool ean isGett erAccessor (String me thodName)
  1055           {
  1056                    retu rn methodN ame.starts With(GET_A CCESSOR_PR EFIX) || m ethodName. startsWith (IS_ACCESS OR_PREFIX)
  1057           }
  1058           
  1059           pr ivate bool ean isIsAc cessor(Str ing method Name)
  1060           {
  1061                    retu rn methodN ame.starts With(IS_AC CESSOR_PRE FIX); 
  1062           }
  1063           
  1064           pr ivate bool ean isSett erAccessor (String me thodName)
  1065           {
  1066                    retu rn methodN ame.starts With(SET_A CCESSOR_PR EFIX); 
  1067           }
  1068           
  1069           pr ivate bool ean isAdde rAccessor( String met hodName)
  1070           {
  1071                    retu rn methodN ame.starts With(ADD_A CCESSOR_PR EFIX);
  1072           }
  1073           
  1074           /* *
  1075            *  Accessor  methods th at start e ith "getLo gger" or " isLogger"  are consid ered
  1076            *  known pro perties bu t are hand led specia l.  This m ethod just  tells us  that the
  1077            *  method na me matches  the patte rn.
  1078            *  
  1079            *  @param me thodName
  1080            *  @return
  1081            * /
  1082           pr ivate bool ean isGetL oggerAcces sor(String  methodNam e)
  1083           {
  1084                    retu rn methodN ame.starts With(GET_A CCESSOR_PR EFIX + LOG GER_ACCESS OR_PREFIX)  || method Name.start sWith(IS_A CCESSOR_PR EFIX + LOG GER_ACCESS OR_PREFIX)
  1085           }
  1086  
  1087   }