From 9b09f4cc5f1005279a13964694000c9be9eb175b Mon Sep 17 00:00:00 2001 From: frauzufall Date: Wed, 12 Aug 2020 17:24:32 +0200 Subject: [PATCH] Adding TextIOService with default implementation * .. which was originally implemented in the TypedIOServiceTest for testing the TypedIOService architecture --- .../scijava/text/io/DefaultTextIOService.java | 43 +++++++++++++++++++ .../org/scijava/text/io/TextIOService.java | 40 +++++++++++++++++ .../java/org/scijava/ContextCreationTest.java | 1 + .../org/scijava/io/TypedIOServiceTest.java | 14 +----- 4 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/scijava/text/io/DefaultTextIOService.java create mode 100644 src/main/java/org/scijava/text/io/TextIOService.java diff --git a/src/main/java/org/scijava/text/io/DefaultTextIOService.java b/src/main/java/org/scijava/text/io/DefaultTextIOService.java new file mode 100644 index 000000000..509216a3c --- /dev/null +++ b/src/main/java/org/scijava/text/io/DefaultTextIOService.java @@ -0,0 +1,43 @@ +/* + * #%L + * SciJava Common shared library for SciJava software. + * %% + * Copyright (C) 2009 - 2020 SciJava developers. + * %% + * 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.text.io; + +import org.scijava.io.AbstractTypedIOService; +import org.scijava.plugin.Plugin; +import org.scijava.service.Service; + +/** + * Default {@link TextIOService} implementation for opening and saving text data + * + * @author Deborah Schmidt + */ +@Plugin(type = Service.class) +public class DefaultTextIOService extends AbstractTypedIOService implements TextIOService { +} diff --git a/src/main/java/org/scijava/text/io/TextIOService.java b/src/main/java/org/scijava/text/io/TextIOService.java new file mode 100644 index 000000000..c87d2847a --- /dev/null +++ b/src/main/java/org/scijava/text/io/TextIOService.java @@ -0,0 +1,40 @@ +/* + * #%L + * SciJava Common shared library for SciJava software. + * %% + * Copyright (C) 2009 - 2020 SciJava developers. + * %% + * 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.text.io; + +import org.scijava.io.TypedIOService; + +/** + * {@link TypedIOService} for opening and saving text data + * + * @author Deborah Schmidt + */ +public interface TextIOService extends TypedIOService { +} diff --git a/src/test/java/org/scijava/ContextCreationTest.java b/src/test/java/org/scijava/ContextCreationTest.java index 4fd266e4b..ccf76e426 100644 --- a/src/test/java/org/scijava/ContextCreationTest.java +++ b/src/test/java/org/scijava/ContextCreationTest.java @@ -114,6 +114,7 @@ public void testFull() { org.scijava.startup.DefaultStartupService.class, org.scijava.task.DefaultTaskService.class, org.scijava.text.DefaultTextService.class, + org.scijava.text.io.DefaultTextIOService.class, org.scijava.thread.DefaultThreadService.class, org.scijava.tool.DefaultToolService.class, org.scijava.ui.DefaultUIService.class, diff --git a/src/test/java/org/scijava/io/TypedIOServiceTest.java b/src/test/java/org/scijava/io/TypedIOServiceTest.java index e72324c60..de64730e2 100644 --- a/src/test/java/org/scijava/io/TypedIOServiceTest.java +++ b/src/test/java/org/scijava/io/TypedIOServiceTest.java @@ -3,12 +3,9 @@ import org.junit.Test; import org.scijava.Context; import org.scijava.plugin.PluginInfo; -import org.scijava.plugin.PluginService; -import org.scijava.plugin.SciJavaPlugin; -import org.scijava.service.SciJavaService; import org.scijava.text.AbstractTextFormat; import org.scijava.text.TextFormat; -import org.scijava.text.TextService; +import org.scijava.text.io.TextIOService; import java.io.IOException; import java.util.Collections; @@ -24,9 +21,6 @@ public void testTextFile() throws IOException { // create context, add dummy text format final Context ctx = new Context(); ctx.getPluginIndex().add(new PluginInfo<>(DummyTextFormat.class, TextFormat.class)); - ctx.getPluginIndex().add(new PluginInfo<>(DefaultTextIOService.class, TextIOService.class)); - TextIOService instance = (TextIOService) ctx.getService(PluginService.class).createInstance(ctx.getPluginIndex().get(TextIOService.class).get(0)); - ctx.getServiceIndex().add(instance); // try to get the TextIOService final TextIOService io = ctx.service(TextIOService.class); @@ -39,12 +33,6 @@ public void testTextFile() throws IOException { assertTrue(obj.contains("content")); } - interface TextIOService extends TypedIOService { - } - - public static class DefaultTextIOService extends AbstractTypedIOService implements TextIOService { - } - public static class DummyTextFormat extends AbstractTextFormat { @Override