You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2004/06/25 19:35:12 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess PersistentFieldAutoProxyImpl.java
tomdz 2004/06/25 10:35:12
Modified: src/java/org/apache/ojb/broker/metadata/fieldaccess
PersistentFieldAutoProxyImpl.java
Log:
Now uses PersistentFieldDirectAccessImpl if a concrete field is present and we're allowed to directly access the field
Revision Changes Path
1.10 +34 -4 db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldAutoProxyImpl.java
Index: PersistentFieldAutoProxyImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldAutoProxyImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PersistentFieldAutoProxyImpl.java 8 May 2004 08:45:01 -0000 1.9
+++ PersistentFieldAutoProxyImpl.java 25 Jun 2004 17:35:12 -0000 1.10
@@ -15,6 +15,9 @@
* limitations under the License.
*/
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+
import org.apache.commons.beanutils.DynaBean;
import org.apache.ojb.broker.metadata.MetadataException;
import org.apache.ojb.broker.util.ClassHelper;
@@ -92,6 +95,17 @@
*/
private AbstractPersistentField getDirectImpl() throws MetadataException
{
+ return getFieldImpl(PersistentFieldDirectAccessImpl.class);
+ }
+
+ /**
+ * Returns an instance of the privileged field-direct handler.
+ *
+ * @return The handler instance
+ * @throws MetadataException If the handler could not be found, or cannot handle the field
+ */
+ private AbstractPersistentField getPrivilegedDirectImpl() throws MetadataException
+ {
return getFieldImpl(PersistentFieldPrivilegedImpl.class);
}
@@ -136,15 +150,31 @@
/*
* this switches on a series of exceptions. Sadly, it is the only real way to detect
- * which one works. The cache should manage things so this chain only need be called
- * once per field. --Brian
+ * which one works. --Brian
*/
try
{
- AbstractPersistentField.computeField(rootObjectType, fieldName, isNestedField(), false);
+ Field field = AbstractPersistentField.computeField(rootObjectType, fieldName, isNestedField(), false);
+ SecurityManager manager = System.getSecurityManager();
- wrapped = getDirectImpl();
+ // ok we have a real field,
+ // however, for non-public fields we have to check whether we're allowed to access
+ // it directly; this is guarded by the security manager, so we ask it
+ try
+ {
+ if ((manager != null) && !field.isAccessible())
+ {
+ // this throws an exception if we're not allowed to the access the declared members
+ manager.checkMemberAccess(field.getDeclaringClass(), Member.DECLARED);
+ }
+ // no security manager or we're allowed to access the field
+ wrapped = getDirectImpl();
+ }
+ catch (SecurityException ex)
+ {
+ wrapped = getPrivilegedDirectImpl();
+ }
hasBeenDetermined = true;
return wrapped;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org