1 22 package org.jboss.aspects.versioned; 23 24 import org.jboss.aop.Advised; 25 import org.jboss.aop.proxy.ClassProxy; 26 import org.jboss.aop.proxy.ClassProxyFactory; 27 import org.jboss.aop.util.PayloadKey; 28 29 36 public class Versioned 37 { 38 public static final String VERSIONED = "VERSIONED"; 39 public static final String VERSIONED_OBJECT = "VERSIONED_OBJECT"; 40 public static final String READONLY = "read-only"; 41 42 public static Object makeVersioned(Object target) 43 throws Exception 44 { 45 if (target instanceof ClassProxy) throw new IllegalStateException ("A ClassProxy is not allowed to be Versioned. You must have a concrete object"); 46 ClassProxy proxy = ClassProxyFactory.newInstance(target.getClass()); 47 VersionedObject versioned = new VersionedObject(target); 48 proxy._getInstanceAdvisor().getMetaData().addMetaData(VERSIONED, VERSIONED_OBJECT, versioned, PayloadKey.TRANSIENT); 49 proxy._getInstanceAdvisor().appendInterceptor(VersionedObjectInterceptorFactory.getInstance()); 50 proxy._getInstanceAdvisor().appendInterceptor(new VersionedObjectForwardingInterceptor()); 51 return proxy; 52 } 53 54 static DistributedVersionManager localManager = null; 55 public static synchronized DistributedVersionManager getLocalVersionManager() throws Exception 56 { 57 if (localManager == null) 58 { 59 LocalSynchronizationManager synchManager = new LocalSynchronizationManager(null); 60 localManager = new DistributedVersionManager(1000, synchManager); 61 synchManager.versionManager = localManager; 62 63 } 64 return localManager; 65 } 66 67 public static void makePerFieldVersioned(Object target) throws Exception 68 { 69 if (!(target instanceof Advised)) throw new IllegalArgumentException ("Cannot do per field versioning with a non-Advised object"); 70 Advised advised = (Advised)target; 71 getLocalVersionManager().makeVersioned(advised); 72 } 73 74 } 75 | Popular Tags |