/*
 * $Header$
 * 
 * Copyright (c) OSGi Alliance (2005). All Rights Reserved.
 * 
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this 
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package org.osgi.service.condpermadmin;

import java.io.File;
import java.io.FilePermission;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.osgi.framework.Bundle;

/**
 * 
 * Checks to see if a Bundle matches the given location pattern. Pattern
 * matching is done using FilePermission style patterns.
 * 
 * @version $Revision$
 */
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 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.
	 */
	static public Condition getCondition(final 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];
		String bundleLocation = (String) AccessController.doPrivileged(new PrivilegedAction() {
					public Object run() {
						return bundle.getLocation();
					}
				});

		if ('/' != File.separatorChar) {
			// must use the seperatorChar of the platform for FilePermission to work
			location = location.replace('/', File.separatorChar);
			bundleLocation = bundleLocation.replace('/', File.separatorChar);
		}
		FilePermission locationPat = new FilePermission(location, "read");
		FilePermission sourcePat = new FilePermission(bundleLocation, "read");
		return locationPat.implies(sourcePat) ? Condition.TRUE
				: Condition.FALSE;
	}

	private BundleLocationCondition() {
		// private constructor to prevent objects of this type
	}
}

@@ -474,16 +474,44 @@
 dAction;
+%0Aimport java.util.Hashtable;
 %0A%0Aimport
@@ -530,22 +530,17 @@
 amework.
-Bundle
+*
 ;%0A%0A/**%0A 
@@ -639,42 +639,52 @@
 one 
-using FilePermission style pattern
+according to the filter string matching rule
 s.%0A 
@@ -1228,56 +1228,48 @@
 the 
-patterns documented%0A%09 *        in FilePermission
+filter string %0A%09 *        matching rules
 .%0A%09 
@@ -1651,37 +1651,8 @@
 h);%0A
-%09%09String location = args%5B0%5D;%0A
 %09%09St
@@ -1818,367 +1818,342 @@
 %7D);%0A
-%0A
 %09%09
-if ('/' != File.separatorChar) %7B%0A%09%09%09// must use the seperatorChar of the platform for FilePermission to work%0A%09%09%09location = location.replace('/', File.separatorChar);%0A%09%09%09bundleLocation = bundleLocation.replace('/', File.separatorChar);%0A%09%09%7D%0A%09%09FilePermission locationPat = new FilePermission(location, %22read%22);%0A%09%09FilePermission sourcePat = new FilePermission(
+Filter filter = null;%0A%09%09try %7B%0A%09%09%09filter = FrameworkUtil.createFilter(%22(location=%22 + args%5B0%5D + %22)%22);%0A%09%09%7D%0A%09%09catch (InvalidSyntaxException e) %7B%0A%09%09%09// this should never happen, but just incase%0A%09%09%09throw new RuntimeException(%22Invalid filter: %22 + e.getFilter());%0A%09%09%7D%0A%09%09Hashtable matchProps = new Hashtable(2);%0A%09%09matchProps.put(%22location%22, 
 bund
@@ -2166,16 +2166,8 @@
 tion
-, %22read%22
 );%0A%09
@@ -2178,37 +2178,31 @@
 urn 
-locationPat.implies(sourcePat
+filter.match(matchProps
 ) ? 
@@ -2215,21 +2215,17 @@
 ion.TRUE
-%0A%09%09%09%09
+ 
 : Condit

Use string filter matching rules on bundle location instead of FilePermission matching rules.