PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/initial/nof/retired/ejb/no-ejb-appclient/appClientModule/org/apache/isis/system/ejb/NakedObjects.java

#
Java | 189 lines | 124 code | 34 blank | 31 comment | 26 complexity | 13bc0f189fa243ed05a66acce51eff50 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, LGPL-2.1, BSD-3-Clause, Apache-2.0, GPL-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.apache.isis.system.ejb;
  20. import org.apache.isis.object.context.StaticContext;
  21. import org.apache.isis.object.context.ThreadContext;
  22. import org.apache.isis.object.help.HelpManagerAssist;
  23. import org.apache.isis.object.help.HelpPeerFactory;
  24. import org.apache.isis.object.help.SimpleHelpManager;
  25. import org.apache.isis.object.security.JbossJaasAuthenticator;
  26. import org.apache.isis.object.security.PasswordFileAuthenticator;
  27. import org.apache.isis.object.transaction.TransactionPeerFactory;
  28. import org.apache.isis.system.IsisSystem;
  29. import org.apache.isis.utility.configuration.DefaultConfigurationLoader;
  30. import org.apache.commons.cli.BasicParser;
  31. import org.apache.commons.cli.CommandLine;
  32. import org.apache.commons.cli.CommandLineParser;
  33. import org.apache.commons.cli.HelpFormatter;
  34. import org.apache.commons.cli.Options;
  35. import org.apache.commons.cli.ParseException;
  36. /**
  37. * Starts [[NAME]] as a standalone application, using the XML object store for persistence.
  38. */
  39. public final class Isis {
  40. private static final String HELP = "h";
  41. private static final String CONFIGURATION = "c";
  42. private static final String CONNECTION = "x";
  43. private static final String PERSISTOR = "p";
  44. private static final String VIEWER = "v";
  45. private static final String TYPE = "t";
  46. private static final String NO_SPLASH = "s";
  47. private static final String CLI = "cli";
  48. private static final String DND = "dnd";
  49. private static final String STANDALONE = "standalone";
  50. private static final String SERVER = "server";
  51. private static final String CLIENT = "client";
  52. private static final String PROTOTYPE = "prototype";
  53. private static final String EXPLORATION = "exploration";
  54. public static void main(final String[] args) {
  55. Options options = new Options();
  56. options.addOption(HELP, "help", false, "show this help");
  57. options.addOption(CONFIGURATION, "config", true, "read in configuration file (as well as isis.properties)");
  58. options.addOption(NO_SPLASH, "nosplash", false, "don't show splash window");
  59. options.addOption(TYPE, "type", true, "type of system: prototype (default); " + STANDALONE +"; " + CLIENT + "; " + SERVER);
  60. options.addOption(VIEWER, "viewer", true, "viewer to use: " + DND + " (default); " + CLI + "; class name (ignored if type is server)");
  61. options.addOption(PERSISTOR, "persistor", true, "object persistor to use: xml (default); in-memory; sql; class name (ignored if type is prototype or client");
  62. options.addOption(CONNECTION, "connection", true, "connection to use for client requests, or server to listen");
  63. CommandLineParser parser = new BasicParser();
  64. CommandLine cmd;
  65. try {
  66. cmd = parser.parse(options, args);
  67. } catch (ParseException e) {
  68. System.out.println("Error: " + e.getMessage());
  69. printHelp(options);
  70. return;
  71. }
  72. // help option
  73. if(cmd.hasOption('h')) {
  74. printHelp(options);
  75. return;
  76. }
  77. // type option
  78. String type = cmd.getOptionValue(TYPE);
  79. type = type == null ? PROTOTYPE : type.toLowerCase();
  80. // viewer option
  81. String viewer = cmd.getOptionValue(VIEWER);
  82. // no splash option
  83. boolean noSplash = cmd.hasOption('s'); // || (v != null && v.equals(CLI));
  84. // persistor option
  85. String persistor = cmd.getOptionValue(PERSISTOR);
  86. // connection option
  87. String connection = cmd.getOptionValue(CONNECTION);
  88. IsisSystem system = new IsisSystem();
  89. system.addAuthenticator(new JbossJaasAuthenticator());
  90. DefaultConfigurationLoader configuration = new DefaultConfigurationLoader();
  91. if (type.equals(CLIENT)) {
  92. configuration.addConfigurationFile("client.properties", false);
  93. } else if (type.equals(SERVER)) {
  94. configuration.addConfigurationFile("server.properties", false);
  95. }
  96. String config = cmd.getOptionValue(CONFIGURATION);
  97. if (config != null) {
  98. configuration.addConfigurationFile(config, true);
  99. }
  100. system.setInstallConfiguration(configuration);
  101. // TODO help should be loaded via configuration so we can change what help we get.
  102. HelpManagerAssist helpManager = new HelpManagerAssist();
  103. helpManager.setDecorated(new SimpleHelpManager());
  104. HelpPeerFactory helpPeerFactory = new HelpPeerFactory();
  105. helpPeerFactory.setHelpManager(helpManager);
  106. system.addReflectivePeer(helpPeerFactory);
  107. if(noSplash) {
  108. system.disableSplash(true);
  109. }
  110. if (type.equals(EXPLORATION) || type.equals(PROTOTYPE) || type.equals(STANDALONE) || type.equals(CLIENT)) {
  111. system.setContext(StaticContext.createInstance());
  112. } else {
  113. system.setContext(ThreadContext.createInstance());
  114. }
  115. if (type.equals(EXPLORATION) || type.equals(PROTOTYPE)) {
  116. if(persistor != null) {
  117. printErrorAndHelp(options, "Error: can't specify persistor for prototype\n");
  118. return;
  119. }
  120. system.setPersistor("in-memory");
  121. } else if (type.equals(CLIENT)) {
  122. if(persistor != null) {
  123. printErrorAndHelp(options, "Error: can't specify persistor for client\n");
  124. return;
  125. }
  126. system.setConnection(connection);
  127. } else {
  128. system.setPersistor(persistor);
  129. }
  130. system.addReflectivePeer(new TransactionPeerFactory());
  131. system.init();
  132. system.removeSplash();
  133. if (type.equals(SERVER)) {
  134. system.addListener(connection);
  135. // system.addListener(new TelnetConsoleListener(IsisContext.getConfiguration(), system));
  136. // system.addListener(new NofSocketListener(IsisContext.getConfiguration(), system));
  137. system.showConsole();
  138. } else {
  139. boolean noAuthentication = type.equals(EXPLORATION) || type.equals(PROTOTYPE);
  140. if (noAuthentication ) {
  141. // system.connect(new ExplorationSession(type));
  142. throw new RuntimeException("no prototypes!");
  143. }
  144. system.showClient(viewer, null, ! noAuthentication, type.equals(EXPLORATION));
  145. }
  146. }
  147. private static void printErrorAndHelp(Options options, String error) {
  148. System.out.println(error);
  149. printHelp(options);
  150. }
  151. private static void printHelp(Options options) {
  152. HelpFormatter help = new HelpFormatter();
  153. help.printHelp("Standalone [OPTIONS]", options);
  154. }
  155. }