| <%# |
| * 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 <%= polygene.packageName %>.app; |
| |
| import org.apache.polygene.api.structure.Application; |
| import org.apache.polygene.bootstrap.layered.LayeredApplicationAssembler; |
| |
| import <%= polygene.packageName %>.bootstrap.<%= polygene.name %>Application; |
| |
| public class <%= polygene.name %>CommandLineApplication |
| { |
| protected Application application; |
| |
| private static final String NAME = "<%= polygene.name %>"; |
| private static final String VERSION = "0.1"; |
| |
| public <%= polygene.name %>CommandLineApplication(String mode) |
| throws AssemblyException |
| { |
| createApplication(mode); |
| } |
| |
| @Override |
| protected LayeredApplicationAssembler createApplicationAssembler( String mode ) |
| throws AssemblyException |
| { |
| return new <%= polygene.name %>Application( NAME, VERSION, Application.Mode.valueOf( mode )); |
| } |
| |
| private void createApplication( String mode ) |
| { |
| try |
| { |
| LayeredApplicationAssembler assembler = createApplicationAssembler( mode ); |
| assembler.initialize(); |
| polygeneApplication = assembler.application(); |
| setName( polygeneApplication.name() ); |
| } |
| catch( Throwable e ) |
| { |
| getLogger().log( Level.SEVERE, "Unable to start Polygene application.", e ); |
| throw new InternalError( "Unable to start Polygene application.", e ); |
| } |
| } |
| |
| @Override |
| public void start() |
| throws Exception |
| { |
| application.activate(); |
| } |
| |
| @Override |
| public void stop() |
| throws Exception |
| { |
| application.passivate(); |
| } |
| |
| public static void main( String[] args ) |
| { |
| <%= polygene.name %>CommandLineApplication app = new <%= polygene.name %>CommandLineApplication("development"); |
| Runtime.getRuntime().addShutdownHook( new Thread( () -> app.stop() ) ); |
| app.start(); |
| } |
| } |