/** * Create an <code>ObjectName</code> for this <code>ContextResource</code> object. * * @param domain Domain in which this name is to be created * @param resource The ContextResource to be named * @exception MalformedObjectNameException if a name cannot be created */ public static ObjectName createObjectName(String domain, ContextResource resource) throws MalformedObjectNameException { ObjectName name = null; String encodedResourceName = encodeStr(resource.getName()); Object container = resource.getNamingResources().getContainer(); if (container instanceof Server) { name = new ObjectName( domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType() + ",name=" + encodedResourceName); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) path = "/"; Host host = (Host) ((Context) container).getParent(); name = new ObjectName( domain + ":type=Resource" + ",resourcetype=Context,path=" + path + ",host=" + host.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName); } else if (container instanceof DefaultContext) { container = ((DefaultContext) container).getParent(); if (container instanceof Host) { Host host = (Host) container; name = new ObjectName( domain + ":type=Resource" + ",resourcetype=HostDefaultContext,host=" + host.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName); } else if (container instanceof Engine) { name = new ObjectName( domain + ":type=Resource" + ",resourcetype=ServiceDefaultContext,class=" + resource.getType() + ",name=" + encodedResourceName); } } return (name); }
/** Set the specified resources in the naming context. */ public void addResource(ContextResource resource) { // Create a reference to the resource. Reference ref = new ResourceRef( resource.getType(), resource.getDescription(), resource.getScope(), resource.getAuth()); // Adding the additional parameters, if any addAdditionalParameters(resource.getNamingResources(), ref, resource.getName()); try { if (debug >= 2) { log(" Adding resource ref " + resource.getName()); log(" " + ref); } createSubcontexts(envCtx, resource.getName()); envCtx.bind(resource.getName(), ref); } catch (NamingException e) { log(sm.getString("naming.bindFailed", e)); } }