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 =======================================================================================================================
10 'Option Private Module
14 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
15 ''' ModuleModel (aka SF_Model)
16 ''' ===========
17 ''' Illustration of how the ScriptForge modules are structured
18 ''' Copy and paste this code in an empty Basic module to start a new service
19 ''' Comment in, comment out, erase what you want, but at the end respect the overall structure
20 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
22 REM ================================================================== EXCEPTIONS
24 ''' FAKENEWSERROR
26 REM ============================================================= PRIVATE MEMBERS
28 Private [Me] As Object
' Should be initialized immediately after the New statement
29 ' Dim obj As Object : Set obj = New SF_Model
30 ' Set obj.[Me] = obj
31 Private [_Parent] As Object
' To keep trace of the instance having created a sub-instance
32 ' Set obj._Parent = [Me]
33 Private ObjectType As String
' Must be UNIQUE
35 REM ============================================================ MODULE CONSTANTS
37 Private Const SOMECONSTANT =
1
39 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
41 REM -----------------------------------------------------------------------------
42 Private Sub Class_Initialize()
44 Set [_Parent] = Nothing
45 ObjectType =
"MODEL
"
46 End Sub
' ScriptForge.SF_Model Constructor
48 REM -----------------------------------------------------------------------------
49 Private Sub Class_Terminate()
50 Call Class_Initialize()
51 End Sub
' ScriptForge.SF_Model Destructor
53 REM -----------------------------------------------------------------------------
54 Public Function Dispose() As Variant
55 Call Class_Terminate()
57 End Function
' ScriptForge.SF_Model Explicit Destructor
59 REM ================================================================== PROPERTIES
61 REM -----------------------------------------------------------------------------
62 Property Get MyProperty() As Boolean
63 ''' Returns True or False
64 ''' Example:
65 ''' myModel.MyProperty
67 MyProperty = _PropertyGet(
"MyProperty
")
69 End Property
' ScriptForge.SF_Model.MyProperty
71 REM ===================================================================== METHODS
73 REM -----------------------------------------------------------------------------
74 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
75 ''' Return the actual value of the given property
76 ''' Args:
77 ''' PropertyName: the name of the property as a string
78 ''' Returns:
79 ''' The actual value of the property
80 ''' If the property does not exist, returns Null
81 ''' Exceptions:
82 ''' see the exceptions of the individual properties
83 ''' Examples:
84 ''' myModel.GetProperty(
"MyProperty
")
86 Const cstThisSub =
"Model.GetProperty
"
87 Const cstSubArgs =
""
89 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
93 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
94 If Not SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
98 GetProperty = _PropertyGet(PropertyName)
101 SF_Utils._ExitFunction(cstThisSub)
105 End Function
' ScriptForge.SF_Model.GetProperty
107 REM -----------------------------------------------------------------------------
108 Public Function Methods() As Variant
109 ''' Return the list of public methods of the Model service as an array
112 "MyFunction
" _
116 End Function
' ScriptForge.SF_Model.Methods
118 REM -----------------------------------------------------------------------------
119 Public Function MyFunction(Optional ByVal Arg1 As Variant _
120 , Optional ByVal Arg2 As Variant _
122 ''' Fictive function that concatenates Arg1 Arg2 times
123 ''' Args:
124 ''' Arg1 String Text
125 ''' Arg2 Numeric Number of times (default =
2)
126 ''' Returns:
127 ''' The new string
128 ''' Exceptions:
129 ''' FAKENEWSERROR
130 ''' Examples:
131 ''' MyFunction(
"value1
") returns
"value1value1
"
133 Dim sOutput As String
' Output buffer
135 Const cstThisSub =
"Model.myFunction
"
136 Const cstSubArgs =
"Arg1, [Arg2=
2]
"
138 ' _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 =
""
143 If IsMissing(Arg2) Then Arg2 =
2
144 ' _EnterFunction returns True when current method is invoked from a user script
145 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
146 ' Check Arg1 is a string and Arg2 is a number.
147 ' Validation rules for scalars and arrays are described in SF_Utils
148 If Not SF_Utils._Validate(Arg1,
"Arg1
", V_STRING) Then GoTo Finally
149 If Not SF_Utils._Validate(Arg2,
"Arg2
", V_NUMERIC) Then GoTo Finally
151 If Arg2
< 0 Then GoTo CatchFake
155 sOutput =
""
157 sOutput = sOutput
& Arg1
162 ' _ExitFunction manages internal (On Local) errors
163 SF_Utils._ExitFunction(cstThisSub)
168 SF_Exception.RaiseFatal(
"FAKENEWSERROR
", cstThisSub)
170 End Function
' ScriptForge.SF_Model.myFunction
172 REM -----------------------------------------------------------------------------
173 Public Function Properties() As Variant
174 ''' Return the list or properties of the Model class as an array
176 Properties = Array( _
177 "MyProperty
" _
181 End Function
' ScriptForge.SF_Model.Properties
183 REM =========================================================== PRIVATE FUNCTIONS
185 REM -----------------------------------------------------------------------------
186 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
187 ''' Return the value of the named property
188 ''' Args:
189 ''' psProperty: the name of the property
191 Dim cstThisSub As String
192 Const cstSubArgs =
""
194 cstThisSub =
"SF_Model.get
" & psProperty
195 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
197 Select Case psProperty
198 Case
"MyProperty
"
205 SF_Utils._ExitFunction(cstThisSub)
207 End Function
' ScriptForge.SF_Model._PropertyGet
209 REM -----------------------------------------------------------------------------
210 Private Function _Repr() As String
211 ''' Convert the Model instance to a readable string, typically for debugging purposes (DebugPrint ...)
212 ''' Args:
213 ''' Return:
214 ''' "[MODEL]: A readable string
"
216 _Repr =
"[MODEL]: A readable string
"
218 End Function
' ScriptForge.SF_Model._Repr
220 REM ============================================ END OF SCRIPTFORGE.SF_MODEL