Return-Path: Delivered-To: apmail-incubator-felix-commits-archive@www.apache.org Received: (qmail 35242 invoked from network); 8 Nov 2005 09:09:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Nov 2005 09:09:31 -0000 Received: (qmail 77742 invoked by uid 500); 8 Nov 2005 09:09:30 -0000 Delivered-To: apmail-incubator-felix-commits-archive@incubator.apache.org Received: (qmail 77710 invoked by uid 500); 8 Nov 2005 09:09:29 -0000 Mailing-List: contact felix-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: felix-dev@incubator.apache.org Delivered-To: mailing list felix-commits@incubator.apache.org Received: (qmail 77688 invoked by uid 99); 8 Nov 2005 09:09:29 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 08 Nov 2005 01:09:29 -0800 Received: (qmail 34983 invoked by uid 65534); 8 Nov 2005 09:09:09 -0000 Message-ID: <20051108090909.34982.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r331747 - /incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java Date: Tue, 08 Nov 2005 09:09:08 -0000 To: felix-commits@incubator.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rickhall Date: Tue Nov 8 01:09:05 2005 New Revision: 331747 URL: http://svn.apache.org/viewcvs?rev=331747&view=rev Log: Added two new methods, one determine if a class is loaded from a particular framework instance and another to convert a bundle resource URL to an input stream. Both methods were needed for the new URL Handlers service implementation. Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java Modified: incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java?rev=331747&r1=331746&r2=331747&view=diff ============================================================================== --- incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java (original) +++ incubator/felix/trunk/framework/src/org/apache/felix/framework/Felix.java Tue Nov 8 01:09:05 2005 @@ -153,6 +153,12 @@ *
  • felix.startlevel.bundle - The default start level for * newly installed bundles; the default value is 1. *
  • + *
  • framework.service.urlhandlers - Flag to indicate whether + * to activate the URL Handlers service for the framework instance; + * the default value is "true". Activating the URL Handlers + * service will result in the URL.setURLStreamHandlerFactory() + * and URLConnection.setContentHandlerFactory() being called. + *
  • *
  • felix.embedded.execution - Flag to indicate whether * the framework is embedded into a host application; the default value is * "false". If this flag is "true" then the framework @@ -880,6 +886,85 @@ return (((BundleImpl) bundle).getInfo().getPersistentState() == Bundle.ACTIVE); } + /** + *

    + * This method is used to determine if the specified class is from + * a bundle installed in the framework instance. This method is used + * by the URL Handlers service when determining the framework instance + * associated with call stack. + *

    + * @param clazz The class to test for whether it comes from a bundle. + * @return true if the class comes from a bundle installed in + * the framework, false otherwise. + **/ + protected boolean isBundleClass(Class clazz) + { + if (clazz.getClassLoader() instanceof ModuleClassLoader) + { + return ((ModuleClassLoader) clazz.getClassLoader()).isModuleManagerEqual(m_mgr); + } + return false; + } + + /** + *

    + * This method returns an input stream for the specified bundle resource + * URL. + *

    + * @param url the URL representing the bundle resource for which an input + * stream is desired. + * @return an input stream to the bundle resource. + * @throws IOException if the input stream could not be created. + **/ + protected InputStream getBundleResourceInputStream(URL url) + throws IOException + { + // The URL is constructed like this: + // bundle://// + + Module module = m_mgr.getModule(url.getHost()); + if (module == null) + { + throw new IOException("Unable to find bundle's module."); + } + + String resource = url.getFile(); + if (resource == null) + { + throw new IOException("Unable to find resource: " + url.toString()); + } + if (resource.startsWith("/")) + { + resource = resource.substring(1); + } + int rsIdx = -1; + try + { + rsIdx = Integer.parseInt(resource.substring(0, resource.indexOf("/"))); + } + catch (NumberFormatException ex) + { + new IOException("Error parsing resource index."); + } + resource = resource.substring(resource.indexOf("/") + 1); + + // Get the resource bytes from the resource source. + byte[] bytes = null; + ResourceSource[] resSources = module.getResourceSources(); + if ((resSources != null) && (rsIdx < resSources.length)) + { + if (resSources[rsIdx].hasResource(resource)) + { + bytes = resSources[rsIdx].getBytes(resource); + } + } + if (bytes == null) + { + throw new IOException("Unable to find resource: " + url.toString()); + } + return new ByteArrayInputStream(bytes); + } + // // Implementation of Bundle interface methods. // @@ -3676,4 +3761,4 @@ m_bundleLock.notifyAll(); } } -} +} \ No newline at end of file