Skip to content

Commit 8ab5f9d

Browse files
committed
Split ImageJ service framework into scijava-common
This code was migrated and adapted from ImageJ: https://github.com/imagej/imagej This new shared library will enable ImageJ and SCIFIO to have a common base for plugin extensibility.
1 parent 9631dd5 commit 8ab5f9d

File tree

113 files changed

+17545
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+17545
-0
lines changed

.factorypath

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<factorypath>
3+
<factorypathentry enabled="true" id="M2_REPO/net/java/sezpoz/sezpoz/1.9/sezpoz-1.9.jar" kind="VARJAR" runInBatchMode="true"/>
4+
</factorypath>

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
.classpath
12
.project
23
.settings
4+
target
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Fri Feb 15 15:28:28 CST 2013
2+
org.eclipse.jdt.apt.aptEnabled=true
3+
org.eclipse.jdt.apt.genSrcDir=target/classes
4+
org.eclipse.jdt.apt.reconcileEnabled=false

pom-scijava/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Maven-based SciJava code, including:
99
* [ImgLib](https://github.com/imagej/imglib)
1010
* [LOCI](https://github.com/uw-loci/pom-loci)
1111
* [SCIFIO](https://github.com/imagej/minimal-ij1-plugin)
12+
* [SciJava Common](https://github.com/scijava/scijava-common/tree/master/scijava-common)
1213

1314
This POM is intended for use as the parent of your own Maven-based code.
1415
See these examples for guidance:

pom.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>org.scijava</groupId>
10+
<artifactId>pom-scijava</artifactId>
11+
<version>1.28</version>
12+
</parent>
13+
14+
<artifactId>scijava-common</artifactId>
15+
<version>1.0.0-SNAPSHOT</version>
16+
17+
<name>SciJava Common</name>
18+
<description>SciJava Common is a service framework. It provides an extensible mechanism for service discovery, driven by the SezPoz library, so that plugins can be loaded dynamically. It is used by both ImageJ and SCIFIO.</description>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>net.java.sezpoz</groupId>
23+
<artifactId>sezpoz</artifactId>
24+
<version>${sezpoz.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.bushe</groupId>
28+
<artifactId>eventbus</artifactId>
29+
<version>1.4</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>junit</groupId>
34+
<artifactId>junit</artifactId>
35+
<version>${junit.version}</version>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<artifactId>maven-jar-plugin</artifactId>
44+
<configuration>
45+
<archive>
46+
<manifest>
47+
<packageName>org.scijava</packageName>
48+
</manifest>
49+
</archive>
50+
</configuration>
51+
</plugin>
52+
<plugin>
53+
<artifactId>maven-source-plugin</artifactId>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.codehaus.mojo</groupId>
57+
<artifactId>buildnumber-maven-plugin</artifactId>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
<scm>
63+
<connection>scm:git:git://github.com/scijava/scijava-common.git</connection>
64+
<developerConnection>scm:git:git@github.com:scijava/scijava-common.git</developerConnection>
65+
<tag>HEAD</tag>
66+
<url>https://github.com/scijava/scijava-common</url>
67+
</scm>
68+
69+
<!-- NB: for project parent -->
70+
<repositories>
71+
<repository>
72+
<id>imagej.releases</id>
73+
<url>http://maven.imagej.net/content/repositories/releases</url>
74+
</repository>
75+
<repository>
76+
<id>imagej.snapshots</id>
77+
<url>http://maven.imagej.net/content/repositories/snapshots</url>
78+
</repository>
79+
</repositories>
80+
81+
</project>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2013 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*
30+
* The views and conclusions contained in the software and documentation are
31+
* those of the authors and should not be interpreted as representing official
32+
* policies, either expressed or implied, of any organization.
33+
* #L%
34+
*/
35+
36+
package org.scijava;
37+
38+
import java.util.List;
39+
40+
import org.scijava.event.EventSubscriber;
41+
import org.scijava.event.EventUtils;
42+
43+
/**
44+
* Abstract base class for {@link Contextual} objects.
45+
* <p>
46+
* This class enforces a single call to {@link #setContext}, throwing an
47+
* {@link IllegalStateException} if the context is already set. It also
48+
* registers the object's {@link org.scijava.event.EventHandler} methods with
49+
* the {@link org.scijava.event.EventService}, if any, at the time the context
50+
* is assigned. This frees subclasses from the burden of maintaining
51+
* {@link EventSubscriber} references manually.
52+
* </p>
53+
*
54+
* @author Curtis Rueden
55+
*/
56+
public abstract class AbstractContextual implements Contextual {
57+
58+
/** This application context associated with the object. */
59+
private Context context;
60+
61+
/**
62+
* The list of event subscribers, maintained to avoid garbage collection.
63+
*
64+
* @see org.scijava.event.EventService#subscribe(Object)
65+
*/
66+
private List<EventSubscriber<?>> subscribers;
67+
68+
// -- Object methods --
69+
70+
@Override
71+
public void finalize() {
72+
// unregister any event handling methods
73+
EventUtils.unsubscribe(getContext(), subscribers);
74+
}
75+
76+
// -- Contextual methods --
77+
78+
@Override
79+
public Context getContext() {
80+
return context;
81+
}
82+
83+
@Override
84+
public void setContext(final Context context) {
85+
if (this.context != null) {
86+
throw new IllegalStateException("Context already set");
87+
}
88+
this.context = context;
89+
90+
// NB: Subscribe to all events handled by this object.
91+
// This greatly simplifies event handling for subclasses.
92+
subscribers = EventUtils.subscribe(context, this);
93+
}
94+
95+
}

0 commit comments

Comments
 (0)