001/* 002 * Stallion Core: A Modern Web Framework 003 * 004 * Copyright (C) 2015 - 2016 Stallion Software LLC. 005 * 006 * This program is free software: you can redistribute it and/or modify it under the terms of the 007 * GNU General Public License as published by the Free Software Foundation, either version 2 of 008 * the License, or (at your option) any later version. This program is distributed in the hope that 009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 011 * License for more details. You should have received a copy of the GNU General Public License 012 * along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>. 013 * 014 * 015 * 016 */ 017 018package io.stallion.plugins; 019 020import io.stallion.boot.StallionRunAction; 021import io.stallion.dataAccess.DataAccessRegistry; 022import io.stallion.dataAccess.ModelBase; 023import io.stallion.dataAccess.DataAccessRegistration; 024import io.stallion.hooks.HookRegistry; 025import io.stallion.hooks.ChainedHook; 026import io.stallion.hooks.HookHandler; 027import io.stallion.restfulEndpoints.RestEndpointBase; 028import io.stallion.restfulEndpoints.EndpointsRegistry; 029import io.stallion.restfulEndpoints.EndpointResource; 030import io.stallion.restfulEndpoints.JavaRestEndpoint; 031import io.stallion.restfulEndpoints.ResourceToEndpoints; 032import io.stallion.services.Log; 033 034import java.util.Collections; 035import java.util.List; 036 037import static io.stallion.utils.Literals.list; 038 039public abstract class StallionJavaPlugin { 040 private PluginRegistry pluginRegistry; 041 042 public abstract String getPluginName(); 043 044 public List<String> getSqlMigrations() { 045 return list(); 046 } 047 048 /** 049 * Get a list of available actions 050 * 051 * @return 052 */ 053 public List<? extends StallionRunAction> getActions() { 054 return Collections.EMPTY_LIST; 055 } 056 057 /** 058 * Override this to implement configuring this plugin via the command-line. 059 */ 060 public void commandlineConfigure() { 061 System.out.println("No special configuration needed for this plugin."); 062 } 063 064 /** 065 * The main method that gets called to load the plugin -- do everything here, 066 * such as loading controllers, loading endpoints, etc. 067 * 068 * @throws Exception 069 */ 070 public abstract void boot() throws Exception; 071 072 /** 073 * This gets called after plugin load, when Stallion is running as an actual 074 * web server. Specifically, this gets called by AppContextLoader.startAllServices(). 075 * Override this if there are background services that do not need 076 * to be run when executing most Stallion actions, but do need to be run 077 * when running a script action. 078 * 079 */ 080 public void startServices() { 081 082 083 } 084 085 /** 086 * Called by AppContextLoader.startServicesForTests(), which is called when loading 087 * an app context via the BaseIntegrationTestCase JUnit test case base class. 088 * 089 */ 090 public void startServicesForTests() { 091 092 } 093 094 095 /** 096 * Override this to shutdown services when the Stallion AppContext shutsdown 097 */ 098 public void shutdown() { 099 100 } 101 102 public void bootForPackage(String packagePath) { 103 104 // TODO: use the Reflect library to find all classes matching each giving interface, insantiate, and load them 105 } 106 107 108 109 public void setPluginRegistry(PluginRegistry pluginRegistry) { 110 this.pluginRegistry = pluginRegistry; 111 } 112}