/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
- /*
- * 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.
- */
- package org.apache.isis.system.ejb;
-
- import org.apache.isis.object.context.StaticContext;
- import org.apache.isis.object.context.ThreadContext;
- import org.apache.isis.object.help.HelpManagerAssist;
- import org.apache.isis.object.help.HelpPeerFactory;
- import org.apache.isis.object.help.SimpleHelpManager;
- import org.apache.isis.object.security.JbossJaasAuthenticator;
- import org.apache.isis.object.security.PasswordFileAuthenticator;
- import org.apache.isis.object.transaction.TransactionPeerFactory;
- import org.apache.isis.system.IsisSystem;
- import org.apache.isis.utility.configuration.DefaultConfigurationLoader;
-
- import org.apache.commons.cli.BasicParser;
- import org.apache.commons.cli.CommandLine;
- import org.apache.commons.cli.CommandLineParser;
- import org.apache.commons.cli.HelpFormatter;
- import org.apache.commons.cli.Options;
- import org.apache.commons.cli.ParseException;
-
-
- /**
- * Starts [[NAME]] as a standalone application, using the XML object store for persistence.
- */
- public final class Isis {
- private static final String HELP = "h";
- private static final String CONFIGURATION = "c";
- private static final String CONNECTION = "x";
- private static final String PERSISTOR = "p";
- private static final String VIEWER = "v";
- private static final String TYPE = "t";
- private static final String NO_SPLASH = "s";
- private static final String CLI = "cli";
- private static final String DND = "dnd";
- private static final String STANDALONE = "standalone";
- private static final String SERVER = "server";
- private static final String CLIENT = "client";
- private static final String PROTOTYPE = "prototype";
- private static final String EXPLORATION = "exploration";
-
- public static void main(final String[] args) {
- Options options = new Options();
- options.addOption(HELP, "help", false, "show this help");
- options.addOption(CONFIGURATION, "config", true, "read in configuration file (as well as isis.properties)");
- options.addOption(NO_SPLASH, "nosplash", false, "don't show splash window");
- options.addOption(TYPE, "type", true, "type of system: prototype (default); " + STANDALONE +"; " + CLIENT + "; " + SERVER);
-
- options.addOption(VIEWER, "viewer", true, "viewer to use: " + DND + " (default); " + CLI + "; class name (ignored if type is server)");
- options.addOption(PERSISTOR, "persistor", true, "object persistor to use: xml (default); in-memory; sql; class name (ignored if type is prototype or client");
- options.addOption(CONNECTION, "connection", true, "connection to use for client requests, or server to listen");
-
- CommandLineParser parser = new BasicParser();
- CommandLine cmd;
- try {
- cmd = parser.parse(options, args);
- } catch (ParseException e) {
- System.out.println("Error: " + e.getMessage());
- printHelp(options);
- return;
- }
-
- // help option
- if(cmd.hasOption('h')) {
- printHelp(options);
- return;
- }
-
- // type option
- String type = cmd.getOptionValue(TYPE);
- type = type == null ? PROTOTYPE : type.toLowerCase();
-
- // viewer option
- String viewer = cmd.getOptionValue(VIEWER);
-
- // no splash option
- boolean noSplash = cmd.hasOption('s'); // || (v != null && v.equals(CLI));
-
- // persistor option
- String persistor = cmd.getOptionValue(PERSISTOR);
-
- // connection option
- String connection = cmd.getOptionValue(CONNECTION);
-
-
- IsisSystem system = new IsisSystem();
- system.addAuthenticator(new JbossJaasAuthenticator());
-
- DefaultConfigurationLoader configuration = new DefaultConfigurationLoader();
- if (type.equals(CLIENT)) {
- configuration.addConfigurationFile("client.properties", false);
- } else if (type.equals(SERVER)) {
- configuration.addConfigurationFile("server.properties", false);
- }
- String config = cmd.getOptionValue(CONFIGURATION);
- if (config != null) {
- configuration.addConfigurationFile(config, true);
- }
- system.setInstallConfiguration(configuration);
-
- // TODO help should be loaded via configuration so we can change what help we get.
- HelpManagerAssist helpManager = new HelpManagerAssist();
- helpManager.setDecorated(new SimpleHelpManager());
- HelpPeerFactory helpPeerFactory = new HelpPeerFactory();
- helpPeerFactory.setHelpManager(helpManager);
- system.addReflectivePeer(helpPeerFactory);
-
- if(noSplash) {
- system.disableSplash(true);
- }
-
- if (type.equals(EXPLORATION) || type.equals(PROTOTYPE) || type.equals(STANDALONE) || type.equals(CLIENT)) {
- system.setContext(StaticContext.createInstance());
- } else {
- system.setContext(ThreadContext.createInstance());
- }
-
-
- if (type.equals(EXPLORATION) || type.equals(PROTOTYPE)) {
- if(persistor != null) {
- printErrorAndHelp(options, "Error: can't specify persistor for prototype\n");
- return;
- }
- system.setPersistor("in-memory");
-
- } else if (type.equals(CLIENT)) {
- if(persistor != null) {
- printErrorAndHelp(options, "Error: can't specify persistor for client\n");
- return;
- }
- system.setConnection(connection);
-
- } else {
- system.setPersistor(persistor);
- }
-
- system.addReflectivePeer(new TransactionPeerFactory());
-
- system.init();
- system.removeSplash();
-
-
- if (type.equals(SERVER)) {
- system.addListener(connection);
-
- // system.addListener(new TelnetConsoleListener(IsisContext.getConfiguration(), system));
- // system.addListener(new NofSocketListener(IsisContext.getConfiguration(), system));
-
- system.showConsole();
- } else {
- boolean noAuthentication = type.equals(EXPLORATION) || type.equals(PROTOTYPE);
- if (noAuthentication ) {
- // system.connect(new ExplorationSession(type));
- throw new RuntimeException("no prototypes!");
- }
- system.showClient(viewer, null, ! noAuthentication, type.equals(EXPLORATION));
- }
-
- }
-
- private static void printErrorAndHelp(Options options, String error) {
- System.out.println(error);
- printHelp(options);
- }
-
- private static void printHelp(Options options) {
- HelpFormatter help = new HelpFormatter();
- help.printHelp("Standalone [OPTIONS]", options);
- }
- }