KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > FieldDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  package com.sun.enterprise.deployment;
24
25 import java.lang.reflect.Field JavaDoc;
26
27 /**
28  * I represent a field on an ejb.
29  * Either an actual field (e.g. for EJB1.1 CMP)
30  * or a virtual field (e.g. for EJb2.0 CMP)
31  *
32  * @author Danny Coward
33  */

34
35 public class FieldDescriptor extends Descriptor {
36
37     /**
38     * Constructrs an empty field descriptor
39     */

40     public FieldDescriptor() {
41     }
42     
43     /**
44     * Constructrs a field descriptor with the given name.
45     */

46     public FieldDescriptor(String JavaDoc name) {
47     super(name, "no description");
48     }
49     
50     /**
51     * Constructrs a field descriptor with the given name and description.
52     */

53     public FieldDescriptor(String JavaDoc name, String JavaDoc description) {
54     super(name, description);
55     }
56     
57     /**
58     * Constructs a field descriptor from the supplied java.lang.reflect.Field object.
59     */

60     
61     public FieldDescriptor(Field JavaDoc field) {
62     this(field.getName(), "no description");
63     }
64     
65     /** Equality iff the other objects is a field descriptor with the same name.
66     */

67     
68     public boolean equals(Object JavaDoc object) {
69     if (object instanceof FieldDescriptor) {
70         FieldDescriptor otherFieldDescriptor = (FieldDescriptor) object;
71         return otherFieldDescriptor.getName().equals(this.getName());
72     }
73     return false;
74     }
75     
76     /** My hashcode.
77     */

78     
79     public int hashCode() {
80     return this.getName().hashCode();
81     }
82     
83     /**
84     * Returns a formatted version of me as a String.
85     */

86     
87     public void print(StringBuffer JavaDoc toStringBuffer) {
88     toStringBuffer.append("Field: ").append(super.getName()).append("@").append(super.getDescription());
89     }
90
91     /**
92      * <p>
93      * Check if a field name is of an acceptable value (start with a lowercase
94      * letter)
95      * </p>
96      * @param fieldName is the field name to test
97      * @throw IllegalArgumentException if the name is unacceptable
98      */

99     public static void checkFieldName(String JavaDoc fieldName) throws IllegalArgumentException JavaDoc {
100         
101         if (fieldName == null || fieldName.length()==0) {
102             throw new IllegalArgumentException JavaDoc("cmp-field or cmr-field name cannot be empty strings");
103         }
104         char firstChar = fieldName.charAt(0);
105         if (!Character.isLetter(firstChar)) {
106             throw new IllegalArgumentException JavaDoc("cmp-field or cmr-field name " + fieldName + " must begin with a letter ");
107         }
108         if (!Character.isLowerCase(firstChar)) {
109             throw new IllegalArgumentException JavaDoc("cmp-field or cmr-field name " + fieldName + " must begin with a lowercase letter");
110         }
111     }
112 }
113
Popular Tags