[Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/config ConfigurationException.jav
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-03-06 04:36:52
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/config In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30624 Modified Files: ConfigurationException.java framework-config.xml FrameworkConfig.java Log Message: no message Index: framework-config.xml =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/config/framework-config.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** framework-config.xml 3 Mar 2006 04:14:11 -0000 1.2 --- framework-config.xml 6 Mar 2006 04:36:48 -0000 1.3 *************** *** 1,4 **** <framework-config> ! <job-config-factory-config config-reader-class-name="org.jmonks.batchserver.framework.config.xml.XMLJobConfigFactory"> <property key="config-file-absolute-location">/batchserver/config/batch-config.xml</property> <!-- --- 1,4 ---- <framework-config> ! <job-config-factory-config job-config-factory-class-name="org.jmonks.batchserver.framework.config.xml.XMLJobConfigFactory"> <property key="config-file-absolute-location">/batchserver/config/batch-config.xml</property> <!-- Index: FrameworkConfig.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/config/FrameworkConfig.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FrameworkConfig.java 4 Mar 2006 04:40:49 -0000 1.2 --- FrameworkConfig.java 6 Mar 2006 04:36:48 -0000 1.3 *************** *** 11,70 **** package org.jmonks.batchserver.framework.config; import java.util.Map; import org.w3c.dom.Element; /** ! * ! * @author Suresh Pragada */ public final class FrameworkConfig { ! private static final FrameworkConfig mFrameworkConfig=new FrameworkConfig(); private static final String FRAMEWORK_CONFIG_FILE = "org.jmonks.batchserver.framework.config.framework-config.xml"; ! /** Creates a new instance of FrameworkConfig */ ! private FrameworkConfig() { } public static FrameworkConfig getInstance() { ! return mFrameworkConfig; } public JobConfigFactoryConfig getJobConfigFactoryConfig() { ! return null; } public LoggingConfig getLoggingConfig() { ! return null; } ! public MgmtMntrConfig getMgmtMntrConfig() { ! return null; } ! public FrameworkConfig.RepositoryConfig getRepositoryConfig() { ! return null; } public class JobConfigFactoryConfig { private JobConfigFactoryConfig(Element jobConfigFactoryElement) { ! } ! public String getJobConfigFactoryClassName() { return null; } ! public Map getJobConfigFactoryProperties() { --- 11,273 ---- package org.jmonks.batchserver.framework.config; + import java.io.IOException; + import java.io.InputStream; + import java.util.HashMap; import java.util.Map; + import javax.xml.parsers.DocumentBuilder; + import javax.xml.parsers.DocumentBuilderFactory; + import javax.xml.parsers.ParserConfigurationException; + import org.jmonks.batchserver.framework.common.ErrorCode; + import org.jmonks.batchserver.framework.common.FrameworkUtil; + import org.w3c.dom.Document; import org.w3c.dom.Element; + import org.w3c.dom.NodeList; + import org.xml.sax.SAXException; /** ! * <p> ! * FrameworkConfig class is responsible to read the framework configuration from ! * framework-config.xml file and gives configuration in the form of ! * configuration objects when needed. Framework configuration will be defined ! * in the file framework-config.xml located in the class path org.jmonks.batchserver.framework.config. ! * </p> ! * ! * @author Suresh Pragada ! * @version 1.0 ! * @since 1.0 */ public final class FrameworkConfig { ! /** ! * FrameworkConfig singleton instance varaible. ! */ ! private static final FrameworkConfig frameworkConfig=new FrameworkConfig(); + /** + * Declaration of XML file holds the framework configuration. + */ private static final String FRAMEWORK_CONFIG_FILE = "org.jmonks.batchserver.framework.config.framework-config.xml"; ! /** ! * JobConfigFactoryConfig variable to hold the JobConfigFactoryObject object. ! */ ! private JobConfigFactoryConfig configFactoryConfig=null; ! /** ! * LoggingConfig variable to hold the LoggingConfig object. ! */ ! private LoggingConfig logginConfig=null; ! /** ! * MgmtMntrConfig variable to hold the MgmtMntrConfig object. ! */ ! private MgmtMntrConfig mgmtMntrConfig=null; ! /** ! * RepositoryConfig variable to hold the RepositoryConfig object. ! */ ! private RepositoryConfig repositoryConfig=null; ! ! /** ! * Private constructor to make sure FrameworkCongi cannot be instantiated. This will ! * read the framework configuration file and create the instances of of JobConfigFactoryConfig, ! * LoggingConfig, MgmtMntrConfig and RepositoryConfig by passing the correct DOM elements to their ! * constructors. This does the validation of configuration file against the defined XML schema file. ! * In case of errors it throws the ConfigurationException with the correct error code. ! * ! * @throws RuntimeException If framework configuration file is not properly formed and validation is failed. ! * @throws ConfigurationException If configuration file could not be found. ! */ ! private FrameworkConfig() { + try + { + InputStream configFileStream=FrameworkConfig.class.getResourceAsStream(FrameworkConfig.FRAMEWORK_CONFIG_FILE); + if(configFileStream==null) + throw new ConfigurationException(ErrorCode.FRAMEWORK_CONFIG_FILE_NOT_FOUND); + + DocumentBuilderFactory documentBuilderFactory=DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setValidating(true); + DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder(); + Document document=documentBuilder.parse(configFileStream); + Element frameworkConfigElement=document.getDocumentElement(); + + NodeList jobConfigFactoryConfigNodeList=frameworkConfigElement.getElementsByTagName(JobConfigFactoryConfig.TAG_NAME); + if(jobConfigFactoryConfigNodeList.getLength()==1) + { + this.configFactoryConfig=new JobConfigFactoryConfig(((Element)jobConfigFactoryConfigNodeList.item(0))); + } + else + { + throw new ConfigurationException(ErrorCode.NONE_OR_MULITPLE_JOB_CONFIG_FACTORY_CONFIG_TAGS); + } + + NodeList loggingConfigNodeList=frameworkConfigElement.getElementsByTagName(LoggingConfig.TAG_NAME); + if(loggingConfigNodeList.getLength()==1) + { + this.logginConfig=new LoggingConfig(((Element)loggingConfigNodeList.item(0))); + } + else + { + throw new ConfigurationException(ErrorCode.NONE_OR_MULITPLE_LOGGING_CONFIG_TAGS); + } + + NodeList mgmtMntrConfigNodeList=frameworkConfigElement.getElementsByTagName(MgmtMntrConfig.TAG_NAME); + if(mgmtMntrConfigNodeList.getLength()==1) + { + this.mgmtMntrConfig=new MgmtMntrConfig(((Element)mgmtMntrConfigNodeList.item(0))); + } + else + { + throw new ConfigurationException(ErrorCode.NONE_OR_MULITPLE_MGMT_MNTR_CONFIG_TAGS); + } + + NodeList repositoryConfigNodeList=frameworkConfigElement.getElementsByTagName(RepositoryConfig.TAG_NAME); + if(repositoryConfigNodeList.getLength()==1) + { + this.repositoryConfig=new RepositoryConfig(((Element)repositoryConfigNodeList.item(0))); + } + else + { + throw new ConfigurationException(ErrorCode.NONE_OR_MULITPLE_REPOSITORY_CONFIG_TAGS); + } + } + catch(IOException ioException) + { + ioException.printStackTrace(); + throw new RuntimeException(ioException); + } + catch(ParserConfigurationException parserConfigException) + { + parserConfigException.printStackTrace(); + throw new RuntimeException(parserConfigException); + } + catch(SAXException saxException) + { + saxException.printStackTrace(); + throw new RuntimeException(saxException); + } } + /** + * Returns the FrameworkConfig instance. + * + * @return Returns the frameworkconfig instance. + */ public static FrameworkConfig getInstance() { ! return frameworkConfig; } + /** + * Returns the job configuration factory configuration defined in framework configuration + * as JobConfigFactoryConfig object. + * + * @return Returns the JobConfigFactoryConfig object. + */ public JobConfigFactoryConfig getJobConfigFactoryConfig() { ! return this.configFactoryConfig; } + /** + * Returns the logging configuration defined in the framework configuration as a LoggingConfig object. + * + * @return Returns the LoggingConfig object. + */ public LoggingConfig getLoggingConfig() { ! return this.logginConfig; } ! /** ! * Returns the mgmt&mntr configuration defines in the framework configuration as MgmtMntrConfig object. ! * @return Returns the MgmtMntrConfig object. ! */ public MgmtMntrConfig getMgmtMntrConfig() { ! return this.mgmtMntrConfig; } ! /** ! * Returns the repository configuration defined in framework configuration as a RepositoryConfig object. ! * ! * @return Returns the RepositoryConfig object. ! */ ! public RepositoryConfig getRepositoryConfig() { ! return this.repositoryConfig; } + /** + * <p> + * JobConfigFactoryConfig class holds the configuration information required + * by Job configuration factory. Factory would need some properties like source + * of the job configuration, credentials to access the source + * based on the factory type. This object provides the factory class name + * and its supported property information. + * </p> + * <p> + * This class will be accessible to all the classes in the framework and can be created + * only by the FrameworkConfig class. + * </p> + * <p> + * Holds the following configuration defined in the framework configuration file. + * <br><br> + * <pre> + * <job-config-factory-config job-config-factory-class-name="org.jmonks.batchserver.framework.config.xml.XMLJobConfigFactory"> + * <property key="config-file-absolute-location">/batchserver/config/batch-config.xml</property> + * <!-- + * Following is the another way to configure the XML Job configuration. + * <property key="config-file-classpath-location">org.jmonks.batchserver.framework.config.batch-config.xml</property> + * --> + * </job-config-factory-config> + * </pre> + * </p> + */ public class JobConfigFactoryConfig { + /** + * Tag name represents the job config factory config in framework configuration file. + */ + private static final String TAG_NAME = "job-config-factory-config"; + /** + * Attribute name represents the job config factory class name. + */ + private static final String FACTORY_CLASS_ATTRIBUTE_NAME = "job-config-factory-class-name"; + + /** + * Job config factory class name. + */ + private String factoryClassName=null; + + private Map jobConfigFactoryProperties=new HashMap(); + + /** + * This constructor will read the job configuration factory information from + * the given DOM element which represents the tag <job-config-factory-config>. + * Private constructor to make sure, it cannot be instantiated from outside of FrameworkConfig class. + * + * @param jobConfigFactoryElement DOM Element represents <job-config-factory-config> tag in framework configuration file. + */ private JobConfigFactoryConfig(Element jobConfigFactoryElement) { ! this.factoryClassName=jobConfigFactoryElement.getAttribute(JobConfigFactoryConfig.FACTORY_CLASS_ATTRIBUTE_NAME); ! if(this.factoryClassName==null) ! throw new ConfigurationException(ErrorCode.JOB_CONFIG_FACTORY_CLASS_NAME_ATTRIB_NOT_FOUND); ! ! FrameworkUtil.loadPropertiesFromElementToMap(jobConfigFactoryElement,jobConfigFactoryProperties); } ! ! /** ! * Returns the class name of the factory used to read the job configuration. ! * @return Returns the factory class name. ! */ public String getJobConfigFactoryClassName() { return null; } ! ! /** ! * Returns the properties map used by the factory class to read the job configuration. ! * @returns Returns properties in a map. In case if there are no properties, it returns empty map. It doesnt return null. ! */ public Map getJobConfigFactoryProperties() { *************** *** 73,93 **** } public class LoggingConfig { private LoggingConfig(Element loggingConfigElement) { - } public String getLoggingDirecotry() { return null; } ! ! public int getFrameworkLogLevel() { ! return 1; } public String getBasePackageName() { --- 276,343 ---- } + /** + * <p> + * LoggingConfig class holds configuration required to enable the framework logging + * by LoggingManager. This configuration would be like the directory needs to write + * job log files and logging level and base package name to be used to create the + * logging handlers. This class can be accessed by all the classes in the framework + * but cannot be instantiated outside of this class. + * </p> + * <p> + * This class represents the following information for the framework configration file + * <br><br> + * <pre> + * <logging-config> + * <logging-directory>/batchserver/logs</logging-directory> + * <logging-level>DEBUG</logging-level> + * <job-base-package-name>com.mycompany.batch</job-base-package-name> + * </logging-config> + * </pre> + * </p> + */ public class LoggingConfig { + /** + * Tag name represents the logging config in framework configuration file. + */ + private static final String TAG_NAME = "logging-config"; + + /** + * This constructor will read the logging configuration from + * the given DOM element which represents the tag <logging-config>. + * Private constructor to make sure, it cannot be instantiated from outside of FrameworkConfig class. + * + * @param loggingConfigElement DOM Element represents <logging-config> tag in framework configuration file. + */ private LoggingConfig(Element loggingConfigElement) { } + /** + * Returns the logging directory name, where to all the job logs needs to be written. + * + * @return Returns the logging directory name. + */ public String getLoggingDirecotry() { return null; } ! ! /** ! * Returns the log level to use for the logging. ! * ! * @return Returns the log level. ! */ ! public String getFrameworkLogLevel() { ! return null; } + /** + * Returns the base package name to be used for the logging. This base package is job + * base package like com.mycompany.batch + * + * @return Returns the jobs base package name. + */ public String getBasePackageName() { *************** *** 96,111 **** } public class MgmtMntrConfig { private MgmtMntrConfig(Element mgmtMntrConfigElement) { } ! public String getMgmtMntrClassName() { return null; } ! public Map getMgmtMntrProperties() { --- 346,398 ---- } + /** + * <p> + * MgmtMntrConfig class holds the configuration required to create the MgmtMntrManager for this + * framework. This configuration defines the specialized manager name and properties required + * by that manager. This class cannot be instantiated by any other classes outside this framework. + * </p> + * <p> + * This class holds the following configuration from the framework configuration file. + * <br><br> + * <pre> + * <mgmt-mntr-config mgmt-mntr-class-name="org.jmonks.batchserver.framework.mgmtmntr.DefaultMgmtMntrManager"> + * <property key="port-range">15000-20000</property> + * </mgmt-mntr-config> + * </pre> + * </p> + */ public class MgmtMntrConfig { + /** + * Tag name represents the mgmt mntr config in framework configuration file. + */ + private static final String TAG_NAME = "mgmt-mntr-config"; + + /** + * This constructor loads the MgmtMntrConfig object with the given + * DOM Element represents the <mgmt-mntr-config> in the framework configuration file. + * + * @param mgmtMntrConfigElement DOM Element represents the <mgmt-mntr-config> tag in framework configuration file. + */ private MgmtMntrConfig(Element mgmtMntrConfigElement) { } ! ! /** ! * Returns the defined MgmtMntrManager class name for the framework. ! * ! * @return Returns the MgmtMntrManager class name. ! */ public String getMgmtMntrClassName() { return null; } ! ! /** ! * Returns the map consist of the properties needed by the defined manager. ! * ! * @return Returns the properties in a map. ! */ public Map getMgmtMntrProperties() { *************** *** 114,123 **** } public class RepositoryConfig { private RepositoryConfig(Element repositoryConfigElement) { } ! public String getRepositoryClassName() { --- 401,446 ---- } + + /** + * <p> + * RepositoryConfig class holds the configuration required to create the class + * provides the interface to the framework repository and properties needed + * to work with the repository. + * </p> + * <p> + * This class represents the following configuration from framework configuration file. + * <br><br> + * <pre> + * <repository-config repository-class-name="org.jmonks.batchserver.framework.DefaultRepository"> + * <property key="repository-location">/batchserver/repository</property> + * <property key="repository-filename">batchserver_repository.db</property> + * </repository-config> + * </pre> + * </p> + */ public class RepositoryConfig { + /** + * Tag name represents the repository config in framework configuration file. + */ + private static final String TAG_NAME = "repository-config"; + + /** + * This constructor would read the configuration from the given DOM Element represents + * the <repository-config> tag and creates + * the object with that information. Private constructor to make sure, this class cannot + * be instantiated from outside of this class. + * + * @param repositoryConfigElement DOM Element repsents the <repository-config> tag in framework configuration. + */ private RepositoryConfig(Element repositoryConfigElement) { } ! ! /** ! * Returns the repository class name responsible to work with the repository. ! * ! * @return Returns the repository class name. ! **/ public String getRepositoryClassName() { *************** *** 125,128 **** --- 448,456 ---- } + /** + * Returns all the properties required by the repository class to interact with the repsoitory in a map. + * + * @return Returns the properties required by repository class in a map. + */ public Map getRepositoryConfigProperties() { Index: ConfigurationException.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/config/ConfigurationException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ConfigurationException.java 4 Mar 2006 04:40:49 -0000 1.2 --- ConfigurationException.java 6 Mar 2006 04:36:48 -0000 1.3 *************** *** 3,19 **** /** ! * @author Suresh Pragada ! * */ ! public class ConfigurationException extends Exception { ! private ErrorCode errorCode=null; /** ! * Constructs an instance of <code>ConfigurationException</code> with the specified detail message. ! * @param msg the detail message. ! * */ ! public ConfigurationException(org.jmonks.batchserver.framework.common.ErrorCode errorCode) { super(errorCode.getMessage()); --- 3,28 ---- /** ! * <p> ! * Exception defines problems in either framework configuration or ! * job configuration. This is the runtime exception because problem ! * cannot be detected until the runtime. This represents the errorCode ! * cause of the exception. ! * </p> ! * ! * @author Suresh Pragada ! * @version 1.0 ! * @since 1.0 */ ! public class ConfigurationException extends RuntimeException { ! /** ! * Error code represents the cause of this exception. ! */ private ErrorCode errorCode=null; /** ! * Constructs an instance of <code>ConfigurationException</code> with the specified error code. ! * @param errorCode Error code represents the cause of the exception. */ ! public ConfigurationException(ErrorCode errorCode) { super(errorCode.getMessage()); *************** *** 21,29 **** } ! public org.jmonks.batchserver.framework.common.ErrorCode getErrorCode() ! { return this.errorCode; } } --- 30,57 ---- } ! /** ! * Returns the error code represents the cause of this exception. ! * ! * @return Returns the error code. ! */ ! public ErrorCode getErrorCode() { return this.errorCode; } + /** + * <p> + * Returns the string representation of ConfigurationException class in the format + * <br> {ConfigurationException [errorCode = value]} + * </p> + * + * @return Returns the string representation of ConfigurationException. + */ + public String toString() + { + StringBuffer stringValue=new StringBuffer("{ConfigurationException "); + stringValue.append("[code = " + this.errorCode.toString() + "]"); + stringValue.append("}"); + return stringValue.toString(); + } } |