Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2005-05-25 18:55:17 +0000
committerThomas Watson2005-05-25 18:55:17 +0000
commit0f241fe2b22f022c6c4d8a4d9a4a4b7009bac8ef (patch)
tree8692a34e5420595e1ac3dc8dd5f147cb3e98900c
parent925b299a8b97437396c38979cd920c2b864fb972 (diff)
downloadrt.equinox.framework-0f241fe2b22f022c6c4d8a4d9a4a4b7009bac8ef.tar.gz
rt.equinox.framework-0f241fe2b22f022c6c4d8a4d9a4a4b7009bac8ef.tar.xz
rt.equinox.framework-0f241fe2b22f022c6c4d8a4d9a4a4b7009bac8ef.zip
Bug 96649 [osgi] ConditionalPermissionAdmin spec changesOSGI_RI_20050525
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ConditionalPermissionInfoImpl.java80
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleLocationCondition.java75
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleSignerCondition.java75
-rw-r--r--bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/Condition.java40
4 files changed, 100 insertions, 170 deletions
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ConditionalPermissionInfoImpl.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ConditionalPermissionInfoImpl.java
index 5f14a5648..a40b0804f 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ConditionalPermissionInfoImpl.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/ConditionalPermissionInfoImpl.java
@@ -69,17 +69,7 @@ public class ConditionalPermissionInfoImpl implements ConditionalPermissionInfo,
/* Used to find permission constructors in addPermissions */
static private Class twoStringClassArray[] = new Class[] {String.class, String.class};
/* Used to find condition constructors getConditions */
- static private Class condClassArray[][];
- static {
- condClassArray = new Class[3][];
- for (int i = 0; i < condClassArray.length; i++) {
- condClassArray[i] = new Class[i + 1];
- condClassArray[i][0] = Bundle.class;
- for (int j = 1; j <= i; j++) {
- condClassArray[i][j] = String.class;
- }
- }
- }
+ static private Class[] condClassArray = new Class[] {Bundle.class, ConditionInfo.class};
/**
* Adds the permissions of the given type (if any) that are part of this
@@ -123,14 +113,8 @@ public class ConditionalPermissionInfoImpl implements ConditionalPermissionInfo,
*
* @return the array of Conditions that must be satisfied before permissions
* in the ConditionPermissionInfoImpl can be used.
- * @throws SecurityException
- * @throws NoSuchMethodException
- * @throws IllegalArgumentException
- * @throws InstantiationException
- * @throws IllegalAccessException
- * @throws InvocationTargetException
*/
- Condition[] getConditions(Bundle bundle) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
+ Condition[] getConditions(Bundle bundle) {
Condition conditions[] = new Condition[conds.length];
for (int i = 0; i < conds.length; i++) {
/*
@@ -146,48 +130,32 @@ public class ConditionalPermissionInfoImpl implements ConditionalPermissionInfo,
}
Constructor constructor = null;
Method method = null;
- int argCount = conds[i].getArgs().length;
- if (argCount < condClassArray.length) {
- try {
- method = clazz.getMethod("getInstance", condClassArray[argCount]); //$NON-NLS-1$
- if ((method.getModifiers() & Modifier.STATIC) == 0) {
- method = null;
- }
- } catch (NoSuchMethodException e) {
- // This is a normal case
- }
- if (method == null) {
- constructor = clazz.getConstructor(condClassArray[argCount]);
- }
- } else {
- Class clazzes[] = new Class[argCount + 1];
- clazzes[0] = Bundle.class;
- for (int j = 1; j <= argCount; j++) {
- clazzes[j] = String.class;
- }
+ try {
+ method = clazz.getMethod("getCondition", condClassArray); //$NON-NLS-1$
+ if ((method.getModifiers() & Modifier.STATIC) == 0)
+ method = null;
+ } catch (NoSuchMethodException e) {
+ // This is a normal case
+ }
+ if (method == null)
try {
- method = clazz.getMethod("getInstance", clazzes); //$NON-NLS-1$
- if ((method.getModifiers() & Modifier.STATIC) == 0) {
- method = null;
- }
+ constructor = clazz.getConstructor(condClassArray);
} catch (NoSuchMethodException e) {
- // This is a normal case
- }
- if (method == null) {
- constructor = clazz.getConstructor(clazzes);
+ // TODO should post a FrameworkEvent of type error here
+ conditions[i] = Condition.FALSE;
+ continue;
}
+
+ Object args[] = {bundle, conds[i]};
+ try {
+ if (method != null)
+ conditions[i] = (Condition) method.invoke(null, args);
+ else
+ conditions[i] = (Condition) constructor.newInstance(args);
+ } catch (Throwable t) {
+ // TODO should post a FrameworkEvent of type error here
+ conditions[i] = Condition.FALSE;
}
- String strArgs[] = conds[i].getArgs();
- Object args[] = new Object[strArgs.length + 1];
- args[0] = bundle;
- System.arraycopy(strArgs, 0, args, 1, strArgs.length);
- Condition condition = null;
- if (method != null) {
- condition = (Condition) method.invoke(null, args);
- } else {
- condition = (Condition) constructor.newInstance(args);
- }
- conditions[i] = condition;
}
return conditions;
}
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleLocationCondition.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleLocationCondition.java
index b50946d97..62962dd42 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleLocationCondition.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleLocationCondition.java
@@ -1,5 +1,5 @@
/*
- * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleLocationCondition.java,v 1.8 2005/05/16 13:46:53 pkriens Exp $
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleLocationCondition.java,v 1.9 2005/05/25 16:22:46 twatson Exp $
*
* Copyright (c) OSGi Alliance (2005). All Rights Reserved.
*
@@ -10,81 +10,40 @@
package org.osgi.service.condpermadmin;
import java.io.FilePermission;
-import java.util.Dictionary;
import org.osgi.framework.Bundle;
-import org.osgi.service.condpermadmin.Condition;
/**
*
* Checks to see if a Bundle matches the given location pattern. Pattern matching
* is done using FilePermission style patterns.
*
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
-public class BundleLocationCondition implements Condition {
- boolean satisfied;
-
+public class BundleLocationCondition {
+ private static final String CONDITION_TYPE = "org.osgi.service.condpermadmin.BundleLocationCondition";
/**
* Constructs a condition that tries to match the passed Bundle's location
* to the location pattern.
*
* @param bundle the Bundle being evaluated.
- * @param location the location specification to match the Bundle
+ * @param info the ConditionInfo to construct the condition for. The args of the
+ * ConditionInfo specify the location to match the Bundle
* location to. Matching is done according to the patterns documented
* in FilePermission.
*/
- public BundleLocationCondition(Bundle bundle, String location) {
+ static public Condition getCondition(Bundle bundle, ConditionInfo info) {
+ if (!CONDITION_TYPE.equals(info.getType()))
+ throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
+ String[] args = info.getArgs();
+ if (args.length != 1)
+ throw new IllegalArgumentException("Illegal number of args: " + args.length);
+ String location = args[0];
FilePermission locationPat = new FilePermission(location, "read");
- FilePermission sourcePat = new FilePermission(bundle.getLocation()
- .toString(), "read");
- satisfied = locationPat.implies(sourcePat);
- }
-
- /**
- * This method is always true since this is an immutable Condition.
- *
- * @return always true.
- * @see org.osgi.service.condpermadmin.Condition#isPostponed()
- */
- public boolean isPostponed() {
- return false;
- }
-
- /**
- * This method returns true if the location of the bundle matches the the
- * location pattern that was used to construct this Condition. The matching
- * is done according to the matching scheme in FilePermission.
- *
- * @return true if the location of the bundle matches the location pattern
- * of this condition.
- * @see org.osgi.service.condpermadmin.Condition#isSatisfied()
- * @see java.io.FilePermission
- */
- public boolean isSatisfied() {
- return satisfied;
+ FilePermission sourcePat = new FilePermission(bundle.getLocation().toString(), "read");
+ return locationPat.implies(sourcePat) ? Condition.TRUE : Condition.FALSE;
}
- /**
- * This Condition never changes, so this method always returns false.
- *
- * @return always returns false.
- * @see org.osgi.service.condpermadmin.Condition#isMutable()
- */
- public boolean isMutable() {
- return false;
- }
-
- /**
- * This method should never get called since this is an immutable Condition. As implemented it simply loops through all the Conditions calling isSatisfied()
- * @param conds the conditions to check for satisfiability.
- * @param context not used.
- * @return true if all of the conditions are satisfied.
- * @see org.osgi.service.condpermadmin.Condition#isSatisfied(org.osgi.service.condpermadmin.Condition[],Dictionary)
- */
- public boolean isSatisfied(Condition[] conds, Dictionary context) {
- for(int i = 0; i < conds.length; i++) {
- if (!conds[i].isSatisfied()) return false;
- }
- return true;
+ private BundleLocationCondition() {
+ // private constructor to prevent objects of this type
}
}
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleSignerCondition.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleSignerCondition.java
index 4f56ca6bb..ad3c70717 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleSignerCondition.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleSignerCondition.java
@@ -1,5 +1,5 @@
/*
- * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleSignerCondition.java,v 1.3 2005/05/16 13:48:39 pkriens Exp $
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/BundleSignerCondition.java,v 1.4 2005/05/25 16:22:46 twatson Exp $
*
* Copyright (c) OSGi Alliance (2005). All Rights Reserved.
*
@@ -10,7 +10,6 @@
package org.osgi.service.condpermadmin;
-import java.util.Dictionary;
import org.eclipse.osgi.framework.internal.core.AbstractBundle;
import org.osgi.framework.Bundle;
@@ -34,65 +33,31 @@ import org.osgi.framework.Bundle;
* the corresponding type in that RDN. If a wildcard is used for a RDN, it must be the
* first RDN and will match any number of RDNs (including zero RDNs).
*
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public class BundleSignerCondition implements Condition {
- boolean satisfied;
-
+public class BundleSignerCondition {
+ private static final String CONDITION_TYPE = "org.osgi.service.condpermadmin.BundleSignerCondition";
/**
- * Constructs a BundleSignerCondition for the given bundle to check against the pattern specified in <code>dnChain</code>.
+ * Constructs a condition that tries to match the passed Bundle's location
+ * to the location pattern.
*
- * @param bundle the bundle to check this condition against.
- * @param dnChain the chain of distinguished names pattern to check against the signer of the bundle.
+ * @param bundle the Bundle being evaluated.
+ * @param info the ConditionInfo to construct the condition for. The args of the
+ * ConditionInfo specify the chain of distinguished names pattern to match
+ * against the signer of the Bundle
*/
- public BundleSignerCondition(Bundle bundle, String dnChain) {
+ static public Condition getCondition(Bundle bundle, ConditionInfo info) {
+ if (!CONDITION_TYPE.equals(info.getType()))
+ throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
+ String[] args = info.getArgs();
+ if (args.length != 1)
+ throw new IllegalArgumentException("Illegal number of args: " + args.length);
+ // implementation specific code used here
AbstractBundle ab = (AbstractBundle) bundle;
- satisfied = ab.getBundleData().matchDNChain(dnChain);
- }
-
-
- /**
- * Always returns true, since this condition is immutable.
- * @return always returns true;
- * @see org.osgi.service.condpermadmin.Condition#isPostponed()
- */
- public boolean isPostponed() {
- return false;
- }
-
- /**
- * Returns true if the bundle used to construct this condition matches
- * the condition's DNChain expression.
- * @return true if the DNChain expression is matched.
- * @see org.osgi.service.condpermadmin.Condition#isSatisfied()
- */
- public boolean isSatisfied() {
- return satisfied;
- }
-
- /**
- * Always returns false, since this condition is immutable.
- * @return always returns false.
- * @see org.osgi.service.condpermadmin.Condition#isMutable()
- */
- public boolean isMutable() {
- return false;
+ return ab.getBundleData().matchDNChain(args[0]) ? Condition.TRUE : Condition.FALSE;
}
- /**
- * This method simply invokes the isSatisfied() method of all the conds
- * and returns true only if all of the method invocations return true.
- * @param conds the conditions to check for satisfiability.
- * @param context not used.
- * @return true only if all the conds are true.
- * @see org.osgi.service.condpermadmin.Condition#isSatisfied(org.osgi.service.condpermadmin.Condition[], java.util.Dictionary)
- */
- public boolean isSatisfied(Condition[] conds, Dictionary context) {
- for (int i = 0; i < conds.length; i++) {
- if (!conds[i].isSatisfied()) {
- return false;
- }
- }
- return true;
+ private BundleSignerCondition() {
+ // private constructor to prevent objects of this type
}
}
diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/Condition.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/Condition.java
index 49e2947df..76dba1c42 100644
--- a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/Condition.java
+++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/Condition.java
@@ -1,5 +1,5 @@
/*
- * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/Condition.java,v 1.8 2005/05/16 13:49:37 pkriens Exp $
+ * $Header: /cvshome/build/org.osgi.service.condpermadmin/src/org/osgi/service/condpermadmin/Condition.java,v 1.9 2005/05/25 16:22:46 twatson Exp $
*
* Copyright (c) OSGi Alliance (2004, 2005). All Rights Reserved.
*
@@ -20,6 +20,16 @@ import java.util.Dictionary;
*/
public interface Condition {
/**
+ * A condition object that will always evaluate to true and that is never postponed.
+ */
+ public final static Condition TRUE = new BooleanCondition(true);
+
+ /**
+ * A condition object that will always evaluate to false and that is never postponed.
+ */
+ public final static Condition FALSE = new BooleanCondition(false);
+
+ /**
* This method returns true if the evaluation of the Condition must be postponed
* until the end of the permission check. If it returns false, it must be able
* to directly answer the isSatisfied method. In other
@@ -56,4 +66,32 @@ public interface Condition {
* @return true if all the Conditions are satisfied.
*/
boolean isSatisfied(Condition conds[], Dictionary context);
+
+ /**
+ * Package internal class used to define the {@link Condition#FALSE} and
+ * {@link Condition#TRUE} constants.
+ */
+ final static class BooleanCondition implements Condition {
+ boolean satisfied;
+ BooleanCondition(boolean satisfied) {
+ this.satisfied = satisfied;
+ }
+ public boolean isPostponed() {
+ return false;
+ }
+ public boolean isSatisfied() {
+ return satisfied;
+ }
+ public boolean isMutable() {
+ return false;
+ }
+ public boolean isSatisfied(Condition[] conds, Dictionary context) {
+ for(int i = 0; i < conds.length; i++) {
+ if (!conds[i].isSatisfied())
+ return false;
+ }
+ return true;
+ }
+
+ }
}

Back to the top