Hi Armin,

I solved my problem. It was the protected method loadData() I needed to
override. It worked but suffered from infinite loop problems when
decrypting/encrypting because of a reference to the collection owner
object in each of the collection element objects. I have since looked at
other ideas and ways to resolve that issue.

Thanks,

Robert Giddings

-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED] 
Sent: 15 September 2007 00:10
To: OJB Users List
Subject: Re: Overriding the ProxyList class

Hi Robert,

Robert Giddings wrote:
> The line " but this isn't really practical as I can
> override methods such as indexOf(Object o) as they rely on equals."
> 
> Should read "can't override methods" because of relying on equals.
> 
> Anyway, seems as if the ojb methods are never called as I put some
> System.out.println() statements in all the methods, and the
constructor
> and getter/setters get called OK, but the ojb methods never print out
> anything.
> Why would they never get called?
> 

I think OJB doesn't know about the List proxy class or do you declare 
this class as List/Collection/(Set) proxy in OJB.properties file?
You can't declare specific collection proxy classes per 1:n, m:n 
reference only a general for all Collection, List and Set references.

regards,
Armin



> Robert Giddings
> 
> -----Original Message-----
> From: Robert Giddings [mailto:[EMAIL PROTECTED] 
> Sent: 13 September 2007 10:16
> To: 'OJB Users List'
> Subject: Overriding the ProxyList class
> 
> Hi,
> 
> Can anyone please tell me why this code doesn't seem to have an
effect?
> That is I get a class cast exception because an encrypted object for
> example EncryptedCostCentre does not get decrypted to a CostCentre.
Both
> classes implement an interface called ICostCentre, but this interface
> has no method signatures etc as the structure of the two classes is
> different. I.e. CostCentre has getter/setters and EncryptedCostCentre
> has an encrypt and decrypt methods.
> The concept works fine, if I override the java.util.List methods and
> encrypt and decrypt there, but this isn't really practical as I can
> override methods such as indexOf(Object o) as they rely on equals.
> The cypherMachine and encryptedClassType are set in the decrypt method
> of the owner object, where a reference to the ICostCentre collection
is
> passed to the decrypted version of that object.
> Also what changes am I likely to need to make to the afterStore
method?
> 
> Thanks,
> 
> Robert Giddings
> 
> 
> The code:
> 
> 
> package com.netcase.database.ojb.proxy;
> 
> import java.lang.reflect.Method;
> 
> import java.util.Iterator;
> 
> import org.apache.ojb.broker.ManageableCollection;
> import org.apache.ojb.broker.PBKey;
> import org.apache.ojb.broker.PersistenceBroker;
> import org.apache.ojb.broker.PersistenceBrokerException;
> import org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl;
> import org.apache.ojb.broker.query.Query;
> 
> import com.netcase.encryption.CypherMachine;
> 
> public class EncryptableCollectionProxy extends ListProxyDefaultImpl {
> 
>       private CypherMachine cypherMachine;
>       
>       private Class encryptedClassType;
>       
>       public EncryptableCollectionProxy(PBKey brokerKey,
> java.lang.Class collClass, Query query) {
>               super(brokerKey, collClass, query);
>               cypherMachine = null;
>               encryptedClassType = null;
>       }
>       
>       public EncryptableCollectionProxy(PBKey brokerKey, Query query)
> {
>               super(brokerKey, query);
>               cypherMachine = null;
>               encryptedClassType = null;
>       }
> 
>       /**
>        * @return the cypherMachine
>        */
>       public CypherMachine getCypherMachine() {
>               return cypherMachine;
>       }
> 
>       /**
>        * @param cypherMachine the cypherMachine to set
>        */
>       public void setCypherMachine(CypherMachine cypherMachine) {
>               this.cypherMachine = cypherMachine;
>       }
>       
>       /**
>        * @return the encryptedClassType
>        */
>       public Class getEncryptedClassType() {
>               return encryptedClassType;
>       }
> 
>       /**
>        * @param encryptedClassType the encryptedClassType to set
>        */
>       public void setEncryptedClassType(Class encryptedClassType) {
>               this.encryptedClassType = encryptedClassType;
>       }
> 
>       private Object decryptObject(Object o) {
>               try {
>                       Method decrypt =
> encryptedClassType.getMethod("decrypt", CypherMachine.class);
>                       return decrypt.invoke(o, cypherMachine);
>               }
>               catch(Exception e) {
>                       return null;
>               }
>       }
>       
>       private Object encryptObject(Object o) {
>               try {
>                       Method encrypt =
> encryptedClassType.getMethod("encrypt", CypherMachine.class);
>                       return encrypt.invoke(o, cypherMachine);
>               }
>               catch(Exception e) {
>                       return null;
>               }
>       }
>       
>       public void ojbAdd(Object anObject) {
>               super.ojbAdd(this.decryptObject(anObject));
>       }
>       
>       public void ojbAddAll(ManageableCollection otherCollection) {
>               Iterator i = otherCollection.ojbIterator();
>               while(i.hasNext()) {
>                       this.ojbAdd(i.next());
>               }
>       }
>       
>       public Iterator ojbIterator() {
>               EncryptableCollectionProxy ecp = 
>                       new
> EncryptableCollectionProxy(this.getBrokerKey(), 
>                                       this.getCollectionClass(),
> this.getQuery());
>               for(Object o: this) {
>                       ecp.add(this.encryptObject(o));
>               }
>               return ecp.ojbIterator();
>       }
>       
>       public void afterStore(PersistenceBroker broker) throws
> PersistenceBrokerException {
>               super.afterStore(broker);
>       }
>       
> }
> 
> 
> 
> An example of the XDoclet code is:
> 
> 
> 
> /**
>        * @ojb.collection
>
element-class-ref="com.netcase.netspat.recordSystem.encryption.encrypted
> Objects.EncryptedCostCentre"
>        *                 foreignkey="clientId"
>        *                 proxy="true"
>        *                 auto-retrieve="true"
>        *                 auto-update="none"
>        *                 auto-delete="none"
>        */
>       private Collection<ICostCentre> costCentres;
> 
> 
> 
> 
> Use of code:
> 
> 
> public Client decrypt(CypherMachine cm) throws
FailedDecryptionException
> {
>               Client c = new Client(this.id);
>               try {
>                       ...
>                       
>                       EncryptableCollectionProxy costCentresProxy =
> (EncryptableCollectionProxy)costCentres;
>                       costCentresProxy.setCypherMachine(cm);
>       
> costCentresProxy.setEncryptedClassType(EncryptedCostCentre.class);
>                       c.setCostCentres(costCentresProxy);
>                       
>               ...
>                       
>                       return c;
>               } catch(Exception e) {
>                       throw new FailedDecryptionException("Unable to
> decrypt encrypted client: " + this.toString(), e);
>               }
>       }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.487 / Virus Database: 269.13.19/1008 - Release Date:
14/09/2007 08:59



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to