/** * given a resource config bean, returns the resource name / jndi-name * @param resource * @return resource name / jndi-name */ public static ResourceInfo getGenericResourceInfo(Resource resource){ ResourceInfo resourceInfo = null; String resourceName = resource.getIdentity(); resourceInfo = getGenericResourceInfo(resource, resourceName); return resourceInfo; }
public static Resource getResourceByName(Class<? extends Resource> clazz, Resources resources, String name) { Collection<? extends Resource> typedResources = resources.getResources(clazz); if (typedResources != null) for (Resource resource : typedResources) { if (resource.getIdentity().equals(name)) { return resource; } } return null; }
public static Resource getResourceByIdentity(Resources resources, String name) { for (Resource resource : resources.getResources()) { if (resource.getIdentity().equals(name)) { return resource; } } return null; }
public static <T> Resource getResourceByName(Resources resources, Class<T> type, String name) { Resource foundRes = null; Iterator itr = resources.getResources(type).iterator(); while (itr.hasNext()) { Resource res = (Resource)(itr.next()); String resourceName = res.getIdentity(); if (name.equals(resourceName)) { foundRes = res; break; } } // make sure that the "type" provided and the matched resource are compatible. // eg: its possible that the requested resource is "ConnectorResource", // and matching resource is "JdbcResource" as we filter based on // the generic type (in this case BindableResource) and not on exact type. if (type != null && foundRes != null && type.isAssignableFrom(foundRes.getClass())) { return foundRes; } else { return null; } } }
private Resource getResourceByIdentity(String id) { for (Resource resource : domain.getResources().getResources()) { if (resource.getIdentity().equals(id)) { return resource; } } return null; }
public String getNameForConfigBean(Object configBean, Class configBeanType) throws InvocationTargetException, IllegalAccessException { if (configBean instanceof Named) { Named nme = (Named) configBean; return nme.getName(); } if (configBean instanceof Resource) { Resource res = (Resource) configBean; return res.getIdentity(); } Method[] methods = configBeanType.getMethods(); for (Method method : methods) { Attribute attributeAnnotation = method.getAnnotation(Attribute.class); if ((attributeAnnotation != null) && attributeAnnotation.key()) { return (String) method.invoke(configBean); } } return null; }
@Override public boolean isValid(final Resource resource, final ConstraintValidatorContext constraintValidatorContext) { if (domain != null) { if (resource.getParent().getParent() instanceof Domain) { for (Resource res : domain.getResources().getResources()) { if (resource.getIdentity().equals(res.getIdentity())) { Class[] resourceInterfaces = resource.getClass().getInterfaces(); Class[] resInterfaces = res.getClass().getInterfaces(); for (Class resourceClass : resourceInterfaces) { for (Class resClass : resInterfaces) { if (resClass.getName().equals(resourceClass.getName())) { return true; } } } return false; } } } } return true; } }
Level.WARNING, ResourceLoggingConstansts.UNABLE_TO_FIND_RESOURCEDEPLOYER, new Object[] { resource.getIdentity() } ); return; if (deployed && !enabledLocally) { if (logger.isLoggable(Level.FINE)) logger.fine("Undeploy resource " + resource.getIdentity()); } else if (enabledLocally) { if (logger.isLoggable(Level.FINE)) logger.fine("Deploy resource " + resource.getIdentity());
/** * undeploy the given set of resources<br> * <b>care has to be taken for the case of dependent resources<br> * eg : all resources need to be undeployed <br> * before undeploying the pool that they refer to</b> * * @param resources list of resources */ public void undeployResources(Collection<Resource> resources) { for (Resource resource : resources) { try { ResourceDeployer deployer = getResourceDeployer(resource); if (deployer != null) deployer.undeployResource(resource); else { Object[] params = {resource.getIdentity()}; logger.log(Level.WARNING, ResourceLoggingConstansts.UNABLE_TO_UNDEPLOY, params); } } catch (Exception e) { Object[] params = {org.glassfish.resourcebase.resources.util.ResourceUtil.getGenericResourceInfo(resource), e}; logger.log(Level.WARNING, ResourceLoggingConstansts.UNABLE_TO_UNDEPLOY_EXCEPTION, params); } finally { removeListenerForResource(resource); } } }
private void deployServerResource(Resource resource) { ResourceDeployer deployer = getResourceDeployer(resource); if (deployer == null) { logger.log( Level.WARNING, ResourceLoggingConstansts.UNABLE_TO_FIND_RESOURCEDEPLOYER, new Object[] { resource.getIdentity() } ); return; } try { if (isServerResourceEnabled(resource, deployer)) { deployer.deployResource(resource); // deploy the resource; should be a no-op on the deployer if already deployed } else if (isServerResourceDeployed(resource)) { deployer.undeployResource(resource); // resource is not enabled in the config, undeploy it if the resource is already deployed } } catch (Exception e) { Object[] params = { ResourceUtil.getGenericResourceInfo(resource), e }; logger.log( Level.WARNING, ResourceLoggingConstansts.UNABLE_TO_DEPLOY, params); } }