1 22 package org.jboss.ejb3.interceptor; 23 24 import java.io.IOException ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 import java.util.Set ; 29 30 import org.jboss.aop.joinpoint.Invocation; 31 import org.jboss.aop.metadata.SimpleMetaData; 32 import org.jboss.aop.util.PayloadKey; 33 34 40 public class ClientInterceptorUtil 41 { 42 public static final String CLIENT_METADATA = "jboss.ejb3.client.invocation.metadata"; 43 44 public static void addMetadata(Invocation invocation, Object key, Object value, PayloadKey payload) 45 { 46 invocation.getMetaData().addMetaData(CLIENT_METADATA, key, value, payload); 47 } 48 49 public static void addMetadata(Invocation invocation, Object key, Object value) 50 { 51 invocation.getMetaData().addMetaData(CLIENT_METADATA, key, value); 52 } 53 54 public static Object getMetadata(Invocation invocation, Object key) 55 { 56 return invocation.getMetaData().getMetaData(CLIENT_METADATA, key); 57 } 58 59 static Map getClientMetadataMap(Invocation invocation) 60 { 61 Map map = invocation.getMetaData().tag(CLIENT_METADATA); 62 if (map != null) 63 { 64 return new ClientValueMap(map); 65 } 66 return null; 67 } 68 69 72 73 private static class ClientValueMap implements Map 74 { 75 Map marshalledMap; 76 boolean haveUnmarshalledAllEntries; 77 78 private ClientValueMap(Map marshalledMap) 79 { 80 this.marshalledMap = marshalledMap; 81 } 82 83 public void clear() 84 { 85 marshalledMap.clear(); 86 } 87 88 public boolean containsKey(Object key) 89 { 90 return marshalledMap.containsKey(key); 91 } 92 93 public boolean containsValue(Object value) 94 { 95 unmarshallAllEntries(); 96 return marshalledMap.containsValue(value); 97 } 98 99 public Set entrySet() 100 { 101 unmarshallAllEntries(); 102 return marshalledMap.entrySet(); 103 } 104 105 public boolean equals(Object o) 106 { 107 return marshalledMap.equals(o); 108 } 109 110 public Object get(Object key) 111 { 112 return unmarshallEntry(key); 113 } 114 115 public int hashCode() 116 { 117 return marshalledMap.hashCode(); 118 } 119 120 public boolean isEmpty() 121 { 122 return marshalledMap.isEmpty(); 123 } 124 125 public Set keySet() 126 { 127 return marshalledMap.keySet(); 128 } 129 130 public Object put(Object key, Object value) 131 { 132 return marshalledMap.put(key, value); 133 } 134 135 public void putAll(Map t) 136 { 137 marshalledMap.putAll(t); 138 } 139 140 public Object remove(Object key) 141 { 142 return marshalledMap.remove(key); 143 } 144 145 public int size() 146 { 147 return marshalledMap.size(); 148 } 149 150 public Collection values() 151 { 152 unmarshallAllEntries(); 153 return marshalledMap.values(); 154 } 155 156 private void unmarshallAllEntries() 157 { 158 if (haveUnmarshalledAllEntries) 159 { 160 return; 161 } 162 163 Iterator keys = marshalledMap.keySet().iterator(); 164 while (keys.hasNext()) 165 { 166 unmarshallEntry(keys.next()); 168 } 169 haveUnmarshalledAllEntries = true; 170 } 171 172 private Object unmarshallEntry(Object key) 173 { 174 try 175 { 176 Object obj = marshalledMap.get(key); 177 if (obj instanceof SimpleMetaData.MetaDataValue) 178 { 179 Object realObj = ((SimpleMetaData.MetaDataValue)obj).get(); 180 marshalledMap.put(key, realObj); 181 return realObj; 182 } 183 return obj; 184 } 185 catch (IOException e) 186 { 187 throw new RuntimeException (e); 188 } 189 catch (ClassNotFoundException e) 190 { 191 throw new RuntimeException (e); 192 } 193 } 194 } 195 } 196 | Popular Tags |