X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibrary.java;h=7869b694b23a562e3d6201bf603541089fcafd36;hb=74a40dfb4551443fcb20dddb50af940e14acee25;hp=f4e8264eca29a536c77f26646bc2cab243a4cccf;hpb=39cd9738bfcdafaf8806d5007e443e572f8994c0;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java index f4e8264..7869b69 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -51,7 +51,7 @@ public class RemoteLibrary extends BasicLibrary { protected List getMetas(Progress pg) { // TODO: progress final List metas = new ArrayList(); - MetaData[] fromNetwork = this. getRemoteObject( // + MetaData[] fromNetwork = this.getRemoteObject( // new Object[] { key, "GET_METADATA", "*" }); if (fromNetwork != null) { @@ -65,19 +65,19 @@ public class RemoteLibrary extends BasicLibrary { @Override public BufferedImage getCover(final String luid) { - return this. getRemoteObject( // + return this.getRemoteObject( // new Object[] { key, "GET_COVER", luid }); } @Override public BufferedImage getSourceCover(final String source) { - return this. getRemoteObject( // + return this.getRemoteObject( // new Object[] { key, "GET_SOURCE_COVER", source }); } @Override public synchronized Story getStory(final String luid, Progress pg) { - return this. getRemoteObject( // + return this.getRemoteStory( // new Object[] { key, "GET_STORY", luid }); } @@ -137,19 +137,63 @@ public class RemoteLibrary extends BasicLibrary { * @param * the expected type of object * @param command - * the command to send + * the command to send (can contain at most ONE {@link Story}) * * @return the object or NULL */ - @SuppressWarnings("unchecked") private T getRemoteObject(final Object[] command) { + return getRemoteObjectOrStory(command, false); + } + + /** + * Return an object from the server. + * + * @param command + * the command to send (can contain at most ONE {@link Story}) + * + * @return the object or NULL + */ + private Story getRemoteStory(final Object[] command) { + return getRemoteObjectOrStory(command, true); + } + + /** + * Return an object from the server. + * + * @param + * the expected type of object + * @param command + * the command to send (can contain at most ONE {@link Story}) + * + * @return the object or NULL + */ + @SuppressWarnings("unchecked") + private T getRemoteObjectOrStory(final Object[] command, + final boolean getStory) { final Object[] result = new Object[1]; try { new ConnectActionClientObject(host, port, true) { @Override public void action(Version serverVersion) throws Exception { try { + Story story = null; + for (int i = 0; i < command.length; i++) { + if (command[i] instanceof Story) { + story = (Story) command[i]; + command[i] = null; + } + } + Object rep = send(command); + + if (story != null) { + RemoteLibraryServer.sendStory(story, this); + } + + if (getStory) { + rep = RemoteLibraryServer.recStory(this); + } + result[0] = rep; } catch (Exception e) { Instance.getTraceHandler().error(e);