1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule; 26 27 import java.util.List ; 28 import java.util.ResourceBundle ; 29 import java.text.MessageFormat ; 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 45 public class PmDescriptorMapping { 46 47 private static final ResourceBundle bundle = ResourceBundle.getBundle( 49 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 51 private static final String formatPattern = "(id={0}, version={1})"; 52 53 private final PmDescriptor pmDescriptor; 54 private String pmIdentifier; 55 private String pmVersion; 56 private String displayText; 57 58 public PmDescriptorMapping(final PmDescriptor pmDesc) { 59 pmDescriptor = pmDesc; 60 displayText = null; 61 } 62 63 public String 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 [] args = { pmIdentifier, pmVersion }; 76 displayText = MessageFormat.format(formatPattern, args); 77 } else { 78 displayText = ""; } 80 } 81 82 private boolean textOutOfDate() { 83 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 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 |