From: Niels Erik G. Nielsen Date: Fri, 1 Mar 2013 17:26:31 +0000 (-0500) Subject: Work-in-progress on interchangeable config mechanisms X-Git-Tag: v0.0.7~223 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=f995bd0cb2162befcbeec565809566730a378641;p=mkjsf-moved-to-github.git Work-in-progress on interchangeable config mechanisms --- diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/FacesModuleConfiguration.java b/src/main/java/com/indexdata/pz2utils4jsf/config/FacesModuleConfiguration.java deleted file mode 100644 index 055ca0e..0000000 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/FacesModuleConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.indexdata.pz2utils4jsf.config; - -import java.io.IOException; -import java.io.Serializable; - -import javax.faces.context.ExternalContext; -import javax.faces.context.FacesContext; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; - -import com.indexdata.masterkey.config.MasterkeyConfiguration; -import com.indexdata.masterkey.config.ModuleConfiguration; -import com.indexdata.masterkey.config.ModuleConfigurationGetter; - -public abstract class FacesModuleConfiguration implements ModuleConfigurationGetter, Serializable { - - private static final long serialVersionUID = -7225977088088592928L; - private ModuleConfiguration config; - - public FacesModuleConfiguration() { - if (FacesContext.getCurrentInstance() != null) { - ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); - HttpServletRequest request = (HttpServletRequest) externalContext.getRequest(); - ServletContext servletContext = (ServletContext) externalContext.getContext(); - String host = request.getServerName(); - try { - config = MasterkeyConfiguration.getModuleConfiguration(servletContext, host, getComponentName(), getModuleName()); - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - } - - public String get(String name) { - return config.get(name); - } - - public String get(String name, String defaultValue) { - return config.get(name, defaultValue); - } - - public ModuleConfiguration getModuleConfiguration () { - return config; - } - - public abstract String getModuleName(); - - public abstract String getComponentName(); - -} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/JsfdemoModuleConfiguration.java b/src/main/java/com/indexdata/pz2utils4jsf/config/JsfdemoModuleConfiguration.java deleted file mode 100644 index 1d4b8bd..0000000 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/JsfdemoModuleConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.indexdata.pz2utils4jsf.config; - -import com.indexdata.pz2utils4jsf.config.FacesModuleConfiguration; - -public abstract class JsfdemoModuleConfiguration extends FacesModuleConfiguration { - - private static final long serialVersionUID = -2936339728016978922L; - - @Override - public abstract String getModuleName(); - - @Override - public String getComponentName() { - return "jsfdemo"; - } - -} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/JsfdemoPazpar2ClientConfiguration.java b/src/main/java/com/indexdata/pz2utils4jsf/config/JsfdemoPazpar2ClientConfiguration.java deleted file mode 100644 index a19a95f..0000000 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/JsfdemoPazpar2ClientConfiguration.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.indexdata.pz2utils4jsf.config; - -import javax.enterprise.context.SessionScoped; -import javax.inject.Named; - -import com.indexdata.pz2utils4jsf.config.JsfdemoModuleConfiguration; - -@Named("pz2clientConfig") -@SessionScoped -public class JsfdemoPazpar2ClientConfiguration extends JsfdemoModuleConfiguration { - - private static final long serialVersionUID = 8865086878660568870L; - - @Override - public String getModuleName() { - return "pz2client"; - } - -} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java new file mode 100644 index 0000000..3caa832 --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java @@ -0,0 +1,71 @@ +package com.indexdata.pz2utils4jsf.config; + +import java.util.HashMap; +import java.util.Map; + +import com.indexdata.masterkey.config.MissingMandatoryParameterException; +import com.indexdata.masterkey.config.ModuleConfigurationGetter; + +public class Pz2Config implements ModuleConfigurationGetter { + + Map properties = new HashMap(); + + public Pz2Config () { + setStatics(); + } + + public Pz2Config (String pazpar2Url, String pazpar2ServiceId) { + setStatics(); + setPazpar2Url(pazpar2Url); + setPazpar2ServiceId(pazpar2ServiceId); + } + + private void setStatics () { + properties.put("PROXY_MODE","1"); + properties.put("SERIALIZE_REQUESTS", "false"); + properties.put("STREAMBUFF_SIZE", "4096"); + properties.put("PARSE_RESPONSES", "true"); + } + + @Override + public String get(String key) { + return properties.get(key); + } + + public void set(String key, String value) { + properties.put(key, value); + } + + public void setPazpar2Url (String value) { + properties.put("PAZPAR2_URL", value); + } + + public void setPazpar2ServiceId (String value) { + properties.put("PAZPAR2_SERVICE_ID",value); + } + + @Override + public String get(String key, String defaultValue) { + if (properties.containsKey(key)) { + return properties.get(key); + } else { + return defaultValue; + } + } + + @Override + public String getMandatory(String key) throws MissingMandatoryParameterException { + if (properties.containsKey(key)) { + return properties.get(key); + } + throw new Error("Missing mandatory parameter: " + key); + } + + @Override + public String getConfigFilePath() { + return null; + } + + + +} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java new file mode 100644 index 0000000..b778821 --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java @@ -0,0 +1,7 @@ +package com.indexdata.pz2utils4jsf.config; + +import java.io.Serializable; + +public interface Pz2Configurator extends Serializable { + public Pz2Config getConfig(); +} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java new file mode 100644 index 0000000..9a225b0 --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java @@ -0,0 +1,32 @@ +package com.indexdata.pz2utils4jsf.config; + +import javax.enterprise.context.SessionScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import javax.inject.Named; +import javax.servlet.ServletContext; + +import org.apache.log4j.Logger; + +@Named("pz2configwebxml") +@SessionScoped +public class Pz2ConfigureByWebXml implements Pz2Configurator { + + private static final long serialVersionUID = 144390224959311772L; + private static Logger logger = Logger.getLogger(Pz2ConfigureByWebXml.class); + private Pz2Config config = null; + + public Pz2ConfigureByWebXml () { + logger.debug("Instantiating Pazpar2 service configuration by web.xml parameters"); + ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); + ServletContext servletContext = (ServletContext) externalContext.getContext(); + String pazpar2Url = servletContext.getInitParameter("PAZPAR2_URL"); + String pazpar2ServiceId = servletContext.getInitParameter("PAZPAR2_SERVICE_id"); + config = new Pz2Config(pazpar2Url,pazpar2ServiceId); + } + + @Override + public Pz2Config getConfig() { + return config; + } +} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index 73042fb..c139786 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -4,8 +4,10 @@ import java.io.Serializable; import java.util.List; import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; import javax.inject.Named; +import com.indexdata.pz2utils4jsf.config.Pz2ConfigureByWebXml; import com.indexdata.pz2utils4jsf.controls.ResultsPager; import com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface; import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session; @@ -23,9 +25,12 @@ public class Pz2Bean implements Pz2Interface, Serializable { private static final long serialVersionUID = 3440277287081557861L; Pz2Session pz2; - + + @Inject + private Pz2ConfigureByWebXml pz2conf; + public Pz2Bean () { - pz2 = new Pz2Session(); + pz2 = new Pz2Session(pz2conf); } /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch(java.lang.String) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index 0d8cc3f..53e542d 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -9,19 +9,9 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; -import com.indexdata.pz2utils4jsf.controls.ResultsPager; -import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter; -import com.indexdata.pz2utils4jsf.pazpar2.CommandThread; -import com.indexdata.pz2utils4jsf.pazpar2.Expression; -import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command; -import com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface; -import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session; -import com.indexdata.pz2utils4jsf.pazpar2.TargetFilter; -import com.indexdata.masterkey.pazpar2.client.Pazpar2Client; -import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration; -import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric; import com.indexdata.masterkey.pazpar2.client.exceptions.ProxyErrorException; -import com.indexdata.pz2utils4jsf.config.JsfdemoPazpar2ClientConfiguration; +import com.indexdata.pz2utils4jsf.config.Pz2Configurator; +import com.indexdata.pz2utils4jsf.controls.ResultsPager; import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget; import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData; import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseParser; @@ -40,16 +30,17 @@ public class Pz2Session implements Serializable, Pz2Interface { private QueryStates queryStates = new QueryStates(); private static final long serialVersionUID = 3947514708343320514L; - private Pazpar2ClientConfiguration cfg = null; - private Pazpar2Client client = null; + private com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration cfg = null; + private com.indexdata.masterkey.pazpar2.client.Pazpar2Client client = null; private TargetFilter targetFilter = null; private ResultsPager pager = null; - - public Pz2Session () { - logger.debug("Instantiating pz2"); + + public Pz2Session (Pz2Configurator pz2conf) { + logger.debug("Instantiating pz2"); + if (pz2conf == null) {logger.error("conf is null!!!!!!!!!!!!!!!"); } try { - cfg = new Pazpar2ClientConfiguration(new JsfdemoPazpar2ClientConfiguration().getModuleConfiguration()); - client = new Pazpar2ClientGeneric(cfg); + cfg = new com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration(pz2conf.getConfig()); + client = new com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric(cfg); resetDataObjects(); } catch (ProxyErrorException e) { e.printStackTrace();