-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XPath: replace reflective calls with native functions #2214
Comments
Scala macro annotations should be able to handle this. You would write something like: @XPathFunction
def runProcessByName(scope: String, name: String): Unit = ... and this would produce: class RunProcessByNameFn extends XFormsFunction with FunctionSupport {
override def iterate(xpathContext: XPathContext): SequenceIterator = {
// 1. Convert function parameters
...
// 2. Call native function
val result = runProcessByName(...)
// 3. Convert and return function result
...
}
} Type conversions, currently done in The functions created this way must also be registered with a function library, with the proper XPath signature: Fun("run-process-by-name", classOf[RunProcessByNameFn], ...) Open questions:
|
As a first step, we should place an |
- missing: Form Builder functions - missing: Other functions which won't be used on client - still need to create an actual annotation
- must still go through all FB functions, see #2214
[+1 from community] for |
Some pointers for Scala macro annotations: |
Tasks:
|
Updated example of generated code: @XPathFunction
def runProcessByName(scope: String, name: String): Unit = ...
MyLibrary.registerFunction(
// Pass signature
xpathName = "run-process-by-name",
minArity = 2, // needed?
returnType = Type.ITEM_TYPE, EMPTY,
args = List(
Arg(STRING, EXACTLY_ONE),
Arg(STRING, EXACTLY_ONE)
),
constructor = new XFormsFunction with FunctionSupport {
override def iterate(xpathContext: XPathContext): SequenceIterator = {
// 1. Convert function parameters
...
// 2. Call native function
val result = runProcessByName(...)
// 3. Convert and return function result
...
}
}
) |
Just hit a bug whereby we incorrectly handle, at runtime, a returned |
We now group all Form Builder functions in |
The Scala side of this feature falls under the "macro paradise" plugin. As of Scala 2.13, this is still experimental, but it is now part of the compiler (see also release notes). |
Q: Do we create one function library per file, or do we have the implementation in the file register the functions to another, external library? The annotation could have parameters if needed: @XPathFunction(ns = "...", lilbrary = ..., xmlName = "...") As a start, make the enclosing class/object explicitly a function library. The macro generates registration code for that. |
Classes/objects that expose
|
We can also consider explicitly or implicitly passing, depending on the function signature:
For example: @XPathFunction
def foo(
a: String,
b: Option[om.NodeInfo])(implicit
xpc: XPathContext,
xffc: XFormsFunction.Context
): Iterable[om.NodeInfo] = ??? In that case, the macro would pass the parameters. |
We now have the first simple functions implemented with macros on the offline branch. Missing:
|
For a small Form Builder-built form, here are the functions used in the resulting XForms:
We can prioritize those. |
If we add the wizard view:
|
This is done for the JavaScript runtime, including XForms and Form Runner, on the offline branch.
|
Scala.js doesn't have reflection, so we cannot use direct Java/Scala calls. We could imagine using
JSExport
in Scala.js to expose functions, but we won't be able to dynamically know their parameter types, which is needed right now to convert parameters back and forth.There are about 70 functions used by Form Runner. They are gathered below. For reference, I added also the Form Builder functions, which we might want to expose natively on the server too.
Only a subset of those might make sense on the client.
Steps:
Functions in
org.orbeon.oxf.fr.FormRunner
:frf:allAuthorizedOperationsAssumingOwnerGroupMember
frf:authorizedOperationsBasedOnRoles
frf:autosaveSupported
frf:buildPDFFieldNameFromHTML
frf:canNavigateNew
frf:canNavigateSummary
frf:canPublishLocal
frf:canPublishLocalToRemote
frf:canPublishRemote
frf:canPublishRemoteToLocal
frf:canSelectLocalNewer
frf:canSelectPublishedLocal
frf:canSelectPublishedRemote
frf:canSelectRemoteNewer
frf:canSelectUnpublishedLocal
frf:canSelectUnpublishedRemote
frf:canUnpublishLocal
frf:canUnpublishRemote
frf:canUpgradeLocal
frf:canUpgradeRemote
frf:collectDataAttachmentNodesJava
frf:controlNameFromId
frf:controlNameFromIdOpt
frf:controlSortString
frf:createFormDataBasePath
frf:createFormDefinitionBasePath
frf:createFormMetadataDocument
frf:currentFormResources
frf:duplicate
frf:errorMessage
frf:findRepeatedControlsForTarget
frf:getFormLangSelection
frf:getPDFFormatExpression
frf:getPDFFormats
frf:htmlFieldLabel
frf:hyperlinkURLs
frf:isLocalNewer
frf:isLocalUnavailable
frf:isMultipleSelectionControl
frf:isRemoteAvailable
frf:isRemoteNewer
frf:isRemoteUnavailable
frf:isSingleSelectionControl
frf:isWizardValidate
frf:joinLocalAndRemoteMetadata
frf:orbeonRolesSequence
frf:ownerGroupPermissionsSupported
frf:pdfFilenameOrNull
frf:publish
frf:remoteServersXPath
frf:resolveTargetRelativeToActionSource
frf:selectFormLang
frf:selectFormRunnerLang
frf:sendError
frf:showCaptcha
frf:successMessage
frf:topLevelSectionNameForControlId
frf:topLevelSectionsWithErrors
frf:updateIteration
frf:versioningSupported
frf:xpathAllAuthorizedOperations
Functions in
org.orbeon.oxf.fr.process.SimpleProcess
:process:runProcess
process:runProcessByName
Other functions:
org.orbeon.oxf.fr.DataMigration
migration:dataMaybeMigratedFrom
migration:dataMaybeMigratedTo
migration:findLegacyGridBindsAndTemplates
(FB)migration:buildGridMigrationMap
(FB)org.orbeon.oxf.util.SecureUtils
secure:randomHexId
org.orbeon.oxf.util.ScalaUtils
utils:truncateWithEllipsis
org.orbeon.oxf.common.Version
version:isPE
Functions in
org.orbeon.oxf.fb.FormBuilder
(won't be used on client):fbf:MinimalIEVersion
fbf:bindId
fbf:bindingForControlElementOrEmpty
fbf:buildFormBuilderControlAbsoluteIdOrEmpty
fbf:buildFormBuilderControlEffectiveIdOrEmpty
fbf:containerById
fbf:controlNameFromId
fbf:controlsInCol
fbf:controlsInContainer
fbf:controlsInRow
fbf:countAllControls
fbf:countAllNonContainers
fbf:countGrids
fbf:countRepeats
fbf:countSectionTemplates
fbf:countSections
fbf:currentLang
fbf:defaultIterationName
fbf:deleteCellContent
fbf:deleteCol
fbf:deleteGridById
fbf:deleteRow
fbf:deleteSectionById
fbf:deleteSectionTemplateContentHolders
fbf:expandCell
fbf:expandCellTouchesControl
fbf:findBindByNameOrEmpty
fbf:findBlankLHHAHoldersAndElements
fbf:findControlBoundNodeByName
fbf:findControlByNameOrEmpty
fbf:findRepeatIterationNameOrEmpty
fbf:findSchemaOrEmpty
fbf:findSchemaPrefixOrEmpty
fbf:formBuilderPermissionsAsXML
fbf:getAllControlNamesXPath
fbf:getBindNameOrEmpty
fbf:getContainerNameOrEmpty
fbf:getControlHelpOrEmpty
fbf:getControlItemsGroupedByValue
fbf:getFormDoc
fbf:getNormalizedMaxOrEmpty
fbf:getNormalizedMin
fbf:gridCanDoClasses
fbf:hasCustomIterationName
fbf:hasEditor
fbf:initializeGrids
fbf:insertColLeft
fbf:insertColRight
fbf:insertRowAbove
fbf:insertRowBelow
fbf:isBrowserSupported
fbf:isContentRepeat
fbf:isControlLHHAHTMLMediatype
fbf:isLegacyRepeat
fbf:isRepeat
fbf:iterateSelfAndDescendantBindsResourceHoldersXPath
fbf:metadataInstanceRoot
fbf:moveSectionDown
fbf:moveSectionLeft
fbf:moveSectionRight
fbf:moveSectionUp
fbf:nextIds
fbf:possibleAppearancesByControlNameAsXML
fbf:publish
fbf:readDefaultAlertAsXML
fbf:readMipAsAttributeOnlyOrEmpty
fbf:readValidationsAsXML
fbf:renameControlIfNeeded
fbf:renameControlIterationIfNeeded
fbf:resourcesInstanceRoot
fbf:resourcesRoot
fbf:sectionCanDoClasses
fbf:setControlHelp
fbf:setControlItems
fbf:setControlLHHAMediatype
fbf:setRepeatProperties
fbf:shrinkCell
fbf:updateMipAsAttributeOnly
fbf:writeAlertsAndValidationsAsXML
Other functions which won't be used on client:
java.util.Map
org.orbeon.oxf.fb.ToolboxOps
org.orbeon.oxf.fb.MigrationOps
org.orbeon.oxf.pipeline.api.FunctionLibrary
org.orbeon.oxf.processor.pipeline.PipelineFunctionLibrary
org.orbeon.oxf.util.NetUtils
org.orbeon.oxf.xml.SaxonUtils
org.orbeon.oxf.xforms.processor.XFormsResourceServer
org.orbeon.xbl.SimpleCaptcha
org.orbeon.saxon.sxpath.IndependentContext
org.orbeon.saxon.sxpath.XPathEvaluator
org.orbeon.saxon.sxpath.XPathExpression
The text was updated successfully, but these errors were encountered: