1 8 package org.codehaus.aspectwerkz; 9 10 import org.codehaus.aspectwerkz.aspect.AspectContainer; 11 import org.codehaus.aspectwerkz.aspect.management.Aspects; 12 import org.codehaus.aspectwerkz.definition.AspectDefinition; 13 14 import java.io.ObjectInputStream ; 15 import java.io.Serializable ; 16 import java.util.HashMap ; 17 import java.util.Map ; 18 import java.lang.ref.WeakReference ; 19 20 25 public final class AspectContext implements Serializable { 26 29 public static final Object [] EMPTY_OBJECT_ARRAY = new Object []{}; 30 31 34 private String m_name; 35 36 39 private String m_qName; 40 41 44 private transient WeakReference m_aspectClassRef; 45 46 49 private transient AspectContainer m_container = null; 50 51 54 private DeploymentModel m_deploymentModel; 55 56 59 private Map m_parameters = new HashMap (); 60 61 64 private Map m_metaData = new HashMap (); 65 66 69 private String m_uuid; 70 71 74 private transient AspectDefinition m_aspectDefinition; 75 76 85 public AspectContext(final String uuid, 86 final Class aspectClass, 87 final String name, 88 final DeploymentModel deploymentModel, 89 final AspectDefinition aspectDef, 90 final Map parameters) { 91 m_uuid = uuid; 92 m_aspectClassRef = new WeakReference (aspectClass); 93 m_name = name; 94 m_qName = aspectDef.getQualifiedName(); 95 m_deploymentModel = deploymentModel; 96 m_aspectDefinition = aspectDef; 97 if (parameters != null) { 98 m_parameters = parameters; 99 } 100 } 101 102 108 public static AspectContext newInstance(final AspectContext prototype) { 109 try { 110 return new AspectContext( 111 prototype.m_uuid, 112 (Class ) prototype.m_aspectClassRef.get(), 113 prototype.m_name, 114 prototype.m_deploymentModel, 115 prototype.m_aspectDefinition, 116 prototype.m_parameters 117 ); 118 } catch (Exception e) { 119 throw new RuntimeException ( 120 "could not clone cross-cutting info [" 121 + prototype.getName() 122 + "]: " 123 + e.toString() 124 ); 125 } 126 } 127 128 133 public String getUuid() { 134 return m_uuid; 135 } 136 137 142 public String getName() { 143 return m_name; 144 } 145 146 151 public DeploymentModel getDeploymentModel() { 152 return m_deploymentModel; 153 } 154 155 160 public Class getAspectClass() { 161 return (Class ) m_aspectClassRef.get(); 162 } 163 164 169 public void setContainer(final AspectContainer container) { 170 m_container = container; 171 } 172 173 178 public AspectContainer getContainer() { 179 return m_container; 180 } 181 182 189 public AspectDefinition getAspectDefinition() { 190 return m_aspectDefinition; 191 } 192 193 199 public void setParameter(final String name, final String value) { 200 m_parameters.put(name, value); 201 } 202 203 209 public String getParameter(final String name) { 210 return (String ) m_parameters.get(name); 211 } 212 213 219 public void addMetaData(final Object key, final Object value) { 220 m_metaData.put(key, value); 221 } 222 223 229 public Object getMetaData(final Object key) { 230 return m_metaData.get(key); 231 } 232 233 236 public boolean isPrototype() { 237 return (m_container == null); 238 } 239 240 246 private void readObject(final ObjectInputStream stream) throws Exception { 247 ObjectInputStream.GetField fields = stream.readFields(); 248 m_uuid = (String ) fields.get("m_uuid", null); 249 m_name = (String ) fields.get("m_name", null); 250 m_qName = (String ) fields.get("m_qName", null); 251 Class aspectClass = Class.forName(m_name); 252 m_aspectClassRef = new WeakReference (aspectClass); 253 m_deploymentModel = (DeploymentModel) fields.get("m_deploymentModel", DeploymentModel.PER_JVM); 254 m_parameters = (Map ) fields.get("m_parameters", new HashMap ()); 255 m_metaData = (Map ) fields.get("m_metaData", new HashMap ()); 256 257 String containerClassName = Aspects.getAspectQNameContainerClassName(Thread.currentThread().getContextClassLoader(), m_qName)[1]; 258 Class containerClass = Class.forName(containerClassName); 259 m_container = Aspects.getContainerQNamed(Thread.currentThread().getContextClassLoader(), containerClass, m_qName); 260 261 } 263 } | Popular Tags |