1 23 package com.sun.enterprise.deployment; 24 25 import com.sun.enterprise.deployment.types.MessageDestinationReferencer; 26 import java.util.Set ; 27 import java.util.Iterator ; 28 29 38 39 public class MessageDestinationReferencerImpl implements 40 MessageDestinationReferencer { 41 42 private String messageDestinationLinkName=null; 44 45 private MessageDestinationDescriptor messageDestination=null; 48 49 private MessageDestinationReferenceDescriptor ownerMsgDestRef = null; 50 private EjbMessageBeanDescriptor ownerMsgBean = null; 51 52 public MessageDestinationReferencerImpl(MessageDestinationReferencerImpl other) { 53 messageDestinationLinkName = other.messageDestinationLinkName; messageDestination = other.messageDestination; ownerMsgDestRef = other.ownerMsgDestRef; ownerMsgBean = other.ownerMsgBean; } 59 60 public MessageDestinationReferencerImpl(Descriptor desc) { 61 if( desc instanceof MessageDestinationReferenceDescriptor ) { 62 ownerMsgDestRef = (MessageDestinationReferenceDescriptor) desc; 63 } else if( desc instanceof EjbMessageBeanDescriptor ) { 64 ownerMsgBean = (EjbMessageBeanDescriptor) desc; 65 } else { 66 throw new IllegalArgumentException ("Invalid desc = " + desc); 67 } 68 } 69 70 73 public boolean ownedByMessageDestinationRef() { 74 return (ownerMsgDestRef != null); 75 } 76 77 80 public MessageDestinationReferenceDescriptor getMessageDestinationRefOwner 81 () { 82 return ownerMsgDestRef; 83 } 84 85 88 public boolean ownedByMessageBean() { 89 return (ownerMsgBean != null); 90 } 91 92 93 96 public EjbMessageBeanDescriptor getMessageBeanOwner() { 97 return ownerMsgBean; 98 } 99 100 104 public boolean isLinkedToMessageDestination() { 105 return (messageDestination != null); 106 } 107 108 private BundleDescriptor getBundleDescriptor() { 109 return ownedByMessageDestinationRef() ? 110 ownerMsgDestRef.getReferringBundleDescriptor() : 111 ownerMsgBean.getEjbBundleDescriptor(); 112 } 113 114 120 public String getMessageDestinationLinkName() { 121 return messageDestinationLinkName; 122 } 123 124 130 public void setMessageDestinationLinkName(String linkName) { 131 setMessageDestinationLinkName(linkName, false); 132 } 133 134 135 143 public MessageDestinationDescriptor setMessageDestinationLinkName 144 (String linkName, boolean resolve) { 145 146 messageDestinationLinkName = linkName; 147 MessageDestinationDescriptor msgDest = null; 148 149 if( resolve ) { 150 msgDest = resolveLinkName(); 151 } 152 return msgDest; 153 } 154 155 162 public MessageDestinationDescriptor resolveLinkName() { 163 MessageDestinationDescriptor msgDest = null; 164 165 String linkName = messageDestinationLinkName; 166 167 if( (linkName != null) && (linkName.length() > 0) ) { 168 int hashIndex = linkName.indexOf('#'); 169 170 BundleDescriptor bundleDescriptor = getBundleDescriptor(); 171 Application app = bundleDescriptor.getApplication(); 172 BundleDescriptor targetBundle = bundleDescriptor; 173 String msgDestName = linkName; 174 175 if( app != null ) { 176 177 if( hashIndex != -1 ) { 179 String relativeModuleUri = linkName.substring(0, hashIndex); 180 msgDestName = linkName.substring(hashIndex + 1); 181 targetBundle = app.getRelativeBundle(bundleDescriptor, 182 relativeModuleUri); 183 } else { 184 if( !bundleDescriptor.hasMessageDestinationByName 193 (msgDestName) ) { 194 Set modules = app.getBundleDescriptors(); 195 for(Iterator iter = modules.iterator(); iter.hasNext();) 196 { 197 BundleDescriptor next=(BundleDescriptor)iter.next(); 198 if( next.hasMessageDestinationByName(msgDestName) ) { 199 targetBundle = next; 200 break; 201 } 202 } 203 } 204 } 205 } 206 try { 207 if( targetBundle != null ) { 208 msgDest = targetBundle.getMessageDestinationByName 209 (msgDestName); 210 } 211 } catch(IllegalArgumentException iae) {} 212 } 213 if( msgDest != null ) { 214 setMessageDestination(msgDest); 215 } 216 217 return msgDest; 218 } 219 220 223 public MessageDestinationDescriptor getMessageDestination() { 224 return messageDestination; 225 } 226 227 230 public void setMessageDestination(MessageDestinationDescriptor newMsgDest) { 231 if( messageDestination != null ) { 232 messageDestination.removeReferencer(this); 233 } 234 if( newMsgDest != null ) { 235 newMsgDest.addReferencer(this); 236 237 BundleDescriptor bundleDescriptor = getBundleDescriptor(); 240 BundleDescriptor targetBundleDescriptor = 241 newMsgDest.getBundleDescriptor(); 242 String linkName = newMsgDest.getName(); 243 if( bundleDescriptor != targetBundleDescriptor ) { 244 Application app = bundleDescriptor.getApplication(); 245 String relativeUri = app.getRelativeUri(bundleDescriptor, 246 targetBundleDescriptor); 247 linkName = relativeUri + "#" + linkName; 248 } 249 messageDestinationLinkName = linkName; 250 } 251 messageDestination = newMsgDest; 252 } 253 254 } 255 | Popular Tags |