Separating initializaiton code into separate class
authorJaroslav Tulach <jtulach@netbeans.org>
Tue, 11 Feb 2014 21:59:17 +0100
changeset 831b1d3f559196
parent 62 a714dd168248
child 84 9fcc1e38b4c9
Separating initializaiton code into separate class
chat/client/src/main/java/org/apidesign/html/chatserver/client/ChatClient.java
chat/client/src/main/java/org/apidesign/html/chatserver/client/Main.java
chat/client/src/main/resources/org/apidesign/html/chatserver/client/chat.html
     1.1 --- a/chat/client/src/main/java/org/apidesign/html/chatserver/client/ChatClient.java	Fri Feb 07 14:05:42 2014 +0100
     1.2 +++ b/chat/client/src/main/java/org/apidesign/html/chatserver/client/ChatClient.java	Tue Feb 11 21:59:17 2014 +0100
     1.3 @@ -87,19 +87,4 @@
     1.4          }
     1.5          m.updateMsgs("" + (now + 1));
     1.6      }
     1.7 -    
     1.8 -    static {
     1.9 -        ChatModel chm = new ChatModel();
    1.10 -        Message m = new Message();
    1.11 -        m.setComment("Waiting for messages from the server...");
    1.12 -        m.setUser("system");
    1.13 -        chm.getMsgs().add(m);
    1.14 -        chm.applyBindings();
    1.15 -        try {
    1.16 -            // XXX: this should not be in static initializer -
    1.17 -            // XXX: prevents unit testing!
    1.18 -            chm.initialRead();
    1.19 -        } catch (Throwable ex) {
    1.20 -        }
    1.21 -    }
    1.22  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/chat/client/src/main/java/org/apidesign/html/chatserver/client/Main.java	Tue Feb 11 21:59:17 2014 +0100
     2.3 @@ -0,0 +1,45 @@
     2.4 +/**
     2.5 + * The MIT License (MIT)
     2.6 + *
     2.7 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.8 + *
     2.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
    2.10 + * of this software and associated documentation files (the "Software"), to deal
    2.11 + * in the Software without restriction, including without limitation the rights
    2.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    2.13 + * copies of the Software, and to permit persons to whom the Software is
    2.14 + * furnished to do so, subject to the following conditions:
    2.15 + *
    2.16 + * The above copyright notice and this permission notice shall be included in
    2.17 + * all copies or substantial portions of the Software.
    2.18 + *
    2.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    2.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    2.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    2.22 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    2.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    2.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    2.25 + * THE SOFTWARE.
    2.26 + */
    2.27 +package org.apidesign.html.chatserver.client;
    2.28 +
    2.29 +import org.apidesign.html.chatserver.model.Message;
    2.30 +
    2.31 +/**
    2.32 + *
    2.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    2.34 + */
    2.35 +public class Main {
    2.36 +    private Main() {
    2.37 +    }
    2.38 +    
    2.39 +    static {
    2.40 +        ChatModel chm = new ChatModel();
    2.41 +        Message m = new Message();
    2.42 +        m.setComment("Waiting for messages from the server...");
    2.43 +        m.setUser("system");
    2.44 +        chm.getMsgs().add(m);
    2.45 +        chm.applyBindings();
    2.46 +        chm.initialRead();
    2.47 +    }
    2.48 +}
     3.1 --- a/chat/client/src/main/resources/org/apidesign/html/chatserver/client/chat.html	Fri Feb 07 14:05:42 2014 +0100
     3.2 +++ b/chat/client/src/main/resources/org/apidesign/html/chatserver/client/chat.html	Tue Feb 11 21:59:17 2014 +0100
     3.3 @@ -47,7 +47,7 @@
     3.4          <script src="bck2brwsr.js"></script>
     3.5          <script type="text/javascript">
     3.6              var vm = bck2brwsr('chat-client-1.0-SNAPSHOT.jar');
     3.7 -            vm.loadClass('org.apidesign.html.chatserver.client.ChatClient');
     3.8 +            vm.loadClass('org.apidesign.html.chatserver.client.Main');
     3.9          </script>
    3.10          
    3.11      </body>