incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 22873 - incubator/depot/trunk/update/src/java/org/apache/depot/update/config
Date Tue, 13 Jul 2004 12:42:28 GMT
Author: ajack
Date: Tue Jul 13 05:42:27 2004
New Revision: 22873

Added:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/config/UpdaterConfig.java
Removed:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/config/UpdateConfig.java
Log:
Fixing the rename.


Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/config/UpdaterConfig.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/config/UpdaterConfig.java
Tue Jul 13 05:42:27 2004
@@ -0,0 +1,96 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.depot.update.config;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.depot.common.log.Logger;
+import org.apache.depot.common.util.envsafe.ClassLoaderContext;
+import org.apache.depot.update.impl.ReferenceManager;
+import org.apache.depot.update.util.UpdateConstants;
+import org.apache.depot.update.util.text.MessageConstants;
+import org.apache.depot.update.util.text.Messages;
+import org.apache.depot.update.util.xml.XMLContext;
+import org.apache.depot.update.util.xml.XMLEntryTable;
+import org.apache.depot.update.util.xml.XMLParser;
+
+/**
+ * @author anou_mana
+ */
+public class UpdaterConfig {
+	private static boolean l_configured = false;
+
+	public static synchronized void configure(String resourceName) {
+		try {
+			XMLEntryTable xmlEntryTable = new ConfigXMLEntryTable();
+			XMLContext xmlContext = null;
+			
+			ClassLoaderContext helper = new ClassLoaderContext(xmlEntryTable);
+			
+			XMLParser parser = new XMLParser(xmlEntryTable, helper);
+			
+			File configFile = new File(resourceName);
+			if (configFile.exists()) {
+				Logger.getLogger().info(
+					Messages.getString(
+						MessageConstants.CONFIG,
+						new Object[] { "file", resourceName }));
+				xmlContext = parser.parse(configFile);
+			}
+			else {
+				InputStream resource =
+				helper.getResourceAsStream(
+						resourceName);
+				if (resource == null) {
+					resource = ClassLoader.getSystemResourceAsStream(resourceName);
+				}
+				
+				Logger.getLogger().info(
+					Messages.getString(
+						MessageConstants.CONFIG,
+						new Object[] { "resource", resourceName }));
+				xmlContext = parser.parse(resource);
+			}
+
+			if (null == xmlContext)
+				Logger.getLogger().error(
+					Messages.getString(
+						MessageConstants.UNABLE_TO_LOAD_CONFIG,
+						resourceName));
+
+		}
+		catch (Exception exp) {
+			Logger.getLogger().error(
+				Messages.getString(MessageConstants.CONFIG_PARSER_ERROR),
+				exp);
+		}
+	}
+
+	public static void configure() {
+		if (!l_configured) {
+			configure(UpdateConstants.DEFAULT_CONFIG_XML);
+			l_configured = true;
+		}
+	}
+
+	public static void main(String[] args) throws Exception {
+		Logger.testInit();
+		UpdaterConfig.configure();
+		ReferenceManager.dump();
+	}
+}

Mime
View raw message