001: /* Copyright (C) 2003 Internet Archive.
002: *
003: * This file is part of the Heritrix web crawler (crawler.archive.org).
004: *
005: * Heritrix is free software; you can redistribute it and/or modify
006: * it under the terms of the GNU Lesser Public License as published by
007: * the Free Software Foundation; either version 2.1 of the License, or
008: * any later version.
009: *
010: * Heritrix is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU Lesser Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser Public License
016: * along with Heritrix; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * ModuleAttributeInfo.java
020: * Created on Dec 18, 2003
021: *
022: * $Header$
023: */
024: package org.archive.crawler.settings;
025:
026: import javax.management.InvalidAttributeValueException;
027: import javax.management.MBeanAttributeInfo;
028:
029: /**
030: *
031: * @author John Erik Halse
032: */
033: public class ModuleAttributeInfo extends MBeanAttributeInfo {
034:
035: private static final long serialVersionUID = -4447321338690051514L;
036:
037: private String type;
038: private boolean isOverrideable;
039: private boolean isTransient;
040: private final Object defaultValue;
041: private final Object legalValueLists[];
042: private boolean complexType = false;
043: private boolean isExpertSetting;
044:
045: /** Construct a new instance of ModuleAttributeInfo.
046: *
047: * @param type the element to create info for.
048: *
049: * @throws InvalidAttributeValueException
050: * @throws java.lang.IllegalArgumentException
051: */
052: public ModuleAttributeInfo(Type type)
053: throws InvalidAttributeValueException {
054:
055: super (type.getName(), type.getClass().getName(), type
056: .getDescription(), true, true, false);
057: setType(type.getDefaultValue());
058: this .isOverrideable = type.isOverrideable();
059: this .isTransient = type.isTransient();
060: this .legalValueLists = type.getLegalValues();
061: this .isExpertSetting = type.isExpertSetting();
062: //this.defaultValue = checkValue(type.getValue());
063: this .defaultValue = type.getValue();
064: if (type.getDefaultValue() instanceof ComplexType) {
065: complexType = true;
066: }
067: }
068:
069: public ModuleAttributeInfo(ModuleAttributeInfo attr) {
070: super (attr.getName(), attr.getType(), attr.getDescription(),
071: true, true, false);
072: setType(attr.getDefaultValue());
073: this .isOverrideable = attr.isOverrideable();
074: this .isTransient = attr.isTransient();
075: this .legalValueLists = attr.getLegalValues();
076: this .isExpertSetting = attr.isExpertSetting();
077: this .defaultValue = attr.getDefaultValue();
078: this .complexType = attr.complexType;
079: }
080:
081: public Object[] getLegalValues() {
082: return legalValueLists;
083: }
084:
085: /** Returns true if this attribute refers to a ComplexType.
086: *
087: * @return true if this attribute refers to a ComplexType.
088: */
089: public boolean isComplexType() {
090: return complexType;
091: }
092:
093: /** Returns true if this attribute could be overridden in per settings.
094: *
095: * @return True if overrideable.
096: */
097: public boolean isOverrideable() {
098: return isOverrideable;
099: }
100:
101: /** Returns true if this attribute should be hidden from UI and not be
102: * serialized to persistent storage.
103: *
104: * @return True if transient.
105: */
106: public boolean isTransient() {
107: return isTransient;
108: }
109:
110: /** Returns true if this Type should only show up in expert mode in UI.
111: *
112: * @return true if this Type should only show up in expert mode in UI.
113: */
114: public boolean isExpertSetting() {
115: return isExpertSetting;
116: }
117:
118: /**
119: * @return Default value.
120: */
121: public Object getDefaultValue() {
122: return defaultValue;
123: }
124:
125: /* (non-Javadoc)
126: * @see javax.management.MBeanAttributeInfo#getType()
127: */
128: public String getType() {
129: return type;
130: }
131:
132: protected void setType(Object type) {
133: this.type = type.getClass().getName();
134: }
135: }
|