Changes for page WebObjects with Scala

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

From version 362.1
edited by Ravi Mendis
on 2010/01/17 19:56
Change comment: There is no comment for this version
To version 364.1
edited by Ravi Mendis
on 2009/10/13 23:39
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,13 +1,10 @@
1 1  === What is Scala? ===
2 2  
3 -Scala is a language for concurrent computing.
4 -In the day and age of multi-core processors, concurrent computing can't be ignored.
3 +Scala is a modern language not unlike Groovy.
4 +It is said to be more powerful (and faster) than Groovy or Ruby which has been the reason for its adoption at sites like Twitter.
5 5  
6 -Many of Scala's features have been designed with concurrency in mind.
7 -Some of these may not be unfamiliar to Objective-C or WebObjects developers.
6 +Many of its features and paradigms favor multi-threading and concurrency. Some of these may not be unfamiliar to Objective-C and WebObjects developers. Here's a summary:
8 8  
9 -Here's a quick summary:
10 -
11 11  |= |= Objective-C |= Java |= Scala
12 12  |= Mutable/Immuable Datatypes | Collections //e.g: NSArray/NSMutableArray// | No | Yes
13 13  |= Closures | Blocks (//Extension//) | No | Anonymous Functions
... ... @@ -26,13 +26,13 @@
26 26  
27 27  === Why Use Scala? ===
28 28  
26 +With Web 2.0, building concurrent WebObjects applications is a must.
29 29  Developing and maintaining a concurrent or multi-threaded WebObjects application can be challenging.
30 30  
31 -The lack of static variables means that Scala is inherently thread-safe.
32 -It has concurrency that is effectively built-in to the language in the form of Actors.
29 +Scala offers concurrency that is (effectively) built-in to the language and is inherently thread-safe.
30 +In other words, developing Ajax (i.e asynchronous communication) with WO will require concurrent request handling and thread-safe code, for which Scala is a better choice than Java.
33 33  
34 -So for WebObjects developers, Scala offers itself as a powerful, safe and easy-to-use solution for concurrent applications.
35 -(In other words, Scala can be used for problems that would normally have required threads).
32 +In addition it may offer new solutions for concurrency in WebObjects and EOF.
36 36  
37 37  === Can WebObjects be Programmed In Scala? ===
38 38  
... ... @@ -54,7 +54,7 @@
54 54  
55 55  Java:
56 56  
57 -{{code value="java"}}
54 +{{code}}
58 58  
59 59  public class _Talent extends EOGenericRecord {
60 60   public static final String ENTITY_NAME = "Talent";
... ... @@ -65,7 +65,7 @@
65 65  
66 66  {{code}}
67 67  
68 -object Talent extends EOGenericRecord {
65 +object _Talent extends EOGenericRecord {
69 69   val ENTITY_NAME = "Talent"
70 70  
71 71  {{/code}}
... ... @@ -76,7 +76,7 @@
76 76  
77 77  In Java:
78 78  
79 -{{code value="java"}}
76 +{{code}}
80 80  
81 81  import com.webobjects.eocontrol.EOGenericRecord;
82 82  import com.webobjects.eocontrol.EORelationshipManipulation;
... ... @@ -99,7 +99,7 @@
99 99  
100 100  In Java:
101 101  
102 -{{code value="java"}}
99 +{{code}}
103 103  
104 104  public class MenuHeader extends WOComponent {
105 105  
... ... @@ -124,7 +124,7 @@
124 124  
125 125  In Java:
126 126  
127 -{{code value="java"}}
124 +{{code}}
128 128  
129 129  try {
130 130   EditPageInterface epi = D2W.factory().editPageForNewObjectWithEntityNamed(_manipulatedEntityName, session());
... ... @@ -158,28 +158,6 @@
158 158  
159 159  {{/code}}
160 160  
161 -==== Scala Annotations vs. Generic Accessors ====
162 -
163 -An example of accessing variables in WebObjects with the following languages:
164 -
165 -|= |= Objective-C |= Java |= Scala
166 -|= getter | ##object name## | ##object.name()## | ##object.name##
167 -|= setter | ##object setName:aName## | ##object.setName(aName)## | ##object.name = aName##
168 -
169 -Of course in Java, we may generate WebObjects classes with "get" methods as well in order to stick to convention.
170 -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.
171 -
172 -E.g, in Main.scala we annotate our component keys with ##@BeanProperty## to automatically create public "set" and "get" methods.
173 -These variables can then be accessed via //KVC//.
174 -
175 -{{code}}
176 -
177 -@BeanProperty var username = new String()
178 -@BeanProperty var password = new String()
179 -@BeanProperty var isAssistantCheckboxVisible = false
180 -
181 -{{/code}}
182 -
183 183  == How to Use Scala Collections with EOF ==
184 184  
185 185  One of the benefits of Scala is its very powerful, concurrency-ready collection classes - primarily ##List##, ##Map##, ##Seq## and ##Set##.
... ... @@ -231,12 +231,4 @@
231 231  
232 232  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//##
233 233  1. Change the File Names Extension to "scala"
234 -1. In Destination Paths set the Superclass Package (e.g: base)
235 235  1. Uncheck Java under Options
236 -
237 -== How to Build & Deploy a WebObjects Scala Project with Ant ==
238 -
239 -1. [[Download>>http://www.scala-lang.org/downloads]] and install Scala
240 -1. Set ##scala.home## (the location Scala has been installed onto) in the project ##build.properties## file
241 -1. [[Add the scalac task and properties>>Configuring Ant to Build Scala with WebObjects]] to the ant build.xml file
242 -1. Run from the project directory: ##sudo ant clean install##