private Object deepCopyObject(Object obj) { if (obj instanceof Map<?, ?>) { Map<?, ?> objMap = (Map<?, ?>) obj; Map<Object, Object> map = Maps.newHashMap(); for (Entry<?, ?> entry : objMap.entrySet()) { map.put(entry.getKey(), deepCopyObject(entry.getValue())); } return map; } else if (obj instanceof List<?>) { List<?> objList = (List<?>) obj; List<Object> list = Lists.newArrayList(); for (Object elem : objList) { list.add(deepCopyObject(elem)); } return list; } else { return obj; } } }
"Unable to locate parent '" + parent + "' required by " + container.get(CONTAINER_KEY)); return mergeObjects(mergeParents(parent, config), container);
"Unable to locate parent '" + parent + "' required by " + container.get(CONTAINER_KEY)); return mergeObjects(mergeParents(parent, config), container);
"Unable to locate parent '" + parent + "' required by " + container.get(CONTAINER_KEY)); return mergeObjects(mergeParents(parent, config), container);
/** * Merges two container configurations together (recursively), adding values * from "parentValues" into "container" if "container" doesn't already * define them. * * @param parentValues The values that will be added if absent. * @param container The container to merge the values into. */ @SuppressWarnings("unchecked") private Map<String, Object> mergeObjects( Map<String, Object> parentValues, Map<String, Object> container) { // Clone the object with the parent values Map<String, Object> clone = Maps.newHashMap(parentValues); // Walk parameter list for the container and merge recursively. for (Map.Entry<String, Object> entry : container.entrySet()) { String field = entry.getKey(); Object fromParents = clone.get(field); Object fromContainer = entry.getValue(); // Merge if object type is Map if (fromContainer instanceof Map<?, ?> && fromParents instanceof Map<?, ?>) { clone.put(field, mergeObjects( (Map<String, Object>) fromParents, (Map<String, Object>) fromContainer)); } else { // Otherwise we just overwrite it. clone.put(field, fromContainer); } } return clone; }
/** * Merges two container configurations together (recursively), adding values * from "parentValues" into "container" if "container" doesn't already * define them. * * @param parentValues The values that will be added if absent. * @param container The container to merge the values into. */ @SuppressWarnings("unchecked") private Map<String, Object> mergeObjects( Map<String, Object> parentValues, Map<String, Object> container) { // Clone the object with the parent values Map<String, Object> clone = Maps.newHashMap(parentValues); // Walk parameter list for the container and merge recursively. for (Map.Entry<String, Object> entry : container.entrySet()) { String field = entry.getKey(); Object fromParents = clone.get(field); Object fromContainer = entry.getValue(); // Merge if object type is Map if (fromContainer instanceof Map<?, ?> && fromParents instanceof Map<?, ?>) { clone.put(field, mergeObjects( (Map<String, Object>) fromParents, (Map<String, Object>) fromContainer)); } else { // Otherwise we just overwrite it. clone.put(field, fromContainer); } } return clone; }
/** * Merges two container configurations together (recursively), adding values * from "parentValues" into "container" if "container" doesn't already * define them. * * @param parentValues The values that will be added if absent. * @param container The container to merge the values into. */ @SuppressWarnings("unchecked") private Map<String, Object> mergeObjects( Map<String, Object> parentValues, Map<String, Object> container) { // Clone the object with the parent values Map<String, Object> clone = Maps.newHashMap(parentValues); // Walk parameter list for the container and merge recursively. for (Map.Entry<String, Object> entry : container.entrySet()) { String field = entry.getKey(); Object fromParents = clone.get(field); Object fromContainer = entry.getValue(); // Merge if object type is Map if (fromContainer instanceof Map<?, ?> && fromParents instanceof Map<?, ?>) { clone.put(field, mergeObjects( (Map<String, Object>) fromParents, (Map<String, Object>) fromContainer)); } else { // Otherwise we just overwrite it. clone.put(field, fromContainer); } } return clone; }
/** * Applies the requested changes in a container configuration. * * @param newConfig The container configuration object to modify. * @param setContainers A map from container name to container to * add/modify. * @param removeContainers A set of names of containers to remove. * @throws ContainerConfigException If there was a problem setting the new * configuration. */ protected void changeContainersInConfig(BasicContainerConfig newConfig, Map<String, Map<String, Object>> setContainers, Set<String> removeContainers) throws ContainerConfigException { newConfig.config.putAll(setContainers); for (String container : removeContainers) { newConfig.config.remove(container); } for (String container : newConfig.config.keySet()) { newConfig.config.put(container, mergeParents(container, newConfig.config)); } }
private Object deepCopyObject(Object obj) { if (obj instanceof Map<?, ?>) { Map<?, ?> objMap = (Map<?, ?>) obj; Map<Object, Object> map = Maps.newHashMap(); for (Entry<?, ?> entry : objMap.entrySet()) { map.put(entry.getKey(), deepCopyObject(entry.getValue())); } return map; } else if (obj instanceof List<?>) { List<?> objList = (List<?>) obj; List<Object> list = Lists.newArrayList(); for (Object elem : objList) { list.add(deepCopyObject(elem)); } return list; } else { return obj; } } }
private Object deepCopyObject(Object obj) { if (obj instanceof Map<?, ?>) { Map<?, ?> objMap = (Map<?, ?>) obj; Map<Object, Object> map = Maps.newHashMap(); for (Entry<?, ?> entry : objMap.entrySet()) { map.put(entry.getKey(), deepCopyObject(entry.getValue())); } return map; } else if (obj instanceof List<?>) { List<?> objList = (List<?>) obj; List<Object> list = Lists.newArrayList(); for (Object elem : objList) { list.add(deepCopyObject(elem)); } return list; } else { return obj; } } }
/** * Applies the requested changes in a container configuration. * * @param newConfig The container configuration object to modify. * @param setContainers A map from container name to container to * add/modify. * @param removeContainers A set of names of containers to remove. * @throws ContainerConfigException If there was a problem setting the new * configuration. */ protected void changeContainersInConfig(BasicContainerConfig newConfig, Map<String, Map<String, Object>> setContainers, Set<String> removeContainers) throws ContainerConfigException { newConfig.config.putAll(setContainers); for (String container : removeContainers) { newConfig.config.remove(container); } for (String container : newConfig.config.keySet()) { newConfig.config.put(container, mergeParents(container, newConfig.config)); } }
/** * Applies the requested changes in a container configuration. * * @param newConfig The container configuration object to modify. * @param setContainers A map from container name to container to * add/modify. * @param removeContainers A set of names of containers to remove. * @throws ContainerConfigException If there was a problem setting the new * configuration. */ protected void changeContainersInConfig(BasicContainerConfig newConfig, Map<String, Map<String, Object>> setContainers, Set<String> removeContainers) throws ContainerConfigException { newConfig.config.putAll(setContainers); for (String container : removeContainers) { newConfig.config.remove(container); } for (String container : newConfig.config.keySet()) { newConfig.config.put(container, mergeParents(container, newConfig.config)); } }
/** * Creates a temporary ContainerConfig object that optionally contains a * copy of the current configuration. * * If you subclass {@link BasicContainerConfig} and you change its * internals, you must generally override this method to generate an object * of the same type as your subclass, and to fill its contents correctly. * * @param copyValues Whether the current configuration should be copied. * @return A new ContainerConfig object of the appropriate type. */ protected BasicContainerConfig getTemporaryConfig(boolean copyValues) { BasicContainerConfig tmp = new BasicContainerConfig(); if (copyValues) { tmp.config = deepCopyConfig(config); } return tmp; }
/** * Creates a temporary ContainerConfig object that optionally contains a * copy of the current configuration. * * If you subclass {@link BasicContainerConfig} and you change its * internals, you must generally override this method to generate an object * of the same type as your subclass, and to fill its contents correctly. * * @param copyValues Whether the current configuration should be copied. * @return A new ContainerConfig object of the appropriate type. */ protected BasicContainerConfig getTemporaryConfig(boolean copyValues) { BasicContainerConfig tmp = new BasicContainerConfig(); if (copyValues) { tmp.config = deepCopyConfig(config); } return tmp; }
/** * Creates a temporary ContainerConfig object that optionally contains a * copy of the current configuration. * * If you subclass {@link BasicContainerConfig} and you change its * internals, you must generally override this method to generate an object * of the same type as your subclass, and to fill its contents correctly. * * @param copyValues Whether the current configuration should be copied. * @return A new ContainerConfig object of the appropriate type. */ protected BasicContainerConfig getTemporaryConfig(boolean copyValues) { BasicContainerConfig tmp = new BasicContainerConfig(); if (copyValues) { tmp.config = deepCopyConfig(config); } return tmp; }
public Transaction newTransaction() { return new BasicTransaction(); }
public Transaction newTransaction() { return new BasicTransaction(); }
public void commit() throws ContainerConfigException { if (throwException != null) { throw throwException; } Set<String> removed = Sets.newHashSet(); Set<String> changed = Sets.newHashSet(); synchronized (BasicContainerConfig.this) { BasicContainerConfig tmpConfig = getTemporaryConfig(!clear); changeContainersInConfig(tmpConfig, setContainers, removeContainers); // This point will not be reached if an exception was thrown. diffConfiguration(tmpConfig, changed, removed); setNewConfig(tmpConfig); } notifyObservers(changed, removed); }
public void commit() throws ContainerConfigException { if (throwException != null) { throw throwException; } Set<String> removed = Sets.newHashSet(); Set<String> changed = Sets.newHashSet(); synchronized (BasicContainerConfig.this) { BasicContainerConfig tmpConfig = getTemporaryConfig(!clear); changeContainersInConfig(tmpConfig, setContainers, removeContainers); // This point will not be reached if an exception was thrown. diffConfiguration(tmpConfig, changed, removed); setNewConfig(tmpConfig); } notifyObservers(changed, removed); }
public void commit() throws ContainerConfigException { if (throwException != null) { throw throwException; } Set<String> removed = Sets.newHashSet(); Set<String> changed = Sets.newHashSet(); synchronized (BasicContainerConfig.this) { BasicContainerConfig tmpConfig = getTemporaryConfig(!clear); changeContainersInConfig(tmpConfig, setContainers, removeContainers); // This point will not be reached if an exception was thrown. diffConfiguration(tmpConfig, changed, removed); setNewConfig(tmpConfig); } notifyObservers(changed, removed); }