http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Interface/ICsConfigurationBuilder.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/ICsConfigurationBuilder.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/ICsConfigurationBuilder.cs new file mode 100644 index 0000000..49787c6 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/ICsConfigurationBuilder.cs @@ -0,0 +1,121 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Util; + +namespace Org.Apache.REEF.Tang.Interface +{ + public interface ICsConfigurationBuilder : IConfigurationBuilder + { + /// <summary> + /// Binds the named parameter. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="value">The value.</param> + ICsConfigurationBuilder BindNamedParameter(Type name, string value); //name must extend from Name<T> + + /// <summary> + /// Binds the class impl as the implementation of the interface iface + /// </summary> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsConfigurationBuilder BindImplementation(Type iface, Type impl); + + /// <summary> + /// Binds the List entry. + /// </summary> + /// <param name="iface">The iface. It is a Name of IList</param> + /// <param name="impl">The impl.</param> + ICsConfigurationBuilder BindList(Type iface, IList<Type> impl); + + /// <summary> + /// Binds the named parameter. + /// </summary> + /// <typeparam name="U"></typeparam> + /// <typeparam name="T"></typeparam> + /// <param name="name">The name.</param> + /// <param name="value">The value.</param> + ICsConfigurationBuilder BindNamedParameter<U, T>(GenericType<U> name, string value) + where U : Name<T>; + + /// <summary> + /// Binds the named parameter. + /// </summary> + /// <typeparam name="U"></typeparam> + /// <typeparam name="V"></typeparam> + /// <typeparam name="T"></typeparam> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsConfigurationBuilder BindNamedParameter<U, V, T>(GenericType<U> iface, GenericType<V> impl) + where U : Name<T> + where V : T; + + /// <summary> + /// Binds the implementation. + /// </summary> + /// <typeparam name="U"></typeparam> + /// <typeparam name="T"></typeparam> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsConfigurationBuilder BindImplementation<U, T>(GenericType<U> iface, GenericType<T> impl) + where T : U; + + //public <T> void bindConstructor(Class<T> c, Class<? extends ExternalConstructor<? extends T>> v) throws BindException; + ICsConfigurationBuilder BindConstructor<T, U>(GenericType<T> c, GenericType<U> v) + where U : IExternalConstructor<T>; + + //public <T> void bindSetEntry(Class<? extends Name<Set<T>>> iface, String value) throws BindException; + ICsConfigurationBuilder BindSetEntry<U, T>(GenericType<U> iface, string value) + where U : Name<ISet<T>>; + + //public <T> void bindSetEntry(Class<? extends Name<Set<T>>> iface, Class<? extends T> impl) throws BindException; + ICsConfigurationBuilder BindSetEntry<U, V, T>(GenericType<U> iface, GenericType<V> impl) + where U : Name<ISet<T>> + where V : T; + + ICsConfigurationBuilder BindList<U, V, T>(GenericType<U> iface, IList<GenericType<V>> impl) + where U : Name<IList<T>> + where V : T; + + ICsConfigurationBuilder BindList<U, T>(GenericType<U> iface, IList<string> impl) + where U : Name<IList<T>>; + + ICsConfigurationBuilder BindNamedParameter<U, V, T>() + where U : Name<T> + where V : T; + + ICsConfigurationBuilder BindNamedParam<TName, TType>(string str) where TName : Name<TType>; + + ICsConfigurationBuilder BindStringNamedParam<T>(string str) where T : Name<string>; + + ICsConfigurationBuilder BindIntNamedParam<T>(string str) where T : Name<int>; + + ICsConfigurationBuilder BindImplementation<T1, T2>() where T2 : T1; + + ICsConfigurationBuilder BindSetEntry<T1, T2, T3>() where T1 : Name<ISet<T3>> where T2 : T3; + + ICsConfigurationBuilder BindSetEntry<U, T>(string value) where U : Name<ISet<T>>; + + ICsConfigurationBuilder BindList<U, T>(IList<string> impl) where U : Name<IList<T>>; + + ICsConfigurationBuilder BindConstructor<T, U>() where U : IExternalConstructor<T>; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Interface/ICsInternalConfigurationBuilder.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/ICsInternalConfigurationBuilder.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/ICsInternalConfigurationBuilder.cs new file mode 100644 index 0000000..c7e0fa8 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/ICsInternalConfigurationBuilder.cs @@ -0,0 +1,70 @@ +/** + * 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. + */ + +using System; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Tang.Interface +{ + internal interface ICsInternalConfigurationBuilder : ICsConfigurationBuilder + { + /// <summary> + /// Bind named parameters, implementations or external constructors, depending + /// on the types of the classes passed in. + /// </summary> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsInternalConfigurationBuilder Bind(Type iface, Type impl); + + /// <summary> + /// Binds the named parameter. + /// </summary> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsInternalConfigurationBuilder BindNamedParameter(Type iface, Type impl); + + /// <summary> + /// Binds an external constructor. + /// </summary> + /// <param name="c">The c.</param> + /// <param name="v">The v.</param> + ICsInternalConfigurationBuilder BindConstructor(Type c, Type v); + + /// <summary> + /// Binds the set entry. + /// </summary> + /// <param name="iface">The iface.</param> + /// <param name="value">The value.</param> + ICsInternalConfigurationBuilder BindSetEntry(Type iface, string value); + + /// <summary> + /// Binds the set entry. + /// </summary> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsInternalConfigurationBuilder BindSetEntry(Type iface, Type impl); + + /// <summary> + /// Binds the List entry. + /// </summary> + /// <param name="iface">The iface.</param> + /// <param name="impl">The impl.</param> + ICsInternalConfigurationBuilder BindList(Type iface, IList<string> impl); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Interface/IExternalConstructor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/IExternalConstructor.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/IExternalConstructor.cs new file mode 100644 index 0000000..86efd1f --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/IExternalConstructor.cs @@ -0,0 +1,26 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Tang.Interface +{ + public interface IExternalConstructor<out T> + { + T NewInstance(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Interface/IInjector.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/IInjector.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/IInjector.cs new file mode 100644 index 0000000..dae4dc1 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/IInjector.cs @@ -0,0 +1,181 @@ +/** + * 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. + */ +using System; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Util; +using Org.Apache.REEF.Tang.Implementations.InjectionPlan; + +namespace Org.Apache.REEF.Tang.Interface +{ + public interface IInjector + { + /// <summary> + /// Gets an instance of iface, or the implementation that has been bound to it. + /// </summary> + /// <param name="iface">The iface.</param> + /// <returns></returns> + object GetInstance(Type iface); + + /// <summary> + /// Gets the instance for a given class + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + T GetInstance<T>() where T : class; + + /// <summary> + /// Gets the instance for a given class name + /// </summary> + /// <param name="iface">The iface.</param> + /// <returns></returns> + object GetInstance(string iface); + + /// <summary> + /// Get an instance of the named parameter. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <typeparam name="U"></typeparam> + /// <param name="clazz">The clazz.</param> + /// <returns></returns> + U GetNamedInstance<T, U>(GenericType<T> clazz) where T : Name<U>; + + /// <summary> + /// Get an instance of the named parameter. + /// </summary> + /// <param name="t">t, it must inherit from Name</param> + /// <returns></returns> + object GetNamedInstance(Type t); + + /// <summary> + /// Gets the injection plan. + /// </summary> + /// <param name="name">The name.</param> + /// <returns></returns> + InjectionPlan GetInjectionPlan(Type name); + + /// <summary> + /// Gets the injection plan for a given class name + /// </summary> + /// <param name="name">The name.</param> + /// <returns></returns> + InjectionPlan GetInjectionPlan(String name); + + /// <summary> + /// Binds the aspect. + /// </summary> + /// <param name="a">A.</param> + void BindAspect(Aspect a); + + /// <summary> + /// Gets the aspect. + /// </summary> + /// <returns></returns> + Aspect GetAspect(); + + /// <summary> + /// Determines whether the specified name is injectable. + /// </summary> + /// <param name="name">The name.</param> + /// <returns> + /// <c>true</c> if the specified name is injectable; otherwise, <c>false</c>. + /// </returns> + bool IsInjectable(string name); + + /// <summary> + /// Determines whether [is parameter set] [the specified name]. + /// </summary> + /// <param name="name">The name.</param> + /// <returns> + /// <c>true</c> if [is parameter set] [the specified name]; otherwise, <c>false</c>. + /// </returns> + bool IsParameterSet(String name); + + /// <summary> + /// Determines whether the specified clazz is injectable. + /// </summary> + /// <param name="clazz">The clazz.</param> + /// <returns> + /// <c>true</c> if the specified clazz is injectable; otherwise, <c>false</c>. + /// </returns> + bool IsInjectable(Type clazz); + + /// <summary> + /// Determines whether [is parameter set] [the specified name]. + /// </summary> + /// <param name="name">The name.</param> + /// <returns> + /// <c>true</c> if [is parameter set] [the specified name]; otherwise, <c>false</c>. + /// </returns> + bool IsParameterSet(Type name); + + /// <summary> + /// Forks the injector. + /// </summary> + /// <returns></returns> + IInjector ForkInjector(); + + /// <summary> + /// Forks the injector. + /// </summary> + /// <param name="configurations">The configurations.</param> + /// <returns></returns> + IInjector ForkInjector(IConfiguration[] configurations); + + /// <summary> + /// Binds the volatile instance. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="iface">The iface.</param> + /// <param name="inst">The inst.</param> + void BindVolatileInstance<T>(GenericType<T> iface, T inst); + + /// <summary> + /// Binds the volatile parameter. + /// </summary> + /// <typeparam name="U"></typeparam> + /// <typeparam name="T"></typeparam> + /// <param name="iface">The iface.</param> + /// <param name="inst">The inst.</param> + void BindVolatileParameter<U, T>(GenericType<U> iface, T inst) where U : Name<T>; + + /// <summary> + /// Gets the named instance. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <typeparam name="U"></typeparam> + /// <returns></returns> + U GetNamedInstance<T, U>() where T : Name<U>; + + /// <summary> + /// Binds the volatile instance. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="inst">The inst.</param> + void BindVolatileInstance<T>(T inst); + + /// <summary> + /// Binds the volatile parameter. + /// </summary> + /// <typeparam name="U"></typeparam> + /// <typeparam name="T"></typeparam> + /// <param name="inst">The inst.</param> + void BindVolatileParameter<U, T>(T inst) where U : Name<T>; + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Interface/ITang.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Interface/ITang.cs b/lang/cs/Org.Apache.REEF.Tang/Interface/ITang.cs new file mode 100644 index 0000000..7715c40 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Interface/ITang.cs @@ -0,0 +1,46 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Tang.Interface +{ + public interface ITang + { + IInjector NewInjector(); + IInjector NewInjector(IConfiguration[] confs); + IInjector NewInjector(IConfiguration confs); + IInjector NewInjector(string[] assemblies, string configurationFileName); + IInjector NewInjector(string[] assemblies, IDictionary<string, string> configurations); + IInjector NewInjector(string[] assemblies, IList<KeyValuePair<string, string>> configurations); + IClassHierarchy GetClassHierarchy(string[] assemblies); + ICsClassHierarchy GetDefaultClassHierarchy(); + ICsClassHierarchy GetDefaultClassHierarchy(string[] assemblies, Type[] parameterParsers); + + ICsConfigurationBuilder NewConfigurationBuilder(); + ICsConfigurationBuilder NewConfigurationBuilder(string[] assemblies); + ICsConfigurationBuilder NewConfigurationBuilder(IConfiguration[] confs); + ICsConfigurationBuilder NewConfigurationBuilder(IConfiguration conf); + ICsConfigurationBuilder NewConfigurationBuilder(string[] assemblies, IConfiguration[] confs, Type[] parameterParsers); + IConfigurationBuilder NewConfigurationBuilder(IClassHierarchy classHierarchy); + ICsConfigurationBuilder NewConfigurationBuilder(ICsClassHierarchy classHierarchy); + + ICsConfigurationBuilder NewConfigurationBuilder(Type[] parameterParsers); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Org.Apache.REEF.Tang.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Org.Apache.REEF.Tang.csproj b/lang/cs/Org.Apache.REEF.Tang/Org.Apache.REEF.Tang.csproj new file mode 100644 index 0000000..b73bb03 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Org.Apache.REEF.Tang.csproj @@ -0,0 +1,195 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +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. +--> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{97DBB573-3994-417A-9F69-FFA25F00D2A6}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.REEF.Tang</RootNamespace> + <AssemblyName>Org.Apache.REEF.Tang</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <RestorePackages>true</RestorePackages> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> + </PropertyGroup> + <Import Project="$(SolutionDir)\Source\build.props" /> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.Hadoop.Avro"> + <HintPath>$(PackagesDir)\Microsoft.Hadoop.Avro.$(AvroVersion)\lib\net40\Microsoft.Hadoop.Avro.dll</HintPath> + </Reference> + <Reference Include="Newtonsoft.Json"> + <HintPath>$(PackagesDir)\Newtonsoft.Json.$(NewtonsoftJsonVersion)\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="protobuf-net"> + <HintPath>$(PackagesDir)\protobuf-net.$(ProtobufVersion)\lib\net40\protobuf-net.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Runtime.Serialization" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Annotations\DefaultImplementation.cs" /> + <Compile Include="Annotations\Inject.cs" /> + <Compile Include="Annotations\Name.cs" /> + <Compile Include="Annotations\NamedParameter.cs" /> + <Compile Include="Annotations\Parameter.cs" /> + <Compile Include="Annotations\Unit.cs" /> + <Compile Include="Exceptions\BindException.cs" /> + <Compile Include="Exceptions\ClassHierarchyException.cs" /> + <Compile Include="Exceptions\IllegalStateException.cs" /> + <Compile Include="Exceptions\InjectionException.cs" /> + <Compile Include="Exceptions\NameResolutionException.cs" /> + <Compile Include="Exceptions\ParseException.cs" /> + <Compile Include="Formats\AvroConfigurationDataContract\AvroConfiguration.cs" /> + <Compile Include="Formats\AvroConfigurationDataContract\ConfigurationEntry.cs" /> + <Compile Include="Formats\AvroConfigurationSerializer.cs" /> + <Compile Include="Formats\ConfigurationFile.cs" /> + <Compile Include="Formats\ConfigurationModule.cs" /> + <Compile Include="Formats\ConfigurationModuleBuilder.cs" /> + <Compile Include="Formats\IConfigurationSerializer.cs" /> + <Compile Include="Formats\IImpl.cs" /> + <Compile Include="Formats\IParam.cs" /> + <Compile Include="Formats\OptionalImpl.cs" /> + <Compile Include="Formats\OptionalParameter.cs" /> + <Compile Include="Formats\Provides.cs" /> + <Compile Include="Formats\RequiredImpl.cs" /> + <Compile Include="Formats\RequiredParameter.cs" /> + <Compile Include="Implementations\ClassHierarchy\AbstractNode.cs" /> + <Compile Include="Implementations\ClassHierarchy\ClassHierarchyImpl.cs" /> + <Compile Include="Implementations\ClassHierarchy\ClassNodeImpl.cs" /> + <Compile Include="Implementations\ClassHierarchy\ConstructorArgImpl.cs" /> + <Compile Include="Implementations\ClassHierarchy\ConstructorDefImpl.cs" /> + <Compile Include="Implementations\ClassHierarchy\NamedParameterNodeImpl.cs" /> + <Compile Include="Implementations\ClassHierarchy\NodeFactory.cs" /> + <Compile Include="Implementations\ClassHierarchy\PackageNodeImpl.cs" /> + <Compile Include="Implementations\ClassHierarchy\ParameterParser.cs" /> + <Compile Include="Implementations\Configuration\ConfigurationBuilderImpl.cs" /> + <Compile Include="Implementations\Configuration\ConfigurationImpl.cs" /> + <Compile Include="Implementations\Configuration\Configurations.cs" /> + <Compile Include="Implementations\Configuration\CsConfigurationBuilderImpl.cs" /> + <Compile Include="Implementations\Configuration\CsConfigurationImpl.cs" /> + <Compile Include="Implementations\InjectionPlan\Constructor.cs" /> + <Compile Include="Implementations\InjectionPlan\CsInstance.cs" /> + <Compile Include="Implementations\InjectionPlan\InjectionFuture.cs" /> + <Compile Include="Implementations\InjectionPlan\InjectionFuturePlan.cs" /> + <Compile Include="Implementations\InjectionPlan\InjectionPlan.cs" /> + <Compile Include="Implementations\InjectionPlan\InjectorImpl.cs" /> + <Compile Include="Implementations\InjectionPlan\ListInjectionPlan.cs" /> + <Compile Include="Implementations\InjectionPlan\SetInjectionPlan.cs" /> + <Compile Include="Implementations\InjectionPlan\Subplan.cs" /> + <Compile Include="Implementations\Tang\TangFactory.cs" /> + <Compile Include="Implementations\Tang\TangImpl.cs" /> + <Compile Include="Interface\IAspect.cs" /> + <Compile Include="Interface\IClassHierarchy.cs" /> + <Compile Include="Interface\IConfiguration.cs" /> + <Compile Include="Interface\IConfigurationBuilder.cs" /> + <Compile Include="Interface\ICsClassHierarchy.cs" /> + <Compile Include="Interface\ICsConfigurationBuilder.cs" /> + <Compile Include="Interface\ICsInternalConfigurationBuilder.cs" /> + <Compile Include="Interface\IExternalConstructor.cs" /> + <Compile Include="Interface\IInjector.cs" /> + <Compile Include="Interface\ITang.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Protobuf\class_hierarchy.cs" /> + <Compile Include="Protobuf\injection_plan.cs" /> + <Compile Include="Protobuf\ProtocolBufferClassHierarchy.cs" /> + <Compile Include="Protobuf\ProtocolBufferInjectionPlan.cs" /> + <Compile Include="Types\IClassNode.cs" /> + <Compile Include="Types\IConstructorArg.cs" /> + <Compile Include="Types\IConstructorDef.cs" /> + <Compile Include="Types\INamedParameterNode.cs" /> + <Compile Include="Types\INode.cs" /> + <Compile Include="Types\IPackageNode.cs" /> + <Compile Include="Types\ITraversable.cs" /> + <Compile Include="Util\AbstractMonotonicMultiMap.cs" /> + <Compile Include="Util\AssemblyLoader.cs" /> + <Compile Include="Util\GenericType.cs" /> + <Compile Include="Util\MonotonicHashMap.cs" /> + <Compile Include="Util\MonotonicHashSet.cs" /> + <Compile Include="Util\MonotonicMultiHashMap.cs" /> + <Compile Include="Util\MonotonicMultiMap.cs" /> + <Compile Include="Util\MonotonicSet.cs" /> + <Compile Include="Util\MonotonicTreeMap.cs" /> + <Compile Include="Util\ReflectionUtilities.cs" /> + <Compile Include="Util\SetValuedKey.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Utilities\Org.Apache.REEF.Utilities.csproj"> + <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project> + <Name>Org.Apache.REEF.Utilities</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Tang/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ab3b0bb --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +/** + * 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. + */ + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Org.Apache.REEF.Tang")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Org.Apache.REEF.Tang")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9be5f89c-7b7e-4236-ac54-10fda8eef58e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferClassHierarchy.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferClassHierarchy.cs b/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferClassHierarchy.cs new file mode 100644 index 0000000..14a77cf --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferClassHierarchy.cs @@ -0,0 +1,474 @@ +/** + * 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. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Org.Apache.REEF.Utilities.Logging; +using Org.Apache.REEF.Tang.Exceptions; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Types; +using ProtoBuf; +using Org.Apache.REEF.Tang.Implementations.ClassHierarchy; + +namespace Org.Apache.REEF.Tang.Protobuf +{ + public class ProtocolBufferClassHierarchy : IClassHierarchy + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(ProtocolBufferClassHierarchy)); + + private IPackageNode rootNode; + private IDictionary<string, INode> lookupTable = new Dictionary<string, INode>(); + + public static void Serialize(string fileName, IClassHierarchy classHierarchy) + { + ClassHierarchyProto.Node node = Serialize(classHierarchy); + + using (var file = File.Create(fileName)) + { + Serializer.Serialize<ClassHierarchyProto.Node>(file, node); + } + } + + public static ClassHierarchyProto.Node Serialize(IClassHierarchy classHierarchy) + { + return SerializeNode(classHierarchy.GetNamespace()); + } + + private static ClassHierarchyProto.Node SerializeNode(INode n) + { + IList<ClassHierarchyProto.Node> children = new List<ClassHierarchyProto.Node>(); + + foreach (INode child in n.GetChildren()) + { + children.Add(SerializeNode(child)); + } + + if (n is IClassNode) + { + IClassNode cn = (IClassNode)n; + IList<IConstructorDef> injectable = cn.GetInjectableConstructors(); + IList<IConstructorDef> all = cn.GetAllConstructors(); + IList<IConstructorDef> others = new List<IConstructorDef>(all); + + foreach (var c in injectable) + { + others.Remove(c); + } + + IList<ClassHierarchyProto.ConstructorDef> injectableConstructors = new List<ClassHierarchyProto.ConstructorDef>(); + foreach (IConstructorDef inj in injectable) + { + injectableConstructors.Add(SerializeConstructorDef(inj)); + } + + IList<ClassHierarchyProto.ConstructorDef> otherConstructors = new List<ClassHierarchyProto.ConstructorDef>(); + foreach (IConstructorDef other in others) + { + otherConstructors.Add(SerializeConstructorDef(other)); + } + + List<string> implFullNames = new List<string>(); + foreach (IClassNode impl in cn.GetKnownImplementations()) + { + implFullNames.Add(impl.GetFullName()); //we use class fully qualifed name + } + + return NewClassNode(cn.GetName(), cn.GetFullName(), + cn.IsInjectionCandidate(), cn.IsExternalConstructor(), cn.IsUnit(), + injectableConstructors, otherConstructors, implFullNames, children); + } + if (n is INamedParameterNode) + { + INamedParameterNode np = (INamedParameterNode)n; + return NewNamedParameterNode(np.GetName(), np.GetFullName(), + np.GetSimpleArgName(), np.GetFullArgName(), np.IsSet(), np.IsList(), np.GetDocumentation(), + np.GetShortName(), np.GetDefaultInstanceAsStrings(), children); + } + if (n is IPackageNode) + { + return NewPackageNode(n.GetName(), n.GetFullName(), children); + } + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Encountered unknown type of Node: " + n), LOGGER); + return null; + } + + private static ClassHierarchyProto.ConstructorDef SerializeConstructorDef(IConstructorDef def) + { + IList<ClassHierarchyProto.ConstructorArg> args = new List<ClassHierarchyProto.ConstructorArg>(); + foreach (IConstructorArg arg in def.GetArgs()) + { + args.Add(NewConstructorArg(arg.Gettype(), arg.GetNamedParameterName(), arg.IsInjectionFuture())); + } + return newConstructorDef(def.GetClassName(), args); + } + + private static ClassHierarchyProto.ConstructorArg NewConstructorArg( + string fullArgClassName, string namedParameterName, bool isFuture) + { + ClassHierarchyProto.ConstructorArg constArg = new ClassHierarchyProto.ConstructorArg(); + constArg.full_arg_class_name = fullArgClassName; + constArg.named_parameter_name = namedParameterName; + constArg.is_injection_future = isFuture; + return constArg; + } + + private static ClassHierarchyProto.ConstructorDef newConstructorDef( + String fullClassName, IList<ClassHierarchyProto.ConstructorArg> args) + { + ClassHierarchyProto.ConstructorDef constDef = new ClassHierarchyProto.ConstructorDef(); + constDef.full_class_name = fullClassName; + foreach (ClassHierarchyProto.ConstructorArg arg in args) + { + constDef.args.Add(arg); + } + + return constDef; + } + + private static ClassHierarchyProto.Node NewClassNode(String name, + String fullName, bool isInjectionCandidate, + bool isExternalConstructor, bool isUnit, + IList<ClassHierarchyProto.ConstructorDef> injectableConstructors, + IList<ClassHierarchyProto.ConstructorDef> otherConstructors, + IList<String> implFullNames, IList<ClassHierarchyProto.Node> children) + { + ClassHierarchyProto.ClassNode classNode = new ClassHierarchyProto.ClassNode(); + classNode.is_injection_candidate = isInjectionCandidate; + foreach (var ic in injectableConstructors) + { + classNode.InjectableConstructors.Add(ic); + } + + foreach (var oc in otherConstructors) + { + classNode.OtherConstructors.Add(oc); + } + foreach (var implFullName in implFullNames) + { + classNode.impl_full_names.Add(implFullName); + } + + ClassHierarchyProto.Node n = new ClassHierarchyProto.Node(); + n.name = name; + n.full_name = fullName; + n.class_node = classNode; + + foreach (var c in children) + { + n.children.Add(c); + } + + return n; + } + + private static ClassHierarchyProto.Node NewNamedParameterNode(string name, + string fullName, string simpleArgClassName, string fullArgClassName, + bool isSet, bool isList, string documentation, // can be null + string shortName, // can be null + string[] instanceDefault, // can be null + IList<ClassHierarchyProto.Node> children) + { + ClassHierarchyProto.NamedParameterNode namedParameterNode = new ClassHierarchyProto.NamedParameterNode(); + namedParameterNode.simple_arg_class_name = simpleArgClassName; + namedParameterNode.full_arg_class_name = fullArgClassName; + namedParameterNode.is_set = isSet; + namedParameterNode.is_list = isList; + + if (documentation != null) + { + namedParameterNode.documentation = documentation; + } + + if (shortName != null) + { + namedParameterNode.short_name = shortName; + } + + foreach (var id in instanceDefault) + { + namedParameterNode.instance_default.Add(id); + } + + ClassHierarchyProto.Node n = new ClassHierarchyProto.Node(); + n.name = name; + n.full_name = fullName; + n.named_parameter_node = namedParameterNode; + + foreach (var c in children) + { + n.children.Add(c); + } + + return n; + } + + private static ClassHierarchyProto.Node NewPackageNode(string name, + string fullName, IList<ClassHierarchyProto.Node> children) + { + ClassHierarchyProto.PackageNode packageNode = new ClassHierarchyProto.PackageNode(); + ClassHierarchyProto.Node n = new ClassHierarchyProto.Node(); + n.name = name; + n.full_name = fullName; + n.package_node = packageNode; + + foreach (var c in children) + { + n.children.Add(c); + } + + return n; + } + + public static IClassHierarchy DeSerialize(string fileName) + { + ClassHierarchyProto.Node root; + + using (var file = File.OpenRead(fileName)) + { + root = Serializer.Deserialize<ClassHierarchyProto.Node>(file); + } + + return new ProtocolBufferClassHierarchy(root); + } + + public ProtocolBufferClassHierarchy() //create a ProtocolBufferClassHierarchy with empty nodes and lookup table. It can be used to merge other class hierarchy to it + { + this.rootNode = new PackageNodeImpl(); + } + + public ProtocolBufferClassHierarchy(ClassHierarchyProto.Node root) + { + this.rootNode = new PackageNodeImpl(); + if (root.package_node == null) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ArgumentException("Expected a package node. Got: " + root), LOGGER); + } + // Register all the classes. + foreach (ClassHierarchyProto.Node child in root.children) + { + ParseSubHierarchy(rootNode, child); + } + + BuildHashTable(rootNode); + + foreach (ClassHierarchyProto.Node child in root.children) + { + WireUpInheritanceRelationships(child); + } + } + + public void BuildHashTable(INode n) + { + foreach (INode child in n.GetChildren()) + { + lookupTable.Add(child.GetFullName(), child); + BuildHashTable(child); + } + } + + private static void ParseSubHierarchy(INode parent, ClassHierarchyProto.Node n) + { + INode parsed = null; + if (n.package_node != null) + { + parsed = new PackageNodeImpl(parent, n.name, n.full_name); + } + else if (n.named_parameter_node != null) + { + ClassHierarchyProto.NamedParameterNode np = n.named_parameter_node; + parsed = new NamedParameterNodeImpl(parent, n.name, + n.full_name, np.full_arg_class_name, np.simple_arg_class_name, + np.is_set, np.is_list, np.documentation, np.short_name, + np.instance_default.ToArray()); + } + else if (n.class_node != null) + { + ClassHierarchyProto.ClassNode cn = n.class_node; + IList<IConstructorDef> injectableConstructors = new List<IConstructorDef>(); + IList<IConstructorDef> allConstructors = new List<IConstructorDef>(); + + foreach (ClassHierarchyProto.ConstructorDef injectable in cn.InjectableConstructors) + { + IConstructorDef def = ParseConstructorDef(injectable, true); + injectableConstructors.Add(def); + allConstructors.Add(def); + } + foreach (ClassHierarchyProto.ConstructorDef other in cn.OtherConstructors) + { + IConstructorDef def = ParseConstructorDef(other, false); + allConstructors.Add(def); + + } + + IConstructorDef[] dummy = new ConstructorDefImpl[0]; + parsed = new ClassNodeImpl(parent, n.name, n.full_name, + cn.is_unit, cn.is_injection_candidate, + cn.is_external_constructor, injectableConstructors, + allConstructors, cn.default_implementation); + } + else + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Bad protocol buffer: got abstract node" + n), LOGGER); + } + + foreach (ClassHierarchyProto.Node child in n.children) + { + ParseSubHierarchy(parsed, child); + } + } + + private static IConstructorDef ParseConstructorDef(ClassHierarchyProto.ConstructorDef def, bool isInjectable) + { + IList<IConstructorArg> args = new List<IConstructorArg>(); + foreach (ClassHierarchyProto.ConstructorArg arg in def.args) + { + args.Add(new ConstructorArgImpl(arg.full_arg_class_name, arg.named_parameter_name, arg.is_injection_future)); + } + return new ConstructorDefImpl(def.full_class_name, args.ToArray(), isInjectable); + } + + private void WireUpInheritanceRelationships(ClassHierarchyProto.Node n) + { + if (n.class_node != null) + { + ClassHierarchyProto.ClassNode cn = n.class_node; + IClassNode iface = null; + try + { + iface = (IClassNode)GetNode(n.full_name); + } + catch (NameResolutionException e) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER); + var ex = new IllegalStateException("When reading protocol buffer node " + + n.full_name + " does not exist. Full record is " + n, e); + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + } + foreach (String impl in cn.impl_full_names) + { + try + { + iface.PutImpl((IClassNode)GetNode(impl)); + } + catch (NameResolutionException e) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER); + var ex = new IllegalStateException("When reading protocol buffer node " + + n + " refers to non-existent implementation:" + impl); + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + + } + catch (InvalidCastException e) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER); + try + { + var ex = new IllegalStateException( + "When reading protocol buffer node " + n + + " found implementation" + GetNode(impl) + + " which is not a ClassNode!"); + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + } + catch (NameResolutionException ne) + { + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(ne, Level.Error, LOGGER); + var ex = new IllegalStateException( + "Got 'cant happen' exception when producing error message for " + e); + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + } + } + } + } + } + + public INode GetNode(String fullName) + { + INode ret; + lookupTable.TryGetValue(fullName, out ret); + if (ret == null) + { + var ex = new NameResolutionException(fullName, "Cannot resolve the name from the class hierarchy during deserialization: " + fullName); + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER); + } + return ret; + } + + public INode GetNamespace() + { + return rootNode; + } + + public bool IsImplementation(IClassNode inter, IClassNode impl) + { + return impl.IsImplementationOf(inter); + } + + 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; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferInjectionPlan.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferInjectionPlan.cs b/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferInjectionPlan.cs new file mode 100644 index 0000000..3bab994 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Protobuf/ProtocolBufferInjectionPlan.cs @@ -0,0 +1,205 @@ +/** + * 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. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Org.Apache.REEF.Utilities.Logging; +using Org.Apache.REEF.Tang.Exceptions; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Types; +using ProtoBuf; +using Org.Apache.REEF.Tang.Implementations.InjectionPlan; + +namespace Org.Apache.REEF.Tang.Protobuf +{ + public class ProtocolBufferInjectionPlan + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(ProtocolBufferInjectionPlan)); + + private static InjectionPlanProto.InjectionPlan NewConstructor(string fullName, List<InjectionPlanProto.InjectionPlan> plans) + { + InjectionPlanProto.Constructor cconstr = new InjectionPlanProto.Constructor(); + foreach (InjectionPlanProto.InjectionPlan p in plans) + { + cconstr.args.Add(p); + } + + InjectionPlanProto.InjectionPlan plan = new InjectionPlanProto.InjectionPlan(); + plan.name = fullName; + plan.constructor = cconstr; + return plan; + } + + private static InjectionPlanProto.InjectionPlan NewSubplan(string fullName, int selectedPlan, List<InjectionPlanProto.InjectionPlan> plans) + { + InjectionPlanProto.Subplan subPlan = new InjectionPlanProto.Subplan(); + + subPlan.selected_plan = selectedPlan; + foreach (InjectionPlanProto.InjectionPlan p in plans) + { + subPlan.plans.Add(p); + } + + InjectionPlanProto.InjectionPlan plan = new InjectionPlanProto.InjectionPlan(); + plan.name = fullName; + plan.subplan = subPlan; + return plan; + } + + private static InjectionPlanProto.InjectionPlan NewInstance(string fullName, string value) + { + InjectionPlanProto.Instance instance = new InjectionPlanProto.Instance(); + instance.value = value; + + InjectionPlanProto.InjectionPlan plan = new InjectionPlanProto.InjectionPlan(); + plan.name = fullName; + plan.instance = instance; + return plan; + + } + + public static void Serialize(string fileName, InjectionPlan ip) + { + InjectionPlanProto.InjectionPlan plan = Serialize(ip); + + using (var file = File.Create(fileName)) + { + Serializer.Serialize<InjectionPlanProto.InjectionPlan>(file, plan); + } + } + + public static InjectionPlanProto.InjectionPlan Serialize(InjectionPlan ip) + { + if (ip is Constructor) + { + Constructor cons = (Constructor) ip; + InjectionPlan[] args = cons.GetArgs(); + InjectionPlanProto.InjectionPlan[] protoArgs = new InjectionPlanProto.InjectionPlan[args.Length]; + for (int i = 0; i < args.Length; i++) + { + protoArgs[i] = Serialize(args[i]); + } + return NewConstructor(ip.GetNode().GetFullName(), protoArgs.ToList<InjectionPlanProto.InjectionPlan>()); + } + if (ip is Subplan) + { + Subplan sp = (Subplan) ip; + InjectionPlan[] args = sp.GetPlans(); + InjectionPlanProto.InjectionPlan[] subPlans = new InjectionPlanProto.InjectionPlan[args.Length]; + for (int i = 0; i < args.Length; i++) + { + subPlans[i] = Serialize(args[i]); + } + return NewSubplan(ip.GetNode().GetFullName(), sp.GetSelectedIndex(), subPlans.ToList<InjectionPlanProto.InjectionPlan>()); + + } + if (ip is CsInstance) + { + CsInstance ji = (CsInstance) ip; + return NewInstance(ip.GetNode().GetFullName(), ji.GetInstanceAsString()); + } + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException( + "Encountered unknown type of InjectionPlan: " + ip), LOGGER); + return null; + } + + public static InjectionPlan DeSerialize(string fileName, IClassHierarchy ch) + { + InjectionPlanProto.InjectionPlan protoPlan; + + using (var file = File.OpenRead(fileName)) + { + protoPlan = Serializer.Deserialize<InjectionPlanProto.InjectionPlan>(file); + } + + return Deserialize(ch, protoPlan); + } + + public static InjectionPlan Deserialize(IClassHierarchy ch, InjectionPlanProto.InjectionPlan ip) + { + string fullName = ip.name; + if (ip.constructor != null) + { + InjectionPlanProto.Constructor cons = ip.constructor; + IClassNode cn = (IClassNode) ch.GetNode(fullName); + + InjectionPlanProto.InjectionPlan[] protoBufArgs = cons.args.ToArray(); + + IClassNode[] cnArgs = new IClassNode[protoBufArgs.Length]; + + for (int i = 0; i < protoBufArgs.Length; i++) + { + INode no = ch.GetNode(protoBufArgs[i].name); + if (no is IClassNode) + { + cnArgs[i] = (IClassNode)no; + } + else if (no is INamedParameterNode) + { + INamedParameterNode np = (INamedParameterNode)no; + cnArgs[i] = (IClassNode)ch.GetNode(np.GetFullArgName()); + } + } + + InjectionPlan[] ipArgs = new InjectionPlan[protoBufArgs.Length]; + + for (int i = 0; i < protoBufArgs.Length; i++) + { + ipArgs[i] = (InjectionPlan) Deserialize(ch, protoBufArgs[i]); + } + + IConstructorDef constructor = cn.GetConstructorDef(cnArgs); + return new Constructor(cn, constructor, ipArgs); + } + if (ip.instance != null) + { + InjectionPlanProto.Instance ins = ip.instance; + object instance = Parse(ip.name, ins.value); + return new CsInstance(ch.GetNode(ip.name), instance); + } + if (ip.subplan != null) + { + InjectionPlanProto.Subplan subplan = ip.subplan; + InjectionPlanProto.InjectionPlan[] protoBufPlans = subplan.plans.ToArray(); + + InjectionPlan[] subPlans = new InjectionPlan[protoBufPlans.Length]; + for (int i = 0; i < protoBufPlans.Length; i++) + { + subPlans[i] = (InjectionPlan) Deserialize(ch, protoBufPlans[i]); + } + INode n = ch.GetNode(fullName); + return new Subplan(n, subPlans); + } + Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException("Encountered unknown type of InjectionPlan: " + ip), LOGGER); + return null; + } + + private static object Parse(String type, String value) + { + // XXX this is a placeholder for now. We need a parser API that will + // either produce a live java object or (partially) validate stuff to + // see if it looks like the target language will be able to handle this + // type + value. + return value; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Protobuf/class_hierarchy.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Protobuf/class_hierarchy.cs b/lang/cs/Org.Apache.REEF.Tang/Protobuf/class_hierarchy.cs new file mode 100644 index 0000000..62ffa08 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Protobuf/class_hierarchy.cs @@ -0,0 +1,274 @@ +/** + * 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. + */ + +//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +// Generated from: class_hierarchy.proto +namespace ClassHierarchyProto +{ + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"Node")] + public partial class Node : global::ProtoBuf.IExtensible + { + public Node() {} + + private string _name; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string name + { + get { return _name; } + set { _name = value; } + } + private string _full_name; + [global::ProtoBuf.ProtoMember(2, IsRequired = true, Name=@"full_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string full_name + { + get { return _full_name; } + set { _full_name = value; } + } + private ClassNode _class_node = null; + [global::ProtoBuf.ProtoMember(3, IsRequired = false, Name=@"class_node", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue(null)] + public ClassNode class_node + { + get { return _class_node; } + set { _class_node = value; } + } + private NamedParameterNode _named_parameter_node = null; + [global::ProtoBuf.ProtoMember(4, IsRequired = false, Name=@"named_parameter_node", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue(null)] + public NamedParameterNode named_parameter_node + { + get { return _named_parameter_node; } + set { _named_parameter_node = value; } + } + private PackageNode _package_node = null; + [global::ProtoBuf.ProtoMember(5, IsRequired = false, Name=@"package_node", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue(null)] + public PackageNode package_node + { + get { return _package_node; } + set { _package_node = value; } + } + private readonly global::System.Collections.Generic.List<Node> _children = new global::System.Collections.Generic.List<Node>(); + [global::ProtoBuf.ProtoMember(6, Name=@"children", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<Node> children + { + get { return _children; } + } + + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"ClassNode")] + public partial class ClassNode : global::ProtoBuf.IExtensible + { + public ClassNode() {} + + private bool _is_injection_candidate; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"is_injection_candidate", DataFormat = global::ProtoBuf.DataFormat.Default)] + public bool is_injection_candidate + { + get { return _is_injection_candidate; } + set { _is_injection_candidate = value; } + } + private bool _is_external_constructor; + [global::ProtoBuf.ProtoMember(2, IsRequired = true, Name=@"is_external_constructor", DataFormat = global::ProtoBuf.DataFormat.Default)] + public bool is_external_constructor + { + get { return _is_external_constructor; } + set { _is_external_constructor = value; } + } + private bool _is_unit; + [global::ProtoBuf.ProtoMember(3, IsRequired = true, Name=@"is_unit", DataFormat = global::ProtoBuf.DataFormat.Default)] + public bool is_unit + { + get { return _is_unit; } + set { _is_unit = value; } + } + private readonly global::System.Collections.Generic.List<ConstructorDef> _InjectableConstructors = new global::System.Collections.Generic.List<ConstructorDef>(); + [global::ProtoBuf.ProtoMember(4, Name=@"InjectableConstructors", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<ConstructorDef> InjectableConstructors + { + get { return _InjectableConstructors; } + } + + private readonly global::System.Collections.Generic.List<ConstructorDef> _OtherConstructors = new global::System.Collections.Generic.List<ConstructorDef>(); + [global::ProtoBuf.ProtoMember(5, Name=@"OtherConstructors", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<ConstructorDef> OtherConstructors + { + get { return _OtherConstructors; } + } + + private readonly global::System.Collections.Generic.List<string> _impl_full_names = new global::System.Collections.Generic.List<string>(); + [global::ProtoBuf.ProtoMember(6, Name=@"impl_full_names", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<string> impl_full_names + { + get { return _impl_full_names; } + } + + private string _default_implementation = ""; + [global::ProtoBuf.ProtoMember(7, IsRequired = false, Name=@"default_implementation", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue("")] + public string default_implementation + { + get { return _default_implementation; } + set { _default_implementation = value; } + } + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"NamedParameterNode")] + public partial class NamedParameterNode : global::ProtoBuf.IExtensible + { + public NamedParameterNode() {} + + private string _simple_arg_class_name; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"simple_arg_class_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string simple_arg_class_name + { + get { return _simple_arg_class_name; } + set { _simple_arg_class_name = value; } + } + private string _full_arg_class_name; + [global::ProtoBuf.ProtoMember(2, IsRequired = true, Name=@"full_arg_class_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string full_arg_class_name + { + get { return _full_arg_class_name; } + set { _full_arg_class_name = value; } + } + private bool _is_set; + [global::ProtoBuf.ProtoMember(3, IsRequired = true, Name=@"is_set", DataFormat = global::ProtoBuf.DataFormat.Default)] + public bool is_set + { + get { return _is_set; } + set { _is_set = value; } + } + private bool _is_list; + [global::ProtoBuf.ProtoMember(4, IsRequired = true, Name=@"is_list", DataFormat = global::ProtoBuf.DataFormat.Default)] + public bool is_list + { + get { return _is_list; } + set { _is_list = value; } + } + private string _documentation = ""; + [global::ProtoBuf.ProtoMember(5, IsRequired = false, Name=@"documentation", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue("")] + public string documentation + { + get { return _documentation; } + set { _documentation = value; } + } + private string _short_name = ""; + [global::ProtoBuf.ProtoMember(6, IsRequired = false, Name=@"short_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue("")] + public string short_name + { + get { return _short_name; } + set { _short_name = value; } + } + private readonly global::System.Collections.Generic.List<string> _instance_default = new global::System.Collections.Generic.List<string>(); + [global::ProtoBuf.ProtoMember(7, Name=@"instance_default", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<string> instance_default + { + get { return _instance_default; } + } + + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"PackageNode")] + public partial class PackageNode : global::ProtoBuf.IExtensible + { + public PackageNode() {} + + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"ConstructorDef")] + public partial class ConstructorDef : global::ProtoBuf.IExtensible + { + public ConstructorDef() {} + + private string _full_class_name; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"full_class_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string full_class_name + { + get { return _full_class_name; } + set { _full_class_name = value; } + } + private readonly global::System.Collections.Generic.List<ConstructorArg> _args = new global::System.Collections.Generic.List<ConstructorArg>(); + [global::ProtoBuf.ProtoMember(2, Name=@"args", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<ConstructorArg> args + { + get { return _args; } + } + + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"ConstructorArg")] + public partial class ConstructorArg : global::ProtoBuf.IExtensible + { + public ConstructorArg() {} + + private string _full_arg_class_name; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"full_arg_class_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string full_arg_class_name + { + get { return _full_arg_class_name; } + set { _full_arg_class_name = value; } + } + private string _named_parameter_name = ""; + [global::ProtoBuf.ProtoMember(2, IsRequired = false, Name=@"named_parameter_name", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue("")] + public string named_parameter_name + { + get { return _named_parameter_name; } + set { _named_parameter_name = value; } + } + private bool _is_injection_future; + [global::ProtoBuf.ProtoMember(3, IsRequired = true, Name=@"is_injection_future", DataFormat = global::ProtoBuf.DataFormat.Default)] + public bool is_injection_future + { + get { return _is_injection_future; } + set { _is_injection_future = value; } + } + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Protobuf/injection_plan.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Protobuf/injection_plan.cs b/lang/cs/Org.Apache.REEF.Tang/Protobuf/injection_plan.cs new file mode 100644 index 0000000..d7a30dc --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Protobuf/injection_plan.cs @@ -0,0 +1,132 @@ +/** + * 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. + */ + +//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +// Generated from: injection_plan.proto +namespace InjectionPlanProto +{ + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name = @"InjectionPlan")] + public partial class InjectionPlan : global::ProtoBuf.IExtensible + { + public InjectionPlan() { } + + private string _name; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name = @"name", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string name + { + get { return _name; } + set { _name = value; } + } + private Constructor _constructor = null; + [global::ProtoBuf.ProtoMember(2, IsRequired = false, Name = @"constructor", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue(null)] + public Constructor constructor + { + get { return _constructor; } + set { _constructor = value; } + } + private Instance _instance = null; + [global::ProtoBuf.ProtoMember(3, IsRequired = false, Name = @"instance", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue(null)] + public Instance instance + { + get { return _instance; } + set { _instance = value; } + } + private Subplan _subplan = null; + [global::ProtoBuf.ProtoMember(4, IsRequired = false, Name = @"subplan", DataFormat = global::ProtoBuf.DataFormat.Default)] + [global::System.ComponentModel.DefaultValue(null)] + public Subplan subplan + { + get { return _subplan; } + set { _subplan = value; } + } + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name = @"Subplan")] + public partial class Subplan : global::ProtoBuf.IExtensible + { + public Subplan() { } + + private int _selected_plan = default(int); + [global::ProtoBuf.ProtoMember(1, IsRequired = false, Name = @"selected_plan", DataFormat = global::ProtoBuf.DataFormat.ZigZag)] + [global::System.ComponentModel.DefaultValue(default(int))] + public int selected_plan + { + get { return _selected_plan; } + set { _selected_plan = value; } + } + private readonly global::System.Collections.Generic.List<InjectionPlan> _plans = new global::System.Collections.Generic.List<InjectionPlan>(); + [global::ProtoBuf.ProtoMember(2, Name = @"plans", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<InjectionPlan> plans + { + get { return _plans; } + } + + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name = @"Constructor")] + public partial class Constructor : global::ProtoBuf.IExtensible + { + public Constructor() { } + + private readonly global::System.Collections.Generic.List<InjectionPlan> _args = new global::System.Collections.Generic.List<InjectionPlan>(); + [global::ProtoBuf.ProtoMember(1, Name = @"args", DataFormat = global::ProtoBuf.DataFormat.Default)] + public global::System.Collections.Generic.List<InjectionPlan> args + { + get { return _args; } + } + + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + + [global::System.Serializable, global::ProtoBuf.ProtoContract(Name = @"Instance")] + public partial class Instance : global::ProtoBuf.IExtensible + { + public Instance() { } + + private string _value; + [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name = @"value", DataFormat = global::ProtoBuf.DataFormat.Default)] + public string value + { + get { return _value; } + set { _value = value; } + } + private global::ProtoBuf.IExtension extensionObject; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Types/IClassNode.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Types/IClassNode.cs b/lang/cs/Org.Apache.REEF.Tang/Types/IClassNode.cs new file mode 100644 index 0000000..478d2ab --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Types/IClassNode.cs @@ -0,0 +1,37 @@ +/** + * 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. + */ +using System.Collections.Generic; + +namespace Org.Apache.REEF.Tang.Types +{ + public interface IClassNode : INode + { + IList<IConstructorDef> GetInjectableConstructors(); + IConstructorDef GetConstructorDef(IList<IClassNode> args); + IList<IConstructorDef> GetAllConstructors(); + + void PutImpl(IClassNode impl); + ISet<IClassNode> GetKnownImplementations(); + string GetDefaultImplementation(); + bool IsUnit(); + bool IsInjectionCandidate(); + bool IsExternalConstructor(); + bool IsImplementationOf(IClassNode inter); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorArg.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorArg.cs b/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorArg.cs new file mode 100644 index 0000000..d77b139 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorArg.cs @@ -0,0 +1,32 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Tang.Types +{ + public interface IConstructorArg + { + string GetName(); + + string Gettype(); + + bool IsInjectionFuture(); + + string GetNamedParameterName(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorDef.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorDef.cs b/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorDef.cs new file mode 100644 index 0000000..606381f --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Types/IConstructorDef.cs @@ -0,0 +1,34 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Tang.Types +{ + public interface IConstructorDef : IComparable + { + string GetClassName(); + + IList<IConstructorArg> GetArgs(); + + bool IsMoreSpecificThan(IConstructorDef def); + + bool TakesParameters(IList<IClassNode> paramTypes); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang/Types/INamedParameterNode.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang/Types/INamedParameterNode.cs b/lang/cs/Org.Apache.REEF.Tang/Types/INamedParameterNode.cs new file mode 100644 index 0000000..cf4aa02 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang/Types/INamedParameterNode.cs @@ -0,0 +1,38 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Tang.Types +{ + public interface INamedParameterNode : INode + { + string GetDocumentation(); + + string GetShortName(); + + string[] GetDefaultInstanceAsStrings(); + + string GetSimpleArgName(); + + string GetFullArgName(); + + bool IsSet(); + + bool IsList(); + } +}
