Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 1996-2004 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.beans;
 
 
 
The FeatureDescriptor class is the common baseclass for PropertyDescriptor, EventSetDescriptor, and MethodDescriptor, etc.

It supports some common information that can be set and retrieved for any of the introspection descriptors.

In addition it provides an extension mechanism so that arbitrary attribute/value pairs can be associated with a design feature.

 
 
 public class FeatureDescriptor {
 
     private Reference<ClassclassRef;

    
Constructs a FeatureDescriptor.
 
     public FeatureDescriptor() {
     }

    
Gets the programmatic name of this feature.

Returns:
The programmatic name of the property/method/event
 
     public String getName() {
         return ;
     }

    
Sets the programmatic name of this feature.

Parameters:
name The programmatic name of the property/method/event
 
     public void setName(String name) {
         this. = name;
     }

    
Gets the localized display name of this feature.

Returns:
The localized display name for the property/method/event. This defaults to the same as its programmatic name from getName.
 
     public String getDisplayName() {
         if ( == null) {
             return getName();
         }
         return ;
     }

    
Sets the localized display name of this feature.

Parameters:
displayName The localized display name for the property/method/event.
 
     public void setDisplayName(String displayName) {
         this. = displayName;
     }

    
The "expert" flag is used to distinguish between those features that are intended for expert users from those that are intended for normal users.

Returns:
True if this feature is intended for use by experts only.
    public boolean isExpert() {
        return ;
    }

    
The "expert" flag is used to distinguish between features that are intended for expert users from those that are intended for normal users.

Parameters:
expert True if this feature is intended for use by experts only.
    public void setExpert(boolean expert) {
        this. = expert;
    }

    
The "hidden" flag is used to identify features that are intended only for tool use, and which should not be exposed to humans.

Returns:
True if this feature should be hidden from human users.
    public boolean isHidden() {
        return ;
    }

    
The "hidden" flag is used to identify features that are intended only for tool use, and which should not be exposed to humans.

Parameters:
hidden True if this feature should be hidden from human users.
    public void setHidden(boolean hidden) {
        this. = hidden;
    }

    
The "preferred" flag is used to identify features that are particularly important for presenting to humans.

Returns:
True if this feature should be preferentially shown to human users.
    public boolean isPreferred() {
        return ;
    }

    
The "preferred" flag is used to identify features that are particularly important for presenting to humans.

Parameters:
preferred True if this feature should be preferentially shown to human users.
    public void setPreferred(boolean preferred) {
        this. = preferred;
    }

    
Gets the short description of this feature.

Returns:
A localized short description associated with this property/method/event. This defaults to be the display name.
    public String getShortDescription() {
        if ( == null) {
            return getDisplayName();
        }
        return ;
    }

    
You can associate a short descriptive string with a feature. Normally these descriptive strings should be less than about 40 characters.

Parameters:
text A (localized) short description to be associated with this property/method/event.
    public void setShortDescription(String text) {
         = text;
    }

    
Associate a named attribute with this feature.

Parameters:
attributeName The locale-independent name of the attribute
value The value.
    public void setValue(String attributeNameObject value) {
        if ( == null) {
             = new java.util.Hashtable();
        }
        .put(attributeNamevalue);
    }

    
Retrieve a named attribute with this feature.

Parameters:
attributeName The locale-independent name of the attribute
Returns:
The value of the attribute. May be null if the attribute is unknown.
    public Object getValue(String attributeName) {
        if ( == null) {
           return null;
        }
        return .get(attributeName);
    }

    
Gets an enumeration of the locale-independent names of this feature.

Returns:
An enumeration of the locale-independent names of any attributes that have been registered with setValue.
        if ( == null) {
             = new java.util.Hashtable();
        }
        return .keys();
    }

    
Package-private constructor, Merge information from two FeatureDescriptors. The merged hidden and expert flags are formed by or-ing the values. In the event of other conflicts, the second argument (y) is given priority over the first argument (x).

