FileDocCategorySizeDatePackage
NamingResources.javaAPI DocApache Tomcat 6.0.1422267Fri Jul 20 04:20:32 BST 2007org.apache.catalina.deploy

NamingResources

public class NamingResources extends Object implements Serializable
Holds and manages the naming resources defined in the J2EE Enterprise Naming Context and their associated JNDI context.
author
Remy Maucherat
version
$Revision: 550048 $ $Date: 2007-06-23 17:00:51 +0200 (sam., 23 juin 2007) $

Fields Summary
private Object
container
Associated container object.
private Hashtable
entries
List of naming entries, keyed by name. The value is the entry type, as declared by the user.
private HashMap
ejbs
The EJB resource references for this web application, keyed by name.
private HashMap
envs
The environment entries for this web application, keyed by name.
private HashMap
localEjbs
The local EJB resource references for this web application, keyed by name.
private HashMap
mdrs
The message destination referencess for this web application, keyed by name.
private HashMap
resourceEnvRefs
The resource environment references for this web application, keyed by name.
private HashMap
resources
The resource references for this web application, keyed by name.
private HashMap
resourceLinks
The resource links for this web application, keyed by name.
private HashMap
services
The web service references for this web application, keyed by name.
private ContextTransaction
transaction
The transaction for this webapp.
protected PropertyChangeSupport
support
The property change support for this component.
Constructors Summary
public NamingResources()
Create a new NamingResources instance.

    
Methods Summary
public voidaddEjb(ContextEjb ejb)
Add an EJB resource reference for this web application.

param
ejb New EJB resource reference


        if (entries.containsKey(ejb.getName())) {
            return;
        } else {
            entries.put(ejb.getName(), ejb.getType());
        }

        synchronized (ejbs) {
            ejb.setNamingResources(this);
            ejbs.put(ejb.getName(), ejb);
        }
        support.firePropertyChange("ejb", null, ejb);

    
public voidaddEnvironment(ContextEnvironment environment)
Add an environment entry for this web application.

param
environment New environment entry


        if (entries.containsKey(environment.getName())) {
            ContextEnvironment ce = findEnvironment(environment.getName());
            ContextResourceLink rl = findResourceLink(environment.getName());
            if (ce != null) {
                if (ce.getOverride()) {
                    removeEnvironment(environment.getName());
                } else {
                    return;
                }
            } else if (rl != null) {
                // Link. Need to look at the global resources
                NamingResources global =
                    ServerFactory.getServer().getGlobalNamingResources();
                if (global.findEnvironment(rl.getGlobal()) != null) {
                    if (global.findEnvironment(rl.getGlobal()).getOverride()) {
                        removeResourceLink(environment.getName());
                    } else {
                        return;
                    }
                }
            } else {
                // It exists but it isn't an env or a res link...
                return;
            }
        }
        
        entries.put(environment.getName(), environment.getType());

        synchronized (envs) {
            environment.setNamingResources(this);
            envs.put(environment.getName(), environment);
        }
        support.firePropertyChange("environment", null, environment);

    
public voidaddLocalEjb(ContextLocalEjb ejb)
Add a local EJB resource reference for this web application.

param
ejb New EJB resource reference


        if (entries.containsKey(ejb.getName())) {
            return;
        } else {
            entries.put(ejb.getName(), ejb.getType());
        }

        synchronized (localEjbs) {
            ejb.setNamingResources(this);
            localEjbs.put(ejb.getName(), ejb);
        }
        support.firePropertyChange("localEjb", null, ejb);

    
public voidaddMessageDestinationRef(MessageDestinationRef mdr)
Add a message destination reference for this web application.

param
mdr New message destination reference


        if (entries.containsKey(mdr.getName())) {
            return;
        } else {
            entries.put(mdr.getName(), mdr.getType());
        }

        synchronized (mdrs) {
            mdr.setNamingResources(this);
            mdrs.put(mdr.getName(), mdr);
        }
        support.firePropertyChange("messageDestinationRef", null, mdr);

    
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to this component.

param
listener The listener to add


        support.addPropertyChangeListener(listener);

    
public voidaddResource(ContextResource resource)
Add a resource reference for this web application.

param
resource New resource reference


        if (entries.containsKey(resource.getName())) {
            return;
        } else {
            entries.put(resource.getName(), resource.getType());
        }

        synchronized (resources) {
            resource.setNamingResources(this);
            resources.put(resource.getName(), resource);
        }
        support.firePropertyChange("resource", null, resource);

    
public voidaddResourceEnvRef(ContextResourceEnvRef resource)
Add a resource environment reference for this web application.

param
resource The resource


        if (entries.containsKey(resource.getName())) {
            return;
        } else {
            entries.put(resource.getName(), resource.getType());
        }

        synchronized (localEjbs) {
            resource.setNamingResources(this);
            resourceEnvRefs.put(resource.getName(), resource);
        }
        support.firePropertyChange("resourceEnvRef", null, resource);

    
