Package org.openbravo.client.kernel
Class KernelUtils
- java.lang.Object
-
- org.openbravo.client.kernel.KernelUtils
-
public class KernelUtils extends Object
Contains several utility methods used in the kernel.- Author:
- mtaal
-
-
Constructor Summary
Constructors Constructor Description KernelUtils()
Note this constructor should not be generally used, use insteadgetInstance()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
computeLowLevelCode(Module module, List<Module> modules)
String
createErrorJavaScript(Exception e)
Creates a javascript string which reports an exception to the client.org.codehaus.jettison.json.JSONObject
createErrorJSON(Exception e)
List<Module>
getDependencyTree(Module module)
Retrieves all the modules that are part of the dependency tree of the given module.String
getI18N(String key, String[] params)
static KernelUtils
getInstance()
Module
getModule(String javaPackage)
Get a module using its java package, the module is read from the internal cache.List<Module>
getModulesOrderedByDependency()
Note the result of this method is cached.String
getParentColumnName(Tab tab)
Returns the name of the parent column of the tabBaseOBObject
getParentRecord(BaseOBObject object, Tab tab)
Returns the parent object for a specified combination of DAL object and tab.Tab
getParentTab(Tab tab)
Returns the parent tab of a BaseOBObject which belongs to a given tabstatic Property
getProperty(Entity entity, Field field)
Compute the property from the field, assuming that the field is defined on the basis of entity.static Property
getProperty(Field field)
CallsgetProperty(Entity, Field)
using the entity of the tab of the field.Property
getPropertyFromColumn(Column column)
Property
getPropertyFromColumn(Column column, boolean includeIdColumn)
List<Tab>
getTabSubtabs(Tab tab, boolean onlyFirstLevel)
Returns the list of subtabs of a given tabString
getVersionParameters(Module module)
Computes parameters to add to a link of a resource.static boolean
hasNullableIdentifierProperties(Entity entity)
Returns true if any of the identifier properties of the provided entity is nullableboolean
isModulePresent(String javaPackage)
Returns "true" if the module given its java package exists and "false" if it doesn't.static void
setInstance(KernelUtils instance)
-
-
-
Constructor Detail
-
KernelUtils
public KernelUtils()
Note this constructor should not be generally used, use insteadgetInstance()
-
-
Method Detail
-
getInstance
public static KernelUtils getInstance()
-
setInstance
public static void setInstance(KernelUtils instance)
-
getPropertyFromColumn
public Property getPropertyFromColumn(Column column, boolean includeIdColumn)
-
createErrorJavaScript
public String createErrorJavaScript(Exception e)
Creates a javascript string which reports an exception to the client.
-
createErrorJSON
public org.codehaus.jettison.json.JSONObject createErrorJSON(Exception e)
-
getVersionParameters
public String getVersionParameters(Module module)
Computes parameters to add to a link of a resource. The parameters include the version and language of the user.- Parameters:
module
- Module to get the version from (if not in developers mode)- Returns:
- the version parameter string, a concatenation of the version and language with parameter names
- See Also:
KernelConstants.RESOURCE_VERSION_PARAMETER
,KernelConstants.RESOURCE_LANGUAGE_PARAMETER
-
isModulePresent
public boolean isModulePresent(String javaPackage)
Returns "true" if the module given its java package exists and "false" if it doesn't.- Parameters:
javaPackage
- the java package used to read the module- Returns:
- boolean
-
getModule
public Module getModule(String javaPackage)
Get a module using its java package, the module is read from the internal cache.- Parameters:
javaPackage
- the java package used to read the module- Returns:
- a Module
- Throws:
OBException
- if the module can not be found.
-
getModulesOrderedByDependency
public List<Module> getModulesOrderedByDependency()
Note the result of this method is cached. If module dependencies change then a system restart is required to refresh this cache.- Returns:
- the modules in order of their dependencies, so core will be the first module etc.
-
getDependencyTree
public List<Module> getDependencyTree(Module module)
Retrieves all the modules that are part of the dependency tree of the given module. This includes all the modules that depend on the provided module (ancestors) and their ancestors, as well as all the modules the provided module depends on (descendants) and their descendants.- Parameters:
module
- the module to get the dependency tree for- Returns:
- the full tree of dependencies for the given module
-
getParentRecord
public BaseOBObject getParentRecord(BaseOBObject object, Tab tab)
Returns the parent object for a specified combination of DAL object and tab. For example, returns the corresponding Sales Order header for a Sales Order Line Returns null if there is no parent object.- Parameters:
object
- The object whose parent should be returnedtab
- The tab the object belongs to- Returns:
- The BaseOBObject of the parent record
-
getParentTab
public Tab getParentTab(Tab tab)
Returns the parent tab of a BaseOBObject which belongs to a given tab- Parameters:
tab
- The tab the object belongs to- Returns:
- The parent tab of the given tab,
null
in case the tab is root
-
getTabSubtabs
public List<Tab> getTabSubtabs(Tab tab, boolean onlyFirstLevel)
Returns the list of subtabs of a given tab- Parameters:
tab
- The tab whose subtabs are to be retrievedonlyFirstLevel
- Boolean used to determine whether all the descendent tabs should be returned or only the next level ones- Returns:
- The list of subtabs of the given tab, an empty List if the tab has none
-
getProperty
public static Property getProperty(Field field)
CallsgetProperty(Entity, Field)
using the entity of the tab of the field.
-
getProperty
public static Property getProperty(Entity entity, Field field)
Compute the property from the field, assuming that the field is defined on the basis of entity.- Returns:
- The property associated to this field,
null
if the field is not associated to any property or column
-
getParentColumnName
public String getParentColumnName(Tab tab)
Returns the name of the parent column of the tab- Parameters:
tab
- The tab the object belongs to- Returns:
- The parent column of the table in the given tab,
null
in case there is no parent tab
-
hasNullableIdentifierProperties
public static boolean hasNullableIdentifierProperties(Entity entity)
Returns true if any of the identifier properties of the provided entity is nullable- Parameters:
entity
- entity whose identifier might be comprised by nullable properties- Returns:
- true if at least one of the identifier properties of the provided entity is nullable, false if all of them are mandatory
-
-