public IClassHierarchy Merge(IClassHierarchy ch)
        {
            if (this == ch)
            {
                return(this);
            }

            if (!(ch is ProtocolBufferClassHierarchy))
            {
                Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new NotSupportedException(
                                                                           "Cannot merge ExternalClassHierarchies yet!"), LOGGER);
            }

            ProtocolBufferClassHierarchy pch = (ProtocolBufferClassHierarchy)ch;

            foreach (var pair in pch.lookupTable)
            {
                if (!this.lookupTable.ContainsKey(pair.Key))
                {
                    this.lookupTable.Add(pair);
                }
            }

            foreach (INode n in ch.GetNamespace().GetChildren())
            {
                if (!rootNode.Contains(n.GetFullName()))
                {
                    if (n is INamedParameterNode)
                    {
                        INamedParameterNode np = (INamedParameterNode)n;
                        new NamedParameterNodeImpl(this.rootNode, np.GetName(),
                                                   np.GetFullName(), np.GetFullArgName(), np.GetSimpleArgName(),
                                                   np.IsSet(), np.IsList(), np.GetDocumentation(), np.GetShortName(),
                                                   np.GetDefaultInstanceAsStrings().ToArray());
                    }
                    else if (n is IClassNode)
                    {
                        IClassNode cn = (IClassNode)n;
                        new ClassNodeImpl(rootNode, cn.GetName(), cn.GetFullName(),
                                          cn.IsUnit(), cn.IsInjectionCandidate(),
                                          cn.IsExternalConstructor(), cn.GetInjectableConstructors(),
                                          cn.GetAllConstructors(), cn.GetDefaultImplementation());
                    }
                }
            }

            return(this);
        }
Пример #2
0
        public static IConfiguration MergeDeserializedConfs(params IConfiguration[] configurations)
        {
            IClassHierarchy ch; 

            if (configurations != null && configurations.Length > 0)
            {
                ch = configurations[0].GetClassHierarchy();
            }
            else
            {
                ch = new ProtocolBufferClassHierarchy();               
            }
           
            IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(ch);

            foreach (IConfiguration tc in configurations)
            {
                cb.AddConfiguration(((ConfigurationImpl)tc));
            }

            return cb.Build();
        }
 private void setup2()
 {
     TangImpl.Reset();
     ns = new ProtocolBufferClassHierarchy(ProtocolBufferClassHierarchy.Serialize(ns));
 }