BundleSignerCondition.java

00001 /*
00002  * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleSignerCondition.java,v 1.10 2006/06/16 16:31:37 hargrave Exp $
00003  * 
00004  * Copyright (c) OSGi Alliance (2005, 2006). All Rights Reserved.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  *      http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
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          * NOTE: A framework implementor may also choose to replace this class in
00055          * their distribution with a class that directly interfaces with the
00056          * framework implementation. This replacement class MUST NOT alter the
00057          * public/protected signature of this class.
00058          */
00059 
00060         /*
00061          * This class will load the BundleSignerCondition class in the package named
00062          * by the org.osgi.vendor.condpermadmin package. This class will delegate
00063          * getCondition methods calls to the vendor BundleSignerCondition class.
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                 // private constructor to prevent objects of this type
00151         }
00152 }

Generated on Mon Jan 11 21:19:13 2010 for OpenMobileIS by  doxygen 1.5.4