KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > create > AbstractCreator


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.create;
17
18 import java.util.Map JavaDoc;
19
20 import org.directwebremoting.extend.Creator;
21 import org.directwebremoting.util.LocalUtil;
22 import org.directwebremoting.util.Messages;
23
24 /**
25  * A simple implementation of the basic parts of Creator
26  * @author Joe Walker [joe at getahead dot ltd dot uk]
27  */

28 public abstract class AbstractCreator implements Creator
29 {
30     /* (non-Javadoc)
31      * @see org.directwebremoting.Creator#setProperties(java.util.Map)
32      */

33     public void setProperties(Map JavaDoc params) throws IllegalArgumentException JavaDoc
34     {
35         // The default is to use getters and setters
36
}
37
38     /**
39      * @return Returns the javascript name.
40      */

41     public String JavaDoc getJavascript()
42     {
43         return javascript;
44     }
45
46     /**
47      * @param javascript The javascript name to set.
48      */

49     public void setJavascript(String JavaDoc javascript)
50     {
51         this.javascript = javascript;
52     }
53
54     /**
55      * @param scope Set the scope.
56      */

57     public void setScope(String JavaDoc scope)
58     {
59         checkScope(scope);
60         this.scope = scope;
61     }
62
63     /* (non-Javadoc)
64      * @see org.directwebremoting.Creator#getScope()
65      */

66     public String JavaDoc getScope()
67     {
68         return scope;
69     }
70
71     /* (non-Javadoc)
72      * @see org.directwebremoting.Creator#isCacheable()
73      */

74     public boolean isCacheable()
75     {
76         return cacheable;
77     }
78
79     /**
80      * @param cacheable Whether or not to cache the script.
81      */

82     public void setCacheable(boolean cacheable)
83     {
84         this.cacheable = cacheable;
85     }
86
87     /**
88      * Is the given scope valid?
89      * @param cscope The scope string to match
90      */

91     protected static void checkScope(String JavaDoc cscope)
92     {
93         if (!cscope.equals(SCRIPT) && !cscope.equals(PAGE) && !cscope.equals(REQUEST) && !cscope.equals(SESSION) && !cscope.equals(APPLICATION))
94         {
95             throw new IllegalArgumentException JavaDoc(Messages.getString("AbstractCreator.IllegalScope", cscope));
96         }
97     }
98
99     /* (non-Javadoc)
100      * @see java.lang.Object#toString()
101      */

102     public String JavaDoc toString()
103     {
104         return LocalUtil.getShortClassName(getClass()) + "[" + getJavascript() + "]";
105     }
106
107     /**
108      * Do the methods on the Creator change over time?
109      */

110     private boolean cacheable = false;
111
112     /**
113      * The javascript name for the class
114      */

115     private String JavaDoc javascript = null;
116
117     /**
118      * The scope of the objects created by this creator
119      */

120     private String JavaDoc scope = PAGE;
121 }
122
Popular Tags