From 218f33f995bb366076b76733f5481bcaad96c6d0 Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 2 Mar 2009 13:46:36 +0000 Subject: Update to work with non-public fields/methods git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@749307 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/runtime/utils/ContextHelper.java | 36 +++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java index ad3136a5fe..a7c03be2ae 100644 --- a/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java +++ b/java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java @@ -70,17 +70,17 @@ public class ContextHelper { Reference ref = field.getAnnotation(Reference.class); String name = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName(); Object value = getReference(name, field.getType(), sc); - field.set(instance, value); + setField(instance, field, value); } else if (field.isAnnotationPresent(Property.class)) { Property prop = field.getAnnotation(Property.class); String name = prop.name() != null && !prop.name().equals("") ? prop.name() : field.getName(); Object value = getProperty(name, sc); - field.set(instance, value); + setField(instance, field, value); } else if (field.isAnnotationPresent(ComponentName.class)) { RuntimeComponent rc = (RuntimeComponent)sc.getAttribute(COMPONENT_ATTR); - field.set(instance, rc.getName()); + setField(instance, field, rc.getName()); } else if (field.isAnnotationPresent(Context.class)) { - field.set(instance, getComponentContext(sc)); + setField(instance, field, getComponentContext(sc)); } } @@ -95,19 +95,39 @@ public class ContextHelper { Reference ref = method.getAnnotation(Reference.class); String name = ref.name() != null && !ref.name().equals("") ? ref.name() : targetName; Object value = getReference(name, type, sc); - method.invoke(instance, new Object[] {value}); + setMethod(instance, method, value); } else if (method.isAnnotationPresent(Property.class)) { Property prop = method.getAnnotation(Property.class); String name = prop.name() != null && !prop.name().equals("") ? prop.name() : targetName; Object value = getProperty(name, sc); - method.invoke(instance, new Object[] {value}); + setMethod(instance, method, value); } else if (method.isAnnotationPresent(ComponentName.class)) { RuntimeComponent rc = (RuntimeComponent)sc.getAttribute(COMPONENT_ATTR); - method.invoke(instance, new Object[] {rc.getName()}); + setMethod(instance, method, rc.getName()); } else if (method.isAnnotationPresent(Context.class)) { - method.invoke(instance, new Object[] {getComponentContext(sc)}); + setMethod(instance, method, getComponentContext(sc)); } } } + private static void setMethod(Object instance, Method method, Object value) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { + if (method.isAccessible()) { + method.invoke(instance, new Object[] {value}); + } else { + method.setAccessible(true); + method.invoke(instance, new Object[] {value}); + method.setAccessible(false); + } + } + + private static void setField(Object instance, Field field, Object value) throws IllegalArgumentException, IllegalAccessException { + if (field.isAccessible()) { + field.set(instance, value); + } else { + field.setAccessible(true); + field.set(instance, value); + field.setAccessible(false); + } + } + } -- cgit v1.2.3