public voidaddResourceLink(ContextResourceLink resourceLink)
Add a resource link for this web application.

param
resourceLink New resource link


        if (entries.containsKey(resourceLink.getName())) {
            return;
        } else {
            Object value = resourceLink.getType();
            if (value == null) {
                value = "";
            }
            entries.put(resourceLink.getName(), value);
        }

        synchronized (resourceLinks) {
            resourceLink.setNamingResources(this);
            resourceLinks.put(resourceLink.getName(), resourceLink);
        }
        support.firePropertyChange("resourceLink", null, resourceLink);

    
public voidaddService(ContextService service)
Add a web service reference for this web application.

param
service New web service reference


        if (entries.containsKey(service.getName())) {
            return;
        } else {
            Object value = service.getType();
            if (value == null) {
                value = "";
            }
            entries.put(service.getName(), value);
        }
        
        synchronized (services) {
            service.setNamingResources(this);
            services.put(service.getName(), service);
        }
        support.firePropertyChange("service", null, service);
        
    
public booleanexists(java.lang.String name)
Return true if the name specified already exists.


        return (entries.containsKey(name));

    
public ContextEjbfindEjb(java.lang.String name)
Return the EJB resource reference with the specified name, if any; otherwise, return null.

param
name Name of the desired EJB resource reference


        synchronized (ejbs) {
            return ((ContextEjb) ejbs.get(name));
        }

    
public ContextEjb[]findEjbs()
Return the defined EJB resource references for this application. If there are none, a zero-length array is returned.


        synchronized (ejbs) {
            ContextEjb results[] = new ContextEjb[ejbs.size()];
            return ((ContextEjb[]) ejbs.values().toArray(results));
        }

    
public ContextEnvironmentfindEnvironment(java.lang.String name)
Return the environment entry with the specified name, if any; otherwise, return null.

param
name Name of the desired environment entry


        synchronized (envs) {
            return ((ContextEnvironment) envs.get(name));
        }

    
public ContextEnvironment[]findEnvironments()
Return the set of defined environment entries for this web application. If none have been defined, a zero-length array is returned.


        synchronized (envs) {
            ContextEnvironment results[] = new ContextEnvironment[envs.size()];
            return ((ContextEnvironment[]) envs.values().toArray(results));
        }

    
public ContextLocalEjbfindLocalEjb(java.lang.String name)
Return the local EJB resource reference with the specified name, if any; otherwise, return null.

param
name Name of the desired EJB resource reference


        synchronized (localEjbs) {
            return ((ContextLocalEjb) localEjbs.get(name));
        }

    
public ContextLocalEjb[]findLocalEjbs()
Return the defined local EJB resource references for this application. If there are none, a zero-length array is returned.


        synchronized (localEjbs) {
            ContextLocalEjb results[] = new ContextLocalEjb[localEjbs.size()];
            return ((ContextLocalEjb[]) localEjbs.values().toArray(results));
        }

    
public MessageDestinationReffindMessageDestinationRef(java.lang.String name)
Return the message destination reference with the specified name, if any; otherwise, return null.

param
name Name of the desired message destination reference


        synchronized (mdrs) {
            return ((MessageDestinationRef) mdrs.get(name));
        }

    
public MessageDestinationRef[]findMessageDestinationRefs()
Return the defined message destination references for this application. If there are none, a zero-length array is returned.


        synchronized (mdrs) {
            MessageDestinationRef results[] =
                new MessageDestinationRef[mdrs.size()];
            return ((MessageDestinationRef[]) mdrs.values().toArray(results));
        }

    
public ContextResourcefindResource(java.lang.String name)
Return the resource reference with the specified name, if any; otherwise return null.

param
name Name of the desired resource reference


        synchronized (resources) {
            return ((ContextResource) resources.get(name));
        }

    
public ContextResourceEnvReffindResourceEnvRef(java.lang.String name)
Return the resource environment reference type for the specified name, if any; otherwise return null.

param
name Name of the desired resource environment reference


        synchronized (resourceEnvRefs) {
            return ((ContextResourceEnvRef) resourceEnvRefs.get(name));
        }

    
public ContextResourceEnvRef[]findResourceEnvRefs()
Return the set of resource environment reference names for this web application. If none have been specified, a zero-length array is returned.


        synchronized (resourceEnvRefs) {
            ContextResourceEnvRef results[] = new ContextResourceEnvRef[resourceEnvRefs.size()];
            return ((ContextResourceEnvRef[]) resourceEnvRefs.values().toArray(results));
        }

    
public ContextResourceLinkfindResourceLink(java.lang.String name)
Return the resource link with the specified name, if any; otherwise return null.

param
name Name of the desired resource link


        synchronized (resourceLinks) {
            return ((ContextResourceLink) resourceLinks.get(name));
        }

    
