From a0bc00a104e4fa97d55f4274f833b0183039a892 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 19 Mar 2008 15:25:38 +0000 Subject: [PATCH] added session/request locale support git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1288 9efc2488-bf62-4759-914b-345cdb29e865 --- src/java/org/opensrf/ClientSession.java | 13 ++++++++++- src/java/org/opensrf/Message.java | 24 +++++++++++++++++++- src/java/org/opensrf/Request.java | 2 +- src/java/org/opensrf/Session.java | 40 +++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/java/org/opensrf/ClientSession.java b/src/java/org/opensrf/ClientSession.java index 385fdbf..3ed4908 100644 --- a/src/java/org/opensrf/ClientSession.java +++ b/src/java/org/opensrf/ClientSession.java @@ -36,10 +36,21 @@ public class ClientSession extends Session { /** * Creates a new client session. Initializes the - * @param service The remove service. + * @param service The remote service. */ public ClientSession(String service) throws ConfigException { + this(service, null); + } + + /** + * Creates a new client session. Initializes the + * @param service The remote service. + * @param locale The locale for this session. + */ + public ClientSession(String service, String locale) throws ConfigException { this.service = service; + if(locale != null) + setLocale(locale); /** generate the remote node string */ domain = (String) Config.global().getFirst("/domain"); diff --git a/src/java/org/opensrf/Message.java b/src/java/org/opensrf/Message.java index fd8ad8c..6bfe1ea 100644 --- a/src/java/org/opensrf/Message.java +++ b/src/java/org/opensrf/Message.java @@ -17,13 +17,15 @@ public class Message implements OSRFSerializable { private String type; /** message payload */ private Object payload; + /** message locale */ + private String locale; /** Create a registry for the osrfMessage object */ private static OSRFRegistry registry = OSRFRegistry.registerObject( "osrfMessage", OSRFRegistry.WireProtocol.HASH, - new String[] {"threadTrace", "type", "payload"}); + new String[] {"threadTrace", "type", "payload", "locale"}); /** * @param id This message's ID @@ -44,6 +46,18 @@ public class Message implements OSRFSerializable { setPayload(payload); } + /** + * @param id This message's ID + * @param type The type of message + * @param payload The message payload + * @param locale The message locale + */ + public Message(int id, String type, Object payload, String locale) { + this(id, type, payload); + setPayload(payload); + setLocale(locale); + } + public int getId() { return id; @@ -54,6 +68,9 @@ public class Message implements OSRFSerializable { public Object getPayload() { return payload; } + public String getLocale() { + return locale; + } public void setId(int id) { this.id = id; } @@ -63,6 +80,9 @@ public class Message implements OSRFSerializable { public void setPayload(Object p) { payload = p; } + public void setLocale(String l) { + locale = l; + } /** * Implements the generic get() API required by OSRFSerializable @@ -74,6 +94,8 @@ public class Message implements OSRFSerializable { return getType().toString(); if("payload".equals(field)) return getPayload(); + if("locale".equals(field)) + return getLocale(); return null; } diff --git a/src/java/org/opensrf/Request.java b/src/java/org/opensrf/Request.java index 32977e0..2d72e2d 100644 --- a/src/java/org/opensrf/Request.java +++ b/src/java/org/opensrf/Request.java @@ -59,7 +59,7 @@ public class Request { * Sends the request to the server. */ public void send() throws SessionException { - session.send(new Message(id, Message.REQUEST, method)); + session.send(new Message(id, Message.REQUEST, method, session.getLocale())); } /** diff --git a/src/java/org/opensrf/Session.java b/src/java/org/opensrf/Session.java index f5045b3..ebcc26f 100644 --- a/src/java/org/opensrf/Session.java +++ b/src/java/org/opensrf/Session.java @@ -24,6 +24,11 @@ public abstract class Session { /** The address of the remote party we are communicating with */ private String remoteNode; + /** Session locale */ + protected String locale; + /** Default session locale */ + protected static String defaultLocale = "en_US"; + /** * The thread is used to link messages to a given session. * In other words, each session has a unique thread, and all messages @@ -121,6 +126,41 @@ public abstract class Session { public void setThread(String thread) { this.thread = thread; } + + /** + * Get locale. + * @return locale as String. + */ + public String getLocale() { + if(locale == null) + return defaultLocale; + return locale; + } + + /** + * Set locale. + * @param locale the value to set. + */ + public void setLocale(String locale) { + this.locale = locale; + } + + /** + * Get defaultLocale. + * @return defaultLocale as String. + */ + public String getDefaultLocale() { + return defaultLocale; + } + + /** + * Set defaultLocale. + * @param defaultLocale the value to set. + */ + public void setDefaultLocale(String defaultLocale) { + this.defaultLocale = defaultLocale; + } + /** * Get connectState. -- 2.11.0