/** * Add a new application parameter for this application. * * @param parameter The new application parameter */ @Override public void addApplicationParameter(ApplicationParameter parameter) { synchronized (applicationParametersLock) { String newName = parameter.getName(); for (ApplicationParameter p : applicationParameters) { if (newName.equals(p.getName()) && !p.getOverride()) return; } ApplicationParameter results[] = Arrays.copyOf( applicationParameters, applicationParameters.length + 1); results[applicationParameters.length] = parameter; applicationParameters = results; } fireContainerEvent("addApplicationParameter", parameter); }
/** * Merge the context initialization parameters specified in the application * deployment descriptor with the application parameters described in the * server configuration, respecting the <code>override</code> property of * the application parameters appropriately. */ private void mergeParameters() { if (parameters != null) return; Map results = new ConcurrentHashMap(); String names[] = context.findParameters(); for (int i = 0; i < names.length; i++) results.put(names[i], context.findParameter(names[i])); ApplicationParameter params[] = context.findApplicationParameters(); for (int i = 0; i < params.length; i++) { if (params[i].getOverride()) { if (results.get(params[i].getName()) == null) results.put(params[i].getName(), params[i].getValue()); } else { results.put(params[i].getName(), params[i].getValue()); } } parameters = results; }
/** * Add a new application parameter for this application. * * @param parameter The new application parameter */ public void addApplicationParameter(ApplicationParameter parameter) { synchronized (applicationParameters) { String newName = parameter.getName(); for (int i = 0; i < applicationParameters.length; i++) { if (newName.equals(applicationParameters[i].getName()) && !applicationParameters[i].getOverride()) return; } ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length + 1]; System.arraycopy(applicationParameters, 0, results, 0, applicationParameters.length); results[applicationParameters.length] = parameter; applicationParameters = results; } fireContainerEvent("addApplicationParameter", parameter); }
/** * Merge the context initialization parameters specified in the application * deployment descriptor with the application parameters described in the * server configuration, respecting the <code>override</code> property of * the application parameters appropriately. */ private void mergeParameters() { if (parameters != null) return; HashMap results = new HashMap(); String names[] = context.findParameters(); for (int i = 0; i < names.length; i++) results.put(names[i], context.findParameter(names[i])); ApplicationParameter params[] = context.findApplicationParameters(); for (int i = 0; i < params.length; i++) { if (params[i].getOverride()) { if (results.get(params[i].getName()) == null) results.put(params[i].getName(), params[i].getValue()); } else { results.put(params[i].getName(), params[i].getValue()); } } parameters = results; }
/** * Add a new application parameter for this application. * * @param parameter The new application parameter */ public void addApplicationParameter(ApplicationParameter parameter) { synchronized (applicationParameters) { String newName = parameter.getName(); for (int i = 0; i < applicationParameters.length; i++) { if (name.equals(applicationParameters[i].getName()) && !applicationParameters[i].getOverride()) return; } ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length + 1]; System.arraycopy(applicationParameters, 0, results, 0, applicationParameters.length); results[applicationParameters.length] = parameter; applicationParameters = results; } fireContainerEvent("addApplicationParameter", parameter); }
/** * Add a new application parameter for this application. * * @param parameter * The new application parameter */ @Override public void addApplicationParameter(ApplicationParameter parameter) { synchronized (applicationParametersLock) { String newName = parameter.getName(); for (ApplicationParameter p : applicationParameters) { if (newName.equals(p.getName()) && !p.getOverride()) return; } ApplicationParameter results[] = Arrays.copyOf(applicationParameters, applicationParameters.length + 1); results[applicationParameters.length] = parameter; applicationParameters = results; } fireContainerEvent("addApplicationParameter", parameter); }
/** * Merge the context initialization parameters specified in the application * deployment descriptor with the application parameters described in the * server configuration, respecting the <code>override</code> property of * the application parameters appropriately. */ private void mergeParameters() { Map<String, String> mergedParams = new HashMap<String, String>(); String names[] = findParameters(); for (int i = 0; i < names.length; i++) { mergedParams.put(names[i], findParameter(names[i])); } ApplicationParameter params[] = findApplicationParameters(); for (int i = 0; i < params.length; i++) { if (params[i].getOverride()) { if (mergedParams.get(params[i].getName()) == null) { mergedParams.put(params[i].getName(), params[i].getValue()); } } else { mergedParams.put(params[i].getName(), params[i].getValue()); } } ServletContext sc = getServletContext(); for (Map.Entry<String, String> entry : mergedParams.entrySet()) { sc.setInitParameter(entry.getKey(), entry.getValue()); } }
/** * Return the set of application parameters for this application. */ @Override public ApplicationParameter[] findApplicationParameters() { synchronized (applicationParametersLock) { return (applicationParameters); } }
/** * Remove the application parameter with the specified name from * the set for this application. * * @param name Name of the application parameter to remove */ @Override public void removeApplicationParameter(String name) { synchronized (applicationParametersLock) { // Make sure this parameter is currently present int n = -1; for (int i = 0; i < applicationParameters.length; i++) { if (name.equals(applicationParameters[i].getName())) { n = i; break; } } if (n < 0) return; // Remove the specified parameter int j = 0; ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length - 1]; for (int i = 0; i < applicationParameters.length; i++) { if (i != n) results[j++] = applicationParameters[i]; } applicationParameters = results; } // Inform interested listeners fireContainerEvent("removeApplicationParameter", name); }
/** * Merge the context initialization parameters specified in the application * deployment descriptor with the application parameters described in the * server configuration, respecting the <code>override</code> property of * the application parameters appropriately. */ private void mergeParameters() { Map<String,String> mergedParams = new HashMap<String,String>(); String names[] = findParameters(); for (int i = 0; i < names.length; i++) { mergedParams.put(names[i], findParameter(names[i])); } ApplicationParameter params[] = findApplicationParameters(); for (int i = 0; i < params.length; i++) { if (params[i].getOverride()) { if (mergedParams.get(params[i].getName()) == null) { mergedParams.put(params[i].getName(), params[i].getValue()); } } else { mergedParams.put(params[i].getName(), params[i].getValue()); } } ServletContext sc = getServletContext(); for (Map.Entry<String,String> entry : mergedParams.entrySet()) { sc.setInitParameter(entry.getKey(), entry.getValue()); } }
/** * Remove the application parameter with the specified name from * the set for this application. * * @param name Name of the application parameter to remove */ public void removeApplicationParameter(String name) { synchronized (applicationParameters) { // Make sure this parameter is currently present int n = -1; for (int i = 0; i < applicationParameters.length; i++) { if (name.equals(applicationParameters[i].getName())) { n = i; break; } } if (n < 0) return; // Remove the specified parameter int j = 0; ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length - 1]; for (int i = 0; i < applicationParameters.length; i++) { if (i != n) results[j++] = applicationParameters[i]; } applicationParameters = results; } // Inform interested listeners fireContainerEvent("removeApplicationParameter", name); }
/** * Add a new application parameter for this application. * * @param parameter The new application parameter */ public void addApplicationParameter(ApplicationParameter parameter) { synchronized (applicationParameters) { ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length + 1]; System.arraycopy(applicationParameters, 0, results, 0, applicationParameters.length); results[applicationParameters.length] = parameter; applicationParameters = results; } }
/** * Remove the application parameter with the specified name from * the set for this application. * * @param name Name of the application parameter to remove */ public void removeApplicationParameter(String name) { synchronized (applicationParameters) { // Make sure this parameter is currently present int n = -1; for (int i = 0; i < applicationParameters.length; i++) { if (name.equals(applicationParameters[i].getName())) { n = i; break; } } if (n < 0) return; // Remove the specified parameter int j = 0; ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length - 1]; for (int i = 0; i < applicationParameters.length; i++) { if (i != n) results[j++] = applicationParameters[i]; } applicationParameters = results; } }
/** * Remove the application parameter with the specified name from the set for * this application. * * @param name * Name of the application parameter to remove */ @Override public void removeApplicationParameter(String name) { synchronized (applicationParametersLock) { // Make sure this parameter is currently present int n = -1; for (int i = 0; i < applicationParameters.length; i++) { if (name.equals(applicationParameters[i].getName())) { n = i; break; } } if (n < 0) return; // Remove the specified parameter int j = 0; ApplicationParameter results[] = new ApplicationParameter[applicationParameters.length - 1]; for (int i = 0; i < applicationParameters.length; i++) { if (i != n) results[j++] = applicationParameters[i]; } applicationParameters = results; } // Inform interested listeners fireContainerEvent("removeApplicationParameter", name); }
/** * Application init params. */ @Test public void applicationInitParams() { Assert.assertNotNull(new Expectations() { { context.findApplicationParameters(); result = new ApplicationParameter(); } }); final Tomcat70ContainerAdapter adapter = new Tomcat70ContainerAdapter(); assertEquals(0, adapter.getApplicationInitParams(context).size()); }
public List getApplicationInitParams(Context context) { // We'll try to determine if a parameter value comes from a deployment descriptor or a context descriptor. // assumption: Context.findParameter() returns only values of parameters that are declared in a deployment descriptor. // If a parameter is declared in a context descriptor with override=false and redeclared in a deployment descriptor, // Context.findParameter() still returns its value, even though the value is taken from a context descriptor. // context.findApplicationParameters() returns all parameters that are declared in a context descriptor regardless // of whether they are overridden in a deployment descriptor or not or not. // creating a set of parameter names that are declared in a context descriptor // and can not be ovevridden in a deployment descriptor. Set nonOverridableParams = new HashSet(); ApplicationParameter[] appParams = context.findApplicationParameters(); for (int i = 0; i < appParams.length; i++) { if (appParams[i] != null && ! appParams[i].getOverride()) { nonOverridableParams.add(appParams[i].getName()); } } List initParams = new ArrayList(); ServletContext servletCtx = context.getServletContext(); for (Enumeration e = servletCtx.getInitParameterNames(); e.hasMoreElements(); ) { String paramName = (String) e.nextElement(); ApplicationParam param = new ApplicationParam(); param.setName(paramName); param.setValue(servletCtx.getInitParameter(paramName)); // if the parameter is declared in a deployment descriptor // and it is not declared in a context descriptor with override=false, // the value comes from the deployment descriptor param.setFromDeplDescr(context.findParameter(paramName) != null && ! nonOverridableParams.contains(paramName)); initParams.add(param); } return initParams; }