boolean addEntry = false; if (resource == null) { resource = new ContextResource(); resource.setName(ref.referenceName); addEntry = true; resource.setProperty(Constants.FACTORY, ResourceFactory.class.getName()); resource.setProperty(NAME, ref.referenceName); resource.setType(ref.referenceType); resource.setAuth(ref.referenceAuth); resource.setProperty(RESOURCE_ID, ref.resourceID); resource.setProperty(JNDI_NAME, ref.location.jndiName); resource.setProperty(JNDI_PROVIDER_ID, ref.location.jndiProviderId); if (!addEntry) namingContextListener.removeResource(resource.getName()); namingContextListener.addResource(resource); ContextAccessController.setReadOnly(namingContextListener.getName());
@Override public void addContextResource(Context context, List<ApplicationResource> resourceList, boolean contextBound) { NamingResources namingResources = context.getNamingResources(); for (ContextResource contextResource : namingResources.findResources()) { ApplicationResource resource = new ApplicationResource(); logger.info("reading resource: {}", contextResource.getName()); resource.setApplicationName(context.getName()); resource.setName(contextResource.getName()); resource.setType(contextResource.getType()); resource.setScope(contextResource.getScope()); resource.setAuth(contextResource.getAuth()); resource.setDescription(contextResource.getDescription()); resourceList.add(resource); } }
/** * Add a resource reference for this web application. * * @param resource New resource reference */ public void addResource(ContextResource resource) { 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 void addResource(ContextResource resource) { try { Context globalNamingContext = standardServer.getGlobalNamingContext(); Object value = globalNamingContext.lookup(resource.getName()); String type = resource.getType(); bindResource(resource.getName(), value, type); } catch (NamingException e) { logger.error("Unable to lookup Global Tomcat resource " + resource.getName(), e); } }
cr.setAuth((String)value); } else if ("description".equals(name)) { cr.setDescription((String)value); } else if ("name".equals(name)) { cr.setName((String)value); } else if ("scope".equals(name)) { cr.setScope((String)value); } else if ("type".equals(name)) { cr.setType((String)value); } else { cr.setProperty(name, ""+value); NamingResources nr = cr.getNamingResources(); nr.removeResource(cr.getName()); nr.addResource(cr);
public ContextResource getContextResource(ClassLoader cl) { ContextResource contextResource = new ContextResource(); contextResource.setAuth(getAuth()); contextResource.setScope(getScope()); contextResource.setDescription(getDescription()); contextResource.setName(getName()); contextResource.setType(getType()); for (Map.Entry<QName, String> entry: getOtherAttributes().entrySet()) { String propertyName = entry.getKey().getLocalPart(); contextResource.setProperty(propertyName, entry.getValue()); } return contextResource; }
/** * Add a resource reference for this web application. * * @param resourceName New resource reference name */ public String addResource(String resourceName, String type) throws MalformedObjectNameException { NamingResources nresources = getNamingResources(); if (nresources == null) { return null; } ContextResource resource = nresources.findResource(resourceName); if (resource != null) { throw new IllegalArgumentException ("Invalid resource name - already exists'" + resourceName + "'"); } resource = new ContextResource(); resource.setName(resourceName); resource.setType(type); nresources.addResource(resource); // Return the corresponding MBean name return createObjectName(resource).toString(); }
/** * Create an <code>ObjectName</code> for <code>ContextResource</code> object. * * @param resource The ContextResource to be named * * @exception MalformedObjectNameException if a name cannot be created */ public ObjectName createObjectName(ContextResource resource) throws MalformedObjectNameException { ObjectName name = null; String encodedResourceName = urlEncoder.encode(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); } return (name); }
/** * Return a String representation of this object. */ @Override public String toString() { StringBuilder sb = new StringBuilder("ContextResource["); sb.append("name="); sb.append(getName()); if (getDescription() != null) { sb.append(", description="); sb.append(getDescription()); } if (getType() != null) { sb.append(", type="); sb.append(getType()); } if (auth != null) { sb.append(", auth="); sb.append(auth); } if (scope != null) { sb.append(", scope="); sb.append(scope); } sb.append("]"); return (sb.toString()); }
public void addResourceRef(ContextResource resourceRef) { if (resourceRefs.containsKey(resourceRef.getName())) { // resource-ref names must be unique within a web(-fragment).xml throw new IllegalArgumentException( sm.getString("webXml.duplicateResourceRef", resourceRef.getName())); } resourceRefs.put(resourceRef.getName(), resourceRef); } public Map<String,ContextResource> getResourceRefs() {
/** * Remove any resource reference with the specified name. * * @param name Name of the resource reference to remove */ public void removeResource(String name) { entries.remove(name); ContextResource resource = null; synchronized (resources) { resource = resources.remove(name); } if (resource != null) { support.firePropertyChange("resource", resource, null); // De-register with JMX if (resourceRequireExplicitRegistration) { try { MBeanUtils.destroyMBean(resource); } catch (Exception e) { log.warn(sm.getString("namingResources.mbeanDestroyFail", resource.getName()), e); } } resource.setNamingResources(null); } }
if (cr.getSingleton()) { String closeMethod = cr.getCloseMethod(); if (closeMethod != null && closeMethod.length() > 0) { String name = cr.getName(); Object resource; try { log.warn(sm.getString( "namingResources.cleanupNoResource", cr.getName(), container), e); continue;
public void setProperty(String name, Object value) { contextResource.setProperty(name, value); } }
cr.setAuth((String)value); } else if ("description".equals(name)) { cr.setDescription((String)value); } else if ("name".equals(name)) { cr.setName((String)value); } else if ("scope".equals(name)) { cr.setScope((String)value); } else if ("type".equals(name)) { cr.setType((String)value); } else { cr.setProperty(name, ""+value); NamingResources nr = cr.getNamingResources(); nr.removeResource(cr.getName()); nr.addResource(cr);
ContextResource resource = new ContextResource(); resource.setName(name); resource.setType(type); resource.setAuth("Container"); resource.setAuth("Application"); resource.setScope(annotation.shareable() ? "Shareable" : "Unshareable"); resource.setProperty("mappedName", annotation.mappedName()); resource.setDescription(annotation.description());
/** * Add a resource reference for this web application. * * @param resourceName New resource reference name * @param type New resource reference type */ public String addResource(String resourceName, String type) throws MalformedObjectNameException { NamingResources nresources = (NamingResources) this.resource; if (nresources == null) { return null; } ContextResource resource = nresources.findResource(resourceName); if (resource != null) { throw new IllegalArgumentException ("Invalid resource name - already exists'" + resourceName + "'"); } resource = new ContextResource(); resource.setName(resourceName); resource.setType(type); nresources.addResource(resource); // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("ContextResource"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resource); return (oname.toString()); }
/** * Add a resource reference for this web application. * * @param resource New resource reference */ public void addResource(ContextResource resource) { 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); }
String quotedResourceName = ObjectName.quote(resource.getName()); Object container = resource.getNamingResources().getContainer(); if (container instanceof Server) { name = new ObjectName(domain + ":type=Resource" + ",resourcetype=Global,class=" + resource.getType() + ",name=" + quotedResourceName); } else if (container instanceof Context) { ",resourcetype=Context,path=" + path + ",host=" + host.getName() + ",class=" + resource.getType() + ",name=" + quotedResourceName);
/** * Return a String representation of this object. */ public String toString() { StringBuffer sb = new StringBuffer("ContextResource["); sb.append("name="); sb.append(getName()); if (getDescription() != null) { sb.append(", description="); sb.append(getDescription()); } if (getType() != null) { sb.append(", type="); sb.append(getType()); } if (auth != null) { sb.append(", auth="); sb.append(auth); } if (scope != null) { sb.append(", scope="); sb.append(scope); } sb.append("]"); return (sb.toString()); }
String quotedResourceName = ObjectName.quote(resource.getName()); if (container instanceof Server) { name = new ObjectName(domain + ":type=DataSource" + ",class=" + resource.getType() + ",name=" + quotedResourceName); } else if (container instanceof Context) { ",path=" + path + ",host=" + host.getName() + ",class=" + resource.getType() + ",name=" + quotedResourceName);