-
Notifications
You must be signed in to change notification settings - Fork 53
Create Initializable #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Initializable #249
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * #%L | ||
| * ImageJ software for multidimensional image processing and analysis. | ||
| * %% | ||
| * Copyright (C) 2014 - 2016 Board of Regents of the University of | ||
| * Wisconsin-Madison, University of Konstanz and Brian Northan. | ||
| * %% | ||
| * 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. | ||
| * #L% | ||
| */ | ||
|
|
||
| package org.scijava; | ||
|
|
||
| /** | ||
| * Interface for objects which can be initialized. | ||
| * | ||
| * @author Curtis Rueden | ||
| */ | ||
| public interface Initializable { | ||
|
|
||
| /** Initializes the object. */ | ||
| default void initialize() { | ||
| // NB: Do nothing by default. | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,8 @@ | |
| import java.util.HashSet; | ||
| import java.util.Map; | ||
|
|
||
| import org.scijava.Initializable; | ||
|
|
||
| /** | ||
| * Abstract superclass of {@link Module} implementations. | ||
| * <p> | ||
|
|
@@ -76,11 +78,16 @@ public void cancel() { | |
| public void initialize() throws MethodCallException { | ||
| // execute global module initializer | ||
| final Object delegateObject = getDelegateObject(); | ||
| if (initializerRef == null) { | ||
| final String initializer = getInfo().getInitializer(); | ||
| initializerRef = new MethodRef(delegateObject.getClass(), initializer); | ||
| if (delegateObject instanceof Initializable) { | ||
| ((Initializable) delegateObject).initialize(); | ||
| } | ||
| else { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do either/or here? If so, we should issue a warning when the module implements
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is also a question of handling the case where the |
||
| if (initializerRef == null) { | ||
| final String initializer = getInfo().getInitializer(); | ||
| initializerRef = new MethodRef(delegateObject.getClass(), initializer); | ||
| } | ||
| initializerRef.execute(delegateObject); | ||
| } | ||
| initializerRef.execute(delegateObject); | ||
|
|
||
| // execute individual module item initializers | ||
| for (final ModuleItem<?> item : getInfo().inputs()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This copyright header should be updated to match the rest of SJC.