Exemplo n.º 1
0
        public ConfigurationModuleBuilder BindImplementation <T>(GenericType <T> iface, string impl)
        {
            ConfigurationModuleBuilder c = DeepCopy();

            c.lateBindClazz.Add(typeof(T), impl);
            return(c);
        }
Exemplo n.º 2
0
        public ConfigurationModuleBuilder BindList <U, T>(GenericType <U> iface, IImpl <IList <T> > opt)
            where U : Name <IList <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();
            Type ifaceType = typeof(U);

            c.ProcessUse(opt);
            c.FreeImpls.Add(ifaceType, opt);
            return(c);
        }
Exemplo n.º 3
0
        public ConfigurationModuleBuilder BindNamedParameter <U, T>(GenericType <U> name, IParam <T> opt)
            where U : Name <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            c.ProcessUse(opt);
            Type nameType = typeof(U);

            c.FreeParams.Add(nameType, opt);
            return(c);
        }
Exemplo n.º 4
0
        public ConfigurationModuleBuilder BindImplementation <U, T>(GenericType <T> iface, IImpl <U> opt)
            where U : T
        {
            ConfigurationModuleBuilder c = DeepCopy();

            c.ProcessUse(opt);
            Type ifaceType = typeof(T);

            c.FreeImpls.Add(ifaceType, opt);
            return(c);
        }
Exemplo n.º 5
0
        public ConfigurationModuleBuilder BindConstructor <T, U>(GenericType <T> cons, IImpl <U> v)
            where U : IExternalConstructor <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            c.ProcessUse(v);
            Type consType = typeof(T);
            var  i        = (IImpl <object>)v;

            c.FreeImpls.Add(consType, i);
            return(c);
        }
Exemplo n.º 6
0
        // public final <T> ConfigurationModuleBuilder bindNamedParameter(Class<? extends Name<T>> iface, Impl<? extends T> opt)
        //if ValueType is T, you would better to use public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> iface, IImpl<T> opt)
        public ConfigurationModuleBuilder BindNamedParameter <U, V, T>(GenericType <U> iface, IImpl <V> opt)
            where U : Name <T>
            where V : T
        {
            ConfigurationModuleBuilder c = DeepCopy();

            c.ProcessUse(opt);
            Type ifaceType = typeof(U);

            c.FreeImpls.Add(ifaceType, opt);
            return(c);
        }
Exemplo n.º 7
0
        public ConfigurationModuleBuilder BindSetEntry <U, T>(GenericType <U> iface, IParam <T> opt)
            where U : Name <ISet <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();
            Type ifaceType = typeof(U);

            c.ProcessUse(opt);

            c.FreeParams.Add(ifaceType, opt);
            if (!SetOpts.Contains(opt))
            {
                c.SetOpts.Add(opt);
            }
            return(c);
        }
Exemplo n.º 8
0
        public ConfigurationModuleBuilder BindConstructor <T, U>(GenericType <T> clazz, GenericType <U> constructor)
            where U : IExternalConstructor <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindConstructor <T, U>(clazz, constructor);
            }
            catch (BindException e)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindConstructor: ", e), LOGGER);
            }
            return(c);
        }
Exemplo n.º 9
0
        public ConfigurationModuleBuilder BindNamedParameter <U, T>(GenericType <U> iface, GenericType <T> impl)
            where U : Name <T>
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindNamedParameter <U, T, T>(iface, impl);
            }
            catch (BindException e)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindNamedParameter: ", e), LOGGER);
            }
            return(c);
        }
Exemplo n.º 10
0
        public ConfigurationModuleBuilder BindList <U, T>(GenericType <U> iface, IList <string> impl)
            where U : Name <IList <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.B;
                b.BindList(typeof(U), impl);
            }
            catch (BindException ex)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.CaughtAndThrow(new ClassHierarchyException("Error in BindList: " + ex), Level.Error, LOGGER);
            }
            return(c);
        }
