remove assert looking for new compatibilityMode DOCX
[LibreOffice.git] / wizards / source / scriptforge / _ModuleModel.xba
blob135eced58af150e8ebbc6ba8ad88fee442d2dad4
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="_ModuleModel" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === Full documentation is available on https://help.libreoffice.org/ ===
6 REM =======================================================================================================================
8 Option Compatible
9 Option ClassModule
10 &apos;Option Private Module
12 Option Explicit
14 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
15 &apos;&apos;&apos; ModuleModel (aka SF_Model)
16 &apos;&apos;&apos; ===========
17 &apos;&apos;&apos; Illustration of how the ScriptForge modules are structured
18 &apos;&apos;&apos; Copy and paste this code in an empty Basic module to start a new service
19 &apos;&apos;&apos; Comment in, comment out, erase what you want, but at the end respect the overall structure
20 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
22 REM ================================================================== EXCEPTIONS
24 &apos;&apos;&apos; FAKENEWSERROR
26 REM ============================================================= PRIVATE MEMBERS
28 Private [Me] As Object &apos; Should be initialized immediately after the New statement
29 &apos; Dim obj As Object : Set obj = New SF_Model
30 &apos; Set obj.[Me] = obj
31 Private [_Parent] As Object &apos; To keep trace of the instance having created a sub-instance
32 &apos; Set obj._Parent = [Me]
33 Private ObjectType As String &apos; Must be UNIQUE
35 REM ============================================================ MODULE CONSTANTS
37 Private Const SOMECONSTANT = 1
39 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
41 REM -----------------------------------------------------------------------------
42 Private Sub Class_Initialize()
43 Set [Me] = Nothing
44 Set [_Parent] = Nothing
45 ObjectType = &quot;MODEL&quot;
46 End Sub &apos; ScriptForge.SF_Model Constructor
48 REM -----------------------------------------------------------------------------
49 Private Sub Class_Terminate()
50 Call Class_Initialize()
51 End Sub &apos; ScriptForge.SF_Model Destructor
53 REM -----------------------------------------------------------------------------
54 Public Function Dispose() As Variant
55 Call Class_Terminate()
56 Set Dispose = Nothing
57 End Function &apos; ScriptForge.SF_Model Explicit Destructor
59 REM ================================================================== PROPERTIES
61 REM -----------------------------------------------------------------------------
62 Property Get MyProperty() As Boolean
63 &apos;&apos;&apos; Returns True or False
64 &apos;&apos;&apos; Example:
65 &apos;&apos;&apos; myModel.MyProperty
67 MyProperty = _PropertyGet(&quot;MyProperty&quot;)
69 End Property &apos; ScriptForge.SF_Model.MyProperty
71 REM ===================================================================== METHODS
73 REM -----------------------------------------------------------------------------
74 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
75 &apos;&apos;&apos; Return the actual value of the given property
76 &apos;&apos;&apos; Args:
77 &apos;&apos;&apos; PropertyName: the name of the property as a string
78 &apos;&apos;&apos; Returns:
79 &apos;&apos;&apos; The actual value of the property
80 &apos;&apos;&apos; If the property does not exist, returns Null
81 &apos;&apos;&apos; Exceptions:
82 &apos;&apos;&apos; see the exceptions of the individual properties
83 &apos;&apos;&apos; Examples:
84 &apos;&apos;&apos; myModel.GetProperty(&quot;MyProperty&quot;)
86 Const cstThisSub = &quot;Model.GetProperty&quot;
87 Const cstSubArgs = &quot;&quot;
89 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
90 GetProperty = Null
92 Check:
93 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
94 If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
95 End If
97 Try:
98 GetProperty = _PropertyGet(PropertyName)
100 Finally:
101 SF_Utils._ExitFunction(cstThisSub)
102 Exit Function
103 Catch:
104 GoTo Finally
105 End Function &apos; ScriptForge.SF_Model.GetProperty
107 REM -----------------------------------------------------------------------------
108 Public Function Methods() As Variant
109 &apos;&apos;&apos; Return the list of public methods of the Model service as an array
111 Methods = Array( _
112 &quot;MyFunction&quot; _
113 , &quot;etc&quot; _
116 End Function &apos; ScriptForge.SF_Model.Methods
118 REM -----------------------------------------------------------------------------
119 Public Function MyFunction(Optional ByVal Arg1 As Variant _
120 , Optional ByVal Arg2 As Variant _
121 ) As Variant
122 &apos;&apos;&apos; Fictive function that concatenates Arg1 Arg2 times
123 &apos;&apos;&apos; Args:
124 &apos;&apos;&apos; Arg1 String Text
125 &apos;&apos;&apos; Arg2 Numeric Number of times (default = 2)
126 &apos;&apos;&apos; Returns:
127 &apos;&apos;&apos; The new string
128 &apos;&apos;&apos; Exceptions:
129 &apos;&apos;&apos; FAKENEWSERROR
130 &apos;&apos;&apos; Examples:
131 &apos;&apos;&apos; MyFunction(&quot;value1&quot;) returns &quot;value1value1&quot;
133 Dim sOutput As String &apos; Output buffer
134 Dim i As Integer
135 Const cstThisSub = &quot;Model.myFunction&quot;
136 Const cstSubArgs = &quot;Arg1, [Arg2=2]&quot;
138 &apos; _ErrorHandling returns False when, for debugging, the standard error handling is preferred
139 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
140 myFunction = &quot;&quot;
142 Check:
143 If IsMissing(Arg2) Then Arg2 = 2
144 &apos; _EnterFunction returns True when current method is invoked from a user script
145 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
146 &apos; Check Arg1 is a string and Arg2 is a number.
147 &apos; Validation rules for scalars and arrays are described in SF_Utils
148 If Not SF_Utils._Validate(Arg1, &quot;Arg1&quot;, V_STRING) Then GoTo Finally
149 If Not SF_Utils._Validate(Arg2, &quot;Arg2&quot;, V_NUMERIC) Then GoTo Finally
150 &apos; Fatal error ?
151 If Arg2 &lt; 0 Then GoTo CatchFake
152 End If
154 Try:
155 sOutput = &quot;&quot;
156 For i = 0 To Arg2
157 sOutput = sOutput &amp; Arg1
158 Next i
159 myFunction = sOutput
161 Finally:
162 &apos; _ExitFunction manages internal (On Local) errors
163 SF_Utils._ExitFunction(cstThisSub)
164 Exit Function
165 Catch:
166 GoTo Finally
167 CatchFake:
168 SF_Exception.RaiseFatal(&quot;FAKENEWSERROR&quot;, cstThisSub)
169 GoTo Finally
170 End Function &apos; ScriptForge.SF_Model.myFunction
172 REM -----------------------------------------------------------------------------
173 Public Function Properties() As Variant
174 &apos;&apos;&apos; Return the list or properties of the Model class as an array
176 Properties = Array( _
177 &quot;MyProperty&quot; _
178 , &quot;etc&quot; _
181 End Function &apos; ScriptForge.SF_Model.Properties
183 REM =========================================================== PRIVATE FUNCTIONS
185 REM -----------------------------------------------------------------------------
186 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
187 &apos;&apos;&apos; Return the value of the named property
188 &apos;&apos;&apos; Args:
189 &apos;&apos;&apos; psProperty: the name of the property
191 Dim cstThisSub As String
192 Const cstSubArgs = &quot;&quot;
194 cstThisSub = &quot;SF_Model.get&quot; &amp; psProperty
195 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
197 Select Case psProperty
198 Case &quot;MyProperty&quot;
199 _PropertyGet = TBD
200 Case Else
201 _PropertyGet = Null
202 End Select
204 Finally:
205 SF_Utils._ExitFunction(cstThisSub)
206 Exit Function
207 End Function &apos; ScriptForge.SF_Model._PropertyGet
209 REM -----------------------------------------------------------------------------
210 Private Function _Repr() As String
211 &apos;&apos;&apos; Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
212 &apos;&apos;&apos; Args:
213 &apos;&apos;&apos; Return:
214 &apos;&apos;&apos; &quot;[MODEL]: A readable string&quot;
216 _Repr = &quot;[MODEL]: A readable string&quot;
218 End Function &apos; ScriptForge.SF_Model._Repr
220 REM ============================================ END OF SCRIPTFORGE.SF_MODEL
221 </script:module>