001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.create;
017:
018: import java.util.Map;
019:
020: import org.apache.commons.logging.Log;
021: import org.apache.commons.logging.LogFactory;
022: import org.directwebremoting.extend.Creator;
023: import org.directwebremoting.util.LocalUtil;
024: import org.directwebremoting.util.Messages;
025:
026: /**
027: * A simple implementation of the basic parts of Creator
028: * @author Joe Walker [joe at getahead dot ltd dot uk]
029: */
030: public abstract class AbstractCreator implements Creator {
031: /* (non-Javadoc)
032: * @see org.directwebremoting.Creator#setProperties(java.util.Map)
033: */
034: public void setProperties(Map<String, String> params)
035: throws IllegalArgumentException {
036: // The default is to use getters and setters
037: }
038:
039: /**
040: * @return Returns the javascript name.
041: */
042: public String getJavascript() {
043: return javascript;
044: }
045:
046: /**
047: * @param javascript The javascript name to set.
048: */
049: public void setJavascript(String javascript) {
050: if (!LocalUtil.isJavaIdentifier(javascript)) {
051: log.error("Illegal identifier: '" + javascript + "'");
052: throw new IllegalArgumentException("Illegal identifier");
053: }
054:
055: this .javascript = javascript;
056: }
057:
058: /**
059: * @param scope Set the scope.
060: */
061: public void setScope(String scope) {
062: checkScope(scope);
063: this .scope = scope;
064: }
065:
066: /* (non-Javadoc)
067: * @see org.directwebremoting.Creator#getScope()
068: */
069: public String getScope() {
070: return scope;
071: }
072:
073: /* (non-Javadoc)
074: * @see org.directwebremoting.Creator#isCacheable()
075: */
076: public boolean isCacheable() {
077: return cacheable;
078: }
079:
080: /**
081: * @param cacheable Whether or not to cache the script.
082: */
083: public void setCacheable(boolean cacheable) {
084: this .cacheable = cacheable;
085: }
086:
087: /**
088: * Is the given scope valid?
089: * @param cscope The scope string to match
090: */
091: protected static void checkScope(String cscope) {
092: if (!cscope.equals(SCRIPT) && !cscope.equals(PAGE)
093: && !cscope.equals(REQUEST) && !cscope.equals(SESSION)
094: && !cscope.equals(APPLICATION)) {
095: throw new IllegalArgumentException(Messages.getString(
096: "AbstractCreator.IllegalScope", cscope));
097: }
098: }
099:
100: /* (non-Javadoc)
101: * @see java.lang.Object#toString()
102: */
103: @Override
104: public String toString() {
105: return getClass().getSimpleName() + "[" + getJavascript() + "]";
106: }
107:
108: /**
109: * Do the methods on the Creator change over time?
110: */
111: private boolean cacheable = false;
112:
113: /**
114: * The javascript name for the class
115: */
116: private String javascript = null;
117:
118: /**
119: * The scope of the objects created by this creator
120: */
121: private String scope = PAGE;
122:
123: /**
124: * The log stream
125: */
126: private static final Log log = LogFactory
127: .getLog(AbstractCreator.class);
128: }
|