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 voidaddDataDescriptor(DataDescriptor dataDescriptor) Adds the specified DataDescriptor to the applicationstatic voidaddDataDescriptorType(String name, Class<? extends DataDescriptor> dataDescriptorClass) Adds a new DataDescriptor type to the framework.static voidaddJavaScript(String javaScriptUrl) Adds a custom JavaScript to the application.static MenuItemaddMenuItem(String menuName, MenuItem menuItem) Adds a menu item to an already existing menu.static MenuItemaddMenuItem(String menuName, String menuItemName, Icon menuItemIcon, String menuItemTitle) Adds a menu item to an already existing menu.static MenuItemaddMenuItem(String menuName, String menuItemName, Icon menuItemIcon, String menuItemTitle, MenuItem... subMenuItems) Adds a menu item with sub menu items to an already existing menu.static MenuItemaddMenuItem(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 voidAdds a page(that doesn't use parameters) to the applicationstatic voidaddPage(String pageId, Class<? extends UI> uiClass, Class<? extends BasePage> pageClass, Parameters parameters) Adds a page (that uses parameters) to the applicationstatic voidaddStyleSheet(String stylesheetUrl) Adds a custom stylesheet to the application.static voidcloseMessageBus(String busName) Closes the specified global level message busstatic voidcreateFileStore(String name, String path) Creates and adds a FileStore to the applicationstatic voidcreateMenu(String menuName) Creates a new menu in the applicationstatic Collection<Client>Get all connected clientstatic StringGets the build number of the JBStrap frameworkstatic ClientGets the specified clientstatic DataDescriptorgetDataDescriptor(String dataDescriptorName) Gets the specified DataDescriptorstatic Collection<DataDescriptor>Gets the application's DataDescriptorsGets the name of every assigned FileStorestatic StringgetFileStorePath(String fileSotreName) Gets the previously assigned FileStore's path.static StringGets 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 ObjectgetParam(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameterstatic booleangetParamAsBoolean(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as a Boolean valuestatic CharactergetParamAsCharacter(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as a Characterstatic IntegergetParamAsInteger(JBStrapParamType paramType) Gets the current value of the specified JBStrap parameter as an Integerstatic StringgetParamAsString(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 StringGets the version number of the JBStrap frameworkstatic voidinit()static booleanisPluginLoaded(String pluginName) Determines if the specified plugin is loaded into the frameworkstatic voidloadPlugin(Class<? extends JBStrapPlugin> pluginClass) Loads the specified plugin to the JBStrap framework.static voidloginUser(Client client, CurrentUser user) Logs the specified user into the application.static voidlogoutUser(Client client) Logs the specified user out.static booleanmessageBusOpened(String busName) Determines if the specified global level message bus is open.static voidopenMessageBus(String busName) Opens a global level message busstatic voidremoveMenu(String menuName) Removes the specified menu and all of its menu items from the applicationstatic voidremoveMenuItem(String menuName, String menuItemName) Removes the specified menu item from the menustatic voidsendMessageToMessageBus(String busName, Serializable message) Sends a message through the specified message busstatic voidsetParam(JBStrapParamType paramType, Object value) Sets a JBStrap parameterstatic voidsubscribeMessageBus(String busName, MessageBusListener listener) Subscribes the specified listener to the specified global level message busstatic voidunsubscribeMessageBus(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 theJBStrapParamTypeenum.value- The parameter value. For applicable parameter values, see theJBStrapParamTypeenum.- Throws:
NullPointerException- If the specified parameter type, or value isnullIllegalArgumentException- 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 theJBStrapParamTypeenum.- 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 theJBStrapParamTypeenum.- 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 theJBStrapParamTypeenum.- 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 theJBStrapParamTypeenum.- 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 theJBStrapParamTypeenum.- 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 isnullIllegalArgumentException- 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_BASEJBStrap 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
nullif 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:
trueif 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 theJBStrapPlugininterface.- 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 theUIclasspageClass- The class containing the implementation of the page. This class must extend from theBasePageclass
-
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 theUIclasspageClass- The class containing the implementation of the page. This class must extend from theBasePageclassparameters- 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 asnullIllegalArgumentException- 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 theIconenum. If specified asnullno 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 theIconenum. If specified asnullno 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 theIconenum. If specified asnullno 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 theMenuOperationenum.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 isnullor 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
MessageBusclass.- Parameters:
busName- The name of the message bus that will be opened- Throws:
NullPointerException- If the message bus name isnullIllegalArgumentException- 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 isnullIllegalArgumentException- 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:
trueif 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
-