public void setBound(String parameterName) { if (bound == null) bound = CollectionFactory.newCaseInsensitiveMap(); bound.put(parameterName, true); }
public void addEventHandler(String eventType) { if (handledEvents == null) handledEvents = CollectionFactory.newCaseInsensitiveMap(); handledEvents.put(eventType, true); }
@SuppressWarnings("unchecked") private <K, V> Map<K, V> newConfigurationMap(Class<K> keyType) { if (keyType.equals(String.class)) { Map<String, K> result = CollectionFactory.newCaseInsensitiveMap(); return (Map<K, V>) result; } return CollectionFactory.newMap(); }
@SuppressWarnings("unchecked") private <K, V> Map<K, V> newConfigurationMap(Class<K> keyType) { if (keyType.equals(String.class)) { Map<String, K> result = CollectionFactory.newCaseInsensitiveMap(); return (Map<K, V>) result; } return CollectionFactory.newMap(); }
public Map<String, String> getFolderToPackageMapping() { Map<String, String> result = CollectionFactory.newCaseInsensitiveMap(); for (Map.Entry<String, List<String>> entry : libraryNameToPackageNames.entrySet()) { String folder = entry.getKey(); List<String> packageNames = entry.getValue(); String packageName = findCommonPackageNameForFolder(folder, packageNames); result.put(folder, packageName); } return result; }
public void addMixinClassName(String mixinClassName, String... order) { if (mixinClassNames == null) mixinClassNames = CollectionFactory.newList(); mixinClassNames.add(mixinClassName); if (order != null && order.length > 0) { if (mixinOrders == null) mixinOrders = CollectionFactory.newCaseInsensitiveMap(); mixinOrders.put(mixinClassName, order); } }
public MutableEmbeddedComponentModel addEmbeddedComponent(String id, String type, String componentClassName, boolean inheritInformalParameters, Location location) { // TODO: Parent compent model? Or would we simply override the parent? if (embeddedComponents == null) embeddedComponents = CollectionFactory.newCaseInsensitiveMap(); else if (embeddedComponents.containsKey(id)) throw new IllegalArgumentException(String.format("Embedded component '%s' has already been defined for component class %s.", id, this.componentClassName)); MutableEmbeddedComponentModel embedded = new MutableEmbeddedComponentModelImpl(id, type, componentClassName, this.componentClassName, inheritInformalParameters, location); embeddedComponents.put(id, embedded); return embedded; // So that parameters can be filled in }
private static Map<String, String> parseKeyValues(String keyValues) { if (keyValues == null) { return Collections.emptyMap(); } Map<String, String> parameters = CollectionFactory.newCaseInsensitiveMap(); StringTokenizer tk = new StringTokenizer(keyValues, ";"); while (tk.hasMoreTokens()) { String token = tk.nextToken(); int sep = token.indexOf('='); parameters.put(token.substring(0, sep), token.substring(sep + 1)); } return parameters; }
private void loadDefaults(Map<String, String> configuration) { for (Map.Entry<String, String> e : configuration.entrySet()) { String key = e.getKey(); int colonx = key.indexOf(':'); String folderKey = colonx < 0 ? "" : key.substring(0, colonx); Map<String, String> forFolder = defaultsByFolder.get(folderKey); if (forFolder == null) { forFolder = CollectionFactory.newCaseInsensitiveMap(); defaultsByFolder.put(folderKey, forFolder); } String defaultKey = colonx < 0 ? key : key.substring(colonx + 1); forFolder.put(defaultKey, e.getValue()); } }
public void addMixin(String mixinClassName, String... constraints) { if (mixinClassNames == null) { mixinClassNames = CollectionFactory.newList(); mixinConstraints = CollectionFactory.newCaseInsensitiveMap(); } else { if (mixinClassNames.contains(mixinClassName)) throw new IllegalArgumentException(String.format("Mixin %s (for component %s) has already been defined.", mixinClassName, id)); } mixinClassNames.add(mixinClassName); mixinConstraints.put(mixinClassName, constraints); }
public void setMeta(String key, String value) { assert InternalUtils.isNonBlank(key); assert InternalUtils.isNonBlank(value); if (metaData == null) metaData = CollectionFactory.newCaseInsensitiveMap(); // TODO: Error if duplicate? metaData.put(key, value); }
public BeanModel<T> include(String... propertyNames) { List<String> reorderedPropertyNames = CollectionFactory.newList(); Map<String, PropertyModel> reduced = CollectionFactory.newCaseInsensitiveMap(); for (String name : propertyNames) { PropertyModel model = get(name); String canonical = model.getPropertyName(); reorderedPropertyNames.add(canonical); reduced.put(canonical, model); } this.propertyNames.clear(); this.propertyNames.addAll(reorderedPropertyNames); properties.clear(); properties.putAll(reduced); return this; }
/** * Provides access to additional service lifecycles. One lifecycle is built in ("singleton") but additional ones are * accessed via this service (and its mapped configuration). Only proxiable services (those with explicit service * interfaces) can be managed in terms of a lifecycle. */ @PreventServiceDecoration public static ServiceLifecycleSource build(Map<String, ServiceLifecycle> configuration) { final Map<String, ServiceLifecycle2> lifecycles = CollectionFactory.newCaseInsensitiveMap(); for (Entry<String, ServiceLifecycle> entry : configuration.entrySet()) { lifecycles.put(entry.getKey(), InternalUtils.toServiceLifecycle2(entry.getValue())); } return new ServiceLifecycleSource() { @Override public ServiceLifecycle get(String scope) { return lifecycles.get(scope); } }; }
/** * Returns a new content type with the indicated parameter. * * @since 5.4 */ public ContentType withParameter(String key, String value) { assert InternalUtils.isNonBlank(key); assert InternalUtils.isNonBlank(value); Map<String, String> newParameters = CollectionFactory.newCaseInsensitiveMap(); newParameters.putAll(parameters); newParameters.put(key, value); return new ContentType(baseType, subType, newParameters); }
public void validateEmbeddedIds(Map<String, Location> componentIds, Resource templateResource) { Map<String, Boolean> embeddedIds = CollectionFactory.newCaseInsensitiveMap(); for (String id : getModel().getEmbeddedComponentIds()) embeddedIds.put(id, true); for (String id : componentIds.keySet()) { allocator.allocateId(id); embeddedIds.remove(id); } if (!embeddedIds.isEmpty()) { String className = getModel().getComponentClassName(); throw new RuntimeException(String.format("Embedded component(s) %s are defined within component class %s (or a super-class of %s), but are not present in the component template (%s).", InternalUtils.joinSorted(embeddedIds.keySet()), className, InternalUtils.lastTerm(className), templateResource)); } }
public void addParameter(String name, boolean required, boolean allowNull, String defaultBindingPrefix, boolean cached) { assert InternalUtils.isNonBlank(name); assert InternalUtils.isNonBlank(defaultBindingPrefix); if (parameters == null) { parameters = CollectionFactory.newCaseInsensitiveMap(); } if (parameters.containsKey(name)) { throw new IllegalArgumentException(String.format("Parameter '%s' of component class %s is already defined.", name, componentClassName)); } ParameterModel existingModel = getParameterModel(name); if (existingModel != null) { throw new IllegalArgumentException(String.format("Parameter '%s' of component class %s conflicts with the parameter defined by the %s base class.", name, componentClassName, existingModel.getComponentModel().getComponentClassName())); } parameters.put(name, new ParameterModelImpl(this, name, required, allowNull, defaultBindingPrefix, cached)); }
@SuppressWarnings("unchecked") EntityManagerFactory createEntityManagerFactory(final String persistenceUnitName) { for (final TapestryPersistenceUnitInfo info : persistenceUnitInfos) { if (info.getPersistenceUnitName().equals(persistenceUnitName)) { final Map properties = info.getEntityManagerProperties() == null ? CollectionFactory.newCaseInsensitiveMap() : info.getEntityManagerProperties(); properties.put(JpaConstants.PERSISTENCE_UNIT_NAME, persistenceUnitName); String providerClassName = info.getPersistenceProviderClassName(); final PersistenceProvider persistenceProvider = getPersistenceProvider(persistenceUnitName, providerClassName); return persistenceProvider.createContainerEntityManagerFactory(info, properties); } } throw new IllegalStateException(String.format( "Failed to create EntityManagerFactory for persistence unit '%s'", persistenceUnitName)); }
@SuppressWarnings("unchecked") EntityManagerFactory createEntityManagerFactory(final String persistenceUnitName) { for (final TapestryPersistenceUnitInfo info : persistenceUnitInfos) { if (info.getPersistenceUnitName().equals(persistenceUnitName)) { final Map properties = info.getEntityManagerProperties() == null ? CollectionFactory.newCaseInsensitiveMap() : info.getEntityManagerProperties(); properties.put(JpaConstants.PERSISTENCE_UNIT_NAME, persistenceUnitName); String providerClassName = info.getPersistenceProviderClassName(); final PersistenceProvider persistenceProvider = getPersistenceProvider(persistenceUnitName, providerClassName); return persistenceProvider.createContainerEntityManagerFactory(info, properties); } } throw new IllegalStateException(String.format( "Failed to create EntityManagerFactory for persistence unit '%s'", persistenceUnitName)); }
@Test public void get_mappings() { // Notice how all the trailing slashes (which are tolerated but not wanted) // have been removed. Map<String, String> expected = CollectionFactory.newCaseInsensitiveMap(); expected.put("tapestry", "org/apache/tapestry5"); expected.put("tapestry-internal", "org/apache/tapestry5/internal"); expected.put("mylib", "com/example/mylib"); ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration()); assertEquals(manager.getMappings(), expected); }
@Test public void failure() { Map<String, NullFieldStrategy> configuration = CollectionFactory.newCaseInsensitiveMap(); configuration.put("fred", mockNullFieldStrategy()); configuration.put("barney", mockNullFieldStrategy()); replay(); NullFieldStrategySource source = new NullFieldStrategySourceImpl(configuration); try { source.get("wilma"); unreachable(); } catch (UnknownValueException ex) { assertEquals(ex.getMessage(), "Unrecognized name 'wilma' locating a null field strategy."); assertListsEquals(ex.getAvailableValues().getValues(), "barney", "fred"); } } }