Package com.iizix.server.app
Class AppFactory
java.lang.Object
com.iizix.server.app.AppFactory
- All Implemented Interfaces:
IAppOwner
,IPropMgrInfoProvider
,IRuntimeReferenceLookup
,IKStringInfoProvider
public final class AppFactory extends Object implements IAppOwner, IRuntimeReferenceLookup, IPropMgrInfoProvider
The application factory contains the application that should be run.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionAppFactory
(String appID, String serverEnvironmentName, IAppLoader loader, IJarFile jarFile, AppDefinition definition) Load the application from an Jar file or just creates a development instance.AppFactory
(String appID, String serverEnvironmentName, IAppLoader loader, File file, AppDefinition definition) Load the application from an Jar file or just creates a development instance.Method Summary
Modifier and TypeMethodDescriptionvoid
addModuleProject
(ModuleProjectPropCnr project) Adds a Module Project to the application.final boolean
addUserLoginProhibitedInterval
(TimeInterval timeInterval) Removes a time interval when user login is prohibited.boolean
Returns the projects ready flag.boolean
Returns the projects ready flag.boolean
cacheCustomCSS
(String url) Caches the custom CSS URL.int
Adds the SVG image information as being sent to the client.createPropMgr
(ServerShell server) Creates the Property Manager with reference resolving to the application static properties.void
dispose()
Disposes of this factory.boolean
Gets the flag for adding the reference string in an attribute when editing the KString in a rich text editor.protected void
finalize()
Upon finalize, the factory is disposed of if not previously done.Gets the application definition that loaded the app.Gets the application factory.static AppFactory
getAppFactory
(GProp<?> anyProp) From a property, virtualized or not, get the AppFactory instance.Gets the information of the application Jar file or the Module projects.getAppID()
Gets the Application ID.Gets the Application Root container that holds all the Module Projects and settings.Gets the class loader for the application used to load the user classes for the application.Gets the unmodifiable map of custom app properties, a map with keys and values.getCustomizedAppHTML
(ServerShell server, File file, String lang) Gets a customized "iiziApp.html" file for a specific application ID and optional language.double
getDPR()
Gets the device pixel ratio.Gets the environment properties to use.Map
<AuthenticationProvider, IServiceCreator<? extends AbstractOAuthService>> Gets the map of defined and initialized external authentication providers for the application.getFileOrResource
(String target) getFontFiles
(String fontFamily) Gets the mapping of a font name to the FontFiles instance.Gets the HTTP Server string prefix including port.getImageTarget
(String ref) Gets the image reference.Gets the Jar file for the Module.getModuleProject
(String name) Gets the Module project property container.Gets all the Module project containers.Gets the module project settings for the application.Gets the possible languages defined in text files that can be used for the application.getPreloadClientCacheResources
(ClientSessionGyro clientGyro) Gets the resources that are required to be downloaded to the client if not present or outdated.GProp
<?> Gets the property used for references look-up's.Gets the base reference name for the resource, typically an image, for the Server or the Designer.getRootFromName
(GProp<?> requestor, String module) Gets the module root for a name.GProp
<?> getRuntimePropFromReference
(String reference, boolean fallBackToNonVirtualized) Gets a reference for runtime use to get the reference of an item.getServerApplicationSetup
(String pluginID) Gets the configuration setup's for a plug-in with specified ID.Gets the server configuration environment properties for the current environment name.Returns the name of the server environment to use, e.g.Gets the language code to use.Gets the user authentication UI interface used for the initial login.final TimeInterval[]
Gets the time intervals when user login is prohibited.getVirtualizedReferenceLookupRetriever
(String reference) Gets the virtuals reference look-up for a reference.void
initialize
(IServer server) Initializes the factory and application.boolean
installFont
(String fontFamily) Installs the font families as specified by the font family.boolean
installFonts
(List<FontFiles> fontList) Installs the font face as specified by theFontFiles
instance for the Client Session.boolean
Is this factory disposed?boolean
Returns if the application requires user authentication every time it's started.final boolean
Checks if user login is enabled.final boolean
Verifies if the user login is permitted at the current time.void
Called when an application is instantiated and started by a user session.void
Called when an application is stopped.int
prepare
(ClassLoader parentClassLoader, Set<File> resources) Prepares the application for use, i.e.void
registerVirtualizedReferenceLookupRetriever
(String type, IVirtualizedReferenceLookupRetriever retriever) Registers a new virtuals reference look-up retriever for a plug-in.final void
setUserLoginEnabled
(boolean on) Sets the user login enabled flag.boolean
Flag indicating the "real" resolved string should be returned.boolean
Checks if the app uses external login or not.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.iizix.text.IKStringInfoProvider
installFonts
Methods inherited from interface com.iizix.server.app.IRuntimeReferenceLookup
getRuntimePropFromReference
Constructor Details
AppFactory
public AppFactory(String appID, String serverEnvironmentName, IAppLoader loader, File file, AppDefinition definition) throws IOException, PropException Load the application from an Jar file or just creates a development instance.- Parameters:
appID
- The application ID.serverEnvironmentName
- The name of the server environment to use, e.g. "default", "devel" or "prod", null for default.loader
- The loader.file
- The Jar file when running in non-development mode.definition
- The app definition, null for none.- Throws:
IOException
- For file errors.PropException
- For property errors.
AppFactory
public AppFactory(String appID, String serverEnvironmentName, IAppLoader loader, IJarFile jarFile, AppDefinition definition) throws IOException, PropException Load the application from an Jar file or just creates a development instance.- Parameters:
appID
- The application ID.serverEnvironmentName
- The name of the server environment to use, e.g. "default", "devel" or "prod", null for default.loader
- The loader.jarFile
- The Jar file when running in non-development mode.definition
- The app definition, null for none.- Throws:
IOException
- For file errors.PropException
- For property errors.
Method Details
getAppFactory
From a property, virtualized or not, get the AppFactory instance.- Parameters:
anyProp
- Any property in the tree.
getAppDefinition
Gets the application definition that loaded the app.- Returns:
- The application definition, or null if not loaded from a definition.
getAppFileSystemLocation
Gets the information of the application Jar file or the Module projects. The returned string is typically used for logging purposes.- Returns:
- A descriptive string of the application file system location.
areProjectsLoaded
public boolean areProjectsLoaded()Returns the projects ready flag.- Returns:
- false if any project is still not loaded, true if all projects are fully loaded.
areProjectsLoadedForReferences
public boolean areProjectsLoadedForReferences()Returns the projects ready flag.- Returns:
- false if any project is still not loaded, true if all projects are fully loaded.
dispose
public void dispose()Disposes of this factory.isDisposed
public boolean isDisposed()Is this factory disposed?- Returns:
true
if factory disposed.
onApplicationSessionStarted
Called when an application is instantiated and started by a user session.- Parameters:
appGyro
- The application session.
onApplicationSessionStopped
Called when an application is stopped.- Parameters:
appGyro
- The application session.
getAppFactory
Gets the application factory.- Specified by:
getAppFactory
in interfaceIRuntimeReferenceLookup
- Returns:
- The AppFactory.
finalize
Upon finalize, the factory is disposed of if not previously done. An error is logged if it has not been disposed of.getServerEnvironmentName
Returns the name of the server environment to use, e.g. "default", "devel" or "prod".getServerConfigEnvProps
Gets the server configuration environment properties for the current environment name. If the properties are not found, a SEVERE event is logged and null is returned.- Returns:
- The ServerConfigEnvProps, or null if not found.
getServerApplicationSetup
Gets the configuration setup's for a plug-in with specified ID. Each plug-in may present several configurations, although most commonly a single one. If the configuration environment is not found, a SEVERE event is logged and null is returned.- Parameters:
pluginID
- The plug-in ID.- Returns:
- The configuration setup, or null if the server environment configuration or plug-in configuration is not found. If the plug-in is found but no configurations, an empty array is returned.
initialize
Initializes the factory and application.- Parameters:
server
- The Server instance.
getJarFile
Gets the Jar file for the Module. This Jar file can be a Jar-in-Jar file, or null if running in development mode (use getDevelopmentDirectory() instead).- Returns:
- The Jar file or null when running in development mode.
registerVirtualizedReferenceLookupRetriever
public void registerVirtualizedReferenceLookupRetriever(String type, IVirtualizedReferenceLookupRetriever retriever) Registers a new virtuals reference look-up retriever for a plug-in.- Parameters:
type
- The reference type, i.e. the string after the Module model, e.g. "panel" for Panels, "vs" for VirtualSpace, and "screen" for Terminal Screens.retriever
- The virtuals reference look-up retriever instance for the type.
getVirtualizedReferenceLookupRetriever
Gets the virtuals reference look-up for a reference.- Parameters:
reference
- The reference.- Returns:
- The reference look-up instance, or null if not found.
getCommonClassLoader
Gets the class loader for the application used to load the user classes for the application.- Specified by:
getCommonClassLoader
in interfaceIAppOwner
- Returns:
- A class loader.
createPropMgr
Creates the Property Manager with reference resolving to the application static properties. The reference resolving is typically used for images, i.e. aIPropMgrInfoProvider
is implemented.- Parameters:
server
- The Server instance.
addModuleProject
Adds a Module Project to the application.- Parameters:
project
- The loaded project.- Throws:
PropException
- If the project cannot be added.
getModuleProject
Gets the Module project property container.- Parameters:
name
- The name of the Module project without alias.- Returns:
- The container, or null if not found.
getModuleProjects
Gets all the Module project containers.- Returns:
- The array of Module project containers.
getModuleSettings
Gets the module project settings for the application.- Returns:
- The settings, null if not yet loaded.
getCustomAppMap
Gets the unmodifiable map of custom app properties, a map with keys and values.- Returns:
- The map, or
null
if not defined.
getExternalAuthenticationProviderMap
public Map<AuthenticationProvider,IServiceCreator<? extends AbstractOAuthService>> getExternalAuthenticationProviderMap()Gets the map of defined and initialized external authentication providers for the application.- Returns:
- An unmodifiable map sorted by
Enum.ordinal()
with its service creator interface. Note that this map may be empty if no external authentication providers are configured for the application.
getPossibleLanguages
Gets the possible languages defined in text files that can be used for the application.- Returns:
- A cached read-only list of possible languages.
prepare
public int prepare(ClassLoader parentClassLoader, Set<File> resources) throws PropException, IOException Prepares the application for use, i.e. load the user classes, resolves references, etc.- Parameters:
parentClassLoader
- The parent class loader, null for default.resources
- The list of classpath resources (files and directories) that is filled in.- Returns:
- The resolve failure count.
- Throws:
PropException
- If a property failed to resolve.IOException
- For I/O errors.IllegalStateException
- If already prepared once.
getAppID
Gets the Application ID.isUserAuthenticationAlwaysRequired
public boolean isUserAuthenticationAlwaysRequired()Returns if the application requires user authentication every time it's started.- Returns:
- true for user authentication always required, by password or fingerprint.
getAppRoot
Gets the Application Root container that holds all the Module Projects and settings.- Returns:
- The App root property container.
getFileOrResource
- Specified by:
getFileOrResource
in interfaceIAppOwner
- Parameters:
target
- The target reference as a normal Module reference string "module:/path/resource".- Returns:
- The
File
orWSJarResourceFile
for the resource,null
if not found.
getFontFiles
Gets the mapping of a font name to the FontFiles instance.- Parameters:
fontFamily
- The font family.- Returns:
- The read-only FontFiles List instance, null if not found.
getRuntimePropFromReference
Gets a reference for runtime use to get the reference of an item. The reference must be fully qualified such as "*ALIAS:/type/path" or "MODULE:/type/path" and cannot be relative.If the flag
fallBackToNonVirtualized
is false, the search will not fallback to searching for the non-virtualized property in the runtime app. The result will only returned virtualized properties, i.e. for a reference as e.g. "module:/vs/someVS", and depending on where this method is called (the client session), also includes other virtualized properties such as panels as e.g. "module:/panel/somePanel".To always fallback to also searching the runtime app, specify
fallBackToNonVirtualized
to true.- Specified by:
getRuntimePropFromReference
in interfaceIRuntimeReferenceLookup
- Parameters:
reference
- The reference to look-up.fallBackToNonVirtualized
- Flag indicating a fallback to non-virtualized properties.- Returns:
- The property found, or null for reference not found.
getEnvironment
Gets the environment properties to use.- Specified by:
getEnvironment
in interfaceIRuntimeReferenceLookup
- Returns:
- The environment for the client session, original session or server in that priority order.
getRootFromName
Gets the module root for a name. In the Editor, the module is the project, and that root container is returned. In the Server, the module doesn't matter, so the real root returns itself.When running with assertions, this call throws an assertion error by default, showing that the call is directed to a non-root property container.
- Specified by:
getRootFromName
in interfaceIRuntimeReferenceLookup
- Parameters:
requestor
- The requestor property.module
- The module name (without colon), i.e. the project name in the Designer.- Returns:
- The root property container, or null if this container is not the root, or if the module name is not found. The default implementation returns null.
getHTTPServer
Gets the HTTP Server string prefix including port.- Specified by:
getHTTPServer
in interfaceIKStringInfoProvider
- Returns:
- The "" because the client loads from relative path.
getImageTarget
Gets the image reference.- Specified by:
getImageTarget
in interfaceIKStringInfoProvider
- Parameters:
ref
- The image definition reference string.- Returns:
- The Image target interface, or null if not found.
doAddReference
public boolean doAddReference()Gets the flag for adding the reference string in an attribute when editing the KString in a rich text editor.- Specified by:
doAddReference
in interfaceIKStringInfoProvider
- Returns:
- Flag to add a special text reference for the rich text editor.
shouldResolve
public boolean shouldResolve()Flag indicating the "real" resolved string should be returned. This value is true for the runtime client when in "real run mode".- Specified by:
shouldResolve
in interfaceIKStringInfoProvider
- Returns:
- Flag to resolve strings or not.
getResolveReferenceProperty
Gets the property used for references look-up's.- Specified by:
getResolveReferenceProperty
in interfaceIKStringInfoProvider
- Returns:
- The property to use for looking up others.
getResourcePrefix
Gets the base reference name for the resource, typically an image, for the Server or the Designer. This reference is "/$" (the default in this interface) for the Designer, but should be "/$APPID/" for the Server, where APPID is the application being run by the client. The Server must therefore implement this method and return that string instead.- Specified by:
getResourcePrefix
in interfaceIKStringInfoProvider
- Returns:
- The resource prefix string: "/$APPID/" for the Server, where APPID is the application being run by the client.
getDPR
public double getDPR()Gets the device pixel ratio.- Specified by:
getDPR
in interfaceIKStringInfoProvider
- Returns:
- The device pixel ratio, default 1.0.
getTargetLanguageCode
Gets the language code to use.- Specified by:
getTargetLanguageCode
in interfaceIKStringInfoProvider
- Returns:
- The language code, or null for default.
installFont
Installs the font families as specified by the font family.- Specified by:
installFont
in interfaceIKStringInfoProvider
- Parameters:
fontFamily
- The font family or families.- Returns:
- true for success, false if the remote part doesn't support installation, e.g. in a preview browser.
installFonts
Installs the font face as specified by theFontFiles
instance for the Client Session. Once installed, the font family can be used.- Specified by:
installFonts
in interfaceIKStringInfoProvider
- Parameters:
fontList
- The list of font files to install.- Returns:
- true for success, false if the remote part doesn't support installation, e.g. in a preview browser.
cacheSVG
Adds the SVG image information as being sent to the client.This method is not intended to be called and logs a severe error and returns 1 (one).
- Specified by:
cacheSVG
in interfaceIPropMgrInfoProvider
- Parameters:
svgString
- The SVG string.- Returns:
- The cached index value for the SVG string. A negative value indicates that it needs sending to the client, whereas a positive means only the index is required to be sent. A return value of zero is an error and means not to send it to client at all.
cacheCustomCSS
Caches the custom CSS URL.- Specified by:
cacheCustomCSS
in interfaceIPropMgrInfoProvider
- Parameters:
url
- The URL of the Custom CSS.- Returns:
- Flag indicating the URL is already cached on the client side.
getPreloadClientCacheResources
public List<PreloadClientCacheResource> getPreloadClientCacheResources(ClientSessionGyro clientGyro) Gets the resources that are required to be downloaded to the client if not present or outdated.- Parameters:
clientGyro
- The client gyro.- Returns:
- The list of resources that are relevant for the client in question. The resources relative URLs must be prefixed with Application ID (i.e.
).getResourcePrefix()
getUserAuthenticationUI
Gets the user authentication UI interface used for the initial login.- Returns:
- The user authentication interface.
getCustomizedAppHTML
Gets a customized "iiziApp.html" file for a specific application ID and optional language.- Parameters:
server
- The server instance.file
- The compressed iiziApp.html file without customization.lang
- The language requested, ornull
for default.- Returns:
- The customized (and cached) file to send instead of the un-customized one, or
null
for none, i.e. in case of error.
isUserLoginEnabled
public final boolean isUserLoginEnabled()Checks if user login is enabled.- Returns:
- The user login enabled flag.
setUserLoginEnabled
Sets the user login enabled flag.- Parameters:
on
- The enabled flag.- Throws:
SecurityException
- If the caller is not allowed to perform this function.
isUserLoginPermittedNow
public final boolean isUserLoginPermittedNow()Verifies if the user login is permitted at the current time.- Returns:
- The login permission flag.
getUserLoginProhibitedIntervals
Gets the time intervals when user login is prohibited.- Returns:
- The array of time intervals.
addUserLoginProhibitedInterval
public final boolean addUserLoginProhibitedInterval(TimeInterval timeInterval) throws SecurityException Removes a time interval when user login is prohibited.- Parameters:
timeInterval
- The time interval.- Returns:
- Success flag
true
meaning OK,false
means no change, or the interval was already present. - Throws:
SecurityException
- If the caller is not allowed to perform this function.
usesExternalLogin
public boolean usesExternalLogin()Checks if the app uses external login or not.- Returns:
true
if external login is required.