KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > TypeData


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
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28  
29 /*
30  */

31
32 package com.sun.enterprise.management.support;
33
34 import java.util.Set JavaDoc;
35 import java.util.Collections JavaDoc;
36
37 import com.sun.appserv.management.util.misc.ObjectUtil;
38
39
40 /**
41     Basic data from which we derive all our TypeInfo. Any j2eeType must either
42     have 1 or more legal parent types ( in which case it is a subType),
43     or must have a contained-by j2eeType (possibly null), in which case it is a
44     top-level type, possibly contained by something else.
45     <p>
46     Separating these two ideas enables reasonably short types that don't have to
47     artifically include the singletons they are logically contained in. For example,
48     it enables the type "X-ConfigConfig" instead of
49     "X-DomainRoot.X-DomainConfig.X-ConfigConfig", which is considerably longer
50     than (unnecessarily so).
51  */

52 class TypeData
53 {
54     private final String JavaDoc mJ2EEType;
55     private final Set JavaDoc<String JavaDoc> mLegalParentsTypes;
56     private final String JavaDoc mContainedByJ2EEType;
57     
58     
59         public int
60     hashCode()
61     {
62         return ObjectUtil.hashCode(
63                 mJ2EEType, mLegalParentsTypes, mContainedByJ2EEType);
64     }
65     
66         public boolean
67     equals( final Object JavaDoc rhs )
68     {
69         boolean equals = false;
70         
71         if ( this == rhs )
72         {
73             equals = true;
74         }
75         else if ( ! (rhs instanceof TypeData) )
76         {
77             equals = false;
78         }
79         else
80         {
81             final TypeData rhsTypeData = (TypeData)rhs;
82             
83             equals = ObjectUtil.equals( mJ2EEType, rhsTypeData.mJ2EEType ) &&
84                         mLegalParentsTypes.equals( rhsTypeData.mLegalParentsTypes ) &&
85                         ObjectUtil.equals( mContainedByJ2EEType, rhsTypeData.mContainedByJ2EEType );
86         }
87         
88         return equals;
89     }
90     
91     /**
92         Same as TypeData( j2eeType, newSet( parentJ2EEType ) )
93      */

94     protected TypeData(
95         final String JavaDoc j2eeType,
96         final String JavaDoc parentJ2EEType )
97     {
98         this( j2eeType, Collections.singleton( parentJ2EEType ) );
99     }
100     
101     /**
102         @param j2eeType the j2eeType
103         @param legalParentJ2EETypes the possible j2eeTypes of the parent (0 or more)
104      */

105     protected TypeData(
106         final String JavaDoc j2eeType,
107         final Set JavaDoc<String JavaDoc> legalParentJ2EETypes )
108     {
109         this( j2eeType, legalParentJ2EETypes, null );
110     }
111     
112     /**
113         @param j2eeType the j2eeType
114         @param legalParentJ2EETypes the possible j2eeTypes of the parent (0 or more)
115         @param containingJ2EEType if non-null, the containing type, legalParentJ2EETypes must be null
116      */

117     protected TypeData(
118         final String JavaDoc j2eeType,
119         final Set JavaDoc<String JavaDoc> legalParentJ2EETypes,
120         final String JavaDoc containedByJ2EEType )
121     {
122         if ( containedByJ2EEType != null && legalParentJ2EETypes != null )
123         {
124             throw new IllegalArgumentException JavaDoc( "can't have both parents and contained type" );
125         }
126         
127         mJ2EEType = j2eeType;
128         if ( containedByJ2EEType != null )
129         {
130             mContainedByJ2EEType = containedByJ2EEType;
131             mLegalParentsTypes = null;
132         }
133         else
134         {
135             mContainedByJ2EEType = null;
136             mLegalParentsTypes = legalParentJ2EETypes == null ?
137                     null : Collections.unmodifiableSet( legalParentJ2EETypes );
138         }
139     }
140     
141         public final Set JavaDoc<String JavaDoc>
142     getLegalParentJ2EETypes()
143     {
144         return( mLegalParentsTypes );
145     }
146     
147         public final String JavaDoc
148     getJ2EEType()
149     {
150         return( mJ2EEType );
151     }
152     
153         public boolean
154     isSubType()
155     {
156         return( mLegalParentsTypes != null );
157     }
158     
159         public final String JavaDoc
160     getContaineeByJ2EEType()
161     {
162         return( mContainedByJ2EEType );
163     }
164 }
165
166
Popular Tags