PageRenderTime 426ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/org.xkonnex.repo.generator.bindingdsl/src/org/xkonnex/repo/generator/bindingdsl/DefaultBindingContractGeneratorSetup.java

https://github.com/andrearn/org.fornax.soa.xtextservicerepository
Java | 258 lines | 200 code | 58 blank | 0 comment | 0 complexity | 304639c5559119f3a07ce7c757ce0a45 MD5 | raw file
  1. package org.xkonnex.repo.generator.bindingdsl;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Map;
  5. import org.eclipse.xtext.ISetup;
  6. import org.eclipse.xtext.generator.IFileSystemAccess;
  7. import org.eclipse.xtext.generator.IGenerator;
  8. import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
  9. import org.eclipse.xtext.generator.OutputConfiguration;
  10. import org.eclipse.xtext.util.Modules2;
  11. import org.xkonnex.repo.generator.moduledsl.ModuleDslGeneratorModule;
  12. import org.xkonnex.repo.generator.moduledsl.VersionedModuleSelector;
  13. import org.xkonnex.repo.generator.profiledsl.ProfileDslGeneratorModule;
  14. import org.xkonnex.repo.generator.profiledsl.ProfileGeneratorConstants;
  15. import org.xkonnex.repo.generator.core.XSRGeneratorConstants;
  16. import org.xkonnex.repo.generator.core.XSRGeneratorModule;
  17. import org.xkonnex.repo.dsl.profiledsl.scoping.versions.ILifecycleStateResolver;
  18. import org.xkonnex.repo.dsl.profiledsl.state.DefaultStateResolver;
  19. import org.xkonnex.repo.generator.environmentdsl.EnvironmentDslGeneratorModule;
  20. import org.xkonnex.repo.generator.basedsl.BaseDslGeneratorModule;
  21. import org.xkonnex.repo.generator.bindingdsl.templates.IProtocolContractBuilder;
  22. import org.xkonnex.repo.generator.servicedsl.ServiceDslGeneratorModule;
  23. import com.google.common.collect.Maps;
  24. import com.google.inject.AbstractModule;
  25. import com.google.inject.Guice;
  26. import com.google.inject.Injector;
  27. import com.google.inject.TypeLiteral;
  28. import com.google.inject.name.Names;
  29. public class DefaultBindingContractGeneratorSetup implements ISetup {
  30. private String profileName = "";
  31. private List<String> moduleBindingNames = new ArrayList<String>();
  32. private List<VersionedModuleSelector> modules = new ArrayList<VersionedModuleSelector>();
  33. private List<ModuleBindingSelector> moduleBindings = new ArrayList<ModuleBindingSelector>();
  34. private List<String> namespaces = new ArrayList<String>();
  35. private List<String> domainNamespaces = new ArrayList<String>();
  36. private List<String> internalNamespaces = new ArrayList<String>();
  37. private Boolean noDependencies = false;
  38. private Boolean includeSubNamespaces = false;
  39. private Boolean useNestedPaths = false;
  40. private Boolean useRegistryBasedFilePaths = false;
  41. private String targetEnvironmentName = "*";
  42. private Boolean ignoreEndpointQualifierNames = false;
  43. public Injector createInjectorAndDoEMFRegistration() {
  44. Injector injector = Guice.createInjector (Modules2.mixin (
  45. new BaseDslGeneratorModule (),
  46. new ServiceDslGeneratorModule (),
  47. new EnvironmentDslGeneratorModule (),
  48. new ModuleDslGeneratorModule (),
  49. new ProfileDslGeneratorModule (),
  50. new BindingDslGeneratorModule (),
  51. new XSRGeneratorModule (),
  52. new AbstractModule () {
  53. @Override
  54. protected void configure () {
  55. bind (IGenerator.class).to (
  56. DefaultBindingContractGenerators.class);
  57. bind (Boolean.class)
  58. .annotatedWith (
  59. Names.named (XSRGeneratorConstants.USE_REGISTRY_BASED_FILE_PATHS))
  60. .toInstance (useRegistryBasedFilePaths);
  61. bind (Boolean.class)
  62. .annotatedWith (
  63. Names.named (XSRGeneratorConstants.USE_NESTED_PATHS))
  64. .toInstance (useNestedPaths);
  65. bind (new TypeLiteral<List<String>>() {})
  66. .annotatedWith (
  67. Names.named (BindingDSLGeneratorConstants.MODULE_BINDING_NAMES))
  68. .toInstance (moduleBindingNames);
  69. bind (new TypeLiteral<List<ModuleBindingSelector>>() {})
  70. .annotatedWith (
  71. Names.named (BindingDSLGeneratorConstants.MODULE_BINDINGS))
  72. .toInstance (getModuleBindings());
  73. bind (new TypeLiteral<List<VersionedModuleSelector>>() {})
  74. .annotatedWith (
  75. Names.named (BindingDSLGeneratorConstants.MODULES))
  76. .toInstance (modules);
  77. bind (new TypeLiteral<List<String>>() {})
  78. .annotatedWith (
  79. Names.named (BindingDSLGeneratorConstants.NAME_SPACES))
  80. .toInstance (namespaces);
  81. bind (new TypeLiteral<List<String>>() {})
  82. .annotatedWith (
  83. Names.named (BindingDSLGeneratorConstants.DOMAIN_NAME_SPACES))
  84. .toInstance (getDomainNamespaces());
  85. bind (new TypeLiteral<List<String>>() {})
  86. .annotatedWith (
  87. Names.named (BindingDSLGeneratorConstants.INTERNAL_NAME_SPACES))
  88. .toInstance (getInternalNamespaces());
  89. bind (Boolean.class)
  90. .annotatedWith (
  91. Names.named (BindingDSLGeneratorConstants.NO_DEPENDENCIES))
  92. .toInstance (noDependencies);
  93. bind (Boolean.class)
  94. .annotatedWith (
  95. Names.named (BindingDSLGeneratorConstants.INCLUDE_SUB_NAMESPACES))
  96. .toInstance (includeSubNamespaces);
  97. bind (String.class)
  98. .annotatedWith (
  99. Names.named (BindingDSLGeneratorConstants.TARGET_ENVIRONMENT_NAME))
  100. .toInstance (getTargetEnvironmentName ());
  101. bind (String.class)
  102. .annotatedWith (
  103. Names.named (BindingDSLGeneratorConstants.PROFILE_NAME))
  104. .toInstance (getProfileName ());
  105. bind (Boolean.class)
  106. .annotatedWith (
  107. Names.named (BindingDSLGeneratorConstants.IGNORE_ENDPOINT_QUALIFIER_NAMES))
  108. .toInstance (ignoreEndpointQualifierNames);
  109. JavaIoFileSystemAccess fileSystemAccess = new JavaIoFileSystemAccess ();
  110. OutputConfiguration out = new OutputConfiguration ("DEFAULT_OUTPUT");
  111. Map<String, OutputConfiguration> outputs = Maps.newHashMap ();
  112. outputs.put ("DEFAULT_OUTPUT", out);
  113. fileSystemAccess.setOutputConfigurations (outputs);
  114. bind (IFileSystemAccess.class).toInstance (fileSystemAccess);
  115. bind (JavaIoFileSystemAccess.class).toInstance (fileSystemAccess);
  116. bind (ILifecycleStateResolver.class).to(DefaultStateResolver.class);
  117. }
  118. }));
  119. return injector;
  120. }
  121. public String getProfileName () {
  122. return profileName;
  123. }
  124. public void setProfileName (String profileName) {
  125. this.profileName = profileName;
  126. }
  127. public List<String> getModuleBindingNames () {
  128. return moduleBindingNames;
  129. }
  130. public void addModuleBindingName (String moduleBindingName) {
  131. moduleBindingNames.add (moduleBindingName);
  132. }
  133. public List<VersionedModuleSelector> getServiceModules () {
  134. return modules;
  135. }
  136. public void addServiceModule (VersionedModuleSelector module) {
  137. modules.add (module);
  138. }
  139. public void addNamespace (String namespaceName) {
  140. namespaces.add (namespaceName);
  141. }
  142. public List<String> getNamespaces () {
  143. return namespaces;
  144. }
  145. public Boolean getNoDependencies () {
  146. return noDependencies;
  147. }
  148. public void setNoDependencies (Boolean noDependencies) {
  149. this.noDependencies = noDependencies;
  150. }
  151. public Boolean getIncludeSubNamespaces () {
  152. return includeSubNamespaces;
  153. }
  154. public void setIncludeSubNamespaces (Boolean includeSubNamespaces) {
  155. this.includeSubNamespaces = includeSubNamespaces;
  156. }
  157. public Boolean getUseNestedPaths () {
  158. return useNestedPaths;
  159. }
  160. public void setUseNestedPaths (Boolean useNestedPaths) {
  161. this.useNestedPaths = useNestedPaths;
  162. }
  163. public Boolean getUseRegistryBasedFilePaths () {
  164. return useRegistryBasedFilePaths;
  165. }
  166. public void setUseRegistryBasedFilePaths (Boolean useRegistryBasedFilePaths) {
  167. this.useRegistryBasedFilePaths = useRegistryBasedFilePaths;
  168. }
  169. public void setTargetEnvironmentName (String environmentName) {
  170. this.targetEnvironmentName = environmentName;
  171. }
  172. public String getTargetEnvironmentName () {
  173. return targetEnvironmentName;
  174. }
  175. public void addDomainNamespace(String domainNamespace) {
  176. this.domainNamespaces.add (domainNamespace);
  177. }
  178. public List<String> getDomainNamespaces() {
  179. return domainNamespaces;
  180. }
  181. public void addInternalNamespace(String internalNamespace) {
  182. this.internalNamespaces.add (internalNamespace);
  183. }
  184. public List<String> getInternalNamespaces() {
  185. return internalNamespaces;
  186. }
  187. public Boolean getIgnoreEndpointQualifierNames() {
  188. return ignoreEndpointQualifierNames;
  189. }
  190. public void setIgnoreEndpointQualifierNames(
  191. Boolean ignoreEndpointQualifierNames) {
  192. this.ignoreEndpointQualifierNames = ignoreEndpointQualifierNames;
  193. }
  194. public List<ModuleBindingSelector> getModuleBindings() {
  195. return moduleBindings;
  196. }
  197. public void addModuleBindings(ModuleBindingSelector moduleBinding) {
  198. this.moduleBindings.add (moduleBinding);
  199. }
  200. }