Skip to content

Commit

Permalink
Adding TextIOService with default implementation
Browse files Browse the repository at this point in the history
* .. which was originally implemented in the TypedIOServiceTest for
testing the TypedIOService architecture
  • Loading branch information
frauzufall committed Aug 12, 2020
1 parent 2c5d0c1 commit 9b09f4c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 13 deletions.
43 changes: 43 additions & 0 deletions src/main/java/org/scijava/text/io/DefaultTextIOService.java
Original file line number Diff line number Diff line change
@@ -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<String> implements TextIOService {
}
40 changes: 40 additions & 0 deletions src/main/java/org/scijava/text/io/TextIOService.java
Original file line number Diff line number Diff line change
@@ -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<String> {
}
1 change: 1 addition & 0 deletions src/test/java/org/scijava/ContextCreationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 1 addition & 13 deletions src/test/java/org/scijava/io/TypedIOServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -39,12 +33,6 @@ public void testTextFile() throws IOException {
assertTrue(obj.contains("content"));
}

interface TextIOService extends TypedIOService<String> {
}

public static class DefaultTextIOService extends AbstractTypedIOService<String> implements TextIOService {
}

public static class DummyTextFormat extends AbstractTextFormat {

@Override
Expand Down

0 comments on commit 9b09f4c

Please sign in to comment.