summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-03-02 13:46:36 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-03-02 13:46:36 +0000
commit218f33f995bb366076b76733f5481bcaad96c6d0 (patch)
tree905098766fff22cc6b31cb90ff3139203c69ddd0 /java/sca
parenta7313bd1ff764e5060b9bb3a090cd41d66e9293c (diff)
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
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/utils/ContextHelper.java36
1 files 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);
+ }
+ }
+
}