001: /*
002: * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Kernel/Sources/es/udc/mypersonalizer/kernel/model/repository/sql/storers/DefaultPropertyStorageStrategyRegistrySingleton.java,v 1.1.1.1 2004/03/25 12:08:36 fbellas Exp $
003: * $Revision: 1.1.1.1 $
004: * $Date: 2004/03/25 12:08:36 $
005: *
006: * =============================================================================
007: *
008: * Copyright (c) 2003, The MyPersonalizer Development Group
009: * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at
010: * University Of A Coruna
011: * All rights reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions are met:
015: *
016: * - Redistributions of source code must retain the above copyright notice,
017: * this list of conditions and the following disclaimer.
018: *
019: * - Redistributions in binary form must reproduce the above copyright notice,
020: * this list of conditions and the following disclaimer in the documentation
021: * and/or other materials provided with the distribution.
022: *
023: * - Neither the name of the University Of A Coruna nor the names of its
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: */
040:
041: package es.udc.mypersonalizer.kernel.model.repository.sql.storers;
042:
043: import java.util.Map;
044: import java.util.HashMap;
045: import java.util.Iterator;
046:
047: import es.udc.mypersonalizer.kernel.config.DatabaseConfig;
048: import es.udc.mypersonalizer.kernel.config.KernelConfigManager;
049: import es.udc.mypersonalizer.kernel.log.Log;
050: import es.udc.mypersonalizer.kernel.log.LogManager;
051: import es.udc.mypersonalizer.kernel.log.LogNamingConventions;
052: import es.udc.mypersonalizer.kernel.model.metainfo.MetaService;
053: import es.udc.mypersonalizer.kernel.model.metainfo.MetaServiceRegistrySingleton;
054:
055: /**
056: * This class provides a default implementation of the
057: * <code>PropertyStorageStrategyRegistrySingleton</code> for the
058: * framework which considers a couple of strategies:
059: * <code>SerializationPropertyStorageStrategy</code> and
060: * <code>RelationalPropertyStorageStrategy</code>.
061: *
062: * @author Fernando Bellas
063: * @author Abel Muinho
064: * @see es.udc.mypersonalizer.kernel.model.repository.sql.storers.PropertyStorageStrategy
065: * @see es.udc.mypersonalizer.kernel.model.repository.sql.storers.PropertyStorageStrategyRegistrySingleton
066: * @see es.udc.mypersonalizer.kernel.model.repository.sql.storers.SerializationPropertyStorageStrategy
067: * @see es.udc.mypersonalizer.kernel.model.repository.sql.storers.RelationalPropertyStorageStrategy
068: * @since 1.0
069: */
070: public class DefaultPropertyStorageStrategyRegistrySingleton extends
071: PropertyStorageStrategyRegistrySingleton {
072:
073: /** The mypersonalizer log name. */
074: private static final String MYPERSONALIZER_LOG_NAME = LogNamingConventions.MYPERSONALIZER;
075:
076: /**
077: * A set of (<code>String, PropertyStorageStrategy</code>). The
078: * <code>String</code> represents the service identifier.
079: */
080: private Map propertyStorageStrategy = null;
081:
082: /**
083: * Creates an instance of this class
084: */
085: public DefaultPropertyStorageStrategyRegistrySingleton() {
086:
087: Log mypersonalizerLog = LogManager
088: .getLog(MYPERSONALIZER_LOG_NAME);
089:
090: try {
091: Iterator metaServicesIterator = MetaServiceRegistrySingleton
092: .getInstance().getAllMetaServices();
093: propertyStorageStrategy = new HashMap();
094:
095: DatabaseConfig config = KernelConfigManager.getConfig()
096: .getKernelModelConfig().getDatabaseConfig();
097: while (metaServicesIterator.hasNext()) {
098: MetaService metaService = (MetaService) metaServicesIterator
099: .next();
100: String serviceIdentifier = (String) metaService
101: .getServiceIdentifier();
102: String storageStrategyClassName = config
103: .getPersistenceTypesConfig(
104: metaService.getPersistenceType())
105: .getStorageStrategyClassName();
106: PropertyStorageStrategy pss = (PropertyStorageStrategy) Class
107: .forName(storageStrategyClassName)
108: .newInstance();
109: pss.setMetainfo(metaService);
110:
111: propertyStorageStrategy.put(serviceIdentifier, pss);
112: }
113: } catch (Exception exception) {
114: mypersonalizerLog
115: .write(
116: "Error initializing "
117: + "DefaultPropertyStorageStrategyRegistrySingleton.",
118: exception, this .getClass());
119: }
120: }
121:
122: public PropertyStorageStrategy getPropertyStorageStrategy(
123: String serviceIdentifier) {
124:
125: return (PropertyStorageStrategy) propertyStorageStrategy
126: .get(serviceIdentifier);
127: }
128:
129: }
|