Class JBStrap
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 Summary
Modifier and TypeMethodDescriptionstatic void
addDataDescriptor
(DataDescriptor dataDescriptor) Adds the specified DataDescriptor to the applicationstatic void
addDataDescriptorType
(String name, Class<? extends DataDescriptor> dataDescriptorClass) Adds a new DataDescriptor type to the framework.static void
addJavaScript
(String javaScriptUrl) Adds a custom JavaScript to the application.static MenuItem
addMenuItem
(String menuName, MenuItem menuItem) Adds a menu item to an already existing menu.static MenuItem
addMenuItem
(String menuName, String menuItemName, Icon menuItemIcon, String menuItemTitle) Adds a menu item to an already existing menu.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.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.static void
Adds a page(that doesn't use parameters) to the applicationstatic void
addPage
(String pageId, Class<? extends UI> uiClass, Class<? extends BasePage> pageClass, Parameters parameters) Adds a page (that uses parameters) to the applicationstatic void
addStyleSheet
(String stylesheetUrl) Adds a custom stylesheet to the application.static void
closeMessageBus
(String busName) Closes the specified global level message busstatic void
createFileStore
(String name, String path) Creates and adds a FileStore to the applicationstatic void
createMenu
(String menuName) Creates a new menu in the applicationstatic Collection<Client>
Get all connected clientstatic String
Gets the build number of the JBStrap frameworkstatic Client
Gets the specified clientstatic DataDescriptor
getDataDescriptor
(String dataDescriptorName) Gets the specified DataDescriptorstatic Collection<DataDescriptor>
Gets the application's DataDescriptorsGets the name of every assigned FileStorestatic String
getFileStorePath
(String fileSotreName) Gets the previously assigned FileStore's path.static String
Gets the full name of the JBStrap frameworkGets a list containing the relative URLs of the assigned custom JavascriptgetMenuItems
(String menuName) Gets a list of the name of menu items that are assigned to the specified menustatic Object
getParam
(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameterstatic boolean
getParamAsBoolean
(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as a Boolean valuestatic Character
getParamAsCharacter
(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as a Characterstatic Integer
getParamAsInteger
(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as an Integerstatic String
getParamAsString
(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as a StringGets a list containing the relative URLs of the assigned stylesheet.static String
Gets the version number of the JBStrap frameworkstatic void
init()
static boolean
isPluginLoaded
(String pluginName) Determines if the specified plugin is loaded into the frameworkstatic void
loadPlugin
(Class<? extends JBStrapPlugin> pluginClass) Loads the specified plugin to the JBStrap framework.static void
loginUser
(Client client, CurrentUser user) Logs the specified user into the application.static void
logoutUser
(Client client) Logs the specified user out.static boolean
messageBusOpened
(String busName) Determines if the specified global level message bus is open.static void
openMessageBus
(String busName) Opens a global level message busstatic void
removeMenu
(String menuName) Removes the specified menu and all of its menu items from the applicationstatic void
removeMenuItem
(String menuName, String menuItemName) Removes the specified menu item from the menustatic void
sendMessageToMessageBus
(String busName, Serializable message) Sends a message through the specified message busstatic void
setParam
(JBStrapParamType paramType, Object value) Sets a JBStrap parameterstatic void
subscribeMessageBus
(String busName, MessageBusListener listener) Subscribes the specified listener to the specified global level message busstatic void
unsubscribeMessageBus
(String busName, MessageBusListener listener) Unsubscribes the specified listener from the specified message bus
-
Method Details
-
init
public static void init() -
setParam
Sets a JBStrap parameter- Parameters:
paramType
- The parameter to be set. For a list of parameters, see theJBStrapParamType
enum.value
- The parameter value. For applicable parameter values, see theJBStrapParamType
enum.- Throws:
NullPointerException
- If the specified parameter type, or value isnull
IllegalArgumentException
- If the specified parameter value is not applicable to the parameter type.
-
getParam
Gets the current value of the specified JBStrap parameter- Parameters:
paramType
- The parameter type. For a list of parameters, see theJBStrapParamType
enum.- Returns:
- The current value of the specified JBStrap parameter
- Throws:
NullPointerException
- If the parameter value isnull
.
-
getParamAsString
Gets the current value of the specified JBStrap parameter as a String- Parameters:
paramType
- The parameter type. For a list of parameters, see theJBStrapParamType
enum.- Returns:
- The current value of the specified JBStrap parameter as a String
- Throws:
NullPointerException
- If the parameter value isnull
.
-
getParamAsBoolean
Gets the current value of the specified JBStrap parameter as a Boolean value- Parameters:
paramType
- The parameter type. For a list of parameters, see theJBStrapParamType
enum.- Returns:
- The current value of the specified JBStrap parameter as a Boolean value
- Throws:
NullPointerException
- If the parameter value isnull
.ClassCastException
- If the specified JBStrap Parameter couldn't be cast as a Boolean value.
-
getParamAsCharacter
Gets the current value of the specified JBStrap parameter as a Character- Parameters:
paramType
- The parameter type. For a list of parameters, see theJBStrapParamType
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 isnull
.
-
getParamAsInteger
Gets the current value of the specified JBStrap parameter as an Integer- Parameters:
paramType
- The parameter type. For a list of parameters, see theJBStrapParamType
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 isnull
.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 isnull
IllegalArgumentException
- Thrown if there is a DataDescriptor with the specified name in the application (the specified name is reserved).
-
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
Adds the specified DataDescriptor to the application- Parameters:
dataDescriptor
- The DataDescriptor object- Throws:
NullPointerException
- If the specified DataDescriptor isnull
- See Also:
-
getDataDescriptor
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 isnull
- See Also:
-
createFileStore
Creates and adds a FileStore to the application- Parameters:
name
- The FileStore namepath
- The FileStore path, relative to theFILE_STORE_BASE
JBStrap parameter.- Throws:
IllegalArgumentException
- If the specified FileStore couldn't be created- See Also:
-
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
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
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 isnull
.NullPointerException
- If the client isnull
- See Also:
-
logoutUser
Logs the specified user out.- Parameters:
client
- The client instance, where the user will be logged out from.
-
isPluginLoaded
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, otherwisefalse
- Throws:
NullPointerException
- If the plugin name is specified asnull
-
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 theJBStrapPlugin
interface.- Throws:
PluginAlreadyLoaded
- If the specified plugin is already loadedIllegalAccessException
- 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
Gets the version number of the JBStrap framework- Returns:
- The version number of the JBStrap framework
-
getBuildNumber
Gets the build number of the JBStrap framework- Returns:
- The build number of the JBStrap framework
-
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 theUI
classpageClass
- The class containing the implementation of the page. This class must extend from theBasePage
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 theUI
classpageClass
- The class containing the implementation of the page. This class must extend from theBasePage
classparameters
- The object containing the page parameters. If specified asnull
, the page won't receive any parameters.
-
createMenu
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 asnull
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 tomenuItemName
- The name of the menu itemmenuItemIcon
- The menu item icon. For a list of icons, see theIcon
enum. If specified asnull
no icon will be added.menuItemTitle
- The menu item title. If specified asnull
, no text will be on the menu item.- Returns:
- The menu item object
- Throws:
NullPointerException
- If the menu name or menu item name isnull
, or if not foundIllegalArgumentException
- 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 tomenuItemName
- The name of the menu itemmenuItemIcon
- The menu item icon. For a list of icons, see theIcon
enum. If specified asnull
no icon will be added.menuItemTitle
- The menu item title. If specified asnull
, 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 isnull
, or if not foundIllegalArgumentException
- 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 tomenuItemName
- The name of the menu itemmenuItemIcon
- The menu item icon. For a list of icons, see theIcon
enum. If specified asnull
no icon will be added.menuItemTitle
- The menu item title. If specified asnull
, 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 theMenuOperation
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 isnull
, or if not foundIllegalArgumentException
- If the specified name is already used on a different menu item within the menu- See Also:
-
addMenuItem
Adds a menu item to an already existing menu.- Parameters:
menuName
- The name of the menu, where the menu item will be added tomenuItem
- The menu item class- Returns:
- The menu item object
- Throws:
NullPointerExceptionIf
- the menu name or menu item name isnull
, or if not foundIllegalArgumentException
- If the specified name is already used on a different menu item within the menu- See Also:
-
removeMenuItem
Removes the specified menu item from the menu- Parameters:
menuName
- The name of the menu, from where the menu item will be removedmenuItemName
- The name of the menu item to be removed. If the name isnull
or doesn't exist in the menu, nothing will be removed- Throws:
NullPointerException
- If the menu name isnull
-
removeMenu
Removes the specified menu and all of its menu items from the application- Parameters:
menuName
- The name of the menu to be removed
-
getMenuItems
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 isnull
-
addStyleSheet
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 isnull
-
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
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 isnull
-
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
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 isnull
IllegalArgumentException
- If the name is already used on a different message bus- See Also:
-
closeMessageBus
Closes the specified global level message bus- Parameters:
busName
- The name of the bus to be closed- Throws:
NullPointerException
- If the message bus name isnull
IllegalArgumentException
- If the specified bus is not found, or is already closed- See Also:
-
subscribeMessageBus
Subscribes the specified listener to the specified global level message bus- Parameters:
busName
- The name of the buslistener
- The implementation of the listener- Throws:
NullPointerException
- If the message bus name or listener implementation isnull
- See Also:
-
unsubscribeMessageBus
Unsubscribes the specified listener from the specified message bus- Parameters:
busName
- The name of the buslistener
- The implementation of the listener- Throws:
NullPointerException
- If the message bus name or listener implementation isnull
- See Also:
-
sendMessageToMessageBus
Sends a message through the specified message bus- Parameters:
busName
- The name of the message busmessage
- The message. Can be any class. Serializable.- Throws:
NullPointerException
- If the message bus name isnull
-
messageBusOpened
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, otherwisefalse
-
getClient
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
Get all connected client- Returns:
- Collection of the all connected client
-