~ldd/oowebdict/trunk

« back to all changes in this revision

Viewing changes to jsrc/com/lddubeau/oowebdict/comp/BasicLexiconImpl.java

  • Committer: ldd at lddubeau
  • Date: 2011-04-22 23:56:20 UTC
  • mfrom: (3.1.5 oowebdict)
  • Revision ID: ldd@lddubeau.com-20110422235620-kx223tvhknlvx541
Tags: oowebdict-0.4
VersionĀ 0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.lddubeau.oowebdict.comp;
 
2
 
 
3
import java.net.MalformedURLException;
 
4
 
 
5
import com.lddubeau.ddb.BasicLexicon;
 
6
import com.lddubeau.ddb.CancelledByUser;
 
7
import com.lddubeau.oowebdict.comp.IndexImpl.ProgressGlue;
 
8
import com.sun.star.lang.XSingleComponentFactory;
 
9
import com.sun.star.lib.uno.helper.Factory;
 
10
import com.sun.star.lib.uno.helper.WeakBase;
 
11
import com.sun.star.registry.XRegistryKey;
 
12
import com.sun.star.uno.Exception;
 
13
import com.sun.star.uno.XComponentContext;
 
14
 
 
15
public final class BasicLexiconImpl extends WeakBase
 
16
                implements
 
17
                        com.sun.star.lang.XInitialization,
 
18
                        com.lddubeau.oowebdict.XBasicLexicon,
 
19
                        com.sun.star.lang.XServiceInfo
 
20
{
 
21
        private final XComponentContext m_xContext;
 
22
 
 
23
        private static final String m_implementationName = BasicLexiconImpl.class
 
24
                        .getName();
 
25
 
 
26
        protected static final String __serviceName = "com.lddubeau.oowebdict.BasicLexicon";
 
27
 
 
28
        private BasicLexicon lexicon = null;
 
29
 
 
30
        public BasicLexiconImpl(XComponentContext context)
 
31
        {
 
32
                m_xContext = context;
 
33
        };
 
34
 
 
35
        public static XSingleComponentFactory __getComponentFactory(
 
36
                        String sImplementationName)
 
37
        {
 
38
                XSingleComponentFactory xFactory = null;
 
39
 
 
40
                if (sImplementationName.equals(m_implementationName))
 
41
                        xFactory = Factory.createComponentFactory(BasicLexiconImpl.class,
 
42
                                        new String[]{__serviceName});
 
43
                return xFactory;
 
44
        }
 
45
 
 
46
        public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey)
 
47
        {
 
48
                return Factory.writeRegistryServiceInfo(m_implementationName,
 
49
                                new String[]{__serviceName}, xRegistryKey);
 
50
        }
 
51
 
 
52
        // com.sun.star.lang.XInitialization:
 
53
        public void initialize(Object [] aArguments)
 
54
                        throws com.sun.star.uno.Exception
 
55
        {
 
56
                try
 
57
                {
 
58
                        String url = (String) aArguments[0];
 
59
                        this.lexicon = new BasicLexicon(url, new ProgressGlue(url));
 
60
                }
 
61
                catch (MalformedURLException ex)
 
62
                {
 
63
                        throw new Exception("bad URL " + (String) aArguments[0] + " "
 
64
                                        + ex.toString());
 
65
                }
 
66
        }
 
67
 
 
68
        // com.lddubeau.oowebdict.XBasicLexicon:
 
69
        public boolean exists(String term)
 
70
                        throws com.lddubeau.oowebdict.CancelledByUser
 
71
        {
 
72
                try
 
73
                {
 
74
                        return this.lexicon.exists(term);
 
75
                }
 
76
                catch (CancelledByUser e)
 
77
                {
 
78
                        throw new com.lddubeau.oowebdict.CancelledByUser();
 
79
                }
 
80
        }
 
81
 
 
82
        public int getLongestTermLength()
 
83
                        throws com.lddubeau.oowebdict.CancelledByUser
 
84
        {
 
85
                try
 
86
                {
 
87
                        return this.lexicon.getLongestTermLength();
 
88
                }
 
89
                catch (CancelledByUser e)
 
90
                {
 
91
                        throw new com.lddubeau.oowebdict.CancelledByUser();
 
92
                }
 
93
        }
 
94
 
 
95
        public String getTermData(String term)
 
96
                        throws com.lddubeau.oowebdict.CancelledByUser
 
97
        {
 
98
                try
 
99
                {
 
100
                        String ret = this.lexicon.getTermData(term);
 
101
                        // By IDL requirements, we can't return null. 
 
102
                        return (ret == null)?"":ret;
 
103
                }
 
104
                catch (CancelledByUser e)
 
105
                {
 
106
                        throw new com.lddubeau.oowebdict.CancelledByUser();
 
107
                }
 
108
        }
 
109
 
 
110
        // com.sun.star.lang.XServiceInfo:
 
111
        public String getImplementationName()
 
112
        {
 
113
                return m_implementationName;
 
114
        }
 
115
 
 
116
        public boolean supportsService(String sService)
 
117
        {
 
118
                return sService.equals(__serviceName);
 
119
        }
 
120
 
 
121
        public String [] getSupportedServiceNames()
 
122
        {
 
123
                return new String[] {__serviceName};
 
124
        }
 
125
 
 
126
}