Skip to content

Commit 7d4a580

Browse files
committed
Re-add reprecated methods
* they were removed in favor of using Location instead of String for IO handling * they are re-added to restore backwards compatibility
1 parent 5906195 commit 7d4a580

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

src/main/java/org/scijava/io/event/DataOpenedEvent.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package org.scijava.io.event;
3131

3232

33+
import org.scijava.io.location.FileLocation;
3334
import org.scijava.io.location.Location;
3435

3536
/**
@@ -43,4 +44,25 @@ public DataOpenedEvent(final Location location, final Object data) {
4344
super(location, data);
4445
}
4546

47+
/**
48+
* @deprecated use {@link #DataOpenedEvent(Location, Object)} instead
49+
*/
50+
@Deprecated
51+
public DataOpenedEvent(final String source, final Object data) {
52+
this(new FileLocation(source), data);
53+
}
54+
55+
/**
56+
* @deprecated use {@link #getLocation} instead
57+
*/
58+
@Deprecated
59+
public String getSource() {
60+
try {
61+
FileLocation fileLocation = (FileLocation) getLocation();
62+
return fileLocation.getFile().getAbsolutePath();
63+
} catch(ClassCastException e) {
64+
return getLocation().getURI().toString();
65+
}
66+
}
67+
4668
}

src/main/java/org/scijava/io/event/DataSavedEvent.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package org.scijava.io.event;
3131

3232

33+
import org.scijava.io.location.FileLocation;
3334
import org.scijava.io.location.Location;
3435

3536
/**
@@ -43,4 +44,24 @@ public DataSavedEvent(final Location destination, final Object data) {
4344
super(destination, data);
4445
}
4546

47+
/**
48+
* @deprecated use {@link #DataSavedEvent(Location, Object)} instead
49+
*/
50+
@Deprecated
51+
public DataSavedEvent(final String destination, final Object data) {
52+
this(new FileLocation(destination), data);
53+
}
54+
55+
/**
56+
* @deprecated use {@link #getLocation} instead
57+
*/
58+
@Deprecated
59+
public String getDestination() {
60+
try {
61+
FileLocation fileLocation = (FileLocation) getLocation();
62+
return fileLocation.getFile().getAbsolutePath();
63+
} catch(ClassCastException e) {
64+
return getLocation().getURI().toString();
65+
}
66+
}
4667
}

src/main/java/org/scijava/io/event/IOEvent.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package org.scijava.io.event;
3131

3232
import org.scijava.event.SciJavaEvent;
33+
import org.scijava.io.location.FileLocation;
3334
import org.scijava.io.location.Location;
3435

3536
/**
@@ -45,6 +46,14 @@ public abstract class IOEvent extends SciJavaEvent {
4546
/** The data for which I/O took place. */
4647
private final Object data;
4748

49+
/**
50+
* @deprecated use {@link #IOEvent(Location, Object)} instead
51+
*/
52+
@Deprecated
53+
public IOEvent(final String descriptor, final Object data) {
54+
this(new FileLocation(descriptor), data);
55+
}
56+
4857
public IOEvent(final Location location, final Object data) {
4958
this.location = location;
5059
this.data = data;
@@ -68,4 +77,17 @@ public String toString() {
6877
data;
6978
}
7079

80+
/**
81+
* @deprecated use {@link #getLocation()} instead
82+
*/
83+
@Deprecated
84+
public String getDescriptor() {
85+
try {
86+
FileLocation fileLocation = (FileLocation) getLocation();
87+
return fileLocation.getFile().getAbsolutePath();
88+
} catch(ClassCastException e) {
89+
return getLocation().getURI().toString();
90+
}
91+
}
92+
7193
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.scijava.io.event;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class DataEventTest {
8+
9+
@Test
10+
public void testDeprecatedMethods() {
11+
String localPath = "/local/absolute/path.txt";
12+
Object obj = null;
13+
DataOpenedEvent openedEvent = new DataOpenedEvent(localPath, obj);
14+
DataSavedEvent savedEvent = new DataSavedEvent(localPath, obj);
15+
assertEquals(localPath, openedEvent.getSource());
16+
assertEquals(localPath, savedEvent.getDestination());
17+
18+
// String remotepath = "https://remote.org/path.txt";
19+
// openedEvent = new DataOpenedEvent(remotepath, obj);
20+
// savedEvent = new DataSavedEvent(remotepath, obj);
21+
// assertEquals(remotepath, openedEvent.getSource());
22+
// assertEquals(remotepath, savedEvent.getDestination());
23+
}
24+
25+
}

0 commit comments

Comments
 (0)