samples/componentinjection/anagram-modular/src-app-property/org/apidesign/anagram/app/property/AnagramsWithProperties.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 10:07:30 +0200
changeset 233 15d31c98a129
parent 224 7a15b5efae6a
permissions -rw-r--r--
Making the examples more appropriate for the book
jtulach@223
     1
package org.apidesign.anagram.app.property;
jtulach@221
     2
jtulach@221
     3
import org.apidesign.anagram.api.Scrambler;
jtulach@221
     4
import org.apidesign.anagram.api.WordLibrary;
jtulach@221
     5
import org.apidesign.anagram.gui.Anagrams;
jtulach@221
     6
jtulach@221
     7
public final class AnagramsWithProperties extends Anagrams {
jtulach@221
     8
    private WordLibrary wordLibrary;
jtulach@221
     9
    private Scrambler scrambler;
jtulach@221
    10
    
jtulach@221
    11
    public AnagramsWithProperties() {
jtulach@221
    12
    }
jtulach@233
    13
jtulach@233
    14
    // BEGIN: anagram.property
jtulach@221
    15
    @Override
jtulach@221
    16
    protected WordLibrary getWordLibrary() {
jtulach@221
    17
        try {
jtulach@221
    18
            if (wordLibrary == null) {
jtulach@224
    19
                String implName = System.getProperty(
jtulach@224
    20
                    "org.apidesign.anagram.api.WordLibrary"
jtulach@224
    21
                );
jtulach@222
    22
                assert implName != null;
jtulach@222
    23
                Class<?> impl = Class.forName(implName);
jtulach@222
    24
                wordLibrary = (WordLibrary)impl.newInstance();
jtulach@221
    25
            }
jtulach@221
    26
            return wordLibrary;
jtulach@221
    27
        } catch (Exception ex) {
jtulach@221
    28
            throw new IllegalStateException(ex);
jtulach@221
    29
        }
jtulach@221
    30
    }
jtulach@221
    31
jtulach@221
    32
    @Override
jtulach@221
    33
    protected Scrambler getScrambler() {
jtulach@221
    34
        try {
jtulach@221
    35
            if (scrambler == null) {
jtulach@224
    36
                String implName = System.getProperty(
jtulach@224
    37
                    "org.apidesign.anagram.api.Scrambler"
jtulach@224
    38
                );
jtulach@222
    39
                assert implName != null;
jtulach@222
    40
                Class<?> impl = Class.forName(implName);
jtulach@222
    41
                scrambler = (Scrambler)impl.newInstance();
jtulach@221
    42
            }
jtulach@221
    43
            return scrambler;
jtulach@221
    44
        } catch (Exception ex) {
jtulach@221
    45
            throw new IllegalStateException(ex);
jtulach@221
    46
        }
jtulach@221
    47
    }
jtulach@233
    48
    // END: anagram.property
jtulach@221
    49
}