krysalis-update/src/java/org/krysalis/depot/update/config UpdaterConfig.java,NONE,1.1 ConfigXMLEntryTable.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:19 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/config
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/config
Added Files:
UpdaterConfig.java ConfigXMLEntryTable.java
Log Message:
Copied from the apache incubator.
--- NEW FILE: ConfigXMLEntryTable.java ---
/*
* 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.krysalis.depot.update.config;
import org.krysalis.depot.update.repository.DefaultRepository;
import org.krysalis.depot.update.repository.RepositoryAttribute;
import org.krysalis.depot.update.repository.RepositorySet;
import org.krysalis.depot.update.util.net.VirtualResourceLocator;
import org.krysalis.depot.update.util.xml.XMLEntryTable;
import org.krysalis.depot.update.util.xml.XMLGrouperElement;
import org.krysalis.depot.update.util.xml.XMLTagConstants;
/**
* Concrete Implementation of an XMLEntryTable, provides some default classes for the configuration:
* <br/>
* <table>
* <tr>
* <th>Tag</th>
* <th>Class</th>
* </tr>
* <tr>
* <td>config</td>
* <td>{@link org.krysalis.depot.update.util.xml.XMLGrouperElement }</td>
* </tr>
* <tr>
* <td>repositoryset</td>
* <td>{@link org.krysalis.depot.update.repository.RepositorySet }</td>
* </tr>
* <tr>
* <td>repository</td>
* <td>{@link org.krysalis.depot.update.repository.DefaultRepository }</td>
* </tr>
* <tr>
* <td>repository.url</td>
* <td>{@link org.krysalis.depot.update.util.net.VirtualResourceLocator }</td>
* </tr>
* <tr>
* <td>repository.active</td>
* <td>{@link org.krysalis.depot.update.repository.RepositoryAttribute }</td>
* </tr>
* <tr>
* <td>repository.remote</td>
* <td>{@link org.krysalis.depot.update.repository.RepositoryAttribute }</td>
* </tr>
* </table>
* <br/>
* Every class used here must provide the methods for the provided attributes.
*
* @author <a href="http://incubator.apache.org/depot">The Apache Incubator Depot Project</a>
*/
public class ConfigXMLEntryTable extends XMLEntryTable {
/**
*
*/
public ConfigXMLEntryTable() {
super();
m_entryToClassMap.put(
XMLTagConstants.CONFIG_TAG,
XMLGrouperElement.XML_GROUPER_ELEMENT_CLASSNAME);
// Repository Set
m_entryToClassMap.put(
XMLTagConstants.REPOSITORYSET_TAG,
RepositorySet.REPOSITORYSET_CLASSNAME);
// Repository
m_entryToClassMap.put(
XMLTagConstants.REPOSITORY_TAG,
DefaultRepository.DEFAULT_REPOSITORY_CLASSNAME);
m_entryToClassMap.put(
XMLTagConstants.REPOSITORY_URL_TAG,
VirtualResourceLocator.VRL_CLASSNAME);
m_entryToClassMap.put(
XMLTagConstants.REPOSITORY_ACTIVE_TAG,
RepositoryAttribute.REPOSITORY_ATTRIBUTE_CLASSNAME);
m_entryToClassMap.put(
XMLTagConstants.REPOSITORY_REMOTE_TAG,
RepositoryAttribute.REPOSITORY_ATTRIBUTE_CLASSNAME);
}
}
--- NEW FILE: UpdaterConfig.java ---
/*
* 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.krysalis.depot.update.config;
import java.io.File;
import java.io.InputStream;
import org.krysalis.depot.common.log.Logger;
import org.krysalis.depot.common.util.envsafe.ClassLoaderContext;
import org.krysalis.depot.update.impl.ReferenceManager;
import org.krysalis.depot.update.util.UpdateConstants;
import org.krysalis.depot.update.util.text.MessageConstants;
import org.krysalis.depot.update.util.text.Messages;
import org.krysalis.depot.update.util.xml.XMLContext;
import org.krysalis.depot.update.util.xml.XMLEntryTable;
import org.krysalis.depot.update.util.xml.XMLParser;
/**
* Provides the configuration of the depot-updater application. Basically reads the configuration
* xml-file and populates the ReferenceManager's tables w/ configured objects.
*
* @author <a href="http://incubator.apache.org/depot">The Apache Incubator Depot Project</a>
*/
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();
}
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/