Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/340#discussion_r80004476
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java 
---
    @@ -0,0 +1,166 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.core.config;
    +
    +import java.util.Map;
    +
    +import org.apache.brooklyn.config.ConfigInheritance;
    +import org.apache.brooklyn.config.ConfigInheritances;
    +import 
org.apache.brooklyn.config.ConfigInheritances.BasicConfigValueAtContainer;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.config.ConfigValueAtContainer;
    +import org.apache.brooklyn.util.collections.CollectionMerger;
    +import org.apache.brooklyn.util.exceptions.ReferenceWithError;
    +import org.apache.brooklyn.util.guava.Maybe;
    +
    +public class BasicConfigInheritance implements ConfigInheritance {
    +
    +    private static final long serialVersionUID = -5916548049057961051L;
    +
    +    public static final String CONFLICT_RESOLUTION_STRATEGY_DEEP_MERGE = 
"deep_merge";
    +    public static final String CONFLICT_RESOLUTION_STRATEGY_OVERWRITE = 
"overwrite";
    +    
    +    /** Indicates that a config key value should not be passed down from a 
container where it is defined.
    +     * Unlike {@link #NEVER_INHERITED} these values can be passed down if 
set as anonymous keys at a container
    +     * (ie the container does not expect it) to a container which does 
expect it, but it will not be passed down further. 
    +     * If the inheritor also defines a value the parent's value is ignored 
irrespective 
    +     * (as in {@link #OVERWRITE}; see {@link 
#NOT_REINHERITED_ELSE_DEEP_MERGE} if merging is desired). */
    +    public static BasicConfigInheritance NOT_REINHERITED = new 
BasicConfigInheritance(false,CONFLICT_RESOLUTION_STRATEGY_OVERWRITE,false);
    +    /** As {@link #NOT_REINHERITED} but in cases where a value is 
inherited because a parent did not recognize it,
    +     * if the inheritor also defines a value the two values should be 
merged. */
    +    public static BasicConfigInheritance NOT_REINHERITED_ELSE_DEEP_MERGE = 
new BasicConfigInheritance(false,CONFLICT_RESOLUTION_STRATEGY_DEEP_MERGE,false);
    +    /** Indicates that a key's value should never be inherited, even if 
defined on a container that does not know the key.
    +     * Most usages will prefer {@link #NOT_REINHERITED}. */
    +    public static BasicConfigInheritance NEVER_INHERITED = new 
BasicConfigInheritance(false,CONFLICT_RESOLUTION_STRATEGY_OVERWRITE,true);
    +    /** Indicates that if a key has a value at both an ancestor and a 
descendant, the descendant and his descendants
    +     * will prefer the value at the descendant. */
    +    public static BasicConfigInheritance OVERWRITE = new 
BasicConfigInheritance(true,CONFLICT_RESOLUTION_STRATEGY_OVERWRITE,false);
    +    /** Indicates that if a key has a value at both an ancestor and a 
descendant, the descendant and his descendants
    +     * should attempt to merge the values. If the values are not mergable 
behaviour is undefined
    +     * (and often the descendant's value will simply overwrite). */
    +    public static BasicConfigInheritance DEEP_MERGE = new 
BasicConfigInheritance(true,CONFLICT_RESOLUTION_STRATEGY_DEEP_MERGE,false);
    +    
    +    // reinheritable? true/false; if false, 
children/descendants/inheritors will never see it; default true
    +    protected final boolean isReinherited;
    +    // conflict-resolution-strategy? overwrite or deep_merge or null; 
default null meaning caller supplies
    +    // (overriding resolveConflict)
    +    protected final String conflictResolutionStrategy;
    +    // use-local-default-value? true/false; if true, overwrite above means 
"always ignore (even if null)"; default false
    +    // whereas merge means "use local default (if non-null)"
    +    protected final boolean useLocalDefaultValue;
    +
    +    protected BasicConfigInheritance(boolean isReinherited, String 
conflictResolutionStrategy, boolean useLocalDefaultValue) {
    +        super();
    +        this.isReinherited = isReinherited;
    +        this.conflictResolutionStrategy = conflictResolutionStrategy;
    +        this.useLocalDefaultValue = useLocalDefaultValue;
    +    }
    +
    +    @SuppressWarnings("deprecation")
    +    @Override
    +    public InheritanceMode isInherited(ConfigKey<?> key, Object from, 
Object to) {
    +        return null;
    +    }
    +    
    +
    +    @Override
    +    public <TContainer, TValue> boolean 
isReinheritable(ConfigValueAtContainer<TContainer, TValue> parent, 
ConfigInheritanceContext context) {
    +        if (!equals(ConfigInheritances.findInheritance(parent, context, 
this))) 
    +            throw new IllegalStateException("Method can only be invoked on 
inheritance at "+parent);
    --- End diff --
    
    made it a `check...` method invoking added `toString()` methods on 
`ConfigValueAtContainer` and `BasicConfigInheritance`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to