Skip to content

Commit 843e23c

Browse files
committed
Add a SciJava gateway
We had a gateway for ImageJ and one for SCIFIO, but no easy-to-use entry point for SciJava Common itself. This gateway changes that!
1 parent 40b8506 commit 843e23c

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* #%L
3+
* SciJava Common shared library for SciJava software.
4+
* %%
5+
* Copyright (C) 2009 - 2014 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+
* #L%
30+
*/
31+
32+
package org.scijava;
33+
34+
import java.util.Collection;
35+
36+
import org.scijava.app.SciJavaApp;
37+
import org.scijava.plugin.Plugin;
38+
import org.scijava.service.Service;
39+
40+
/**
41+
* Main entry point into SciJava. This class enables working with SciJava
42+
* services in a simple way, while retaining extensibility (i.e., access to
43+
* third-party services).
44+
*
45+
* @author Curtis Rueden
46+
*/
47+
@Plugin(type = Gateway.class)
48+
public class SciJava extends AbstractGateway {
49+
50+
// -- Constructors --
51+
52+
/** Creates a new SciJava application context with all available services. */
53+
public SciJava() {
54+
this(new Context());
55+
}
56+
57+
/**
58+
* Creates a new Scijava application context.
59+
*
60+
* @param empty If true, the context will be empty; otherwise, it will be
61+
* initialized with all available services.
62+
*/
63+
public SciJava(final boolean empty) {
64+
this(new Context(empty));
65+
}
66+
67+
/**
68+
* Creates a new SciJava application context with the specified services (and
69+
* any required service dependencies).
70+
* <p>
71+
* <b>Developer's note:</b> This constructor's argument is raw (i.e.,
72+
* {@code Class...} instead of {@code Class<? extends Service>...}) because
73+
* otherwise, downstream invocations (e.g.,
74+
* {@code new SciJava(LogService.class)}) yield the potentially confusing
75+
* warning:
76+
* </p>
77+
* <blockquote>Type safety: A generic array of Class<? extends Service> is
78+
* created for a varargs parameter</blockquote>
79+
* <p>
80+
* To avoid this, we have opted to use raw types and suppress the relevant
81+
* warning here instead.
82+
* </p>
83+
*
84+
* @param serviceClasses A list of types that implement the {@link Service}
85+
* interface (e.g., {@code LogService.class}).
86+
* @throws ClassCastException If any of the given arguments do not implement
87+
* the {@link Service} interface.
88+
*/
89+
@SuppressWarnings({ "rawtypes" })
90+
public SciJava(final Class... serviceClasses) {
91+
this(new Context(serviceClasses));
92+
}
93+
94+
/**
95+
* Creates a new SciJava application context with the specified services (and
96+
* any required service dependencies).
97+
*
98+
* @param serviceClasses A collection of types that implement the
99+
* {@link Service} interface (e.g., {@code LogService.class}).
100+
*/
101+
public SciJava(final Collection<Class<? extends Service>> serviceClasses) {
102+
this(new Context(serviceClasses));
103+
}
104+
105+
/**
106+
* Creates a new SciJava application context which wraps the given existing
107+
* SciJava context.
108+
*
109+
* @see Context
110+
*/
111+
public SciJava(final Context context) {
112+
super(SciJavaApp.NAME, context);
113+
}
114+
115+
}

0 commit comments

Comments
 (0)