Coverage Report - org.apache.ojb.broker.core.proxy.VirtualProxy
 
Classes in this File Line Coverage Branch Coverage Complexity
VirtualProxy
N/A
N/A
1
 
 1  
 package org.apache.ojb.broker.core.proxy;
 2  
 
 3  
 /* Copyright 2002-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import java.io.Serializable;
 19  
 
 20  
 import org.apache.ojb.broker.Identity;
 21  
 import org.apache.ojb.broker.PBKey;
 22  
 import org.apache.ojb.broker.PersistenceBrokerException;
 23  
 
 24  
 /**
 25  
  * Proxy base class. can be used to implement lazy materialization techniques.
 26  
  * 
 27  
  * @author <a href="mailto:thomas.mahler@itellium.com">Thomas Mahler<a>
 28  
  * @version $Id: VirtualProxy.java,v 1.1 2007-08-24 22:17:32 ewestfal Exp $
 29  
  */
 30  
 public abstract class VirtualProxy implements OJBProxy,Serializable
 31  
 {
 32  
         static final long serialVersionUID = -3999451313262635171L;
 33  
 
 34  
     /**
 35  
      * reference to the IndirectionHandler that encapsulates the delegation mechanism
 36  
      * */
 37  
     private IndirectionHandler indirectionHandler = null;
 38  
 
 39  
     /**
 40  
      * Creates a new, uninitialized proxy.
 41  
      */
 42  
     public VirtualProxy()
 43  
     {}
 44  
 
 45  
     /**
 46  
      * Creates a VirtualProxy for the subject with the given identity.
 47  
      * 
 48  
      * @param key The key of the PersistenceBroker
 49  
      * @param oid The identity of the subject
 50  
      */
 51  
     public VirtualProxy(PBKey key, Identity oid)
 52  
     {
 53  
         indirectionHandler = AbstractProxyFactory.getProxyFactory().createIndirectionHandler(key, oid);
 54  
     }
 55  
 
 56  
     /**
 57  
      * Create a VirtualProxy that uses the given invocation handler.
 58  
      * [tomdz] Why here the use of InvocationHandler ?
 59  
      * 
 60  
      * @param handler The indirection handler of the proxy
 61  
      * 
 62  
      */
 63  
     
 64  
     public VirtualProxy(IndirectionHandler handler)
 65  
     {
 66  
         indirectionHandler = handler;
 67  
     }
 68  
 
 69  
     /**
 70  
      * Returns the indirection handler of the given proxy.
 71  
      * 
 72  
      * @param proxy The proxy
 73  
      * @return The indirection handler
 74  
      */
 75  
     public static IndirectionHandler getIndirectionHandler(VirtualProxy proxy)
 76  
     {
 77  
         return proxy.indirectionHandler;
 78  
     }
 79  
 
 80  
     /**
 81  
      * Determines whether this proxy already has been materialized.
 82  
      * 
 83  
      * @return <code>true</code> if the real subject already been loaded
 84  
      */
 85  
     public boolean alreadyMaterialized()
 86  
     {
 87  
         return indirectionHandler.alreadyMaterialized();
 88  
     }
 89  
 
 90  
 
 91  
     /**
 92  
      * Returns the proxies real subject. The subject will be materialized if necessary.
 93  
      * 
 94  
      * @return The subject
 95  
      */
 96  
     public Object getRealSubject() throws PersistenceBrokerException
 97  
     {
 98  
         return indirectionHandler.getRealSubject();
 99  
     }
 100  
     
 101  
     /**
 102  
      * Returns the IndirectionHandler
 103  
      * 
 104  
      * @return The indirectionHandler
 105  
      */
 106  
     public IndirectionHandler getIndirectionHandler()
 107  
     {
 108  
         return indirectionHandler; 
 109  
     }
 110  
 
 111  
     /**
 112  
      * Returns the identity of the subject.
 113  
      * 
 114  
      * @return The identity
 115  
      */
 116  
     Identity getIdentity()
 117  
     {
 118  
         return indirectionHandler.getIdentity();
 119  
     }
 120  
     
 121  
         public Object writeReplace()
 122  
         {
 123  
                 return this; 
 124  
         }
 125  
     
 126  
 
 127  
 }