Class JBStrap

java.lang.Object
com.jbstrap.core.JBStrap

public final class JBStrap extends Object

Class representing the JBStrap framework

Through this class, the JBStrap parameters can be set, or their values can be queried. Also, the application pages, menus, file stores, and DataDescriptors get registered through this class. The custom style sheets or JavaScripts can be loaded here as well.

A more detailed description and examples of these individual functions can be found in their own each specific methods in this class.

Since:
4.0
Author:
JBStrap
  • Method Details

    • init

      public static void init()
    • setParam

      public static void setParam(JBStrapParamType paramType, Object value)
      Sets a JBStrap parameter
      Parameters:
      paramType - The parameter to be set. For a list of parameters, see the JBStrapParamType enum.
      value - The parameter value. For applicable parameter values, see the JBStrapParamType enum.
      Throws:
      NullPointerException - If the specified parameter type, or value is null
      IllegalArgumentException - If the specified parameter value is not applicable to the parameter type.
    • getParam

      public static Object getParam(JBStrapParamType paramType)
      Gets the current value of the specified JBStrap parameter
      Parameters:
      paramType - The parameter type. For a list of parameters, see the JBStrapParamType enum.
      Returns:
      The current value of the specified JBStrap parameter
      Throws:
      NullPointerException - If the parameter value is null.
    • getParamAsString

      public static String getParamAsString(JBStrapParamType paramType)
      Gets the current value of the specified JBStrap parameter as a String
      Parameters:
      paramType - The parameter type. For a list of parameters, see the JBStrapParamType enum.
      Returns:
      The current value of the specified JBStrap parameter as a String
      Throws:
      NullPointerException - If the parameter value is null.
    • getParamAsBoolean

      public static boolean getParamAsBoolean(JBStrapParamType paramType)
      Gets the current value of the specified JBStrap parameter as a Boolean value
      Parameters:
      paramType - The parameter type. For a list of parameters, see the JBStrapParamType enum.
      Returns:
      The current value of the specified JBStrap parameter as a Boolean value
      Throws:
      NullPointerException - If the parameter value is null.
      ClassCastException - If the specified JBStrap Parameter couldn't be cast as a Boolean value.
    • getParamAsCharacter

      public static Character getParamAsCharacter(JBStrapParamType paramType)
      Gets the current value of the specified JBStrap parameter as a Character
      Parameters:
      paramType - The parameter type. For a list of parameters, see the JBStrapParamType enum.
      Returns:
      The current value of the specified JBStrap parameter as a Character. If this method is used with a parameter, that doesn't contain Characters, it will return with the first character of the parameter's String.
      Throws:
      NullPointerException - If the parameter value is null.
    • getParamAsInteger

      public static Integer getParamAsInteger(JBStrapParamType paramType)
      Gets the current value of the specified JBStrap parameter as an Integer
      Parameters:
      paramType - The parameter type. For a list of parameters, see the JBStrapParamType enum.
      Returns:
      The current value of the specified JBStrap parameter as an Integer. If the value is a number, but not an Integer, then the value will be rounded. For example, the value of 12.25 will be returned as 12.
      Throws:
      NullPointerException - If the parameter value is null.
      IllegalArgumentException - If the specified parameter doesn't have a number value
    • addDataDescriptorType

      public static void addDataDescriptorType(String name, Class<? extends DataDescriptor> dataDescriptorClass)
      Adds a new DataDescriptor type to the framework.
      Parameters:
      name - Unique DataDescriptor name You can specify any text name here. Use it to reference the DataDescriptor. The specified name must be unique within the application.
      dataDescriptorClass - The class implementing the DataDescriptor
      Throws:
      NullPointerException - Thrown if the specified name or class is null
      IllegalArgumentException - Thrown if there is a DataDescriptor with the specified name in the application (the specified name is reserved).
    • getDataDescriptors

      public static Collection<DataDescriptor> getDataDescriptors()
      Gets the application's DataDescriptors
      Returns:
      A list containing every DataDescriptor that the application is using. If there aren't any, returns with an empty list
      See Also:
    • addDataDescriptor

      public static void addDataDescriptor(DataDescriptor dataDescriptor)
      Adds the specified DataDescriptor to the application
      Parameters:
      dataDescriptor - The DataDescriptor object
      Throws:
      NullPointerException - If the specified DataDescriptor is null
      See Also:
    • getDataDescriptor

      public static DataDescriptor getDataDescriptor(String dataDescriptorName)
      Gets the specified DataDescriptor
      Parameters:
      dataDescriptorName - The name of the DataDescriptor
      Returns:
      The DataDescriptor object or null, if a DataDescriptor by the specified name was not found
      Throws:
      NullPointerException - If the specified name is null
      See Also:
    • createFileStore

      public static void createFileStore(String name, String path)
      Creates and adds a FileStore to the application
      Parameters:
      name - The FileStore name
      path - The FileStore path, relative to the FILE_STORE_BASE JBStrap parameter.
      Throws:
      IllegalArgumentException - If the specified FileStore couldn't be created
      See Also:
    • getFileStoreNames

      public static List<String> getFileStoreNames()
      Gets the name of every assigned FileStore
      Returns:
      A list containing the name of every assigned FileStore. If there are none, it will return with an empty list
    • getFileStorePath

      public static String getFileStorePath(String fileSotreName)
      Gets the previously assigned FileStore's path.
      Parameters:
      fileSotreName - The name of the FileStore, whose location we want to get
      Returns:
      The FileStore path or null if not found
      See Also:
    • loginUser

      public static void loginUser(Client client, CurrentUser user)

      Logs the specified user into the application.

      Parameters:
      client - The client instance, where the user will be logged into.
      user - The user who will be logged in
      Throws:
      IllegalArgumentException - If the user is null.
      NullPointerException - If the client is null
      See Also:
    • logoutUser

      public static void logoutUser(Client client)
      Logs the specified user out.
      Parameters:
      client - The client instance, where the user will be logged out from.
    • isPluginLoaded

      public static boolean isPluginLoaded(String pluginName)
      Determines if the specified plugin is loaded into the framework
      Parameters:
      pluginName - The name of the plugin that is examined
      Returns:
      true if the specified plugin is loaded, otherwise false
      Throws:
      NullPointerException - If the plugin name is specified as null
    • loadPlugin

      public static void loadPlugin(Class<? extends JBStrapPlugin> pluginClass) throws PluginAlreadyLoaded, InstantiationException, IllegalAccessException, PluginNotInitialized
      Loads the specified plugin to the JBStrap framework.
      Parameters:
      pluginClass - The JBStrap plugin class. This class must implement the JBStrapPlugin interface.
      Throws:
      PluginAlreadyLoaded - If the specified plugin is already loaded
      IllegalAccessException - If the framework couldn't instantiate the specified plugin class with the use of the default constructor.
      InstantiationException - If the framework couldn't instantiate the specified plugin class with the use of the default constructor.
      PluginNotInitialized - If the plugin couldn't be initialized
    • getVersion

      public static String getVersion()
      Gets the version number of the JBStrap framework
      Returns:
      The version number of the JBStrap framework
    • getBuildNumber

      public static String getBuildNumber()
      Gets the build number of the JBStrap framework
      Returns:
      The build number of the JBStrap framework
    • getFullName

      public static String getFullName()
      Gets the full name of the JBStrap framework
      Returns:
      The full name of the JBStrap framework
    • addPage

      public static void addPage(String pageId, Class<? extends UI> uiClass, Class<? extends BasePage> pageClass)
      Adds a page(that doesn't use parameters) to the application
      Parameters:
      pageId - The page's unique ID, used within the application (pageID)
      uiClass - The class, that contains the implementation of the UI, where the page will be. The class must be a extended from the UI class
      pageClass - The class containing the implementation of the page. This class must extend from the BasePage class
    • addPage

      public static void addPage(String pageId, Class<? extends UI> uiClass, Class<? extends BasePage> pageClass, Parameters parameters)
      Adds a page (that uses parameters) to the application
      Parameters:
      pageId - The page's unique ID, used within the application (pageID)
      uiClass - The class, that contains the implementation of the UI, where the page will be. The class must extend from the UI class
      pageClass - The class containing the implementation of the page. This class must extend from the BasePage class
      parameters - The object containing the page parameters. If specified as null, the page won't receive any parameters.
    • createMenu

      public static void createMenu(String menuName)

      Creates a new menu in the application

      Within the JBStrap framework, any number of menus can be used within the application. Each menu has to have a unique name that is used to identify them. The menu items can be added to menus that are created here. These menus, when put together, are used to create the menu components that can appear on the interface

      Parameters:
      menuName - The menu's unique name
      Throws:
      NullPointerException - If the name is specified as null
      IllegalArgumentException - If the name is already used on a different menu within the application
      See Also:
    • addMenuItem

      public static MenuItem addMenuItem(String menuName, String menuItemName, Icon menuItemIcon, String menuItemTitle)
      Adds a menu item to an already existing menu.
      Parameters:
      menuName - The name of the menu, where the menu item will be added to
      menuItemName - The name of the menu item
      menuItemIcon - The menu item icon. For a list of icons, see the Icon enum. If specified as null no icon will be added.
      menuItemTitle - The menu item title. If specified as null, no text will be on the menu item.
      Returns:
      The menu item object
      Throws:
      NullPointerException - If the menu name or menu item name is null, or if not found
      IllegalArgumentException - If the name is already used on a different menu item within the menu
      See Also:
    • addMenuItem

      public static MenuItem addMenuItem(String menuName, String menuItemName, Icon menuItemIcon, String menuItemTitle, MenuItem... subMenuItems)
      Adds a menu item with sub menu items to an already existing menu.
      Parameters:
      menuName - The name of the menu, where the menu item will be added to
      menuItemName - The name of the menu item
      menuItemIcon - The menu item icon. For a list of icons, see the Icon enum. If specified as null no icon will be added.
      menuItemTitle - The menu item title. If specified as null, no text will be on the menu item.
      subMenuItems - The sub menu items that are added under the specified menu item.
      Returns:
      The menu item object
      Throws:
      NullPointerException - If the menu name or menu item name is null, or if not found
      IllegalArgumentException - If the specified name is already used on a different menu item within the menu
      See Also:
    • addMenuItem

      public static MenuItem addMenuItem(String menuName, String menuItemName, Icon menuItemIcon, String menuItemTitle, MenuOperation operation, String targetPageId)
      Adds a menu item with sub menu items to an already existing menu. The menu item can have an operation assigned to it.
      Parameters:
      menuName - The name of the menu, where the menu item will be added to
      menuItemName - The name of the menu item
      menuItemIcon - The menu item icon. For a list of icons, see the Icon enum. If specified as null no icon will be added.
      menuItemTitle - The menu item title. If specified as null, no text will be on the menu item.
      operation - The operation that will run when it's clicked. For a list of applicable operations, see the MenuOperation enum.
      targetPageId - If the operation opens a page, then the ID of page to be opened must be specified here. If the operation isn't used for opening page, this parameter will be ignored.
      Returns:
      The menu item object
      Throws:
      NullPointerException - If the menu name or menu item name is null, or if not found
      IllegalArgumentException - If the specified name is already used on a different menu item within the menu
      See Also:
    • addMenuItem

      public static MenuItem addMenuItem(String menuName, MenuItem menuItem)
      Adds a menu item to an already existing menu.
      Parameters:
      menuName - The name of the menu, where the menu item will be added to
      menuItem - The menu item class
      Returns:
      The menu item object
      Throws:
      NullPointerExceptionIf - the menu name or menu item name is null, or if not found
      IllegalArgumentException - If the specified name is already used on a different menu item within the menu
      See Also:
    • removeMenuItem

      public static void removeMenuItem(String menuName, String menuItemName)
      Removes the specified menu item from the menu
      Parameters:
      menuName - The name of the menu, from where the menu item will be removed
      menuItemName - The name of the menu item to be removed. If the name is null or doesn't exist in the menu, nothing will be removed
      Throws:
      NullPointerException - If the menu name is null
    • removeMenu

      public static void removeMenu(String menuName)
      Removes the specified menu and all of its menu items from the application
      Parameters:
      menuName - The name of the menu to be removed
    • getMenuItems

      public static List<MenuItem> getMenuItems(String menuName)
      Gets a list of the name of menu items that are assigned to the specified menu
      Parameters:
      menuName - The name of the menu
      Returns:
      A list containing the names of every list item assigned to the specified menu. If the menu is not found, it will return with null
      Throws:
      NullPointerException - If the menu name is null
    • addStyleSheet

      public static void addStyleSheet(String stylesheetUrl)
      Adds a custom stylesheet to the application. Stylesheets added like this are automatically loaded when a client connects.
      Parameters:
      stylesheetUrl - The Stylesheet's URL, relative to the application's URL.
      Throws:
      NullPointerException - If the Stylesheet url is null
    • getStylesheets

      public static List<String> getStylesheets()
      Gets a list containing the relative URLs of the assigned stylesheet.
      Returns:
      A list containing the relative URLs of the assigned stylesheets. If none are assigned, the list will be empty.
    • addJavaScript

      public static void addJavaScript(String javaScriptUrl)
      Adds a custom JavaScript to the application. Every JavaScript added like this are automatically loaded when a client connects.
      Parameters:
      javaScriptUrl - The URL of the JavaScript, relative to the application's URL
      Throws:
      NullPointerException - IF the specified JavaScript URL is null
    • getJavaScripts

      public static List<String> getJavaScripts()
      Gets a list containing the relative URLs of the assigned custom Javascript
      Returns:
      A list containing the relative URLs of the assigned custom Javascript If none are assigned, the list will be empty.
    • openMessageBus

      public static void openMessageBus(String busName)

      Opens a global level message bus

      This message bus can be added to any class or component within the application. This also means that messages sent with this will be received by them.

      For more information about how the message bus works see the MessageBus class.

      Parameters:
      busName - The name of the message bus that will be opened
      Throws:
      NullPointerException - If the message bus name is null
      IllegalArgumentException - If the name is already used on a different message bus
      See Also:
    • closeMessageBus

      public static void closeMessageBus(String busName)
      Closes the specified global level message bus
      Parameters:
      busName - The name of the bus to be closed
      Throws:
      NullPointerException - If the message bus name is null
      IllegalArgumentException - If the specified bus is not found, or is already closed
      See Also:
    • subscribeMessageBus

      public static void subscribeMessageBus(String busName, MessageBusListener listener)
      Subscribes the specified listener to the specified global level message bus
      Parameters:
      busName - The name of the bus
      listener - The implementation of the listener
      Throws:
      NullPointerException - If the message bus name or listener implementation is null
      See Also:
    • unsubscribeMessageBus

      public static void unsubscribeMessageBus(String busName, MessageBusListener listener)
      Unsubscribes the specified listener from the specified message bus
      Parameters:
      busName - The name of the bus
      listener - The implementation of the listener
      Throws:
      NullPointerException - If the message bus name or listener implementation is null
      See Also:
    • sendMessageToMessageBus

      public static void sendMessageToMessageBus(String busName, Serializable message)
      Sends a message through the specified message bus
      Parameters:
      busName - The name of the message bus
      message - The message. Can be any class. Serializable.
      Throws:
      NullPointerException - If the message bus name is null
    • messageBusOpened

      public static boolean messageBusOpened(String busName)
      Determines if the specified global level message bus is open.
      Parameters:
      busName - The name of the message bus
      Returns:
      true if there is a message bus with the specified name that is open, otherwise false
    • getClient

      public static Client getClient(String clientId)
      Gets the specified client
      Parameters:
      clientId - The ID of the client
      Returns:
      The instance of the client that corresponds to the specified ID or null, if not found
    • getAllClients

      public static Collection<Client> getAllClients()
      Get all connected client
      Returns:
      Collection of the all connected client