View Javadoc

1   /* Copyright (C) 2003 Internet Archive.
2    *
3    * This file is part of the Heritrix web crawler (crawler.archive.org).
4    *
5    * Heritrix is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser Public License as published by
7    * the Free Software Foundation; either version 2.1 of the License, or
8    * any later version.
9    *
10   * Heritrix is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser Public License
16   * along with Heritrix; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *
19   * ModuleAttributeInfo.java
20   * Created on Dec 18, 2003
21   *
22   * $Header$
23   */
24  package org.archive.crawler.settings;
25  
26  import javax.management.InvalidAttributeValueException;
27  import javax.management.MBeanAttributeInfo;
28  
29  /***
30   *
31   * @author John Erik Halse
32   */
33  public class ModuleAttributeInfo extends MBeanAttributeInfo {
34  
35      private static final long serialVersionUID = -4447321338690051514L;
36  
37      private String type;
38      private boolean isOverrideable;
39      private boolean isTransient;
40      private final Object defaultValue;
41      private final Object legalValueLists[];
42      private boolean complexType = false;
43      private boolean isExpertSetting;
44  
45      /*** Construct a new instance of ModuleAttributeInfo.
46       *
47       * @param type the element to create info for.
48       *
49       * @throws InvalidAttributeValueException
50       * @throws java.lang.IllegalArgumentException
51       */
52      public ModuleAttributeInfo(Type type)
53              throws InvalidAttributeValueException {
54  
55          super(type.getName(), type.getClass().getName(), type.getDescription(),
56                  true, true, false);
57          setType(type.getDefaultValue());
58          this.isOverrideable = type.isOverrideable();
59          this.isTransient = type.isTransient();
60          this.legalValueLists = type.getLegalValues();
61          this.isExpertSetting = type.isExpertSetting();
62          //this.defaultValue = checkValue(type.getValue());
63          this.defaultValue = type.getValue();
64          if (type.getDefaultValue() instanceof ComplexType) {
65              complexType = true;
66          }
67      }
68  
69      public ModuleAttributeInfo(ModuleAttributeInfo attr) {
70          super(attr.getName(), attr.getType(), attr.getDescription(),
71                  true, true, false);
72          setType(attr.getDefaultValue());
73          this.isOverrideable = attr.isOverrideable();
74          this.isTransient = attr.isTransient();
75          this.legalValueLists = attr.getLegalValues();
76          this.isExpertSetting = attr.isExpertSetting();
77          this.defaultValue = attr.getDefaultValue();
78          this.complexType = attr.complexType;
79      }
80  
81      public Object[] getLegalValues() {
82          return legalValueLists;
83      }
84  
85      /*** Returns true if this attribute refers to a ComplexType.
86       *
87       * @return true if this attribute refers to a ComplexType.
88       */
89      public boolean isComplexType() {
90          return complexType;
91      }
92  
93      /*** Returns true if this attribute could be overridden in per settings.
94       *
95       * @return True if overrideable.
96       */
97      public boolean isOverrideable() {
98          return isOverrideable;
99      }
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 }