1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.impl; |
18 |
|
|
19 |
|
import org.apache.camel.CamelContext; |
20 |
|
import org.apache.camel.NoSuchLanguageException; |
21 |
|
import org.apache.camel.spi.Language; |
22 |
|
import org.apache.camel.spi.LanguageResolver; |
23 |
|
import org.apache.camel.util.FactoryFinder; |
24 |
|
import org.apache.camel.util.NoFactoryAvailableException; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
363 |
public class DefaultLanguageResolver implements LanguageResolver { |
30 |
3 |
protected static final FactoryFinder LANGUAGE_FACTORY = new FactoryFinder("META-INF/services/org/apache/camel/language/"); |
31 |
3 |
protected static final FactoryFinder LANGUAGE_RESOLVER = new FactoryFinder("META-INF/services/org/apache/camel/language/resolver/"); |
32 |
|
|
33 |
|
public Language resolveLanguage(String name, CamelContext context) { |
34 |
39 |
Class type = null; |
35 |
|
try { |
36 |
39 |
type = LANGUAGE_FACTORY.findClass(name); |
37 |
0 |
} catch (NoFactoryAvailableException e) { |
38 |
|
|
39 |
0 |
} catch (Throwable e) { |
40 |
0 |
throw new IllegalArgumentException("Invalid URI, no Language registered for scheme : " + name, e); |
41 |
39 |
} |
42 |
39 |
if (type != null) { |
43 |
39 |
if (Language.class.isAssignableFrom(type)) { |
44 |
39 |
return (Language)context.getInjector().newInstance(type); |
45 |
|
} else { |
46 |
0 |
throw new IllegalArgumentException("Type is not a Language implementation. Found: " + type.getName()); |
47 |
|
} |
48 |
|
} |
49 |
0 |
return noSpecificLanguageFound(name, context); |
50 |
|
} |
51 |
|
|
52 |
|
protected Language noSpecificLanguageFound(String name, CamelContext context) { |
53 |
0 |
Class type = null; |
54 |
|
try { |
55 |
0 |
type = LANGUAGE_RESOLVER.findClass("default"); |
56 |
0 |
} catch (NoFactoryAvailableException e) { |
57 |
|
|
58 |
0 |
} catch (Throwable e) { |
59 |
0 |
throw new IllegalArgumentException("Invalid URI, no Language registered for scheme : " + name, e); |
60 |
0 |
} |
61 |
0 |
if (type != null) { |
62 |
0 |
if (LanguageResolver.class.isAssignableFrom(type)) { |
63 |
0 |
LanguageResolver resolver = (LanguageResolver)context.getInjector().newInstance(type); |
64 |
0 |
return resolver.resolveLanguage(name, context); |
65 |
|
} else { |
66 |
0 |
throw new IllegalArgumentException("Type is not a LanguageResolver implementation. Found: " + type.getName()); |
67 |
|
} |
68 |
|
} |
69 |
0 |
throw new NoSuchLanguageException(name); |
70 |
|
} |
71 |
|
} |