Skip to content

Commit

Permalink
Split ImageJ service framework into scijava-common
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctrueden committed Feb 17, 2013
1 parent 9631dd5 commit 8ab5f9d
Show file tree
Hide file tree
Showing 113 changed files with 17,545 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .factorypath
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<factorypath>
<factorypathentry enabled="true" id="M2_REPO/net/java/sezpoz/sezpoz/1.9/sezpoz-1.9.jar" kind="VARJAR" runInBatchMode="true"/>
</factorypath>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.classpath
.project
.settings
target
4 changes: 4 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Fri Feb 15 15:28:28 CST 2013
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=target/classes
org.eclipse.jdt.apt.reconcileEnabled=false
1 change: 1 addition & 0 deletions pom-scijava/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Maven-based SciJava code, including:
* [ImgLib](https://github.com/imagej/imglib)
* [LOCI](https://github.com/uw-loci/pom-loci)
* [SCIFIO](https://github.com/imagej/minimal-ij1-plugin)
* [SciJava Common](https://github.com/scijava/scijava-common/tree/master/scijava-common)

This POM is intended for use as the parent of your own Maven-based code.
See these examples for guidance:
Expand Down
81 changes: 81 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>1.28</version>
</parent>

<artifactId>scijava-common</artifactId>
<version>1.0.0-SNAPSHOT</version>

<name>SciJava Common</name>
<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>

<dependencies>
<dependency>
<groupId>net.java.sezpoz</groupId>
<artifactId>sezpoz</artifactId>
<version>${sezpoz.version}</version>
</dependency>
<dependency>
<groupId>org.bushe</groupId>
<artifactId>eventbus</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<packageName>org.scijava</packageName>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<scm>
<connection>scm:git:git://github.com/scijava/scijava-common.git</connection>
<developerConnection>scm:git:git@github.com:scijava/scijava-common.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/scijava/scijava-common</url>
</scm>

<!-- NB: for project parent -->
<repositories>
<repository>
<id>imagej.releases</id>
<url>http://maven.imagej.net/content/repositories/releases</url>
</repository>
<repository>
<id>imagej.snapshots</id>
<url>http://maven.imagej.net/content/repositories/snapshots</url>
</repository>
</repositories>

</project>
95 changes: 95 additions & 0 deletions src/main/java/org/scijava/AbstractContextual.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* #%L
* ImageJ software for multidimensional image processing and analysis.
* %%
* Copyright (C) 2009 - 2013 Board of Regents of the University of
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
* Institute of Molecular Cell Biology and Genetics.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of any organization.
* #L%
*/

package org.scijava;

import java.util.List;

import org.scijava.event.EventSubscriber;
import org.scijava.event.EventUtils;

/**
* Abstract base class for {@link Contextual} objects.
* <p>
* This class enforces a single call to {@link #setContext}, throwing an
* {@link IllegalStateException} if the context is already set. It also
* registers the object's {@link org.scijava.event.EventHandler} methods with
* the {@link org.scijava.event.EventService}, if any, at the time the context
* is assigned. This frees subclasses from the burden of maintaining
* {@link EventSubscriber} references manually.
* </p>
*
* @author Curtis Rueden
*/
public abstract class AbstractContextual implements Contextual {

/** This application context associated with the object. */
private Context context;

/**
* The list of event subscribers, maintained to avoid garbage collection.
*
* @see org.scijava.event.EventService#subscribe(Object)
*/
private List<EventSubscriber<?>> subscribers;

// -- Object methods --

@Override
public void finalize() {
// unregister any event handling methods
EventUtils.unsubscribe(getContext(), subscribers);
}

// -- Contextual methods --

@Override
public Context getContext() {
return context;
}

@Override
public void setContext(final Context context) {
if (this.context != null) {
throw new IllegalStateException("Context already set");
}
this.context = context;

// NB: Subscribe to all events handled by this object.
// This greatly simplifies event handling for subclasses.
subscribers = EventUtils.subscribe(context, this);
}

}
Loading

0 comments on commit 8ab5f9d

Please sign in to comment.