From 754cb731b2d5f4888815c16c530fc3674264a4f2 Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 11 Feb 2009 19:59:02 +0000 Subject: make applet better extensible (override BKUWorker,...) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@294 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../at/gv/egiz/bku/online/applet/BKUApplet.java | 122 +++++++++++++-------- 1 file changed, 77 insertions(+), 45 deletions(-) (limited to 'BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java') diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java index d4b2018d..a4337bbd 100644 --- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java +++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java @@ -31,7 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.gui.BKUGUIFacade; -import at.gv.egiz.bku.gui.BKUGUIFactory; +import at.gv.egiz.bku.gui.BKUGUIImpl; import at.gv.egiz.stal.service.STALPortType; import at.gv.egiz.stal.service.STALService; import java.awt.Container; @@ -57,8 +57,6 @@ public class BKUApplet extends JApplet { public static final String BACKGROUND_IMG = "Background"; public static final String REDIRECT_URL = "RedirectURL"; public static final String REDIRECT_TARGET = "RedirectTarget"; -// public static final String HASHDATA_DISPLAY_INTERNAL = "internal"; -// public static final String HASHDATA_DISPLAY_BROWSER = "browser"; public static final String HASHDATA_DISPLAY_FRAME = "frame"; /** * STAL WSDL namespace and service name @@ -69,6 +67,14 @@ public class BKUApplet extends JApplet { * Dummy session id, used if no sessionId parameter is provided */ protected static final String TEST_SESSION_ID = "TestSession"; + + static { + if (log.isTraceEnabled()) { + log.trace("enabling webservice communication dump"); + System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true"); + } + } + /** * STAL */ @@ -82,7 +88,7 @@ public class BKUApplet extends JApplet { @Override public void init() { log.info("Welcome to MOCCA"); - log.debug("Called init()"); + log.trace("Called init()"); HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance()); @@ -127,19 +133,19 @@ public class BKUApplet extends JApplet { backgroundImgURL, helpListener); - worker = new AppletBKUWorker(this, gui); + worker = createBKUWorker(this, gui); } @Override public void start() { - log.debug("Called start()"); + log.trace("Called start()"); workerThread = new Thread(worker); workerThread.start(); } @Override public void stop() { - log.debug("Called stop()"); + log.trace("Called stop()"); if ((workerThread != null) && (workerThread.isAlive())) { workerThread.interrupt(); } @@ -147,52 +153,36 @@ public class BKUApplet extends JApplet { @Override public void destroy() { - log.debug("Called destroy()"); + log.trace("Called destroy()"); } - protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { - String urlParam = getParameter(paramKey); - if (urlParam != null) { - URL codebase = getCodeBase(); - try { - URL url; - if (codebase.getProtocol().equalsIgnoreCase("file")) { - // for debugging in appletrunner - url = new URL(urlParam); - } else { - if (sessionId != null) { - urlParam = urlParam + ";jsessionid=" + sessionId; - } - url = new URL(codebase, urlParam); - } - log.info("applet parameter " + url); - return url; - } catch (MalformedURLException ex) { - log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); - throw ex; - } - } else { - log.error("applet paremeter " + urlParam + " not set"); - throw new MalformedURLException(urlParam + " not set"); - } - } - - /** - * provides a means to for subclasses to inject a different GUI - */ + ///////////////////////////////////////////////////////////////////////////// + // factory methods for subclasses to inject different components + ///////////////////////////////////////////////////////////////////////////// + protected BKUGUIFacade createGUI(Container contentPane, Locale locale, Style guiStyle, URL backgroundImgURL, AbstractHelpListener helpListener) { - return BKUGUIFactory.createGUI(contentPane, - locale, - guiStyle, - backgroundImgURL, - helpListener); + return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL, helpListener); + } + + protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) { + return new AppletBKUWorker(applet, gui); } - protected STALPortType getSTALPort() throws MalformedURLException { + + ///////////////////////////////////////////////////////////////////////////// + // callback for BKUWorker to allow extension + ///////////////////////////////////////////////////////////////////////////// + + /** + * Callback for BKUWorker to allow extension + * @return + * @throws java.net.MalformedURLException + */ + public STALPortType getSTALPort() throws MalformedURLException { URL wsdlURL = getURLParameter(WSDL_URL, null); log.debug("setting STAL WSDL: " + wsdlURL); QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE); @@ -200,10 +190,21 @@ public class BKUApplet extends JApplet { return stal.getSTALPort(); } - protected STALTranslator getSTALTranslator() { + /** + * Callback for BKUWorker to allow extension + * (TODO STALPort could know its STALTranslator) + * @return + * @throws java.net.MalformedURLException + */ + public STALTranslator getSTALTranslator() { return new STALTranslator(); } + /** + * Callback for BKUWorker to keep applet context out of BKUWorker + * @return + * @throws java.net.MalformedURLException + */ protected void sendRedirect(String sessionId) { try { URL redirectURL = getURLParameter(REDIRECT_URL, sessionId); @@ -220,4 +221,35 @@ public class BKUApplet extends JApplet { // gui.showErrorDialog(errorMsg, okListener, actionCommand) } } + + + ///////////////////////////////////////////////////////////////////////////// + // utility methods + ///////////////////////////////////////////////////////////////////////////// + + protected URL getURLParameter(String paramKey, String sessionId) throws MalformedURLException { + String urlParam = getParameter(paramKey); + if (urlParam != null) { + URL codebase = getCodeBase(); + try { + URL url; + if (codebase.getProtocol().equalsIgnoreCase("file")) { + // for debugging in appletrunner + url = new URL(urlParam); + } else { + if (sessionId != null) { + urlParam = urlParam + ";jsessionid=" + sessionId; + } + url = new URL(codebase, urlParam); + } + return url; + } catch (MalformedURLException ex) { + log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage()); + throw ex; + } + } else { + log.error("applet paremeter " + urlParam + " not set"); + throw new MalformedURLException(urlParam + " not set"); + } + } } -- cgit v1.2.3