equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. |
2 * Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Sun designates this |
7 * published by the Free Software Foundation. Sun designates this |
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
25 package java.beans; |
25 package java.beans; |
26 |
26 |
27 import java.util.Collections; |
27 import com.sun.beans.finder.PersistenceDelegateFinder; |
|
28 |
28 import java.util.HashMap; |
29 import java.util.HashMap; |
29 import java.util.IdentityHashMap; |
30 import java.util.IdentityHashMap; |
30 import java.util.Map; |
31 import java.util.Map; |
31 |
32 |
32 /** |
33 /** |
43 * |
44 * |
44 * @author Philip Milne |
45 * @author Philip Milne |
45 */ |
46 */ |
46 |
47 |
47 public class Encoder { |
48 public class Encoder { |
48 private final Map<Class<?>, PersistenceDelegate> delegates |
49 private final PersistenceDelegateFinder finder = new PersistenceDelegateFinder(); |
49 = Collections.synchronizedMap(new HashMap<Class<?>, PersistenceDelegate>()); |
|
50 private Map bindings = new IdentityHashMap(); |
50 private Map bindings = new IdentityHashMap(); |
51 private ExceptionListener exceptionListener; |
51 private ExceptionListener exceptionListener; |
52 boolean executeStatements = true; |
52 boolean executeStatements = true; |
53 private Map attributes; |
53 private Map attributes; |
54 |
54 |
164 * @see #setPersistenceDelegate |
164 * @see #setPersistenceDelegate |
165 * @see java.beans.Introspector#getBeanInfo |
165 * @see java.beans.Introspector#getBeanInfo |
166 * @see java.beans.BeanInfo#getBeanDescriptor |
166 * @see java.beans.BeanInfo#getBeanDescriptor |
167 */ |
167 */ |
168 public PersistenceDelegate getPersistenceDelegate(Class<?> type) { |
168 public PersistenceDelegate getPersistenceDelegate(Class<?> type) { |
169 PersistenceDelegate pd = this.delegates.get(type); |
169 synchronized (this.finder) { |
170 return (pd != null) ? pd : MetaData.getPersistenceDelegate(type); |
170 PersistenceDelegate pd = this.finder.find(type); |
|
171 if (pd != null) { |
|
172 return pd; |
|
173 } |
|
174 } |
|
175 return MetaData.getPersistenceDelegate(type); |
171 } |
176 } |
172 |
177 |
173 /** |
178 /** |
174 * Sets the persistence delegate associated with this <code>type</code> to |
179 * Sets the persistence delegate associated with this <code>type</code> to |
175 * <code>persistenceDelegate</code>. |
180 * <code>persistenceDelegate</code>. |
182 * @see java.beans.BeanInfo#getBeanDescriptor |
187 * @see java.beans.BeanInfo#getBeanDescriptor |
183 */ |
188 */ |
184 public void setPersistenceDelegate(Class<?> type, |
189 public void setPersistenceDelegate(Class<?> type, |
185 PersistenceDelegate persistenceDelegate) |
190 PersistenceDelegate persistenceDelegate) |
186 { |
191 { |
187 if (persistenceDelegate != null) { |
192 synchronized (this.finder) { |
188 this.delegates.put(type, persistenceDelegate); |
193 this.finder.register(type, persistenceDelegate); |
189 } else { |
|
190 this.delegates.remove(type); |
|
191 } |
194 } |
192 } |
195 } |
193 |
196 |
194 /** |
197 /** |
195 * Removes the entry for this instance, returning the old entry. |
198 * Removes the entry for this instance, returning the old entry. |