00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.osgi.service.condpermadmin;
00020
00021 import java.lang.reflect.*;
00022 import java.security.AccessController;
00023 import java.security.PrivilegedAction;
00024
00025 import org.osgi.framework.Bundle;
00026
00052 public class BundleSignerCondition {
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 private static final String packageProperty = "org.osgi.vendor.condpermadmin";
00066 private static final Method getCondition;
00067 static {
00068 getCondition = (Method) AccessController
00069 .doPrivileged(new PrivilegedAction() {
00070 public Object run() {
00071 String packageName = System
00072 .getProperty(packageProperty);
00073 if (packageName == null) {
00074 throw new NoClassDefFoundError(packageProperty
00075 + " property not set");
00076 }
00077
00078 Class delegateClass;
00079 try {
00080 delegateClass = Class.forName(packageName
00081 + ".BundleSignerCondition");
00082 }
00083 catch (ClassNotFoundException e) {
00084 throw new NoClassDefFoundError(e.toString());
00085 }
00086
00087 Method result;
00088 try {
00089 result = delegateClass.getMethod("getCondition",
00090 new Class[] {Bundle.class,
00091 ConditionInfo.class });
00092 }
00093 catch (NoSuchMethodException e) {
00094 throw new NoSuchMethodError(e.toString());
00095 }
00096
00097 if (!Modifier.isStatic(result.getModifiers())) {
00098 throw new NoSuchMethodError(
00099 "getCondition method must be static");
00100 }
00101
00102 return result;
00103 }
00104 });
00105 }
00106
00107 private static final String CONDITION_TYPE = "org.osgi.service.condpermadmin.BundleSignerCondition";
00108
00120 static public Condition getCondition(Bundle bundle, ConditionInfo info) {
00121 if (!CONDITION_TYPE.equals(info.getType()))
00122 throw new IllegalArgumentException(
00123 "ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
00124 String[] args = info.getArgs();
00125 if (args.length != 1)
00126 throw new IllegalArgumentException("Illegal number of args: "
00127 + args.length);
00128
00129 try {
00130 try {
00131 return (Condition) getCondition.invoke(null, new Object[] {
00132 bundle, info});
00133 }
00134 catch (InvocationTargetException e) {
00135 throw e.getTargetException();
00136 }
00137 }
00138 catch (Error e) {
00139 throw e;
00140 }
00141 catch (RuntimeException e) {
00142 throw e;
00143 }
00144 catch (Throwable e) {
00145 throw new RuntimeException(e.toString());
00146 }
00147 }
00148
00149 private BundleSignerCondition() {
00150
00151 }
00152 }