01: /*
02: * Copyright 2007 Tim Peierls
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.guice;
17:
18: import com.google.inject.Key;
19: import com.google.inject.Injector;
20:
21: import java.util.Map;
22:
23: import org.directwebremoting.extend.Creator;
24:
25: /**
26: * Specialized creator implementation that uses an injector to
27: * look up its instances. This class is used by {@link InternalCreatorManager}.
28: * @author Tim Peierls [tim at peierls dot net]
29: */
30: class InternalCreator implements Creator {
31: InternalCreator(Injector injector, Key<?> key, String scriptName) {
32: this .injector = injector;
33: this .key = key;
34: this .scriptName = scriptName;
35: }
36:
37: /* (non-Javadoc)
38: * @see org.directwebremoting.extend.Creator#setProperties(java.util.Map)
39: */
40: public void setProperties(Map<String, String> params)
41: throws IllegalArgumentException {
42: // Do nothing, we ignore properties (since we inject everything we create).
43: }
44:
45: /* (non-Javadoc)
46: * @see org.directwebremoting.extend.Creator#getType()
47: */
48: public Class<?> getType() {
49: return (Class<?>) key.getTypeLiteral().getType();
50: }
51:
52: /* (non-Javadoc)
53: * @see org.directwebremoting.extend.Creator#getInstance()
54: */
55: public Object getInstance() throws InstantiationException {
56: return injector.getInstance(key);
57: }
58:
59: /* (non-Javadoc)
60: * @see org.directwebremoting.extend.Creator#getScope()
61: */
62: public String getScope() {
63: return Creator.PAGE; // i.e., tell DWR always to create
64: }
65:
66: /* (non-Javadoc)
67: * @see org.directwebremoting.extend.Creator#isCacheable()
68: */
69: public boolean isCacheable() {
70: return true;
71: }
72:
73: /* (non-Javadoc)
74: * @see org.directwebremoting.extend.Creator#getJavascript()
75: */
76: public String getJavascript() {
77: return scriptName;
78: }
79:
80: private final Injector injector;
81:
82: private final Key<?> key;
83:
84: private final String scriptName;
85: }
|