Changes for page WebObjects with Scala

Last modified by Ravi Mendis on 2011/05/10 02:10

From version 340.1
edited by Ravi Mendis
on 2009/10/13 18:54
Change comment: There is no comment for this version
To version 338.1
edited by Ravi Mendis
on 2009/12/15 18:08
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -47,8 +47,10 @@
47 47  Scala doesn't have static variables or methods. However, a class can have a //Companion Object// that will allow you to achieve something equivalent to static variables.
48 48  One of the advantages of this approach is that it is **thread-safe**, so you don't have to worry about synchronizing access to these fields in a concurrent application.
49 49  
50 -In Java:
50 +The following is an example of the use of a //Companion Object// for Talent in Scala instead of Talent static fields in Java.
51 51  
52 +Java:
53 +
52 52  {{code}}
53 53  
54 54  public class _Talent extends EOGenericRecord {
... ... @@ -56,11 +56,11 @@
56 56  
57 57  {{/code}}
58 58  
59 -In Scala:
61 +Scala:
60 60  
61 61  {{code}}
62 62  
63 -object _Talent extends EOGenericRecord {
65 +object Talent extends EOGenericRecord {
64 64   val ENTITY_NAME = "Talent"
65 65  
66 66  {{/code}}
... ... @@ -153,6 +153,28 @@
153 153  
154 154  {{/code}}
155 155  
158 +==== Scala Annotations vs. Generic Accessors ====
159 +
160 +An example of accessing variables in WebObjects with the following languages:
161 +
162 +|= |= Objective-C |= Java |= Scala
163 +|= getter | ##object name## | ##object.name()## | ##object.name##
164 +|= setter | ##object setName:aName## | ##object.setName(aName)## | ##object.name = aName##
165 +
166 +Of course in Java, we may generate WebObjects classes with "get" methods as well in order to stick to convention.
167 +In scala there is an additional convenience we may use to produce "get" and "set" methods in addition to the default Scala accessors - Scala Annotations.
168 +
169 +E.g, in Main.scala we annotate our component keys with ##@BeanProperty## to automatically create public "set" and "get" methods.
170 +These variables can then be accessed via //KVC//.
171 +
172 +{{code}}
173 +
174 +@BeanProperty var username = new String()
175 +@BeanProperty var password = new String()
176 +@BeanProperty var isAssistantCheckboxVisible = false
177 +
178 +{{/code}}
179 +
156 156  == How to Use Scala Collections with EOF ==
157 157  
158 158  One of the benefits of Scala is its very powerful, concurrency-ready collection classes - primarily ##List##, ##Map##, ##Seq## and ##Set##.
... ... @@ -195,15 +195,21 @@
195 195  === Setup ===
196 196  
197 197  1. [[Install the Scala eclipse IDE>>http://www.scala-lang.org/node/94]]
198 -1. Install and run the OpenBase OBMovies database.
222 +1. Install and start the OpenBase OBMovies database.
199 199  1. Right-click on Application.java and run as a WOApplication (as usual).
200 200  
201 201  ==== EO Templates ====
202 202  
203 -See: [[Scala templates>>http://wiki.objectstyle.org/confluence/display/WOL/EOGenerator+Templates+and+Additions]]
204 -
205 205  When you create your ##.eogen## file, be sure to make the following changes in the EOGenerator Editor:
206 206  
207 -1. Point to the local .eotemplate files for ##Entity## and ##//Entity//##
229 +1. Point to the local [[Scala versions>>http://wiki.objectstyle.org/confluence/display/WOL/EOGenerator+Templates+and+Additions]] of the .eotemplate files for ##Entity## and ##//Entity//##
208 208  1. Change the File Names Extension to "scala"
231 +1. In Destination Paths set the Superclass Package (e.g: base)
209 209  1. Uncheck Java under Options
233 +
234 +== How to Build & Deploy a WebObjects Scala Project with Ant ==
235 +
236 +1. Download an install Scala
237 +1. The ##scala.home## (the location Scala has been installed onto) to the project ##build.properties## file
238 +1. Add the ##scalac## tasks to the ant build.xml file
239 +1. Customise the app classpath file. i.e either ##MacOSClasspath.txt## or ##UNIXClasspath.txt##. You will need to add an entry for ##scala-library.jar##