protected Configuration createConfiguration(String beanName) { return new DefaultConfiguration(beanName); }
public void rebuildRuntimeConfiguration() { runtimeConfiguration = buildRuntimeConfiguration(); }
public void setConstants(ContainerBuilder builder) { for (Object keyobj : keySet()) { String key = (String)keyobj; builder.factory(String.class, key, new LocatableConstantFactory<String>(getProperty(key), getPropertyLocation(key))); } } }
/** * Gets the configuration information for an action name, or returns null if the * name is not recognized. * * @param name the name of the action * @param namespace the namespace for the action or null for the empty namespace, "" * @return the configuration information for action requested */ public ActionConfig getActionConfig(String namespace, String name) { ActionConfig config = findActionConfigInNamespace(namespace, name); // try wildcarded namespaces if (config == null) { NamespaceMatch match = namespaceMatcher.match(namespace); if (match != null) { config = findActionConfigInNamespace(match.getPattern(), name); // If config found, place all the matches found in the namespace processing in the action's parameters if (config != null) { config = new ActionConfig.Builder(config) .addParams(match.getVariables()) .build(); } } } // fail over to empty namespace if ((config == null) && (namespace != null) && (!"".equals(namespace.trim()))) { config = findActionConfigInNamespace("", name); } return config; }
/** * <p> Matches the path against the compiled wildcard patterns. </p> * * @param potentialMatch The portion of the request URI for selecting a config. * @return The action config if matched, else null */ public E match(String potentialMatch) { E config = null; if (compiledPatterns.size() > 0) { if (log.isDebugEnabled()) { log.debug("Attempting to match '" + potentialMatch + "' to a wildcard pattern, "+ compiledPatterns.size() + " available"); } Map<String,String> vars = new LinkedHashMap<String,String>(); for (Mapping<E> m : compiledPatterns) { if (wildcard.match(vars, potentialMatch, m.getPattern())) { if (log.isDebugEnabled()) { log.debug("Value matches pattern '" + m.getOriginalPattern() + "'"); } config = convert(potentialMatch, m.getTarget(), vars); break; } } } return config; }
/** * Matches namespace strings against a wildcard pattern matcher * * @Since 2.1 */ public class NamespaceMatcher extends AbstractMatcher<NamespaceMatch> { public NamespaceMatcher(PatternMatcher<?> patternMatcher, Set<String> namespaces) { super(patternMatcher); for (String name : namespaces) { if (!patternMatcher.isLiteral(name)) { addPattern(name, new NamespaceMatch(name, null), false); } } } @Override protected NamespaceMatch convert(String path, NamespaceMatch orig, Map<String, String> vars) { /*Map<String,String> origVars = (Map<String,String>)vars; Map<String,String> map = new HashMap<String,String>(); for (Map.Entry<String,String> entry : origVars.entrySet()) { if (entry.getKey().length() == 1) { map.put("ns"+entry.getKey(), entry.getValue()); } } */ return new NamespaceMatch(orig.getPattern(), vars); } }
public NamespaceMatcher(PatternMatcher<?> patternMatcher, Set<String> namespaces) { super(patternMatcher); for (String name : namespaces) { if (!patternMatcher.isLiteral(name)) { addPattern(name, new NamespaceMatch(name, null), false); } } }
public RuntimeConfigurationImpl(Map<String, Map<String, ActionConfig>> namespaceActionConfigs, Map<String, String> namespaceConfigs, PatternMatcher<int[]> matcher) { this.namespaceActionConfigs = namespaceActionConfigs; this.namespaceConfigs = namespaceConfigs; this.namespaceActionConfigMatchers = new LinkedHashMap<String, ActionConfigMatcher>(); this.namespaceMatcher = new NamespaceMatcher(matcher, namespaceActionConfigs.keySet()); for (String ns : namespaceActionConfigs.keySet()) { namespaceActionConfigMatchers.put(ns, new ActionConfigMatcher(matcher, namespaceActionConfigs.get(ns), true)); } }
@Override public String toString() { String fields = new LinkedHashMap<String, Object>() { { put("type", type); put("name", name); put("implementation", implementation); put("scope", scope); } }.toString(); StringBuilder sb = new StringBuilder(fields); sb.append(super.toString()); sb.append(" defined at "); sb.append(getLocation().toString()); return sb.toString(); } }
@BeforeTest protected void setUp() throws Exception { configurationManager = XWorkTestCaseHelper.setUp(); configuration = new MockConfiguration(); ((MockConfiguration) configuration).selfRegister(); container = configuration.getContainer(); actionProxyFactory = container.getInstance(ActionProxyFactory.class); }
String actionName = (String) o; ActionConfig baseConfig = actionConfigs.get(actionName); configs.put(actionName, buildFullActionConfig(packageConfig, baseConfig)); return new RuntimeConfigurationImpl(Collections.unmodifiableMap(namespaceActionConfigs), Collections.unmodifiableMap(namespaceConfigs), matcher);
/** * Calls the ConfigurationProviderFactory.getConfig() to tell it to reload the configuration and then calls * buildRuntimeConfiguration(). * * @throws ConfigurationException */ public synchronized void reload(List<ConfigurationProvider> providers) throws ConfigurationException { // Silly copy necessary due to lack of ability to cast generic lists List<ContainerProvider> contProviders = new ArrayList<ContainerProvider>(); contProviders.addAll(providers); reloadContainer(contProviders); }
/** * <p> Finds and precompiles the wildcard patterns from the ActionConfig * "path" attributes. ActionConfig's will be evaluated in the order they * exist in the config file. Only paths that actually contain a * wildcard will be compiled. </p> * * <p>Patterns can optionally be matched "loosely". When * the end of the pattern matches \*[^*]\*$ (wildcard, no wildcard, * wildcard), if the pattern fails, it is also matched as if the * last two characters didn't exist. The goal is to support the * legacy "*!*" syntax, where the "!*" is optional.</p> * * @param configs An array of ActionConfig's to process * @param looseMatch To loosely match wildcards or not */ public ActionConfigMatcher(PatternMatcher<?> patternMatcher, Map<String, ActionConfig> configs, boolean looseMatch) { super(patternMatcher); for (String name : configs.keySet()) { addPattern(name, configs.get(name), looseMatch); } }
public LocatableFactory(String name, Class type, Class implementation, Scope scope, Object location) { this.implementation = implementation; this.type = type; this.name = name; this.scope = scope; setLocation(LocationUtils.getLocation(location)); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(super.toString()); sb.append(" defined at "); sb.append(getLocation().toString()); return sb.toString(); }
public LocatableConstantFactory(T constant, Object location) { this.constant = constant; setLocation(LocationUtils.getLocation(location)); }
private ActionConfig findActionConfigInNamespace(String namespace, String name) { ActionConfig config = null; if (namespace == null) { namespace = ""; } Map<String, ActionConfig> actions = namespaceActionConfigs.get(namespace); if (actions != null) { config = actions.get(name); // Check wildcards if (config == null) { config = namespaceActionConfigMatchers.get(namespace).match(name); // fail over to default action if (config == null) { String defaultActionRef = namespaceConfigs.get(namespace); if (defaultActionRef != null) { config = actions.get(defaultActionRef); } } } } return config; }
/** * <p> Replaces parameter values * </p> * * @param orig The original parameters with placehold values * @param vars A Map of wildcard-matched strings */ protected Map<String,String> replaceParameters(Map<String, String> orig, Map<String,String> vars) { Map<String,String> map = new LinkedHashMap<String,String>(); //this will set the group index references, like {1} for (String key : orig.keySet()) { map.put(key, convertParam(orig.get(key), vars)); } //the values map will contain entries like name->"Lex Luthor" and 1->"Lex Luthor" //now add the non-numeric values for (String key: vars.keySet()) { if (!NumberUtils.isNumber(key)) { map.put(key, vars.get(key)); } } return map; }
@Override public Object setProperty(String key, String value) { String oldValue = getProperty(key); if (LOG.isInfoEnabled() && oldValue != null && !oldValue.equals(value) && !defaultFrameworkBeanName.equals(oldValue)) { LOG.info("Overriding property "+key+" - old value: "+oldValue+" new value: "+value); } return super.setProperty(key, value); }