|
From: <lh...@us...> - 2010-02-27 18:45:22
|
Revision: 154
http://tmapi.svn.sourceforge.net/tmapi/?rev=154&view=rev
Author: lheuer
Date: 2010-02-27 18:45:15 +0000 (Sat, 27 Feb 2010)
Log Message:
-----------
Added OSGi support
Added package info
Modified Paths:
--------------
trunk/CHANGES.txt
trunk/build.xml
Added Paths:
-----------
trunk/NOTICE.txt
trunk/lib/LICENSE.osgi.txt
trunk/lib/osgi.core.jar
trunk/src/main/java/org/tmapi/core/internal/
trunk/src/main/java/org/tmapi/core/internal/Activator.java
trunk/src/main/java/org/tmapi/core/internal/OsgiLocator.java
trunk/src/main/java/org/tmapi/core/internal/package-info.java
trunk/src/main/java/org/tmapi/core/package-info.java
trunk/src/main/java/org/tmapi/index/package-info.java
Modified: trunk/CHANGES.txt
===================================================================
--- trunk/CHANGES.txt 2010-02-27 14:34:53 UTC (rev 153)
+++ trunk/CHANGES.txt 2010-02-27 18:45:15 UTC (rev 154)
@@ -5,6 +5,7 @@
TMAPI 2.0.1 - 2010-mm-dd
------------------------
* Added more illegal Variant scope test.
+* Added support for OSGi
TMAPI 2.0 - 2010-02-06
----------------------
Added: trunk/NOTICE.txt
===================================================================
--- trunk/NOTICE.txt (rev 0)
+++ trunk/NOTICE.txt 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,9 @@
+The classes
+
+* org.tmapi.core.internal.OSGILocator
+* org.tmapi.core.internal.Activator
+
+were copied (and modified) from the Apache ServiceMix 4.0
+<http://servicemix.apache.org> project and therefor are
+licensed under the Apache License 2.0
+<http://www.apache.org/licenses/LICENSE-2.0>.
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2010-02-27 14:34:53 UTC (rev 153)
+++ trunk/build.xml 2010-02-27 18:45:15 UTC (rev 154)
@@ -24,6 +24,7 @@
<property name="dir.lib" value="${basedir}/lib"/>
<property name="lib.junit" value="${dir.lib}/junit-4.8.1.jar"/>
+ <property name="lib.osgi" value="${dir.lib}/osgi.core.jar"/>
<target name="help">
<echo message="--------------------"/>
@@ -85,6 +86,7 @@
<classpath>
<pathelement location="${dir.build.classes}"/>
<pathelement location="${lib.junit}"/>
+ <pathelement location="${lib.osgi}"/>
</classpath>
<src path="${dir.test}"/>
</javac>
@@ -98,19 +100,26 @@
TopicMapSystemFactory
-->
<!-- =================================================================== -->
- <target name="internal.tests" depends="test">
+ <target name="internal.tests" depends="test, jar">
<mkdir dir="tmp/META-INF/services"/>
<copy todir="tmp/META-INF/services">
<fileset dir="${dir.test}/org/tmapi/core">
<include name="org.tmapi.core.TopicMapSystemFactory"/>
</fileset>
</copy>
- <jar jarfile="tmapi-test.jar" basedir="tmp"/>
+ <jar jarfile="tmapi-test.jar" basedir="tmp">
+ <manifest>
+ <attribute name="Import-Package" value="org.tmapi.core,org.tmapi.index"/>
+ <attribute name="Bundle-Name" value="tmapitest"/>
+ <attribute name="Bundle-SymbolicName" value="org.tmapi.test"/>
+ </manifest>
+ </jar>
<junit
printsummary="true" showoutput="false"
errorProperty="test.failed" failureProperty="test.failed">
<classpath>
<pathelement location="${lib.junit}"/>
+ <pathelement location="${lib.osgi}"/>
<pathelement location="tmapi-test.jar"/>
<pathelement location="${dir.build.classes}"/>
<pathelement location="${dir.build.tests}"/>
@@ -129,6 +138,9 @@
debug="${debug}"
target="1.5">
<src path="${dir.src}"/>
+ <classpath>
+ <pathelement location="${lib.osgi}"/>
+ </classpath>
</javac>
</target>
@@ -147,14 +159,14 @@
failonerror="true"
additionalparam="-author -version"
windowtitle="TMAPI v${dist.version}"
- doctitle="TMAPI v${dist.version}">
+ doctitle="TMAPI v${dist.version}"
+ sourcepath="${dir.src}"
+ excludepackagenames="org.tmapi.core.internal.*">
<!--
<doclet name="net.gleamynode.apiviz.APIviz"
path="${dir.lib}/apiviz-1.1.3.jar">
</doclet>
-->
- <fileset dir="${dir.src}">
- </fileset>
</javadoc>
</target>
@@ -173,10 +185,12 @@
<attribute name="Implementation-URL" value="http://www.tmapi.org/"/>
<!-- OSGi-specific -->
<attribute name="Export-Package" value="org.tmapi.core;version=${dist.version},org.tmapi.index;version=${dist.version}"/>
+ <attribute name="Import-Package" value="org.osgi.framework"/>
<attribute name="Bundle-Name" value="TMAPI"/>
<attribute name="Bundle-SymbolicName" value="org.tmapi"/>
<attribute name="Bundle-Vendor" value="TMAPI.org"/>
<attribute name="Bundle-Description" value="Common Topic Maps API"/>
+ <attribute name="Bundle-Activator" value="org.tmapi.core.internal.Activator"/>
<attribute name="Bundle-Version" value="${dist.version}"/>
</manifest>
</jar>
@@ -236,6 +250,7 @@
<copy todir="${dir.dist}" file="CHANGES.txt"/>
<copy todir="${dir.dist}" file="LICENSE.txt"/>
+ <copy todir="${dir.dist}" file="NOTICE.txt"/>
<copy todir="${dir.dist}" file="README.txt"/>
<copy todir="${dir.dist}" file="TMAPI-1.0_MIGRATION.txt"/>
</target>
Added: trunk/lib/LICENSE.osgi.txt
===================================================================
--- trunk/lib/LICENSE.osgi.txt (rev 0)
+++ trunk/lib/LICENSE.osgi.txt 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,42 @@
+OSGi Specification License, Version 1.0.
+
+The OSGi Alliance ("OSGi Alliance") hereby grants you a fully-paid, non-
+exclusive, non-transferable, worldwide, limited license (without the right to
+sublicense), under the OSGi Alliance's applicable intellectual property rights
+to view, download, and reproduce the OSGi Specification ("Specification") which
+follows this License Agreement ("Agreement"). You are not authorized to create
+any derivative work of the Specification. The OSGi Alliance also grants you a
+perpetual, non-exclusive, worldwide, fully paid-up, royalty free, limited
+license (without the right to sublicense) under any applicable copyrights, to
+create and/or distribute an implementation of the Specification that: (i) fully
+implements the Specification including all its required interfaces and
+functionality; (ii) does not modify, subset, superset or otherwise extend the
+OSGi Name Space, or include any public or protected packages, classes, Java
+interfaces, fields or methods within the OSGi Name Space other than those
+required and authorized by the Specification. An implementation that does not
+satisfy limitations (i)-(ii) is not considered an implementation of the
+Specification, does not receive the benefits of this license, and must not be
+described as an implementation of the Specification. An implementation of the
+Specification must not claim to be a compliant implementation of the
+Specification unless it passes the OSGi Alliance Compliance Tests for the
+Specification in accordance with OSGi Alliance processes. "OSGi Name Space"
+shall mean the public class or interface declarations whose names begin with
+"org.osgi" or any recognized successors or replacements thereof.
+
+THE SPECIFICATION IS PROVIDED "AS IS," AND THE OSGi ALLIANCE, ITS MEMBERS AND
+ANY OTHER AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
+INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF THE
+SPECIFICATION ARE SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH
+CONTENTS WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR
+OTHER RIGHTS. THE OSGi ALLIANCE, ITS MEMBERS AND ANY OTHER AUTHORS WILL NOT BE
+LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF ANY USE OF THE SPECIFICATION OR THE PERFORMANCE OR IMPLEMENTATION
+OF THE CONTENTS THEREOF.
+
+The name and trademarks of the OSGi Alliance or any other Authors may NOT be
+used in any manner, including advertising or publicity pertaining to the
+Specification or its contents without specific, written prior permission. Title
+to copyright in the Specification will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
Added: trunk/lib/osgi.core.jar
===================================================================
(Binary files differ)
Property changes on: trunk/lib/osgi.core.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/src/main/java/org/tmapi/core/internal/Activator.java
===================================================================
--- trunk/src/main/java/org/tmapi/core/internal/Activator.java (rev 0)
+++ trunk/src/main/java/org/tmapi/core/internal/Activator.java 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,147 @@
+/**
+ * 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.tmapi.core.internal;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+
+@SuppressWarnings("unchecked")
+public class Activator implements BundleActivator, SynchronousBundleListener {
+
+ private ConcurrentMap<Long, Map<String, Callable<Class>>> factories = new ConcurrentHashMap<Long, Map<String, Callable<Class>>>();
+
+ private BundleContext _bundleContext;
+
+ public synchronized void start(BundleContext bundleContext) throws Exception {
+ _bundleContext = bundleContext;
+ bundleContext.addBundleListener(this);
+ for (Bundle bundle : bundleContext.getBundles()) {
+ if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING ||
+ bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) {
+ register(bundle);
+ }
+ }
+ }
+
+ @SuppressWarnings("boxing")
+ public synchronized void stop(BundleContext bundleContext) throws Exception {
+ bundleContext.removeBundleListener(this);
+ while (!factories.isEmpty()) {
+ unregister(factories.keySet().iterator().next());
+ }
+ _bundleContext = null;
+ }
+
+ public void bundleChanged(BundleEvent event) {
+ if (event.getType() == BundleEvent.RESOLVED) {
+ register(event.getBundle());
+ } else if (event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED) {
+ unregister(event.getBundle().getBundleId());
+ }
+ }
+
+ protected void register(final Bundle bundle) {
+ Map<String, Callable<Class>> map = factories.get(bundle.getBundleId());
+ Enumeration e = bundle.findEntries("META-INF/services/", "*", false);
+ if (e != null) {
+ while (e.hasMoreElements()) {
+ final URL u = (URL) e.nextElement();
+ final String url = u.toString();
+ if (url.endsWith("/")) {
+ continue;
+ }
+ final String factoryId = url.substring(url.lastIndexOf("/") + 1);
+ if (map == null) {
+ map = new HashMap<String, Callable<Class>>();
+ factories.put(bundle.getBundleId(), map);
+ }
+ map.put(factoryId, new BundleFactoryLoader(factoryId, u, bundle));
+ }
+ }
+ if (map != null) {
+ for (Map.Entry<String, Callable<Class>> entry : map.entrySet()) {
+ OsgiLocator.register(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ protected void unregister(long bundleId) {
+ Map<String, Callable<Class>> map = factories.remove(bundleId);
+ if (map != null) {
+ for (Map.Entry<String, Callable<Class>> entry : map.entrySet()) {
+ OsgiLocator.unregister(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ private class BundleFactoryLoader implements Callable<Class> {
+ //private final String factoryId;
+ private final URL u;
+ private final Bundle bundle;
+
+ public BundleFactoryLoader(String factoryId, URL u, Bundle bundle) {
+ //this.factoryId = factoryId;
+ this.u = u;
+ this.bundle = bundle;
+ }
+
+ public Class call() throws Exception {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream(), "UTF-8"));
+ String factoryClassName = br.readLine();
+ br.close();
+ return bundle.loadClass(factoryClassName);
+ } catch (Exception e) {
+ throw e;
+ } catch (Error e) {
+ throw e;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return u.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return u.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof BundleFactoryLoader) {
+ return u.equals(((BundleFactoryLoader) obj).u);
+ } else {
+ return false;
+ }
+ }
+ }
+}
Added: trunk/src/main/java/org/tmapi/core/internal/OsgiLocator.java
===================================================================
--- trunk/src/main/java/org/tmapi/core/internal/OsgiLocator.java (rev 0)
+++ trunk/src/main/java/org/tmapi/core/internal/OsgiLocator.java 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,68 @@
+/**
+ * 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.tmapi.core.internal;
+
+import java.util.concurrent.Callable;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+public class OsgiLocator {
+
+ private static Map<String, List<Callable<Class>>> _factories;
+
+ private OsgiLocator() {
+ }
+
+ public static synchronized void unregister(String id, Callable<Class> factory) {
+ if (_factories != null) {
+ List<Callable<Class>> l = _factories.get(id);
+ if (l != null) {
+ l.remove(factory);
+ }
+ }
+ }
+
+ public static synchronized void register(String id, Callable<Class> factory) {
+ if (_factories == null) {
+ _factories = new HashMap<String, List<Callable<Class>>>();
+ }
+ List<Callable<Class>> l = _factories.get(id);
+ if (l == null) {
+ l = new ArrayList<Callable<Class>>();
+ _factories.put(id, l);
+ }
+ l.add(factory);
+ }
+
+ public static synchronized Class locate(String factoryId) {
+ if (_factories != null) {
+ List<Callable<Class>> l = _factories.get(factoryId);
+ if (l != null && !l.isEmpty()) {
+ Callable<Class> c = l.get(l.size() - 1);
+ try {
+ return c.call();
+ }
+ catch (Exception e) {
+ }
+ }
+ }
+ return null;
+ }
+
+}
Added: trunk/src/main/java/org/tmapi/core/internal/package-info.java
===================================================================
--- trunk/src/main/java/org/tmapi/core/internal/package-info.java (rev 0)
+++ trunk/src/main/java/org/tmapi/core/internal/package-info.java 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,18 @@
+/*
+ * The Topic Maps API (TMAPI) was created collectively by
+ * the membership of the tmapi-discuss mailing list
+ * <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
+ * is hereby released into the public domain; and comes with
+ * NO WARRANTY.
+ *
+ * No one owns TMAPI: you may use it freely in both commercial and
+ * non-commercial applications, bundle it with your software
+ * distribution, include it on a CD-ROM, list the source code in a
+ * book, mirror the documentation at your own web site, or use it in
+ * any other way you see fit.
+ */
+
+/**
+ * Internal OSGi-specific package. This is not meant to be used by client code.
+ */
+package org.tmapi.core.internal;
Added: trunk/src/main/java/org/tmapi/core/package-info.java
===================================================================
--- trunk/src/main/java/org/tmapi/core/package-info.java (rev 0)
+++ trunk/src/main/java/org/tmapi/core/package-info.java 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,19 @@
+/*
+ * The Topic Maps API (TMAPI) was created collectively by
+ * the membership of the tmapi-discuss mailing list
+ * <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
+ * is hereby released into the public domain; and comes with
+ * NO WARRANTY.
+ *
+ * No one owns TMAPI: you may use it freely in both commercial and
+ * non-commercial applications, bundle it with your software
+ * distribution, include it on a CD-ROM, list the source code in a
+ * book, mirror the documentation at your own web site, or use it in
+ * any other way you see fit.
+ */
+
+/**
+ * Core interfaces which provide the functionality of the
+ * <a href="http://www.isotopicmaps.org/sam/sam-model">Topic Maps - Data Model</a>.
+ */
+package org.tmapi.core;
Added: trunk/src/main/java/org/tmapi/index/package-info.java
===================================================================
--- trunk/src/main/java/org/tmapi/index/package-info.java (rev 0)
+++ trunk/src/main/java/org/tmapi/index/package-info.java 2010-02-27 18:45:15 UTC (rev 154)
@@ -0,0 +1,19 @@
+/*
+ * The Topic Maps API (TMAPI) was created collectively by
+ * the membership of the tmapi-discuss mailing list
+ * <http://lists.sourceforge.net/mailman/listinfo/tmapi-discuss>,
+ * is hereby released into the public domain; and comes with
+ * NO WARRANTY.
+ *
+ * No one owns TMAPI: you may use it freely in both commercial and
+ * non-commercial applications, bundle it with your software
+ * distribution, include it on a CD-ROM, list the source code in a
+ * book, mirror the documentation at your own web site, or use it in
+ * any other way you see fit.
+ */
+
+/**
+ * Index interfaces which provide lookup of Topic Maps
+ * {@link org.tmapi.core.Construct}s.
+ */
+package org.tmapi.index;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|