001: /*
002: * $Id: BaseTableOrganizationContext.java,v 1.3 2005/06/18 01:03:45 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2004 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040: package org.axiondb.engine.tables;
041:
042: import java.util.Collections;
043: import java.util.Enumeration;
044: import java.util.HashSet;
045: import java.util.Iterator;
046: import java.util.Properties;
047: import java.util.Set;
048:
049: import org.axiondb.AxionException;
050: import org.axiondb.ExternalTable;
051: import org.axiondb.TableOrganizationContext;
052:
053: /**
054: * Table Organization Context.
055: *
056: * @author Jonathan Giron
057: * @author Ahimanikya Satapathy
058: * @version $Revision: 1.3 $ $Date: 2005/06/18 01:03:45 $
059: */
060: public abstract class BaseTableOrganizationContext implements
061: TableOrganizationContext {
062:
063: private Set PROPERTY_KEYS = new HashSet(2);
064:
065: public BaseTableOrganizationContext() {
066: // Build set of recognized property keys for external tables.
067: PROPERTY_KEYS.add(ExternalTable.PROP_LOADTYPE);
068: PROPERTY_KEYS.add(ExternalTable.COLUMNS_ARE_CASE_SENSITIVE);
069: }
070:
071: public Properties getTableProperties() {
072: return _props;
073: }
074:
075: public abstract Set getPropertyKeys();
076:
077: public abstract Set getRequiredPropertyKeys();
078:
079: public abstract void readOrSetDefaultProperties(Properties props)
080: throws AxionException;
081:
082: public void updateProperties() {
083: _props.clear();
084: }
085:
086: public void setProperty(String key, String value) {
087: if (value == null) {
088: value = "";
089: }
090: _props.setProperty(key, value);
091: }
092:
093: public Set getBasePropertyKeys() {
094: return Collections.unmodifiableSet(PROPERTY_KEYS);
095: }
096:
097: public Set getBaseRequiredPropertyKeys() {
098: return Collections.EMPTY_SET;
099: }
100:
101: public void assertValidPropertyKeys(Properties props)
102: throws AxionException {
103: Enumeration keys = props.keys();
104: Set validKeys = getPropertyKeys();
105: while (keys.hasMoreElements()) {
106: String key = (String) keys.nextElement();
107: if (!validKeys.contains(key)) {
108: throw new AxionException("Property '" + key
109: + "' not recognized for this table type.");
110: }
111: }
112:
113: Set requiredKeys = new HashSet(getRequiredPropertyKeys());
114: if (!(props.keySet().containsAll(requiredKeys))) {
115: requiredKeys.removeAll(props.keySet());
116:
117: StringBuffer errMsgBuf = new StringBuffer(
118: "Missing required properties in organization clause: ");
119: Iterator iter = requiredKeys.iterator();
120: int k = 0;
121: while (iter.hasNext()) {
122: if (k++ != 0) {
123: errMsgBuf.append(", ");
124: }
125: errMsgBuf.append(iter.next());
126: }
127:
128: throw new AxionException(errMsgBuf.toString());
129: }
130: }
131:
132: protected Properties _props = new Properties();
133: }
|