From: Julien V. <coo...@us...> - 2003-05-18 16:53:47
|
User: cooperfbi Date: 03/05/18 09:53:46 Modified: nukes/src/main/org/jboss/nukes/core/modules/core CoreModule.java Log: sync nukes-website with CoreModule variable config changes Revision Changes Path 1.26 +48 -54 nukes/nukes/src/main/org/jboss/nukes/core/modules/core/CoreModule.java Index: CoreModule.java =================================================================== RCS file: /cvsroot/jboss/nukes/nukes/src/main/org/jboss/nukes/core/modules/core/CoreModule.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- CoreModule.java 16 May 2003 22:35:15 -0000 1.25 +++ CoreModule.java 18 May 2003 16:53:46 -0000 1.26 @@ -67,6 +67,7 @@ import java.lang.reflect.Constructor; import java.lang.Class; import java.lang.StringBuffer; +import java.beans.PropertyEditor; /** * The module at the core of the Nuke's application. This module @@ -76,6 +77,9 @@ * * <PRE> * $Log: CoreModule.java,v $ + * Revision 1.26 2003/05/18 16:53:46 cooperfbi + * sync nukes-website with CoreModule variable config changes + * * Revision 1.25 2003/05/16 22:35:15 yanikc * Configuration elements like site name, slogan, default theme etc. are not * hard coded anymore. the buildConfigVars() method does the job to fill @@ -86,7 +90,7 @@ * * @author <a href="mailto:jul...@ya...">Julien Viet</a> * @author <a href="mailto:ya...@ex...">Yanik Crepeau</a> - * @version $Revision: 1.25 $ + * @version $Revision: 1.26 $ * */ public class CoreModule @@ -98,15 +102,10 @@ public static final int PERMANENT_USER_MAX_INACTIVE = 60 * 60 * 24 * 5 * 1000; //5 days in ms public static final int TRANSIENT_USER_MAX_INACTIVE = 60 * 60 * 3; //3 hours in minutes - - - public CoreModule() { super("core"); - locales.add(Locale.US); - } public Object getConfigVar(String name) @@ -465,15 +464,8 @@ public void start() throws Exception { super.start(); - try - { - timer.scheduleAtFixedRate(task, 0, 10000L); - userHome = (UserEJBLocalHome) new InitialContext().lookup(UserEJBLocalHome.JNDI_NAME); - } - catch (NamingException e) - { - log.error("Cannot get EJBLocalHome", e); - } + timer.scheduleAtFixedRate(task, 0, 10000L); + userHome = (UserEJBLocalHome) new InitialContext().lookup(UserEJBLocalHome.JNDI_NAME); } public void stop() @@ -490,7 +482,6 @@ super.destroy(); } - public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { @@ -693,10 +684,6 @@ // security - /** - * @jmx.managed-attribute - * access="read-only" - */ public List getGroupPermissions() { return groupPermissions; @@ -1045,10 +1032,8 @@ setConfigVar(Constants.CFG_DEFAULT_FILE_UPLOAD_SIZE_MAX, getIntegerInitParameter(Constants.CFG_DEFAULT_FILE_UPLOAD_SIZE_MAX, 1024 * 1024 * 8)); setConfigVar(Constants.CFG_DEFAULT_USER_PAGE, getStringInitParameter(Constants.CFG_DEFAULT_USER_PAGE,"index.html?module=user&op=main")); setConfigVar(Constants.CFG_BANNERS, getBooleanInitParameter(Constants.CFG_BANNERS, true)); - setConfigVar(Constants.CFG_ALLOWABLE_HTML, getAllowableHtml()); setConfigVar(Constants.CFG_FOOT1, getFoot1()); - addKeyHandler("config", new KeyHandler() { public String forKey(String key) @@ -1141,13 +1126,8 @@ */ private Object getInitParameter(String paramName, Object defaultValue) { - Element cfg = getConfiguration(); - String prefix = "/server/mbean[@name=\"nukes.modules:name=core\"]" + - "/attribute[@name=\"Configuration\"]" + - "/module/coreModule-attributes/attribute[@name='"+ paramName + "']/"; - - - if (cfg == null) + Element cfg = getConfiguration(); + if (cfg == null) { log.warn("getConfiguration() unable to return the configuration DOM Element"); return defaultValue; @@ -1155,37 +1135,48 @@ try { - Node nt = XPathAPI.selectSingleNode(cfg,prefix + "@type"); - Node nv = XPathAPI.selectSingleNode(cfg,prefix + "@value"); - - if (nt == null) { + Node variableNode = XPathAPI.selectSingleNode(cfg, "./variable[@name='"+ paramName + "']"); + + Node nt = variableNode.getAttributes().getNamedItem("type"); + if (nt == null) + { log.warn("Unable to get the type of the" + paramName + " attribute"); return defaultValue; } - if (nt == null) { + Node nv = variableNode.getAttributes().getNamedItem("value"); + if (nv == null) + { log.warn("Unable to get the value of the" + paramName + " attribute"); return defaultValue; - } - - Class elementClass = Class.forName(nt.getNodeValue()); - Class [] argClass = { String.class }; - Constructor elementConstructor = elementClass.getConstructor(argClass); - Object [] args = { nv.getNodeValue() }; - Object ret = elementConstructor.newInstance(args); - - //Uncomment the next 2 lines for debug. - //String ww = " "; - //log.info(("Read: " + paramName + ww).substring(0,20) + (nt.getNodeValue() + ww).substring(0,20) + (nv.getNodeValue() + ww).substring(0,20)); - - return ret; - - } catch (Exception ex) { - log.warn("getInitParameter EXCEPTION for " + paramName, ex); + } + + // get a property editor + PropertyEditor editor = (PropertyEditor) server.invoke( + new ObjectName("jboss:name=PropertyEditorManager,type=Service"), + "findEditor", + new Object[] { nt.getNodeValue() }, + new String[] { String.class.getName() }); + + if (editor == null) + { + log.warn("Unable to get the value of the" + paramName + " attribute"); + return defaultValue; + } + + String ww = " "; + log.debug(("Read: " + paramName + ww).substring(0,20) + (nt.getNodeValue() + ww).substring(0,20) + (nv.getNodeValue() + ww).substring(0,20)); + + editor.setAsText(nv.getNodeValue()); + return editor.getValue(); + } + catch (Exception ex) + { + log.error("getInitParameter EXCEPTION for " + paramName, ex); + log.debug("getInitParameter " + paramName + " NOT FOUND in jboss-service.xml file"); + log.debug("defaultValue: " + defaultValue.toString() + " will be used"); + return defaultValue; } - log.warn("getInitParameter " + paramName + " NOT FOUND in jboss-service.xml file"); - log.warn("defaultValue: " + defaultValue.toString() + " will be used"); - return defaultValue; } /** |