001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017:
018: package java.beans;
019:
020: /**
021: * Describes a bean's global information.
022: */
023: public class BeanDescriptor extends FeatureDescriptor {
024:
025: private Class<?> beanClass;
026:
027: private Class<?> customizerClass;
028:
029: /**
030: * <p>
031: * Constructs an instance with the bean's {@link Class} and a customizer
032: * {@link Class}. The descriptor's {@link #getName()} is set as the
033: * unqualified name of the <code>beanClass</code>.
034: * </p>
035: *
036: * @param beanClass
037: * The bean's Class.
038: * @param customizerClass
039: * The bean's customizer Class.
040: */
041: public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {
042: super ();
043: if (beanClass == null) {
044: throw new NullPointerException();
045: }
046: setName(getShortClassName(beanClass));
047: this .beanClass = beanClass;
048: this .customizerClass = customizerClass;
049: }
050:
051: /**
052: * <p>
053: * Constructs an instance with the bean's {@link Class}. The descriptor's
054: * {@link #getName()} is set as the unqualified name of the
055: * <code>beanClass</code>.
056: * </p>
057: *
058: * @param beanClass
059: * The bean's Class.
060: */
061: public BeanDescriptor(Class<?> beanClass) {
062: super ();
063:
064: if (beanClass == null) {
065: throw new NullPointerException();
066: }
067: setName(getShortClassName(beanClass));
068: this .beanClass = beanClass;
069: }
070:
071: /**
072: * <p>
073: * Gets the bean's customizer {@link Class}/
074: * </p>
075: *
076: * @return A {@link Class} instance or <code>null</code>.
077: */
078: public Class<?> getCustomizerClass() {
079: return customizerClass;
080: }
081:
082: /**
083: * <p>
084: * Gets the bean's {@link Class}.
085: * </p>
086: *
087: * @return A {@link Class} instance.
088: */
089: public Class<?> getBeanClass() {
090: return beanClass;
091: }
092:
093: /**
094: * <p>
095: * Utility method for getting the unqualified name of a {@link Class}.
096: * </p>
097: *
098: * @param leguminaClass
099: * The Class to get the name from.
100: * @return A String instance or <code>null</code>.
101: */
102: private String getShortClassName(Class<?> leguminaClass) {
103: String result = null;
104:
105: if (leguminaClass != null) {
106: String beanClassName = leguminaClass.getName();
107: int idx = beanClassName.lastIndexOf("."); //$NON-NLS-1$
108:
109: result = (idx == -1) ? beanClassName : beanClassName
110: .substring(idx + 1);
111: }
112:
113: return result;
114: }
115:
116: }
|