commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "Betwixt/TipsAndHints/ForwardReferenceChainedBeanCreator" by JesseSweetland
Date Mon, 22 Jan 2007 15:15:40 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by JesseSweetland:
http://wiki.apache.org/jakarta-commons/Betwixt/TipsAndHints/ForwardReferenceChainedBeanCreator

------------------------------------------------------------------------------
      
      private HashMap<Integer, Reference> _identityRefs = new HashMap<Integer, Reference>();
      private HashMap<String, Reference> _idRefs = new HashMap<String, Reference>();
+     private boolean _reset = false;
+     
+     public boolean isReset() {
+         return _reset;
-     
+     }
+ 
      public IdentityIdStoringStrategy() {
          System.out.println("Boo");
      }
      
      public void setReference(Context context, Object bean, String id) {
+         if(_reset) doReset();
          Reference ref = new Reference(bean, id);
          _identityRefs.put(ref.getIdentity(), ref);
          _idRefs.put(ref.getId(), ref);
@@ -66, +72 @@

      }
      
      public void reset() {
-         // DO NOT CLEAR VALUES!  We need these references after
-         // unmarshalling has completed to resolve references.
+         // Delay the actual reset until this instance IdentityIdStoringStrategy
+         // is used again.  The references needs to persist as long as possible
+         // after unmarshalling so that the forward reference proxies can resolve.
+ 
+         // Called when unmarshalling is complete.  Set a flag to trigger cleanup
+         // if and when this instance is used again.  This flag also serves as an
+         // indicator to ForwardReferenceInvocationHandler that unmarshalling is
+         // complete, meaning that if a proxy target does not resolve then it
+         // never will.
+         _reset = true;
+     }
+ 
+     private void doReset() {
+         _identityRefs.clear();
+         _idRefs.clear();
      }
  }
  }}}
@@ -159, +178 @@

      public Object getTarget() {
          if(_target == null) {
              _target = _references.getReferenced(_context, _id);
+             if((_target == null) && isFinishedUnmarshalling(_references)) {
+                 throw new RuntimeException("IDREF " + _id + " can not be resolved");
+             }
          }
          return _target;
      }
@@ -185, +207 @@

              for(QueuedCall call: _queue) {
                  call.method.invoke(target, call.args);
              }
+             _queue.clear();
              return method.invoke(target, args);
          }
+     }
+ 
+     private boolean isFinishedUnmarshalling(IdStoringStrategy _references) {
+         if(_references instanceof IdentityIdStoringStrategy) {
+             return ((IdentityIdStoringStrategy)_references).isReset();
+         }
+         return false;
      }
  }
  }}}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message