Parameters:
x The first (lower priority) MethodDescriptor
y The second (higher priority) MethodDescriptor
         = x.expert | y.expert;
         = x.hidden | y.hidden;
         = x.preferred | y.preferred;
         = y.name;
         = x.shortDescription;
        if (y.shortDescription != null) {
             = y.shortDescription;
        }
         = x.displayName;
        if (y.displayName != null) {
             = y.displayName;
        }
         = x.classRef;
        if (y.classRef != null) {
             = y.classRef;
        }
        addTable(x.table);
        addTable(y.table);
    }
    /*
     * Package-private dup constructor
     * This must isolate the new object from any changes to the old object.
     */
         = old.expert;
         = old.hidden;
         = old.preferred;
         = old.name;
         = old.shortDescription;
         = old.displayName;
         = old.classRef;
        addTable(old.table);
    }
    private void addTable(java.util.Hashtable t) {
        if (t == null) {
            return;
        }
        java.util.Enumeration keys = t.keys();
        while (keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            Object value = t.get(key);
            setValue(keyvalue);
        }
    }
    // Package private methods for recreating the weak/soft referent
    void setClass0(Class cls) {
        this. = getWeakReference(cls);
    }
    Class getClass0() {
        return (this. != null)
                ? this..get()
                : null;
    }

    
Create a Reference wrapper for the object.

Parameters:
obj object that will be wrapped
soft true if a SoftReference should be created; otherwise Soft
Returns:
a Reference or null if obj is null.
    static Reference createReference(Object objboolean soft) {
        Reference ref = null;
        if (obj != null) {
            if (soft) {
                ref = new SoftReference(obj);
            } else {
                ref = new WeakReference(obj);
            }
        }
        return ref;
    }
    // Convenience method which creates a WeakReference.
    static Reference createReference(Object obj) {
        return createReference(objfalse);
    }

    
Returns an object from a Reference wrapper.

Returns:
the Object in a wrapper or null.
    static Object getObject(Reference ref) {
        return (ref == null) ? null : (Object)ref.get();
    }

    
Creates a new soft reference that refers to the given object.

Returns:
a new soft reference or null if object is null
See also:
java.lang.ref.SoftReference
    static <T> Reference<T> getSoftReference(T object) {
        return (object != null)
                ? new SoftReference<T>(object)
                : null;
    }

    
Creates a new weak reference that refers to the given object.

Returns:
a new weak reference or null if object is null
See also:
java.lang.ref.WeakReference
    static <T> Reference<T> getWeakReference(T object) {
        return (object != null)
                ? new WeakReference<T>(object)
                : null;
    }

    
Resolves the return type of the method.

Parameters:
base the class that contains the method in the hierarchy
method the object that represents the method
Returns:
a class identifying the return type of the method
See also:
java.lang.reflect.Method.getGenericReturnType()
java.lang.reflect.Method.getReturnType()
    static Class getReturnType(Class baseMethod method) {
        if (base == null) {
            base = method.getDeclaringClass();
        }
        return TypeResolver.erase(TypeResolver.resolveInClass(basemethod.getGenericReturnType()));
    }

    
Resolves the parameter types of the method.

Parameters:
base the class that contains the method in the hierarchy
method the object that represents the method
Returns:
an array of classes identifying the parameter types of the method
See also:
java.lang.reflect.Method.getGenericParameterTypes()
java.lang.reflect.Method.getParameterTypes()
    static Class[] getParameterTypes(Class baseMethod method) {
        if (base == null) {
            base = method.getDeclaringClass();
        }
        return TypeResolver.erase(TypeResolver.resolveInClass(basemethod.getGenericParameterTypes()));
    }
    private boolean expert;
    private boolean hidden;
    private boolean preferred;
    private String shortDescription;
    private String name;
    private String displayName;
    private java.util.Hashtable table;
New to GrepCode? Check out our FAQ X