001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.framework;
011:
012: import org.mmbase.datatypes.*;
013: import org.mmbase.datatypes.util.xml.DataTypeReader;
014: import org.mmbase.datatypes.util.xml.DependencyException;
015: import org.mmbase.util.LocalizedString;
016: import org.w3c.dom.Element;
017:
018: import org.mmbase.util.logging.Logger;
019: import org.mmbase.util.logging.Logging;
020:
021: /**
022: * Representation of component related settings. These settings can be defined in the component
023: * XML.
024: *
025: * @todo The <em>values</em> of the settings can still only be set in memory and in the component
026: * xml. There must be some way to persistify them. There should also be a editor in the admin pages.
027: *
028: *
029: * @author Michiel Meeuwissen
030: * @version $Id: Setting.java,v 1.6 2008/01/28 16:28:22 michiel Exp $
031: * @since MMBase-1.9
032: */
033: public class Setting<C> {
034:
035: private static final Logger log = Logging
036: .getLoggerInstance(Setting.class);
037: protected final DataTypeCollector dataTypeCollector = new DataTypeCollector(
038: new Object());
039:
040: private final String name;
041: private final LocalizedString description;
042: private final Component parent;
043: private final DataType<C> dataType;
044:
045: public Setting(Component component, Element element) {
046: name = element.getAttribute("name");
047: description = new LocalizedString(name);
048: description.fillFromXml("description", element);
049: parent = component;
050: Element dataTypeElement = (Element) element
051: .getElementsByTagName("datatype").item(0);
052: BasicDataType base = dataTypeCollector.getDataType(
053: dataTypeElement.getAttribute("base"), true);
054: BasicDataType dt;
055: try {
056: dt = DataTypeReader.readDataType(dataTypeElement, base,
057: dataTypeCollector).dataType;
058: } catch (DependencyException de) {
059: dt = de.fallback();
060: }
061: dataType = dt;
062: }
063:
064: /**
065: */
066: public String getName() {
067: return name;
068: }
069:
070: public LocalizedString getDescription() {
071: return description;
072: }
073:
074: public Component getComponent() {
075: return parent;
076: }
077:
078: /**
079: *
080: */
081: public DataType<C> getDataType() {
082: return dataType;
083: }
084:
085: public String toString() {
086: return "Setting_" + getName() + " " + getDataType();
087: }
088:
089: public int hashCode() {
090: return 13 * parent.hashCode() + dataType.hashCode();
091: }
092:
093: public boolean equals(Object o) {
094: if (o instanceof Setting) {
095: Setting s = (Setting) o;
096: return s.parent.equals(parent)
097: && s.dataType.equals(dataType);
098: } else {
099: return false;
100: }
101: }
102:
103: }
|