KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > ejbmodule > PmDescriptorMapping


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ListMapping.java
21  *
22  * Created on January 9, 2004, 3:05 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
26
27 import java.util.List JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29 import java.text.MessageFormat JavaDoc;
30
31 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
32 import org.netbeans.modules.j2ee.sun.dd.api.ejb.PmDescriptor;
33 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
34
35
36 /** Class that associates a PmDescriptor element to a calculated string for display
37  * in a combobox or table.
38  *
39  * It is expected that the underlying bean referenced may be changed during this
40  * object's lifetime, and between calls to toString().
41  *
42  * @author Peter Williams
43  * @version %I%, %G%
44  */

45 public class PmDescriptorMapping {
46     
47     // Standard resource bundle to use for non-property list fields
48
private static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
49         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
50

51     private static final String JavaDoc formatPattern = "(id={0}, version={1})";
52     
53     private final PmDescriptor pmDescriptor;
54     private String JavaDoc pmIdentifier;
55     private String JavaDoc pmVersion;
56     private String JavaDoc displayText;
57
58     public PmDescriptorMapping(final PmDescriptor pmDesc) {
59         pmDescriptor = pmDesc;
60         displayText = null;
61     }
62
63     public String JavaDoc toString() {
64         if(textOutOfDate()) {
65             buildDisplayText();
66         }
67         
68         return displayText;
69     }
70     
71     private void buildDisplayText() {
72         if(pmDescriptor != null) {
73             pmIdentifier = pmDescriptor.getPmIdentifier();
74             pmVersion = pmDescriptor.getPmVersion();
75             Object JavaDoc [] args = { pmIdentifier, pmVersion };
76             displayText = MessageFormat.format(formatPattern, args);
77         } else {
78             displayText = ""; // NOI18N
79
}
80     }
81     
82     private boolean textOutOfDate() {
83         // Rebuild display Text if text is null or identifier or version field has changed.
84
if(displayText == null) {
85             return true;
86         }
87         
88         if(pmDescriptor == null) {
89             return false;
90         }
91         
92         if(!Utils.strEquals(pmIdentifier, pmDescriptor.getPmIdentifier())) {
93             return true;
94         }
95
96         if(!Utils.strEquals(pmVersion, pmDescriptor.getPmVersion())) {
97             return true;
98         }
99         
100         return false;
101     }
102     
103     public PmDescriptor getPmDescriptor() {
104         return pmDescriptor;
105     }
106
107     public boolean equals(Object JavaDoc obj) {
108         boolean result = false;
109         if(obj instanceof PmDescriptorMapping) {
110             PmDescriptorMapping targetMapping = (PmDescriptorMapping) obj;
111             result = (pmDescriptor == targetMapping.pmDescriptor);
112         }
113         return result;
114     }
115     
116     public int hashCode() {
117         int hashCode = 37;
118         if(pmDescriptor != null) {
119             if(Utils.notEmpty(pmDescriptor.getPmIdentifier())) {
120                 hashCode += 37*hashCode + pmDescriptor.getPmIdentifier().hashCode();
121             }
122             
123             if(Utils.notEmpty(pmDescriptor.getPmVersion())) {
124                 hashCode += 37*hashCode + pmDescriptor.getPmVersion().hashCode();
125             }
126         }
127         return hashCode;
128     }
129 }
130
Popular Tags