0
|
1 // MODIFIED FOR THE MSGPACK PROJECT
|
|
2 // Licensed to the Apache Software Foundation (ASF) under one or more
|
|
3 // contributor license agreements. See the NOTICE file distributed with
|
|
4 // this work for additional information regarding copyright ownership.
|
|
5 // The ASF licenses this file to You under the Apache License, Version 2.0
|
|
6 // (the "License"); you may not use this file except in compliance with
|
|
7 // the License. You may obtain a copy of the License at
|
|
8 //
|
|
9 // http://www.apache.org/licenses/LICENSE-2.0
|
|
10 //
|
|
11 // Unless required by applicable law or agreed to in writing, software
|
|
12 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
13 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
14 // License for the specific language governing permissions and limitations under
|
|
15 // the License.
|
|
16 //
|
|
17
|
|
18 package org.msgpack.template.builder.beans;
|
|
19
|
|
20
|
|
21 /**
|
|
22 * Describes a bean's global information.
|
|
23 */
|
|
24 public class BeanDescriptor extends FeatureDescriptor {
|
|
25
|
|
26 private Class<?> beanClass;
|
|
27
|
|
28 private Class<?> customizerClass;
|
|
29
|
|
30 /**
|
|
31 * <p>
|
|
32 * Constructs an instance with the bean's {@link Class} and a customizer
|
|
33 * {@link Class}. The descriptor's {@link #getName()} is set as the
|
|
34 * unqualified name of the <code>beanClass</code>.
|
|
35 * </p>
|
|
36 *
|
|
37 * @param beanClass
|
|
38 * The bean's Class.
|
|
39 * @param customizerClass
|
|
40 * The bean's customizer Class.
|
|
41 */
|
|
42 public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {
|
|
43 if (beanClass == null) {
|
|
44 throw new NullPointerException();
|
|
45 }
|
|
46 setName(getShortClassName(beanClass));
|
|
47 this.beanClass = beanClass;
|
|
48 this.customizerClass = customizerClass;
|
|
49 }
|
|
50
|
|
51 /**
|
|
52 * <p>
|
|
53 * Constructs an instance with the bean's {@link Class}. The descriptor's
|
|
54 * {@link #getName()} is set as the unqualified name of the
|
|
55 * <code>beanClass</code>.
|
|
56 * </p>
|
|
57 *
|
|
58 * @param beanClass
|
|
59 * The bean's Class.
|
|
60 */
|
|
61 public BeanDescriptor(Class<?> beanClass) {
|
|
62 this(beanClass, null);
|
|
63 }
|
|
64
|
|
65 /**
|
|
66 * <p>
|
|
67 * Gets the bean's customizer {@link Class}/
|
|
68 * </p>
|
|
69 *
|
|
70 * @return A {@link Class} instance or <code>null</code>.
|
|
71 */
|
|
72 public Class<?> getCustomizerClass() {
|
|
73 return customizerClass;
|
|
74 }
|
|
75
|
|
76 /**
|
|
77 * <p>
|
|
78 * Gets the bean's {@link Class}.
|
|
79 * </p>
|
|
80 *
|
|
81 * @return A {@link Class} instance.
|
|
82 */
|
|
83 public Class<?> getBeanClass() {
|
|
84 return beanClass;
|
|
85 }
|
|
86
|
|
87 /**
|
|
88 * <p>
|
|
89 * Utility method for getting the unqualified name of a {@link Class}.
|
|
90 * </p>
|
|
91 *
|
|
92 * @param leguminaClass
|
|
93 * The Class to get the name from.
|
|
94 * @return A String instance or <code>null</code>.
|
|
95 */
|
|
96 private String getShortClassName(Class<?> leguminaClass) {
|
|
97 if(leguminaClass == null) {
|
|
98 return null;
|
|
99 }
|
|
100 String beanClassName = leguminaClass.getName();
|
|
101 int lastIndex = beanClassName.lastIndexOf("."); //$NON-NLS-1$
|
|
102 return (lastIndex == -1) ? beanClassName : beanClassName.substring(lastIndex + 1);
|
|
103 }
|
|
104
|
|
105 }
|