FileDocCategorySizeDatePackage
MessageDestinationReferencerImpl.javaAPI DocGlassfish v2 API10545Fri May 04 22:31:22 BST 2007com.sun.enterprise.deployment

MessageDestinationReferencerImpl

public class MessageDestinationReferencerImpl extends Object implements com.sun.enterprise.deployment.types.MessageDestinationReferencer, Serializable
Shared implementation for deployment descriptor entities that can refer to a message destination. Each MessageDestinationReferencer has an owner. The owner can either be a MessageDestinationReference or a MessageDrivenBean.
author
Kenneth Saks

Fields Summary
private String
messageDestinationLinkName
private MessageDestinationDescriptor
messageDestination
private MessageDestinationReferenceDescriptor
ownerMsgDestRef
private EjbMessageBeanDescriptor
ownerMsgBean
Constructors Summary
public MessageDestinationReferencerImpl(MessageDestinationReferencerImpl other)


       
	//super(other);
	messageDestinationLinkName = other.messageDestinationLinkName; // immutable String
	messageDestination = other.messageDestination; // copy as-is
	ownerMsgDestRef = other.ownerMsgDestRef; // copy as-is
	ownerMsgBean = other.ownerMsgBean; // copy as-is
    
public MessageDestinationReferencerImpl(Descriptor desc)

        if( desc instanceof MessageDestinationReferenceDescriptor ) {
            ownerMsgDestRef = (MessageDestinationReferenceDescriptor) desc;
        } else if( desc instanceof EjbMessageBeanDescriptor ) {
            ownerMsgBean = (EjbMessageBeanDescriptor) desc;
        } else {
            throw new IllegalArgumentException("Invalid desc = " + desc);
        }
    
Methods Summary
private BundleDescriptorgetBundleDescriptor()

        return ownedByMessageDestinationRef() ?
            ownerMsgDestRef.getReferringBundleDescriptor() :
            ownerMsgBean.getEjbBundleDescriptor();
    
public EjbMessageBeanDescriptorgetMessageBeanOwner()
Get the descriptor for the message-driven bean owner.

        return ownerMsgBean;
    
public MessageDestinationDescriptorgetMessageDestination()

return
the message destination to which I refer. Can be NULL.

	return messageDestination;
    
public java.lang.StringgetMessageDestinationLinkName()

return
the link name of the message destination to which I refer NOTE that this "link name" is potentially different from the actual name of the target message destination, since the message destination could be defined in a different module.

        return messageDestinationLinkName;
    
public MessageDestinationReferenceDescriptorgetMessageDestinationRefOwner()
Get the descriptor for the message destination reference owner.

        return ownerMsgDestRef;
    
public booleanisLinkedToMessageDestination()
True if this reference has been resolved to a valid MessageDestination object.

	return (messageDestination != null);
    
public booleanownedByMessageBean()
True if the owner is a message-driven bean.

        return (ownerMsgBean != null);
    
public booleanownedByMessageDestinationRef()
True if the owner is a message destination reference.

        return (ownerMsgDestRef != null);
    
public MessageDestinationDescriptorresolveLinkName()
Try to resolve the current link name value to a MessageDestination object.

return
MessageDestination to which link was resolved, or null if link name resolution failed.

        MessageDestinationDescriptor msgDest = null;

        String linkName = messageDestinationLinkName;

        if( (linkName != null) && (linkName.length() > 0) ) {
            int hashIndex = linkName.indexOf('#");

            BundleDescriptor bundleDescriptor = getBundleDescriptor();
            Application app = bundleDescriptor.getApplication();
            BundleDescriptor targetBundle = bundleDescriptor;
            String msgDestName = linkName;
            
            if( app != null ) {

                // explicit reference to another module
                if( hashIndex != -1 )  {
                    String relativeModuleUri = linkName.substring(0, hashIndex);
                    msgDestName = linkName.substring(hashIndex + 1);
                    targetBundle = app.getRelativeBundle(bundleDescriptor,
                                                         relativeModuleUri);
                } else {
                    // Default is to find message destination within this
                    // module.  If it's not there, try searching the other
                    // modules.  NOTE that it's up to the deployer to ensure
                    // that any message destinations that are referred to
                    // from outside the defining module without an explicit
                    // reference have names that are unique within all the
                    // message destinations in the .ear.  There is no 
                    // required search ordering.  
                    if( !bundleDescriptor.hasMessageDestinationByName
                          (msgDestName) ) {
                        Set modules = app.getBundleDescriptors();
                        for(Iterator iter = modules.iterator(); iter.hasNext();)
                        {
                            BundleDescriptor next=(BundleDescriptor)iter.next();
                            if( next.hasMessageDestinationByName(msgDestName) ) {
                                targetBundle = next;
                                break;
                            }
                        }
                    }
                }
            }
            try {
                if( targetBundle != null ) {
                    msgDest = targetBundle.getMessageDestinationByName
                        (msgDestName);
                }
            } catch(IllegalArgumentException iae) {}
        }
        if( msgDest != null ) {
            setMessageDestination(msgDest);
        }

        return msgDest;
    
public voidsetMessageDestination(MessageDestinationDescriptor newMsgDest)

param
messageDestiation the message destination to which I refer.

        if( messageDestination != null ) {
            messageDestination.removeReferencer(this);
        }
        if( newMsgDest != null ) {
            newMsgDest.addReferencer(this);

            // Keep message destination link name in synch with message 
            // destination object.
            BundleDescriptor bundleDescriptor = getBundleDescriptor();
            BundleDescriptor targetBundleDescriptor = 
                newMsgDest.getBundleDescriptor();
            String linkName = newMsgDest.getName();
            if( bundleDescriptor != targetBundleDescriptor ) {
                Application app = bundleDescriptor.getApplication();
                String relativeUri = app.getRelativeUri(bundleDescriptor,
                                                        targetBundleDescriptor);
                linkName = relativeUri + "#" + linkName;
            }
            messageDestinationLinkName = linkName;
        }
        messageDestination = newMsgDest;
    
public voidsetMessageDestinationLinkName(java.lang.String linkName)
Sets the name of the message destination to which I refer. NOTE : Does *NOT* attempt to resolve link name. Use alternate version of setMessageDestinationLinkName or resolveLink if link resolution is required.

        setMessageDestinationLinkName(linkName, false);
    
public MessageDestinationDescriptorsetMessageDestinationLinkName(java.lang.String linkName, boolean resolve)
Sets the name of the message destination to which I refer.

param
resolve if true, *try* to resolve link to the target message destination.
return
MessageDestination to which link was resolved, or null if link name resolution failed.

                                                            
        messageDestinationLinkName = linkName;
        MessageDestinationDescriptor msgDest = null;        

        if( resolve ) {
            msgDest = resolveLinkName();
        }
        return msgDest;