public ContextResourceLink[]findResourceLinks()
Return the defined resource links for this application. If none have been defined, a zero-length array is returned.


        synchronized (resourceLinks) {
            ContextResourceLink results[] = 
                new ContextResourceLink[resourceLinks.size()];
            return ((ContextResourceLink[]) resourceLinks.values()
                    .toArray(results));
        }

    
public ContextResource[]findResources()
Return the defined resource references for this application. If none have been defined, a zero-length array is returned.


        synchronized (resources) {
            ContextResource results[] = new ContextResource[resources.size()];
            return ((ContextResource[]) resources.values().toArray(results));
        }

    
public ContextServicefindService(java.lang.String name)
Return the web service reference for the specified name, if any; otherwise return null.

param
name Name of the desired web service


        synchronized (services) {
            return ((ContextService) services.get(name));
        }

    
public ContextService[]findServices()
Return the defined web service references for this application. If none have been defined, a zero-length array is returned.

        
        synchronized (services) {
            ContextService results[] = new ContextService[services.size()];
            return ((ContextService[]) services.values().toArray(results));
        }
        
    
public java.lang.ObjectgetContainer()
Get the container with which the naming resources are associated.



    // ------------------------------------------------------------- Properties


                   
       
        return container;
    
public ContextTransactiongetTransaction()
Get the transaction object.

        return transaction;
    
public voidremoveEjb(java.lang.String name)
Remove any EJB resource reference with the specified name.

param
name Name of the EJB resource reference to remove


        entries.remove(name);

        ContextEjb ejb = null;
        synchronized (ejbs) {
            ejb = (ContextEjb) ejbs.remove(name);
        }
        if (ejb != null) {
            support.firePropertyChange("ejb", ejb, null);
            ejb.setNamingResources(null);
        }

    
public voidremoveEnvironment(java.lang.String name)
Remove any environment entry with the specified name.

param
name Name of the environment entry to remove


        entries.remove(name);

        ContextEnvironment environment = null;
        synchronized (envs) {
            environment = (ContextEnvironment) envs.remove(name);
        }
        if (environment != null) {
            support.firePropertyChange("environment", environment, null);
            environment.setNamingResources(null);
        }

    
public voidremoveLocalEjb(java.lang.String name)
Remove any local EJB resource reference with the specified name.

param
name Name of the EJB resource reference to remove


        entries.remove(name);

        ContextLocalEjb localEjb = null;
        synchronized (localEjbs) {
            localEjb = (ContextLocalEjb) ejbs.remove(name);
        }
        if (localEjb != null) {
            support.firePropertyChange("localEjb", localEjb, null);
            localEjb.setNamingResources(null);
        }

    
public voidremoveMessageDestinationRef(java.lang.String name)
Remove any message destination reference with the specified name.

param
name Name of the message destination resource reference to remove


        entries.remove(name);

        MessageDestinationRef mdr = null;
        synchronized (mdrs) {
            mdr = (MessageDestinationRef) mdrs.remove(name);
        }
        if (mdr != null) {
            support.firePropertyChange("messageDestinationRef",
                                       mdr, null);
            mdr.setNamingResources(null);
        }

    
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener from this component.

param
listener The listener to remove


        support.removePropertyChangeListener(listener);

    
public voidremoveResource(java.lang.String name)
Remove any resource reference with the specified name.

param
name Name of the resource reference to remove


        entries.remove(name);

        ContextResource resource = null;
        synchronized (resources) {
            resource = (ContextResource) resources.remove(name);
        }
        if (resource != null) {
            support.firePropertyChange("resource", resource, null);
            resource.setNamingResources(null);
        }

    
public voidremoveResourceEnvRef(java.lang.String name)
Remove any resource environment reference with the specified name.

param
name Name of the resource environment reference to remove


        entries.remove(name);

        String type = null;
        synchronized (resourceEnvRefs) {
            type = (String) resourceEnvRefs.remove(name);
        }
        if (type != null) {
            support.firePropertyChange("resourceEnvRef",
                                       name + ":" + type, null);
        }

    
public voidremoveResourceLink(java.lang.String name)
Remove any resource link with the specified name.

param
name Name of the resource link to remove


        entries.remove(name);

        ContextResourceLink resourceLink = null;
        synchronized (resourceLinks) {
            resourceLink = (ContextResourceLink) resourceLinks.remove(name);
        }
        if (resourceLink != null) {
            support.firePropertyChange("resourceLink", resourceLink, null);
            resourceLink.setNamingResources(null);
        }

    
public voidremoveService(java.lang.String name)
Remove any web service reference with the specified name.

param
name Name of the web service reference to remove

        
        entries.remove(name);
        
        ContextService service = null;
        synchronized (services) {
            service = (ContextService) services.remove(name);
        }
        if (service != null) {
            support.firePropertyChange("service", service, null);
            service.setNamingResources(null);
        }
        
    
public voidsetContainer(java.lang.Object container)
Set the container with which the naming resources are associated.

        this.container = container;
    
public voidsetTransaction(ContextTransaction transaction)
Set the transaction object.

        this.transaction = transaction;