jdk/src/share/classes/java/beans/FeatureDescriptor.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 466 6acd5ec503a8
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1996-2004 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.beans.TypeResolver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.ref.Reference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.reflect.Type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * EventSetDescriptor, and MethodDescriptor, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * It supports some common information that can be set and retrieved for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * any of the introspection descriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * In addition it provides an extension mechanism so that arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * attribute/value pairs can be associated with a design feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class FeatureDescriptor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private Reference<Class> classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Constructs a <code>FeatureDescriptor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public FeatureDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Gets the programmatic name of this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @return The programmatic name of the property/method/event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Sets the programmatic name of this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param name  The programmatic name of the property/method/event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void setName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Gets the localized display name of this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return The localized display name for the property/method/event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *  This defaults to the same as its programmatic name from getName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public String getDisplayName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (displayName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            return getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Sets the localized display name of this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param displayName  The localized display name for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *          property/method/event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public void setDisplayName(String displayName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.displayName = displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The "expert" flag is used to distinguish between those features that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * intended for expert users from those that are intended for normal users.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return True if this feature is intended for use by experts only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public boolean isExpert() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return expert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * The "expert" flag is used to distinguish between features that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * intended for expert users from those that are intended for normal users.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param expert True if this feature is intended for use by experts only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public void setExpert(boolean expert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.expert = expert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The "hidden" flag is used to identify features that are intended only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * for tool use, and which should not be exposed to humans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return True if this feature should be hidden from human users.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public boolean isHidden() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return hidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * The "hidden" flag is used to identify features that are intended only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * for tool use, and which should not be exposed to humans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param hidden  True if this feature should be hidden from human users.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void setHidden(boolean hidden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.hidden = hidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * The "preferred" flag is used to identify features that are particularly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * important for presenting to humans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return True if this feature should be preferentially shown to human users.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public boolean isPreferred() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * The "preferred" flag is used to identify features that are particularly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * important for presenting to humans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param preferred  True if this feature should be preferentially shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *                   to human users.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void setPreferred(boolean preferred) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        this.preferred = preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Gets the short description of this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return  A localized short description associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *   property/method/event.  This defaults to be the display name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public String getShortDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (shortDescription == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return shortDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * You can associate a short descriptive string with a feature.  Normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * these descriptive strings should be less than about 40 characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param text  A (localized) short description to be associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * this property/method/event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void setShortDescription(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        shortDescription = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Associate a named attribute with this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param attributeName  The locale-independent name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param value  The value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public void setValue(String attributeName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (table == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            table = new java.util.Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        table.put(attributeName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Retrieve a named attribute with this feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param attributeName  The locale-independent name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return  The value of the attribute.  May be null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *     the attribute is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public Object getValue(String attributeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (table == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
           return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return table.get(attributeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Gets an enumeration of the locale-independent names of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * feature.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return  An enumeration of the locale-independent names of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *    attributes that have been registered with setValue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public java.util.Enumeration<String> attributeNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (table == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            table = new java.util.Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return table.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Package-private constructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Merge information from two FeatureDescriptors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * The merged hidden and expert flags are formed by or-ing the values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * In the event of other conflicts, the second argument (y) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * given priority over the first argument (x).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param x  The first (lower priority) MethodDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param y  The second (higher priority) MethodDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    FeatureDescriptor(FeatureDescriptor x, FeatureDescriptor y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        expert = x.expert | y.expert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        hidden = x.hidden | y.hidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        preferred = x.preferred | y.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        name = y.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        shortDescription = x.shortDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (y.shortDescription != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            shortDescription = y.shortDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        displayName = x.displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (y.displayName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            displayName = y.displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        classRef = x.classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (y.classRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            classRef = y.classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        addTable(x.table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        addTable(y.table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Package-private dup constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * This must isolate the new object from any changes to the old object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    FeatureDescriptor(FeatureDescriptor old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        expert = old.expert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        hidden = old.hidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        preferred = old.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        name = old.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        shortDescription = old.shortDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        displayName = old.displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        classRef = old.classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        addTable(old.table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private void addTable(java.util.Hashtable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (t == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        java.util.Enumeration keys = t.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        while (keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            String key = (String)keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            Object value = t.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            setValue(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    // Package private methods for recreating the weak/soft referent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    void setClass0(Class cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        this.classRef = getWeakReference(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    Class getClass0() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        return (this.classRef != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                ? this.classRef.get()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Create a Reference wrapper for the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param obj object that will be wrapped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param soft true if a SoftReference should be created; otherwise Soft
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @return a Reference or null if obj is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    static Reference createReference(Object obj, boolean soft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        Reference ref = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (obj != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (soft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                ref = new SoftReference(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                ref = new WeakReference(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    // Convenience method which creates a WeakReference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    static Reference createReference(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return createReference(obj, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Returns an object from a Reference wrapper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return the Object in a wrapper or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    static Object getObject(Reference ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return (ref == null) ? null : (Object)ref.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * Creates a new soft reference that refers to the given object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return a new soft reference or <code>null</code> if object is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see SoftReference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    static <T> Reference<T> getSoftReference(T object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return (object != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                ? new SoftReference<T>(object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Creates a new weak reference that refers to the given object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @return a new weak reference or <code>null</code> if object is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @see WeakReference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    static <T> Reference<T> getWeakReference(T object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return (object != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                ? new WeakReference<T>(object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Resolves the return type of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param base    the class that contains the method in the hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param method  the object that represents the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return a class identifying the return type of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @see Method#getGenericReturnType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see Method#getReturnType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    static Class getReturnType(Class base, Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        if (base == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            base = method.getDeclaringClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return TypeResolver.erase(TypeResolver.resolveInClass(base, method.getGenericReturnType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Resolves the parameter types of the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @param base    the class that contains the method in the hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param method  the object that represents the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @return an array of classes identifying the parameter types of the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @see Method#getGenericParameterTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @see Method#getParameterTypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    static Class[] getParameterTypes(Class base, Method method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (base == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            base = method.getDeclaringClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return TypeResolver.erase(TypeResolver.resolveInClass(base, method.getGenericParameterTypes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    private boolean expert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    private boolean hidden;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    private boolean preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    private String shortDescription;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private String displayName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private java.util.Hashtable table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
}