You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2005/08/16 20:34:41 UTC
svn commit: r233031 [5/21] - in /incubator/oscar/trunk: ./ etc/ lib/ src/
src/org/ src/org/apache/ src/org/apache/osgi/ src/org/apache/osgi/bundle/
src/org/apache/osgi/bundle/bundlerepository/
src/org/apache/osgi/bundle/bundlerepository/kxmlsax/ src/or...
Added: incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLConnection.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLConnection.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLConnection.java (added)
+++ incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLConnection.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.osgi.framework;
+
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.Permission;
+
+import org.apache.osgi.moduleloader.*;
+
+class BundleURLConnection extends URLConnection
+{
+ private ModuleManager m_mgr = null;
+ private int contentLength;
+ private long contentTime;
+ private String contentType;
+ private InputStream is;
+
+ public BundleURLConnection(ModuleManager mgr, URL url)
+ {
+ super(url);
+ m_mgr = mgr;
+ }
+
+ public void connect() throws IOException
+ {
+ if (!connected)
+ {
+ // The URL is constructed like this:
+ // bundle://<module-id>/<source-idx>/<resource-path>
+
+ 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());
+ }
+
+ is = new ByteArrayInputStream(bytes);
+ contentLength = bytes.length;
+ contentTime = 0L; // TODO: Change this.
+ contentType = URLConnection.guessContentTypeFromName(resource);
+ connected = true;
+ }
+ }
+
+ public InputStream getInputStream()
+ throws IOException
+ {
+ if (!connected)
+ {
+ connect();
+ }
+ return is;
+ }
+
+ public int getContentLength()
+ {
+ if (!connected)
+ {
+ try {
+ connect();
+ } catch(IOException ex) {
+ return -1;
+ }
+ }
+ return contentLength;
+ }
+
+ public long getLastModified()
+ {
+ if (!connected)
+ {
+ try {
+ connect();
+ } catch(IOException ex) {
+ return 0;
+ }
+ }
+ if(contentTime != -1L)
+ return contentTime;
+ else
+ return 0L;
+ }
+
+ public String getContentType()
+ {
+ if (!connected)
+ {
+ try {
+ connect();
+ } catch(IOException ex) {
+ return null;
+ }
+ }
+ return contentType;
+ }
+
+ public Permission getPermission()
+ {
+ // TODO: This should probably return a FilePermission
+ // to access the bundle JAR file, but we don't have the
+ // necessary information here to construct the absolute
+ // path of the JAR file...so it would take some
+ // re-arranging to get this to work.
+ return null;
+ }
+}
\ No newline at end of file
Added: incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLStreamHandler.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLStreamHandler.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLStreamHandler.java (added)
+++ incubator/oscar/trunk/src/org/apache/osgi/framework/BundleURLStreamHandler.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.osgi.framework;
+
+import java.io.IOException;
+import java.net.*;
+
+import org.apache.osgi.moduleloader.ModuleManager;
+
+class BundleURLStreamHandler extends URLStreamHandler
+{
+ private ModuleManager m_mgr = null;
+
+ public BundleURLStreamHandler(ModuleManager mgr)
+ {
+ m_mgr = mgr;
+ }
+
+ protected URLConnection openConnection(URL url) throws IOException
+ {
+ return new BundleURLConnection(m_mgr, url);
+ }
+}
\ No newline at end of file
Added: incubator/oscar/trunk/src/org/apache/osgi/framework/ExportedPackageImpl.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/apache/osgi/framework/ExportedPackageImpl.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/apache/osgi/framework/ExportedPackageImpl.java (added)
+++ incubator/oscar/trunk/src/org/apache/osgi/framework/ExportedPackageImpl.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.osgi.framework;
+
+import org.apache.osgi.framework.searchpolicy.R4Version;
+import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.ExportedPackage;
+
+class ExportedPackageImpl implements ExportedPackage
+{
+ private Felix m_felix = null;
+ private BundleImpl m_exporter = null;
+ private String m_name = null;
+ private R4Version m_version = null;
+ private String m_toString = null;
+ private String m_versionString = null;
+
+ public ExportedPackageImpl(
+ Felix felix, BundleImpl exporter, String name, R4Version version)
+ {
+ m_felix = felix;
+ m_exporter = exporter;
+ m_name = name;
+ m_version = version;
+ }
+
+ public Bundle getExportingBundle()
+ {
+ // If remove is pending due to a bundle update, then
+ // return null per the spec.
+ if (m_exporter.getInfo().isRemovalPending())
+ {
+ return null;
+ }
+ return m_exporter;
+ }
+
+ /**
+ * Returns the exporting bundle whether the package is state or
+ * not. This is called internally to get access to the exporting
+ * bundle during a refresh operation, which is not possible using
+ * <tt>getExportingBundle</tt> since the specification says that
+ * method must return <tt>null</tt> for stale packages.
+ * @return the exporting bundle for the package.
+ **/
+ protected Bundle getExportingBundleInternal()
+ {
+ return m_exporter;
+ }
+
+ public Bundle[] getImportingBundles()
+ {
+ // If remove is pending due to a bundle update, then
+ // return null per the spec.
+ if (m_exporter.getInfo().isRemovalPending())
+ {
+ return null;
+ }
+ return m_felix.getImportingBundles(this);
+ }
+
+ public String getName()
+ {
+ return m_name;
+ }
+
+ public String getSpecificationVersion()
+ {
+ if (m_versionString == null)
+ {
+ if (m_version == null)
+ {
+ m_versionString = "0.0.0";
+ }
+ else
+ {
+ m_versionString = m_version.toString();
+ }
+ }
+ return m_versionString;
+ }
+
+ public boolean isRemovalPending()
+ {
+ return m_exporter.getInfo().isRemovalPending();
+ }
+
+ public String toString()
+ {
+ if (m_toString == null)
+ {
+ m_toString = m_name
+ + "; version=" + getSpecificationVersion();
+ }
+ return m_toString;
+ }
+}
\ No newline at end of file
Added: incubator/oscar/trunk/src/org/apache/osgi/framework/FakeURLStreamHandler.java
URL: http://svn.apache.org/viewcvs/incubator/oscar/trunk/src/org/apache/osgi/framework/FakeURLStreamHandler.java?rev=233031&view=auto
==============================================================================
--- incubator/oscar/trunk/src/org/apache/osgi/framework/FakeURLStreamHandler.java (added)
+++ incubator/oscar/trunk/src/org/apache/osgi/framework/FakeURLStreamHandler.java Tue Aug 16 11:33:34 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.osgi.framework;
+
+import java.io.IOException;
+import java.net.*;
+
+/**
+ * This class implements a fake stream handler. This class is necessary in
+ * some cases when assigning <tt>CodeSource</tt>s to classes in
+ * <tt>BundleClassLoader</tt>. In general, the bundle location is an URL
+ * and this URL is used as the code source for the bundle's associated
+ * classes. The OSGi specification does not require that the bundle
+ * location be an URL, though, so in that case we try to generate a
+ * fake URL for the code source of the bundle, which is just the location
+ * string prepended with the "location:" protocol, by default. We need
+ * this fake handler to avoid an unknown protocol exception.
+**/
+class FakeURLStreamHandler extends URLStreamHandler
+{
+ protected URLConnection openConnection(URL url) throws IOException
+ {
+ return null;
+ }
+}