![JAR search and dependency download from the Maven repository](/logo.png)
lite.beans.FeatureDescriptor Maven / Gradle / Ivy
Show all versions of litebeans Show documentation
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package lite.beans;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
/**
* Common base class for Descriptors.
*/
public class FeatureDescriptor {
private Map values;
boolean preferred, hidden, expert;
String shortDescription;
String name;
String displayName;
/**
*
* Constructs an instance.
*
*/
public FeatureDescriptor() {
this.values = new HashMap();
}
/**
*
* Sets the value for the named attribute.
*
*
* @param attributeName
* The name of the attribute to set a value with.
* @param value
* The value to set.
*/
public void setValue(String attributeName, Object value) {
if (attributeName == null || value == null) {
throw new NullPointerException();
}
values.put(attributeName, value);
}
/**
*
* Gets the value associated with the named attribute.
*
*
* @param attributeName
* The name of the attribute to get a value for.
* @return The attribute's value.
*/
public Object getValue(String attributeName) {
if (attributeName != null) {
return values.get(attributeName);
}
return null;
}
/**
*
* Enumerates the attribute names.
*
*
* @return An instance of {@link Enumeration}.
*/
public Enumeration attributeNames() {
// Create a new list, so that the references are copied
return Collections.enumeration(new LinkedList(values.keySet()));
}
/**
*
* Sets the short description.
*
*
* @param text
* The description to set.
*/
public void setShortDescription(String text) {
this.shortDescription = text;
}
/**
*
* Sets the name.
*
*
* @param name
* The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
*
* Sets the display name.
*
*
* @param displayName
* The display name to set.
*/
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
/**
*
* Gets the short description or {@link #getDisplayName()} if not set.
*
*
* @return The description.
*/
public String getShortDescription() {
return shortDescription == null ? getDisplayName() : shortDescription;
}
/**
*
* Gets the name.
*
*
* @return The name.
*/
public String getName() {
return name;
}
/**
*
* Gets the display name or {@link #getName()} if not set.
*
*
* @return The display name.
*/
public String getDisplayName() {
return displayName == null ? getName() : displayName;
}
/**
*
* Sets the preferred indicator.
*
*
* @param preferred
* true
if preferred, false
* otherwise.
*/
public void setPreferred(boolean preferred) {
this.preferred = preferred;
}
/**
*
* Sets the hidden indicator.
*
*
* @param hidden
* true
if hidden, false
otherwise.
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
*
* Sets the expert indicator.
*
*
* @param expert
* true
if expert, false
otherwise.
*/
public void setExpert(boolean expert) {
this.expert = expert;
}
/**
*
* Indicates if this feature is preferred.
*
*
* @return true
if preferred, false
otherwise.
*/
public boolean isPreferred() {
return preferred;
}
/**
*
* Indicates if this feature is hidden.
*
*
* @return true
if hidden, false
otherwise.
*/
public boolean isHidden() {
return hidden;
}
/**
*
* Indicates if this feature is an expert feature.
*
*
* @return true
if hidden, false
otherwise.
*/
public boolean isExpert() {
return expert;
}
void merge(FeatureDescriptor feature){
assert(name.equals(feature.name));
expert |= feature.expert;
hidden |= feature.hidden;
preferred |= feature.preferred;
if(shortDescription == null){
shortDescription = feature.shortDescription;
}
if(name == null){
name = feature.name;
}
if(displayName == null){
displayName = feature.displayName;
}
}
}