Exemplo n.º 11
0
        public ConfigurationModule Build()
        {
            ConfigurationModuleBuilder c = DeepCopy();

            if (!(c.reqUsed.ContainsAll(c.ReqDecl) && c.optUsed.ContainsAll(c.OptDecl)))
            {
                ISet <FieldInfo> fset = new MonotonicHashSet <FieldInfo>();
                foreach (FieldInfo f in c.ReqDecl)
                {
                    if (!c.reqUsed.Contains(f))
                    {
                        fset.Add(f);
                    }
                }
                foreach (FieldInfo f in c.OptDecl)
                {
                    if (!c.optUsed.Contains(f))
                    {
                        fset.Add(f);
                    }
                }
                var e = new ClassHierarchyException(
                    "Found declared options that were not used in binds: "
                    + ToString(fset));
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            foreach (Type clz in c.lateBindClazz.Keys)
            {
                try
                {
                    c.B.Bind(ReflectionUtilities.GetAssemblyQualifiedName(clz), c.lateBindClazz.Get(clz));
                }
                catch (NameResolutionException e)
                {
                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                    var ex = new ClassHierarchyException("ConfigurationModule refers to unknown class: " + c.lateBindClazz.Get(clz), e);
                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
                }
                catch (BindException e)
                {
                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
                    var ex = new ClassHierarchyException("bind failed while initializing ConfigurationModuleBuilder", e);
                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
                }
            }
            return(new ConfigurationModule(c));
        }
Exemplo n.º 12
0
        public ConfigurationModuleBuilder BindSetEntry <U, V, T>(GenericType <U> iface, GenericType <V> impl)
            where U : Name <ISet <T> >
            where V : T
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.BindSetEntry <U, V, T>(iface, impl);
            }
            catch (BindException ex)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
                var e = new ClassHierarchyException("Error in BindSetEntry: " + ex);
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            return(c);
        }
Exemplo n.º 13
0
        public ConfigurationModuleBuilder BindSetEntry <U, T>(GenericType <U> iface, string impl)
            where U : Name <ISet <T> >
        {
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.B;
                b.BindSetEntry(typeof(U), impl);
            }
            catch (BindException ex)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
                var e = new ClassHierarchyException("Error in BindSetEntry: " + ex);
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            return(c);
        }
Exemplo n.º 14
0
        public ConfigurationModuleBuilder Merge(ConfigurationModule d)
        {
            if (d == null)
            {
                var e = new NullReferenceException("If merge() was passed a static final field that is initialized to non-null, then this is almost certainly caused by a circular class dependency.");
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            try
            {
                d.AssertStaticClean();
            }
            catch (ClassHierarchyException ex)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
                var e = new ClassHierarchyException(ReflectionUtilities.GetAssemblyQualifiedName(GetType()) + ": detected attempt to merge with ConfigurationModule that has had set() called on it", ex);
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            ConfigurationModuleBuilder c = DeepCopy();

            try
            {
                c.B.AddConfiguration(d.Builder.B.Build());
            }
            catch (BindException ex)
            {
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
                var e = new ClassHierarchyException("Error in AddConfiguration in Merge: " + ex);
                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
            }
            c.ReqDecl.AddAll(d.Builder.ReqDecl);
            c.OptDecl.AddAll(d.Builder.OptDecl);
            c.reqUsed.AddAll(d.Builder.reqUsed);
            c.optUsed.AddAll(d.Builder.optUsed);
            c.SetOpts.AddAll(d.Builder.SetOpts);
            //c.ListOpts.AddAll(d.Builder.ListOpts);
            c.Map.AddAll(d.Builder.Map);
            c.FreeImpls.AddAll(d.Builder.FreeImpls);
            c.FreeParams.AddAll(d.Builder.FreeParams);
            c.lateBindClazz.AddAll(d.Builder.lateBindClazz);

            return(c);
        }
Exemplo n.º 15
0
 private ConfigurationModuleBuilder(ConfigurationModuleBuilder c)
 {
     try
     {
         B.AddConfiguration(c.B.Build());
     }
     catch (BindException e)
     {
         Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
         var ex = new ClassHierarchyException("Build error in ConfigurationModuleBuilder: " + e);
         Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
     }
     ReqDecl.UnionWith(c.ReqDecl);
     OptDecl.UnionWith(c.OptDecl);
     reqUsed.UnionWith(c.reqUsed);
     optUsed.UnionWith(c.optUsed);
     SetOpts.UnionWith(c.SetOpts);
     Map.AddAll(c.Map);
     FreeImpls.AddAll(c.FreeImpls);
     FreeParams.AddAll(c.FreeParams);
     lateBindClazz.AddAll(c.lateBindClazz);
 }
Exemplo n.º 16
0
 public ConfigurationModule(ConfigurationModuleBuilder builder)
 {
     this.Builder = builder.DeepCopy();
 }