- From: Thomas Gambet via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 12 Aug 2009 13:15:20 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2006/unicorn/src/org/w3c/unicorn In directory hutz:/tmp/cvs-serv22119/src/org/w3c/unicorn Modified Files: Tag: dev2 UnicornCall.java Framework.java Removed Files: Tag: dev2 Init.java Controller.java Log Message: All initialization actions moved to Framework.java Index: Framework.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/Attic/Framework.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- Framework.java 11 Aug 2009 16:05:38 -0000 1.1.2.1 +++ Framework.java 12 Aug 2009 13:15:18 -0000 1.1.2.2 @@ -7,23 +7,27 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.Map.Entry; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import javax.xml.namespace.NamespaceContext; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; import org.w3c.unicorn.contract.Observer; import org.w3c.unicorn.contract.WADLUnmarshaller; import org.w3c.unicorn.contract.WADLUnmarshallerXPath; +import org.w3c.unicorn.output.OutputFactory; import org.w3c.unicorn.response.parser.ResponseParser; import org.w3c.unicorn.tasklist.RDFUnmarshaller; import org.w3c.unicorn.tasklist.RDFUnmarshallerJena; @@ -33,6 +37,8 @@ import org.w3c.unicorn.util.ListFiles; import org.w3c.unicorn.util.LocalizedString; import org.w3c.unicorn.util.Property; +import org.w3c.unicorn.util.TemplateHelper; +import org.w3c.unicorn.util.UCNProperties; /** * Main class of the central module of UniCORN. @@ -42,12 +48,6 @@ public class Framework { /** - * Instance of log class to, as his name say, log any information during - * execution. - */ - public static final Log logger = LogFactory.getLog(Framework.class); - - /** * Data structure for the Observers */ public static Map<String, Observer> mapOfObserver = null; @@ -71,24 +71,180 @@ * Data structure for the various response parser */ public static Map<String, ResponseParser> mapOfReponseParser = null; + /** - * Load the list of extensions + * Log4j Logger */ - public static void init() { - /*try { - /*URL aURLPropFile = Property - .getPropertyFileURL("extensions.properties"); - - final Properties aProperties = new Properties(); - aProperties.load(aURLPropFile.openStream());*/ - - Framework.aPropertiesExtension = Property.getProps("extensions.properties"); + public static Logger logger; + + /** + * URI to unicorn home + */ + public static URI unicornHome; + + /** + * True if initialization did not throw any exception + */ + public static boolean isUcnInitialized = false; + + /** + * Initialize Unicorn + * @throws Exception + */ + public static void init() throws Exception { + // Checks that unicorn.home (JVM parameter) is set to an existing directory + String ucnHome = System.getProperty("unicorn.home"); + System.err.println(ucnHome); + File ucnHomeFile = new File(ucnHome); + if (ucnHome == null) { + String error = "ERROR: \"unicorn.home\" is not set in the JVM parameters. Please read the README file before trying to install Unicorn"; + System.err.println(error); + throw new Exception(error); + } else if (!ucnHomeFile.exists() && ucnHomeFile.isDirectory()) { + String error = "ERROR: \"unicorn.home\" is not an existing directory: " + System.getProperty("unicorn.home"); + System.err.println(error); + throw new Exception(error); + } else { + unicornHome = ucnHomeFile.toURI(); + System.out.println("OK - \"unicorn.home\" was found: " + unicornHome.getPath()); + } + + // Log4j initialization attempt + String log4jPath = unicornHome.getPath() + "/WEB-INF/conf/log4j.properties"; + File log4jPropFile = new File(log4jPath); + if (!log4jPropFile.exists()) { + String error = "WARN: \"log4j.properties\" could not be found: " + log4jPath; + System.err.println(error); + System.err.println("WARN: Log4j will not be initialized."); + } else { + System.out.println("OK - Log4j initialized with file: " + log4jPath); + PropertyConfigurator.configure(log4jPropFile.toURI().toURL()); + logger = Logger.getLogger("Framework"); + logger.info("Unicorn home directory was found"); + logger.debug("Unicorn home path = " + unicornHome.getPath()); + logger.info("Log4j has been successfully initialized"); + logger.debug("Log4j properties file = " + log4jPropFile.toURI().getPath()); + } + + // Loading unicorn.properties + logger.debug("Loading unicorn.properties"); + String unicornPath = unicornHome.getPath() + "/WEB-INF/conf/unicorn.properties"; + logger.debug("Unicorn properties file = " + unicornPath); + File unicornPropFile = new File(unicornPath); + if (!unicornPropFile.exists()) { + String error = "ERROR: \"unicorn.properties\" could not be found: " + unicornPath; + System.err.println(error); + logger.error("Unicorn properties file does not exists! Path is: " + unicornPath); + throw new Exception(error); + } else { + UCNProperties ucnProperties = new UCNProperties(); + ucnProperties.put("UNICORN_HOME", unicornHome.getPath()); + ucnProperties.load(unicornPropFile.toURI().toURL().openStream()); + Property.getUnicornPropertiesFiles().put("unicorn.properties", ucnProperties); + //Property.setUnicornProps(ucnProperties); + logger.info("Unicorn properties file successfully loaded"); + logger.debug("Loaded properties: " + ucnProperties); + } + + // Checking Unicorn properties + String[] mandatoryProperties = {"PATH_TO_CONF_FILES","ROUTE_XML","PATH_TO_CACHE"}; + for (String property: mandatoryProperties) { + if (Property.get(property) == null) { + String error = "\""+ property +"\" is not defined in unicorn.properties. This property is mandatory."; + logger.error(error); + throw new Exception(error); + } + } + + // Loading config files + String[] propertyFiles = {"extensions.properties", "responseParsers.properties", "specialFormaters.properties", "velocity.properties"}; + for (String fileName : propertyFiles) { + logger.debug("Loading " + fileName); + String path = Property.get("PATH_TO_CONF_FILES") + fileName; + logger.debug(fileName + " path = " + path); + File file = new File(path); + if (!file.exists()) { + String error = "ERROR: \"" + fileName + "\" could not be found: " + path; + System.err.println(error); + logger.error(fileName + " file does not exists! Path is: " + path); + throw new Exception(error); + } else { + Properties properties = new Properties(); + properties.load(file.toURI().toURL().openStream()); + Property.getUnicornPropertiesFiles().put(fileName, properties); + logger.info(fileName + " file successfully loaded"); + logger.debug("Loaded properties: " + properties); + } + } + + TemplateHelper.init(); + + // Initialize WADLUnmarshallerXPath (Gets the Namespace URI and the prefix) + WADLUnmarshallerXPath.setNamespaceContext(new NamespaceContext() { + public String getNamespaceURI(final String sPrefix) { + if ("xs".equals(sPrefix)) { + return "http://www.w3.org/2001/XMLSchema"; + } else if ("uco".equals(sPrefix)) { + return "http://www.w3.org/unicorn/observationresponse"; + } else { + return null; + } + } + public String getPrefix(final String sNamespaceURI) { + if ("http://www.w3.org/2001/XMLSchema".equals(sNamespaceURI)) { + return "xs"; + } else if ("http://www.w3.org/unicorn/observationresponse" + .equals(sNamespaceURI)) { + return "uco"; + } else { + return null; + } + } + public Iterator<String> getPrefixes(final String sNamespaceURI) { + return null; + } + }); + + + // Initialize RDFUnmarshallerJena + FileInputStream fis = new FileInputStream(org.w3c.unicorn.util.Property + .get("TASKLIST_RDF_MODEL")); + RDFUnmarshallerJena.getModel().read(fis, null); + // define resource use to find information into the RDF graph + RDFUnmarshallerJena.setRESOURCE_TASK(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "Task")); + // define property use to find information into the RDF graph + RDFUnmarshallerJena.setPROPERTY_DESCRIPTION(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "description")); + RDFUnmarshallerJena.setPROPERTY_HASMAPPING(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "hasMapping")); + RDFUnmarshallerJena.setPROPERTY_HASPARAMETER(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "hasParameter")); + RDFUnmarshallerJena.setPROPERTY_HASVALUE(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "hasValue")); + RDFUnmarshallerJena.setPROPERTY_LONGNAME(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "longName")); + RDFUnmarshallerJena.setPROPERTY_OBSERVER(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "observer")); + RDFUnmarshallerJena.setPROPERTY_PARAMETER(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "parameter")); + RDFUnmarshallerJena.setPROPERTY_REFERENCE(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "reference")); + RDFUnmarshallerJena.setPROPERTY_TYPE(RDFUnmarshallerJena.getModel() + .getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")); + RDFUnmarshallerJena.setPROPERTY_VALUE(RDFUnmarshallerJena.getModel() + .getProperty(RDFUnmarshallerJena.getUcnNamespace() + "value")); + + // Initialize OutputFactory + OutputFactory.setPropertiesSpecialFormaters(Property.getProps("specialFormaters.properties")); + + //WADLUnmarshallerXPath.init(); + //RDFUnmarshallerJena.init(); + //Framework.init(); + //OutputFactory.init(); + //IndexGenerator.init(); - //Framework.aPropertiesExtension = aProperties; - /*} catch (final IOException e) { - Framework.logger.error("IOException : " + e.getMessage(), e); - e.printStackTrace(); - }*/ + Framework.aPropertiesExtension = Property.getProps("extensions.properties"); //Load the map of ResponseParser @@ -99,12 +255,7 @@ // Retrieve the properties of the response parsers in the resources mapOfReponseParser = new LinkedHashMap<String, ResponseParser>(); - //URL aURLPropFile = Property - // .getPropertyFileURL("responseParsers.properties"); - - //final Properties aProperties = new Properties(); Properties aProperties = Property.getProps("responseParsers.properties"); - //aProperties.load(aURLPropFile.openStream()); for (Entry<Object, Object> e : aProperties.entrySet()) { ResponseParser aResponseParser = (ResponseParser) (Class @@ -119,8 +270,7 @@ } } - // Static operations to initialize framework the first time this class is used. - + // Static operations to initialize framework the first time this class is used. if (Framework.logger.isDebugEnabled()) { Framework.logger.debug("Loading available observers..."); } @@ -145,8 +295,7 @@ } // Get URL of the contract. If the name of wadl file is not - // defined, - // the contract's name will be observer.wadl + // defined, the contract's name will be observer.wadl final String sWADL; if (sReadLine.matches(".*\\.wadl$")) { sWADL = sReadLine; @@ -253,5 +402,6 @@ } Framework.logger.info("End of initialisation of UniCORN."); + isUcnInitialized = true; } } --- Controller.java DELETED --- --- Init.java DELETED --- Index: UnicornCall.java =================================================================== RCS file: /sources/public/2006/unicorn/src/org/w3c/unicorn/Attic/UnicornCall.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- UnicornCall.java 11 Aug 2009 16:05:38 -0000 1.1.2.1 +++ UnicornCall.java 12 Aug 2009 13:15:18 -0000 1.1.2.2 @@ -15,7 +15,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import javax.activation.MimeType; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -23,9 +22,8 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; - import org.apache.commons.fileupload.FileItem; -import org.apache.commons.logging.Log; +import org.apache.log4j.Logger; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.w3c.dom.Document; @@ -52,7 +50,6 @@ import org.w3c.unicorn.tasklisttree.TLTNode; import org.w3c.unicorn.util.Property; import org.w3c.unicorn.util.TemplateHelper; - import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl; /** @@ -65,7 +62,7 @@ /** * Log Object to perform powerful logs */ - private static final Log logger = Framework.logger; + private static final Logger logger = Framework.logger; // Request /** @@ -799,7 +796,7 @@ /** * Used for complex logging purpose */ - private static final Log logger = Framework.logger; + private static final Logger logger = Framework.logger; /** * Data Structure for the responses
Received on Wednesday, 12 August 2009 13:16:01 UTC