You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2008/09/01 17:08:10 UTC
svn commit: r690991 [13/20] - in /cxf/sandbox/dosgi: ./ discovery/
discovery/local/ discovery/local/src/ discovery/local/src/main/
discovery/local/src/main/java/ discovery/local/src/main/java/org/
discovery/local/src/main/java/org/apache/ discovery/loc...
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,1167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.net.JarURLConnection;
+import java.net.MalformedURLException;
+import java.net.*;
+import java.security.*;
+import java.util.Hashtable;
+import java.util.jar.JarFile;
+
+import org.apache.felix.framework.searchpolicy.ContentClassLoader;
+import org.apache.felix.framework.searchpolicy.ContentLoaderImpl;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * <p>
+ * This is a utility class to centralize all action that should be performed
+ * in a <tt>doPrivileged()</tt> block. To perform a secure action, simply
+ * create an instance of this class and use the specific method to perform
+ * the desired action. When an instance is created, this class will capture
+ * the security context and will then use that context when checking for
+ * permission to perform the action. Instances of this class should not be
+ * passed around since they may grant the receiver a capability to perform
+ * privileged actions.
+ * </p>
+**/
+public class SecureAction
+{
+ private static final ThreadLocal m_actions = new ThreadLocal()
+ {
+ public Object initialValue()
+ {
+ return new Actions();
+ }
+ };
+
+ protected static transient int BUFSIZE = 4096;
+
+ private AccessControlContext m_acc = null;
+
+ public SecureAction()
+ {
+ m_acc = AccessController.getContext();
+ }
+
+ public String getSystemProperty(String name, String def)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_PROPERTY_ACTION, name, def);
+ return (String) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return System.getProperty(name, def);
+ }
+ }
+
+ public Class forName(String name) throws ClassNotFoundException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.FOR_NAME_ACTION, name);
+ return (Class) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof ClassNotFoundException)
+ {
+ throw (ClassNotFoundException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return Class.forName(name);
+ }
+ }
+
+ public URL createURL(String protocol, String host,
+ int port, String path, URLStreamHandler handler)
+ throws MalformedURLException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.CREATE_URL_ACTION, protocol, host,
+ new Integer(port), path, handler);
+ return (URL) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof MalformedURLException)
+ {
+ throw (MalformedURLException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new URL(protocol, host, port, path, handler);
+ }
+ }
+
+ public URL createURL(URL context, String spec, URLStreamHandler handler)
+ throws MalformedURLException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.CREATE_URL_WITH_CONTEXT_ACTION, context,
+ spec, handler);
+ return (URL) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof MalformedURLException)
+ {
+ throw (MalformedURLException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new URL(context, spec, handler);
+ }
+ }
+
+ public String getAbsolutePath(File file)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_ABSOLUTE_PATH_ACTION, file);
+ return (String) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return file.getAbsolutePath();
+ }
+ }
+
+ public boolean fileExists(File file)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.FILE_EXISTS_ACTION, file);
+ return ((Boolean) AccessController.doPrivileged(actions, m_acc))
+ .booleanValue();
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return file.exists();
+ }
+ }
+
+ public boolean isFileDirectory(File file)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.FILE_IS_DIRECTORY_ACTION, file);
+ return ((Boolean) AccessController.doPrivileged(actions, m_acc))
+ .booleanValue();
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return file.isDirectory();
+ }
+ }
+
+ public boolean mkdir(File file)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.MAKE_DIRECTORY_ACTION, file);
+ return ((Boolean) AccessController.doPrivileged(actions, m_acc))
+ .booleanValue();
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return file.mkdir();
+ }
+ }
+
+ public boolean mkdirs(File file)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.MAKE_DIRECTORIES_ACTION, file);
+ return ((Boolean) AccessController.doPrivileged(actions, m_acc))
+ .booleanValue();
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return file.mkdirs();
+ }
+ }
+
+ public File[] listDirectory(File file)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.LIST_DIRECTORY_ACTION, file);
+ return (File[]) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return file.listFiles();
+ }
+ }
+
+ public boolean renameFile(File oldFile, File newFile)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.RENAME_FILE_ACTION, oldFile, newFile);
+ return ((Boolean) AccessController.doPrivileged(actions, m_acc))
+ .booleanValue();
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return oldFile.renameTo(newFile);
+ }
+ }
+
+ public InputStream getFileInputStream(File file) throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_FILE_INPUT_ACTION, file);
+ return (InputStream) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new FileInputStream(file);
+ }
+ }
+
+ public OutputStream getFileOutputStream(File file) throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_FILE_OUTPUT_ACTION, file);
+ return (OutputStream) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new FileOutputStream(file);
+ }
+ }
+
+ public InputStream getURLConnectionInputStream(URLConnection conn)
+ throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_URL_INPUT_ACTION, conn);
+ return (InputStream) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return conn.getInputStream();
+ }
+ }
+
+ public boolean deleteFile(File target)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.DELETE_FILE_ACTION, target);
+ return ((Boolean) AccessController.doPrivileged(actions, m_acc))
+ .booleanValue();
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return target.delete();
+ }
+ }
+
+ public File createTempFile(String prefix, String suffix, File dir)
+ throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.CREATE_TMPFILE_ACTION, prefix, suffix, dir);
+ return (File) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return File.createTempFile(prefix, suffix, dir);
+ }
+ }
+
+ public URLConnection openURLConnection(URL url) throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.OPEN_URLCONNECTION_ACTION, url);
+ return (URLConnection) AccessController.doPrivileged(actions,
+ m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return url.openConnection();
+ }
+ }
+
+ public JarFile getJarURLConnectionJAR(JarURLConnection connection)
+ throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.OPEN_JARURLCONNECTIONJAR_ACTION, connection);
+ return (JarFile) AccessController.doPrivileged(actions,
+ m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return connection.getJarFile();
+ }
+ }
+
+ public JarFileX openJAR(File file) throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.OPEN_JARX_ACTION, file);
+ return (JarFileX) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new JarFileX(file);
+ }
+ }
+
+ public JarFile openJAR(File file, boolean verify) throws IOException
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.OPEN_JAR_ACTION, file, (verify ? Boolean.TRUE : Boolean.FALSE));
+ return (JarFile) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ if (ex.getException() instanceof IOException)
+ {
+ throw (IOException) ex.getException();
+ }
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new JarFileX(file);
+ }
+ }
+
+ public ContentClassLoader createContentClassLoader(ContentLoaderImpl impl)
+ {
+ return createContentClassLoader(impl, null);
+ }
+
+ public ContentClassLoader createContentClassLoader(ContentLoaderImpl impl,
+ ProtectionDomain protectionDomain)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.CREATE_CONTENTCLASSLOADER_ACTION, impl, protectionDomain);
+ return (ContentClassLoader) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return new ContentClassLoader(impl, protectionDomain);
+ }
+ }
+
+ public void startActivator(BundleActivator activator, BundleContext context)
+ throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.START_ACTIVATOR_ACTION, activator, context);
+ AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw ex.getException();
+ }
+ }
+ else
+ {
+ activator.start(context);
+ }
+ }
+
+ public void stopActivator(BundleActivator activator, BundleContext context)
+ throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.STOP_ACTIVATOR_ACTION, activator, context);
+ AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw ex.getException();
+ }
+ }
+ else
+ {
+ activator.stop(context);
+ }
+ }
+
+ public void exit(int code)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.SYSTEM_EXIT_ACTION, new Integer(code));
+ AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ // We don't need to rethrow anything since System.exit throws
+ // runtime exceptions only
+ }
+ }
+ else
+ {
+ System.exit(code);
+ }
+ }
+
+ public Policy getPolicy()
+ {
+ if (System.getSecurityManager() != null)
+ {
+ try
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_POLICY_ACTION, null);
+ return (Policy) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException ex)
+ {
+ throw (RuntimeException) ex.getException();
+ }
+ }
+ else
+ {
+ return Policy.getPolicy();
+ }
+ }
+
+ public void addURLToURLClassLoader(URL extension, ClassLoader loader) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.ADD_EXTENSION_URL, extension, loader);
+ try
+ {
+ AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ Method addURL =
+ URLClassLoader.class.getDeclaredMethod("addURL",
+ new Class[] {URL.class});
+ addURL.setAccessible(true);
+ addURL.invoke(loader, new Object[]{extension});
+ }
+ }
+
+ public Constructor getConstructor(Class target, Class[] types) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_CONSTRUCTOR_ACTION, target, types);
+ try
+ {
+ return (Constructor) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ return target.getConstructor(types);
+ }
+ }
+
+ public Method getMethod(Class target, String method, Class[] types) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_METHOD_ACTION, target, method, types);
+ try
+ {
+ return (Method) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ return target.getMethod(method, types);
+ }
+ }
+
+ public Method getDeclaredMethod(Class target, String method, Class[] types) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_DECLAREDMETHOD_ACTION, target, method, types);
+ try
+ {
+ return (Method) AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ return target.getDeclaredMethod(method, types);
+ }
+ }
+
+ public Object invoke(Method method, Object target, Object[] params) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.INVOKE_METHOD_ACTION, method, target, params);
+ try
+ {
+ return AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ method.setAccessible(true);
+ return method.invoke(target, params);
+ }
+ }
+
+ public Object invoke(Constructor constructor, Object[] params) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.INVOKE_CONSTRUCTOR_ACTION, constructor, params);
+ try
+ {
+ return AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ constructor.setAccessible(true);
+ return constructor.newInstance(params);
+ }
+ }
+
+ public Object getDeclaredField(Class targetClass, String name, Object target)
+ throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.GET_FIELD_ACTION, targetClass, name, target);
+ try
+ {
+ return AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ Field field = targetClass.getDeclaredField(name);
+ field.setAccessible(true);
+
+ return field.get(target);
+ }
+ }
+
+ public Object swapStaticFieldIfNotClass(Class targetClazz,
+ Class targetType, Class condition, String lockName) throws Exception
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Actions actions = (Actions) m_actions.get();
+ actions.set(Actions.SWAP_FIELD_ACTION, targetClazz, targetType,
+ condition, lockName);
+ try
+ {
+ return AccessController.doPrivileged(actions, m_acc);
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw e.getException();
+ }
+ }
+ else
+ {
+ return _swapStaticFieldIfNotClass(targetClazz, targetType,
+ condition, lockName);
+ }
+ }
+
+ private static Object _swapStaticFieldIfNotClass(Class targetClazz,
+ Class targetType, Class condition, String lockName) throws Exception
+ {
+ Object lock = null;
+ if (lockName != null)
+ {
+ try
+ {
+ Field lockField =
+ targetClazz.getDeclaredField(lockName);
+ lockField.setAccessible(true);
+ lock = lockField.get(null);
+ }
+ catch (NoSuchFieldException ex)
+ {
+ }
+ }
+ if (lock == null)
+ {
+ lock = targetClazz;
+ }
+ synchronized (lock)
+ {
+ Field[] fields = targetClazz.getDeclaredFields();
+
+ Object result = null;
+ for (int i = 0; (i < fields.length) && (result == null); i++)
+ {
+ if (Modifier.isStatic(fields[i].getModifiers()) &&
+ (fields[i].getType() == targetType))
+ {
+ fields[i].setAccessible(true);
+
+ result = fields[i].get(null);
+
+ if (result != null)
+ {
+ if ((condition == null) ||
+ !result.getClass().getName().equals(condition.getName()))
+ {
+ fields[i].set(null, null);
+ }
+ }
+ }
+ }
+ if (result != null)
+ {
+ if ((condition == null) || !result.getClass().getName().equals(condition.getName()))
+ {
+ // reset cache
+ for (int i = 0; i < fields.length; i++)
+ {
+ if (Modifier.isStatic(fields[i].getModifiers()) &&
+ (fields[i].getType() == Hashtable.class))
+ {
+ fields[i].setAccessible(true);
+ Hashtable cache = (Hashtable) fields[i].get(null);
+ if (cache != null)
+ {
+ cache.clear();
+ }
+ }
+ }
+ }
+ return result;
+ }
+ }
+ return null;
+ }
+
+ private static class Actions implements PrivilegedExceptionAction
+ {
+ public static final int GET_PROPERTY_ACTION = 0;
+ public static final int FOR_NAME_ACTION = 1;
+ public static final int CREATE_URL_ACTION = 2;
+ public static final int CREATE_URL_WITH_CONTEXT_ACTION = 3;
+ public static final int GET_ABSOLUTE_PATH_ACTION = 4;
+ public static final int FILE_EXISTS_ACTION = 5;
+ public static final int FILE_IS_DIRECTORY_ACTION = 6;
+ public static final int MAKE_DIRECTORY_ACTION = 7;
+ public static final int MAKE_DIRECTORIES_ACTION = 8;
+ public static final int LIST_DIRECTORY_ACTION = 9;
+ public static final int RENAME_FILE_ACTION = 10;
+ public static final int GET_FILE_INPUT_ACTION = 11;
+ public static final int GET_FILE_OUTPUT_ACTION = 12;
+ public static final int DELETE_FILE_ACTION = 13;
+ public static final int OPEN_JARX_ACTION = 14;
+ public static final int GET_URL_INPUT_ACTION = 15;
+ public static final int CREATE_CONTENTCLASSLOADER_ACTION = 16;
+ public static final int START_ACTIVATOR_ACTION = 17;
+ public static final int STOP_ACTIVATOR_ACTION = 18;
+ public static final int SYSTEM_EXIT_ACTION = 19;
+ public static final int OPEN_JAR_ACTION= 20;
+ public static final int GET_POLICY_ACTION = 21;
+ public static final int CREATE_TMPFILE_ACTION = 22;
+ public static final int OPEN_URLCONNECTION_ACTION = 23;
+ public static final int OPEN_JARURLCONNECTIONJAR_ACTION = 24;
+ public static final int ADD_EXTENSION_URL = 25;
+ public static final int GET_CONSTRUCTOR_ACTION = 26;
+ public static final int GET_METHOD_ACTION = 27;
+ public static final int INVOKE_METHOD_ACTION = 28;
+ public static final int INVOKE_CONSTRUCTOR_ACTION = 29;
+ public static final int SWAP_FIELD_ACTION = 30;
+ public static final int GET_FIELD_ACTION = 31;
+ public static final int GET_DECLAREDMETHOD_ACTION = 32;
+
+ private int m_action = -1;
+ private Object m_arg1 = null;
+ private Object m_arg2 = null;
+ private Object m_arg3 = null;
+ private Object m_arg4 = null;
+ private Object m_arg5 = null;
+
+ public void set(int action, Object arg1)
+ {
+ m_action = action;
+ m_arg1 = arg1;
+ }
+
+ public void set(int action, Object arg1, Object arg2)
+ {
+ m_action = action;
+ m_arg1 = arg1;
+ m_arg2 = arg2;
+ }
+
+ public void set(int action, Object arg1, Object arg2, Object arg3)
+ {
+ m_action = action;
+ m_arg1 = arg1;
+ m_arg2 = arg2;
+ m_arg3 = arg3;
+ }
+
+ public void set(int action, Object arg1, Object arg2, Object arg3,
+ Object arg4)
+ {
+ m_action = action;
+ m_arg1 = arg1;
+ m_arg2 = arg2;
+ m_arg3 = arg3;
+ m_arg4 = arg4;
+ }
+
+ public void set(int action, Object arg1, Object arg2, Object arg3,
+ Object arg4, Object arg5)
+ {
+ m_action = action;
+ m_arg1 = arg1;
+ m_arg2 = arg2;
+ m_arg3 = arg3;
+ m_arg4 = arg4;
+ m_arg5 = arg5;
+ }
+
+ private void unset()
+ {
+ m_action = -1;
+ m_arg1 = null;
+ m_arg2 = null;
+ m_arg3 = null;
+ m_arg4 = null;
+ m_arg5 = null;
+ }
+
+ public Object run() throws Exception
+ {
+ try
+ {
+ if (m_action == GET_PROPERTY_ACTION)
+ {
+ return System.getProperty((String) m_arg1, (String) m_arg2);
+ }
+ else if (m_action == FOR_NAME_ACTION)
+ {
+ return Class.forName((String) m_arg1);
+ }
+ else if (m_action == CREATE_URL_ACTION)
+ {
+ return new URL((String) m_arg1, (String) m_arg2,
+ ((Integer) m_arg3).intValue(), (String) m_arg4,
+ (URLStreamHandler) m_arg5);
+ }
+ else if (m_action == CREATE_URL_WITH_CONTEXT_ACTION)
+ {
+ return new URL((URL) m_arg1, (String) m_arg2,
+ (URLStreamHandler) m_arg3);
+ }
+ else if (m_action == GET_ABSOLUTE_PATH_ACTION)
+ {
+ return ((File) m_arg1).getAbsolutePath();
+ }
+ else if (m_action == FILE_EXISTS_ACTION)
+ {
+ return ((File) m_arg1).exists() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (m_action == FILE_IS_DIRECTORY_ACTION)
+ {
+ return ((File) m_arg1).isDirectory() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (m_action == MAKE_DIRECTORY_ACTION)
+ {
+ return ((File) m_arg1).mkdir() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (m_action == MAKE_DIRECTORIES_ACTION)
+ {
+ return ((File) m_arg1).mkdirs() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (m_action == LIST_DIRECTORY_ACTION)
+ {
+ return ((File) m_arg1).listFiles();
+ }
+ else if (m_action == RENAME_FILE_ACTION)
+ {
+ return ((File) m_arg1).renameTo((File) m_arg2) ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (m_action == GET_FILE_INPUT_ACTION)
+ {
+ return new FileInputStream((File) m_arg1);
+ }
+ else if (m_action == GET_FILE_OUTPUT_ACTION)
+ {
+ return new FileOutputStream((File) m_arg1);
+ }
+ else if (m_action == DELETE_FILE_ACTION)
+ {
+ return ((File) m_arg1).delete() ? Boolean.TRUE : Boolean.FALSE;
+ }
+ else if (m_action == OPEN_JARX_ACTION)
+ {
+ return new JarFileX((File) m_arg1);
+ }
+ else if (m_action == OPEN_JAR_ACTION)
+ {
+ return new JarFile((File) m_arg1, ((Boolean) m_arg2).booleanValue());
+ }
+ else if (m_action == GET_URL_INPUT_ACTION)
+ {
+ return ((URLConnection) m_arg1).getInputStream();
+ }
+ else if (m_action == CREATE_CONTENTCLASSLOADER_ACTION)
+ {
+ return new ContentClassLoader((ContentLoaderImpl) m_arg1,
+ (ProtectionDomain) m_arg2);
+ }
+ else if (m_action == START_ACTIVATOR_ACTION)
+ {
+ ((BundleActivator) m_arg1).start((BundleContext) m_arg2);
+ return null;
+ }
+ else if (m_action == STOP_ACTIVATOR_ACTION)
+ {
+ ((BundleActivator) m_arg1).stop((BundleContext) m_arg2);
+ return null;
+ }
+ else if (m_action == SYSTEM_EXIT_ACTION)
+ {
+ System.exit(((Integer) m_arg1).intValue());
+ }
+ else if (m_action == GET_POLICY_ACTION)
+ {
+ return Policy.getPolicy();
+ }
+ else if (m_action == CREATE_TMPFILE_ACTION)
+ {
+ return File.createTempFile((String) m_arg1, (String) m_arg2,
+ (File) m_arg3);
+ }
+ else if (m_action == OPEN_URLCONNECTION_ACTION)
+ {
+ return ((URL) m_arg1).openConnection();
+ }
+ else if (m_action == OPEN_JARURLCONNECTIONJAR_ACTION)
+ {
+ return ((JarURLConnection) m_arg1).getJarFile();
+ }
+ else if (m_action == ADD_EXTENSION_URL)
+ {
+ Method addURL =
+ URLClassLoader.class.getDeclaredMethod("addURL",
+ new Class[] {URL.class});
+ addURL.setAccessible(true);
+ addURL.invoke(m_arg2, new Object[]{m_arg1});
+ }
+ else if (m_action == GET_CONSTRUCTOR_ACTION)
+ {
+ return ((Class) m_arg1).getConstructor((Class[]) m_arg2);
+ }
+ else if (m_action == GET_METHOD_ACTION)
+ {
+ return ((Class) m_arg1).getMethod((String) m_arg2, (Class[]) m_arg3);
+ }
+ else if (m_action == INVOKE_METHOD_ACTION)
+ {
+ ((Method) m_arg1).setAccessible(true);
+ return ((Method) m_arg1).invoke(m_arg2, (Object[]) m_arg3);
+ }
+ else if (m_action == INVOKE_CONSTRUCTOR_ACTION)
+ {
+ ((Constructor) m_arg1).setAccessible(true);
+ return ((Constructor) m_arg1).newInstance((Object[]) m_arg2);
+ }
+ else if (m_action == SWAP_FIELD_ACTION)
+ {
+ return _swapStaticFieldIfNotClass((Class) m_arg1,
+ (Class) m_arg2, (Class) m_arg3, (String) m_arg4);
+ }
+ else if (m_action == GET_FIELD_ACTION)
+ {
+ Field field = ((Class) m_arg1).getDeclaredField((String) m_arg2);
+ field.setAccessible(true);
+ return field.get(m_arg3);
+ }
+ else if (m_action == GET_DECLAREDMETHOD_ACTION)
+ {
+ return ((Class) m_arg1).getDeclaredMethod((String) m_arg2, (Class[]) m_arg3);
+ }
+
+ return null;
+ }
+ finally
+ {
+ unset();
+ }
+ }
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecureAction.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecurityManagerEx.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecurityManagerEx.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecurityManagerEx.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecurityManagerEx.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util;
+
+/**
+ * <p>
+ * Simple utility class used to provide public access to the protected
+ * <tt>getClassContext()</tt> method of <tt>SecurityManager</tt>
+ * </p>
+**/
+public class SecurityManagerEx extends SecurityManager
+{
+ public Class[] getClassContext()
+ {
+ return super.getClassContext();
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecurityManagerEx.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/SecurityManagerEx.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/StringMap.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/StringMap.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/StringMap.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/StringMap.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util;
+
+import java.util.*;
+
+/**
+ * Simple utility class that creates a map for string-based keys by
+ * extending <tt>TreeMap</tt>. This map can be set to use case-sensitive
+ * or case-insensitive comparison when searching for the key.
+ * Any keys put into this map will be converted to
+ * a <tt>String</tt> using the <tt>toString()</tt> method,
+ * since it is only intended to compare strings.
+**/
+public class StringMap extends TreeMap
+{
+ public StringMap()
+ {
+ this(true);
+ }
+
+ public StringMap(boolean caseSensitive)
+ {
+ super(new StringComparator(caseSensitive));
+ }
+
+ public StringMap(Map map, boolean caseSensitive)
+ {
+ this(caseSensitive);
+ putAll(map);
+ }
+
+ public Object put(Object key, Object value)
+ {
+ return super.put(key.toString(), value);
+ }
+
+ public boolean isCaseSensitive()
+ {
+ return ((StringComparator) comparator()).isCaseSensitive();
+ }
+
+ public void setCaseSensitive(boolean b)
+ {
+ ((StringComparator) comparator()).setCaseSensitive(b);
+ }
+
+ private static class StringComparator implements Comparator
+ {
+ private boolean m_isCaseSensitive = true;
+
+ public StringComparator(boolean b)
+ {
+ m_isCaseSensitive = b;
+ }
+
+ public int compare(Object o1, Object o2)
+ {
+ if (m_isCaseSensitive)
+ {
+ return o1.toString().compareTo(o2.toString());
+ }
+ else
+ {
+ return o1.toString().compareToIgnoreCase(o2.toString());
+ }
+ }
+
+ public boolean isCaseSensitive()
+ {
+ return m_isCaseSensitive;
+ }
+
+ public void setCaseSensitive(boolean b)
+ {
+ m_isCaseSensitive = b;
+ }
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/StringMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/StringMap.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/Util.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/Util.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/Util.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/Util.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util;
+
+import java.io.*;
+
+import org.apache.felix.framework.util.manifestparser.Capability;
+import org.apache.felix.moduleloader.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+public class Util
+{
+ /**
+ * Converts a module identifier to a bundle identifier. Module IDs
+ * are typically <tt><bundle-id>.<revision></tt>; this
+ * method returns only the portion corresponding to the bundle ID.
+ **/
+ public static long getBundleIdFromModuleId(String id)
+ {
+ try
+ {
+ String bundleId = (id.indexOf('.') >= 0)
+ ? id.substring(0, id.indexOf('.')) : id;
+ return Long.parseLong(bundleId);
+ }
+ catch (NumberFormatException ex)
+ {
+ return -1;
+ }
+ }
+
+ /**
+ * Converts a module identifier to a bundle identifier. Module IDs
+ * are typically <tt><bundle-id>.<revision></tt>; this
+ * method returns only the portion corresponding to the revision.
+ **/
+ public static int getModuleRevisionFromModuleId(String id)
+ {
+ try
+ {
+ String rev = (id.indexOf('.') >= 0)
+ ? id.substring(id.indexOf('.') + 1) : id;
+ return Integer.parseInt(rev);
+ }
+ catch (NumberFormatException ex)
+ {
+ return -1;
+ }
+ }
+
+ public static String getClassName(String className)
+ {
+ if (className == null)
+ {
+ className = "";
+ }
+ return (className.lastIndexOf('.') < 0)
+ ? "" : className.substring(className.lastIndexOf('.') + 1);
+ }
+
+ public static String getClassPackage(String className)
+ {
+ if (className == null)
+ {
+ className = "";
+ }
+ return (className.lastIndexOf('.') < 0)
+ ? "" : className.substring(0, className.lastIndexOf('.'));
+ }
+
+ public static String getResourcePackage(String resource)
+ {
+ if (resource == null)
+ {
+ resource = "";
+ }
+ // NOTE: The package of a resource is tricky to determine since
+ // resources do not follow the same naming conventions as classes.
+ // This code is pessimistic and assumes that the package of a
+ // resource is everything up to the last '/' character. By making
+ // this choice, it will not be possible to load resources from
+ // imports using relative resource names. For example, if a
+ // bundle exports "foo" and an importer of "foo" tries to load
+ // "/foo/bar/myresource.txt", this will not be found in the exporter
+ // because the following algorithm assumes the package name is
+ // "foo.bar", not just "foo". This only affects imported resources,
+ // local resources will work as expected.
+ String pkgName = (resource.startsWith("/")) ? resource.substring(1) : resource;
+ pkgName = (pkgName.lastIndexOf('/') < 0)
+ ? "" : pkgName.substring(0, pkgName.lastIndexOf('/'));
+ pkgName = pkgName.replace('/', '.');
+ return pkgName;
+ }
+
+ /**
+ * <p>
+ * This is a simple utility class that attempts to load the named
+ * class using the class loader of the supplied class or
+ * the class loader of one of its super classes or their implemented
+ * interfaces. This is necessary during service registration to test
+ * whether a given service object implements its declared service
+ * interfaces.
+ * </p>
+ * <p>
+ * To perform this test, the framework must try to load
+ * the classes associated with the declared service interfaces, so
+ * it must choose a class loader. The class loader of the registering
+ * bundle cannot be used, since this disallows third parties to
+ * register service on behalf of another bundle. Consequently, the
+ * class loader of the service object must be used. However, this is
+ * also not sufficient since the class loader of the service object
+ * may not have direct access to the class in question.
+ * </p>
+ * <p>
+ * The service object's class loader may not have direct access to
+ * its service interface if it extends a super class from another
+ * bundle which implements the service interface from an imported
+ * bundle or if it implements an extension of the service interface
+ * from another bundle which imports the base interface from another
+ * bundle. In these cases, the service object's class loader only has
+ * access to the super class's class or the extended service interface,
+ * respectively, but not to the actual service interface.
+ * </p>
+ * <p>
+ * Thus, it is necessary to not only try to load the service interface
+ * class from the service object's class loader, but from the class
+ * loaders of any interfaces it implements and the class loaders of
+ * all super classes.
+ * </p>
+ * @param svcObj the class that is the root of the search.
+ * @param name the name of the class to load.
+ * @return the loaded class or <tt>null</tt> if it could not be
+ * loaded.
+ **/
+ public static Class loadClassUsingClass(Class clazz, String name)
+ {
+ Class loadedClass = null;
+
+ while (clazz != null)
+ {
+ // Get the class loader of the current class object.
+ ClassLoader loader = clazz.getClassLoader();
+ // A null class loader represents the system class loader.
+ loader = (loader == null) ? ClassLoader.getSystemClassLoader() : loader;
+ try
+ {
+ return loader.loadClass(name);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // Ignore and try interface class loaders.
+ }
+
+ // Try to see if we can load the class from
+ // one of the class's implemented interface
+ // class loaders.
+ Class[] ifcs = clazz.getInterfaces();
+ for (int i = 0; i < ifcs.length; i++)
+ {
+ loadedClass = loadClassUsingClass(ifcs[i], name);
+ if (loadedClass != null)
+ {
+ return loadedClass;
+ }
+ }
+
+ // Try to see if we can load the class from
+ // the super class class loader.
+ clazz = clazz.getSuperclass();
+ }
+
+ return null;
+ }
+
+ /**
+ * This method determines if the requesting bundle is able to cast
+ * the specified service reference based on class visibility rules
+ * of the underlying modules.
+ * @param requester The bundle requesting the service.
+ * @param ref The service in question.
+ * @return <tt>true</tt> if the requesting bundle is able to case
+ * the service object to a known type.
+ **/
+ public static boolean isServiceAssignable(Bundle requester, ServiceReference ref)
+ {
+ // Boolean flag.
+ boolean allow = true;
+ // Get the service's objectClass property.
+ String[] objectClass = (String[]) ref.getProperty(FelixConstants.OBJECTCLASS);
+
+ // The the service reference is not assignable when the requesting
+ // bundle is wired to a different version of the service object.
+ // NOTE: We are pessimistic here, if any class in the service's
+ // objectClass is not usable by the requesting bundle, then we
+ // disallow the service reference.
+ for (int classIdx = 0; (allow) && (classIdx < objectClass.length); classIdx++)
+ {
+ if (!ref.isAssignableTo(requester, objectClass[classIdx]))
+ {
+ allow = false;
+ }
+ }
+ return allow;
+ }
+
+ public static ICapability getSatisfyingCapability(IModule m, IRequirement req)
+ {
+ ICapability[] caps = m.getDefinition().getCapabilities();
+ for (int i = 0; (caps != null) && (i < caps.length); i++)
+ {
+ if (caps[i].getNamespace().equals(req.getNamespace()) &&
+ req.isSatisfied(caps[i]))
+ {
+ return caps[i];
+ }
+ }
+ return null;
+ }
+
+ public static IWire getWire(IModule m, String name)
+ {
+ IWire[] wires = m.getWires();
+ for (int i = 0; (wires != null) && (i < wires.length); i++)
+ {
+ if (wires[i].getCapability().getNamespace().equals(ICapability.PACKAGE_NAMESPACE) &&
+ ((Capability) wires[i].getCapability()).getPackageName().equals(name))
+ {
+ return wires[i];
+ }
+ }
+ return null;
+ }
+
+ private static final byte encTab[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
+ 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52,
+ 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64,
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31,
+ 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f };
+
+ private static final byte decTab[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1,
+ -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1,
+ -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+ 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29,
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, -1, -1, -1, -1, -1 };
+
+ public static String base64Encode(String s) throws IOException
+ {
+ return encode(s.getBytes(), 0);
+ }
+
+ /**
+ * Encode a raw byte array to a Base64 String.
+ *
+ * @param in Byte array to encode.
+ * @param len Length of Base64 lines. 0 means no line breaks.
+ **/
+ public static String encode(byte[] in, int len) throws IOException
+ {
+ ByteArrayOutputStream baos = null;
+ ByteArrayInputStream bais = null;
+ try
+ {
+ baos = new ByteArrayOutputStream();
+ bais = new ByteArrayInputStream(in);
+ encode(bais, baos, len);
+ // ASCII byte array to String
+ return (new String(baos.toByteArray()));
+ }
+ finally
+ {
+ if (baos != null)
+ {
+ baos.close();
+ }
+ if (bais != null)
+ {
+ bais.close();
+ }
+ }
+ }
+
+ public static void encode(InputStream in, OutputStream out, int len)
+ throws IOException
+ {
+
+ // Check that length is a multiple of 4 bytes
+ if (len % 4 != 0)
+ {
+ throw new IllegalArgumentException("Length must be a multiple of 4");
+ }
+
+ // Read input stream until end of file
+ int bits = 0;
+ int nbits = 0;
+ int nbytes = 0;
+ int b;
+
+ while ((b = in.read()) != -1)
+ {
+ bits = (bits << 8) | b;
+ nbits += 8;
+ while (nbits >= 6)
+ {
+ nbits -= 6;
+ out.write(encTab[0x3f & (bits >> nbits)]);
+ nbytes++;
+ // New line
+ if (len != 0 && nbytes >= len)
+ {
+ out.write(0x0d);
+ out.write(0x0a);
+ nbytes -= len;
+ }
+ }
+ }
+
+ switch (nbits)
+ {
+ case 2:
+ out.write(encTab[0x3f & (bits << 4)]);
+ out.write(0x3d); // 0x3d = '='
+ out.write(0x3d);
+ break;
+ case 4:
+ out.write(encTab[0x3f & (bits << 2)]);
+ out.write(0x3d);
+ break;
+ }
+
+ if (len != 0)
+ {
+ if (nbytes != 0)
+ {
+ out.write(0x0d);
+ out.write(0x0a);
+ }
+ out.write(0x0d);
+ out.write(0x0a);
+ }
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/Util.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/Util.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util;
+
+import org.osgi.framework.Version;
+
+public class VersionRange
+{
+ private Version m_low = null;
+ private boolean m_isLowInclusive = false;
+ private Version m_high = null;
+ private boolean m_isHighInclusive = false;
+ private String m_toString = null;
+ public static final VersionRange infiniteRange = new VersionRange(Version.emptyVersion, true, null, true);
+
+ public VersionRange(Version low, boolean isLowInclusive,
+ Version high, boolean isHighInclusive)
+ {
+ m_low = low;
+ m_isLowInclusive = isLowInclusive;
+ m_high = high;
+ m_isHighInclusive = isHighInclusive;
+ }
+
+ public Version getLow()
+ {
+ return m_low;
+ }
+
+ public boolean isLowInclusive()
+ {
+ return m_isLowInclusive;
+ }
+
+ public Version getHigh()
+ {
+ return m_high;
+ }
+
+ public boolean isHighInclusive()
+ {
+ return m_isHighInclusive;
+ }
+
+ public boolean isInRange(Version version)
+ {
+ // We might not have an upper end to the range.
+ if (m_high == null)
+ {
+ return (version.compareTo(m_low) >= 0);
+ }
+ else if (isLowInclusive() && isHighInclusive())
+ {
+ return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) <= 0);
+ }
+ else if (isHighInclusive())
+ {
+ return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) <= 0);
+ }
+ else if (isLowInclusive())
+ {
+ return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) < 0);
+ }
+ return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) < 0);
+ }
+
+ public static VersionRange parse(String range)
+ {
+ // Check if the version is an interval.
+ if (range.indexOf(',') >= 0)
+ {
+ String s = range.substring(1, range.length() - 1);
+ String vlo = s.substring(0, s.indexOf(',')).trim();
+ String vhi = s.substring(s.indexOf(',') + 1, s.length()).trim();
+ return new VersionRange (
+ new Version(vlo), (range.charAt(0) == '['),
+ new Version(vhi), (range.charAt(range.length() - 1) == ']'));
+ }
+ else
+ {
+ return new VersionRange(new Version(range), true, null, false);
+ }
+ }
+
+ public String toString()
+ {
+ if (m_toString == null)
+ {
+ if (m_high != null)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append(m_isLowInclusive ? '[' : '(');
+ sb.append(m_low.toString());
+ sb.append(',');
+ sb.append(m_high.toString());
+ sb.append(m_isHighInclusive ? ']' : ')');
+ m_toString = sb.toString();
+ }
+ else
+ {
+ m_toString = m_low.toString();
+ }
+ }
+ return m_toString;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/VersionRange.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/AttributeNotFoundException.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/AttributeNotFoundException.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/AttributeNotFoundException.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/AttributeNotFoundException.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util.ldap;
+
+public class AttributeNotFoundException extends EvaluationException
+{
+ public AttributeNotFoundException(String msg)
+ {
+ super(msg);
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/AttributeNotFoundException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/AttributeNotFoundException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Driver.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Driver.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Driver.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Driver.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util.ldap;
+
+import java.io.*;
+import java.util.*;
+
+public class Driver {
+
+ public static void main(String[] argv)
+ {
+ Mapper mapper = new DriverMapper();
+
+ if(argv== null || argv.length == 0) {
+ System.err.println("usage: Driver <ldap spec file>");
+ return;
+ }
+ LdapLexer lexer = new LdapLexer();
+ FileReader fr = null;
+ char[] line = null;
+ Evaluator engine = new Evaluator();
+
+ Parser parser = new Parser();
+// parser.setDebug(System.out);
+
+ try {
+ File spec = new File(argv[0]);
+ fr = new FileReader(spec);
+
+ // The basic operation of the driver is:
+ // 1. read a line from the file
+ // 2. parse that line
+ // 3. print the resulting program
+ // 4. repeat 1 until eof
+
+ for(;;) {
+ line = getLine(fr);
+ if(line == null) break;
+ System.out.println("Driver: filter: "+new String(line));
+ CharArrayReader car = new CharArrayReader(line);
+ lexer.setReader(car);
+ parser.reset(lexer);
+ boolean status = false;
+ try {
+ status = parser.start();
+ if(!status) {
+ System.err.println("parse failed");
+ printErrorLocation(line,lexer.charno());
+ }
+ } catch (ParseException pe) {
+ System.err.println(pe.toString());
+ printErrorLocation(line,lexer.charno());
+ }
+ if(status) {
+ try {
+ engine.reset(parser.getProgram());
+// System.out.println("Driver: program: "+engine.toString());
+ System.out.println("Driver: program: "+engine.toStringInfix());
+ System.out.println("Eval = " + engine.evaluate(mapper));
+ } catch (EvaluationException ee) {
+ System.err.print("Driver: ");
+ printEvaluationStack(engine.getOperands());
+ System.err.println(ee.toString());
+ }
+ }
+ }
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ printErrorLocation(line,lexer.charno());
+ e.printStackTrace();
+ }
+ }
+
+ // Get a line of input at a time and return a char[] buffer
+ // containing the line
+
+ static char[] getLine(Reader reader) throws IOException
+ {
+ StringBuffer buf = new StringBuffer();
+ for(;;) {
+ int c = reader.read();
+ if(c == '\r') continue;
+ if(c < 0) {
+ if(buf.length() == 0) return null; // no more lines
+ break;
+ }
+ if(c == '\n') break;
+ buf.append((char)c);
+ }
+
+ char[] cbuf = new char[buf.length()];
+ buf.getChars(0,buf.length(),cbuf,0);
+ return cbuf;
+ }
+
+
+ static void printErrorLocation(char[] line, int charno)
+ {
+ System.err.print("|");
+ if(line != null) System.err.print(new String(line));
+ System.err.println("|");
+ for(int i=0;i<charno;i++) System.err.print(" ");
+ System.err.println("^");
+ }
+
+ // Report the final contents of the evaluation stack
+ static void printEvaluationStack(Stack stack)
+ {
+ System.err.print("Stack:");
+ // recast operands as Vector to make interior access easier
+ Vector operands = stack;
+ int len = operands.size();
+ for(int i=0;i<len;i++) System.err.print(" "+operands.elementAt(i));
+ System.err.println();
+ }
+
+}
+
+class DriverMapper implements Mapper {
+
+ Hashtable hash = new Hashtable();
+
+ public DriverMapper()
+ {
+ hash.put("cn","Babs Jensen");
+ hash.put("objectClass","Person");
+ hash.put("sn","Jensen");
+ hash.put("o","university of michigan");
+ hash.put("foo","bar");
+ }
+
+ public Object lookup(String key)
+ {
+ return hash.get(key);
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Driver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Driver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/EvaluationException.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/EvaluationException.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/EvaluationException.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/EvaluationException.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util.ldap;
+
+public class EvaluationException extends Exception
+{
+ private Class m_unsupportedType = null;
+
+ public EvaluationException(String msg)
+ {
+ super(msg);
+ }
+
+ public EvaluationException(String msg, Class clazz)
+ {
+ super(msg);
+ m_unsupportedType = clazz;
+ }
+
+ public boolean isUnsupportedType()
+ {
+ return (m_unsupportedType != null);
+ }
+
+ public Class getUnsupportedType()
+ {
+ return m_unsupportedType;
+ }
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/EvaluationException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/EvaluationException.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Evaluator.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Evaluator.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Evaluator.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Evaluator.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util.ldap;
+
+import java.util.Stack;
+import java.util.Vector;
+
+public class Evaluator {
+
+ Object[] program = null;
+ Stack operands = new Stack();
+ Mapper mapper = null;
+
+ public Evaluator()
+ {
+ reset();
+ }
+
+ public Evaluator(Object[] prog)
+ {
+ reset(prog);
+ }
+
+ public void reset()
+ {
+ program = null;
+ mapper = null;
+ operands.clear();
+ }
+
+ public void reset(Object[] prog)
+ {
+ reset();
+ setProgram(prog);
+ }
+
+ public void setProgram(Object[] prog)
+ {
+ program = prog;
+ }
+
+ public void setMapper(Mapper mapper)
+ {
+ this.mapper = mapper;
+ }
+
+ public Stack getOperands()
+ {
+ return operands;
+ }
+
+ public boolean evaluate(Mapper mapper) throws EvaluationException
+ {
+ try
+ {
+ // The following code is a little complicated because it
+ // is trying to deal with evaluating a given filter expression
+ // when it contains an attribute that does not exist in the
+ // supplied mapper. In such a situation the code below
+ // catches the "attribute not found" exception and inserts
+ // an instance of Unknown, which is used as a marker for
+ // non-existent attributes. The Unknown instance forces the
+ // operator to throw an "unsupported type" exception, which
+ // the code below converts into a FALSE and this has the effect
+ // of evaluating the subexpression that contained the
+ // non-existent attribute to FALSE. The rest of the filter
+ // expression evaluates normally. Any other exceptions are
+ // rethrown.
+ setMapper(mapper);
+ for (int i = 0; i < program.length; i++)
+ {
+ try
+ {
+ Operator op = (Operator) program[i];
+ op.execute(operands, mapper);
+// printAction(op); // for debug output
+ }
+ catch (AttributeNotFoundException ex)
+ {
+ operands.push(new Unknown());
+ }
+ catch (EvaluationException ex)
+ {
+ // If the exception is for an unsupported type of
+ // type Unknown, then just push FALSE onto the
+ // operand stack because this type will only appear
+ // if an attribute was not found.
+ if (ex.isUnsupportedType() &&
+ (ex.getUnsupportedType() == Unknown.class))
+ {
+ operands.push(Boolean.FALSE);
+ }
+ // Otherwise, rethrow the exception.
+ else
+ {
+ throw ex;
+ }
+ }
+ }
+
+ if (operands.empty())
+ {
+ throw new EvaluationException(
+ "Evaluation.evalute: final stack is empty");
+ }
+
+ Object result = operands.pop();
+
+ if (!operands.empty())
+ {
+ throw new EvaluationException(
+ "Evaluation.evalute: final stack has more than one result");
+ }
+
+ if (!(result instanceof Boolean))
+ {
+ throw new EvaluationException(
+ "Evaluation.evalute: final result is not Boolean");
+ }
+
+ return ((Boolean) result).booleanValue();
+ }
+ finally
+ {
+ // Clear the operands just in case an exception was thrown,
+ // otherwise stuff will be left in the stack.
+ operands.clear();
+ }
+ }
+
+ // For debugging; Dump the operator and stack
+ void printAction(Operator op)
+ {
+ System.err.println("Operator:"+op.toString());
+ System.err.print("Stack After:");
+ // recast operands as Vector to make interior access easier
+ Vector v = operands;
+ int len = v.size();
+ for (int i = 0; i < len; i++)
+ System.err.print(" " + v.elementAt(i));
+ System.err.println();
+ }
+
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < program.length; i++)
+ {
+ buf.append((i==0) ? "{" : ";");
+ buf.append(((Operator) program[i]).toString());
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+
+ public String toStringInfix()
+ {
+ // First, we "evaluate" the program
+ // but for the purpose of re-constructing
+ // a parsetree.
+ operands.clear();
+ for (int i = 0; i < program.length; i++)
+ {
+ ((Operator) program[i]).buildTree(operands);
+ }
+ StringBuffer b = new StringBuffer();
+ Object result = operands.pop();
+ ((Operator)result).toStringInfix(b);
+ operands.clear();
+ return b.toString();
+ }
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Evaluator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Evaluator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/LdapLexer.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/LdapLexer.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/LdapLexer.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/LdapLexer.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util.ldap;
+
+import java.io.IOException;
+import java.io.Reader;
+
+public class LdapLexer {
+
+ static final int EOF = -1;
+ static final int NOCHAR = 0; // signal no peeked char; different from EOF
+
+ Reader reader = null;
+
+ int nextChar = NOCHAR; // last peeked character
+
+ public LdapLexer() {}
+
+ public LdapLexer(Reader r)
+ {
+ setReader(r);
+ charno = 1;
+ }
+
+ public void setReader(Reader r)
+ {
+ reader = r;
+ }
+
+ /*
+ The procedures get(),peek(),skipwhitespace(),getnw(), and peeknw()
+ provide the essential LdapLexer interface.
+ */
+
+ public int get() throws IOException // any next char
+ {
+ if(nextChar == NOCHAR) return readChar();
+ int c = nextChar;
+ nextChar = NOCHAR;
+ return c;
+ }
+
+ public int peek() throws IOException
+ {
+ if(nextChar == NOCHAR) {
+ nextChar = readChar();
+ }
+ return nextChar;
+ }
+
+ void skipwhitespace() throws IOException
+ {
+ while (Character.isWhitespace((char) peek())) get();
+ }
+
+ public int getnw() throws IOException // next non-whitespace char
+ { // (note: not essential but useful)
+ skipwhitespace();
+ return get();
+ }
+
+ public int peeknw() throws IOException // next non-whitespace char
+ { // (note: not essential but useful)
+ skipwhitespace();
+ return peek();
+ }
+
+ // Following is for error reporting
+
+ // Pass all character reads thru this so we can track char count
+
+ int charno; // 1-based
+
+ public int charno() {return charno;}
+
+ int readChar() throws IOException
+ {
+ charno++;
+ return reader.read();
+ }
+
+}
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/LdapLexer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/LdapLexer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Mapper.java
URL: http://svn.apache.org/viewvc/cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Mapper.java?rev=690991&view=auto
==============================================================================
--- cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Mapper.java (added)
+++ cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Mapper.java Mon Sep 1 08:08:01 2008
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.framework.util.ldap;
+
+public interface Mapper
+{
+ public Object lookup(String key);
+}
\ No newline at end of file
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Mapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/sandbox/dosgi/felix/framework/src/main/java/org/apache/felix/framework/util/ldap/Mapper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date