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 jsx3.app;
017:
018: import org.directwebremoting.ScriptBuffer;
019: import org.directwebremoting.proxy.ScriptProxy;
020: import org.directwebremoting.proxy.io.Context;
021:
022: /**
023: * Read-Only system settings interface.
024: * @author Joe Walker [joe at getahead dot org]
025: * @author DRAPGEN - Dwr Reverse Ajax Proxy GENerator
026: */
027: public class Settings extends jsx3.lang.Object {
028: /**
029: * All reverse ajax proxies need context to work from
030: * @param scriptProxy The place we are writing scripts to
031: * @param context The script that got us to where we are now
032: */
033: public Settings(Context context, String extension,
034: ScriptProxy scriptProxy) {
035: super (context, extension, scriptProxy);
036: }
037:
038: /**
039: * The instance initializer. Creates a view onto the settings persisted on disk. All identical instances of this
040: class are backed by the same XML source document.
041: * @param intDomain the domain of the settings to load, one of <code>jsx3.app.Settings.DOMAIN</code>...
042: * @param objInstance if in the project or addin domain, the key of the specific project or addin to load settings for
043: */
044: public Settings(int intDomain, String objInstance) {
045: super ((Context) null, (String) null, (ScriptProxy) null);
046: ScriptBuffer script = new ScriptBuffer();
047: script.appendCall("new Settings", intDomain, objInstance);
048: setInitScript(script);
049: }
050:
051: /**
052: * The instance initializer. Creates a view onto the settings persisted on disk. All identical instances of this
053: class are backed by the same XML source document.
054: * @param intDomain the domain of the settings to load, one of <code>jsx3.app.Settings.DOMAIN</code>...
055: * @param objInstance if in the project or addin domain, the key of the specific project or addin to load settings for
056: */
057: public Settings(jsx3.xml.CdfDocument intDomain,
058: jsx3.lang.Object objInstance) {
059: super ((Context) null, (String) null, (ScriptProxy) null);
060: ScriptBuffer script = new ScriptBuffer();
061: script.appendCall("new Settings", intDomain, objInstance);
062: setInitScript(script);
063: }
064:
065: /**
066: * The instance initializer. Creates a view onto the settings persisted on disk. All identical instances of this
067: class are backed by the same XML source document.
068: * @param intDomain the domain of the settings to load, one of <code>jsx3.app.Settings.DOMAIN</code>...
069: * @param objInstance if in the project or addin domain, the key of the specific project or addin to load settings for
070: */
071: public Settings(jsx3.xml.CdfDocument intDomain, String objInstance) {
072: super ((Context) null, (String) null, (ScriptProxy) null);
073: ScriptBuffer script = new ScriptBuffer();
074: script.appendCall("new Settings", intDomain, objInstance);
075: setInitScript(script);
076: }
077:
078: /**
079: * The instance initializer. Creates a view onto the settings persisted on disk. All identical instances of this
080: class are backed by the same XML source document.
081: * @param intDomain the domain of the settings to load, one of <code>jsx3.app.Settings.DOMAIN</code>...
082: * @param objInstance if in the project or addin domain, the key of the specific project or addin to load settings for
083: */
084: public Settings(int intDomain, jsx3.lang.Object objInstance) {
085: super ((Context) null, (String) null, (ScriptProxy) null);
086: ScriptBuffer script = new ScriptBuffer();
087: script.appendCall("new Settings", intDomain, objInstance);
088: setInitScript(script);
089: }
090:
091: /**
092: *
093: */
094: public static final int DOMAIN_PROJECT = 2;
095:
096: /**
097: *
098: */
099: public static final int DOMAIN_ADDIN = 3;
100:
101: /**
102: * Returns a stored setting value.
103: * @param strKey the setting key.
104: * @param callback the stored value.
105: */
106: @SuppressWarnings("unchecked")
107: public void get(String strKey,
108: org.directwebremoting.proxy.Callback<String> callback) {
109: ScriptBuffer script = new ScriptBuffer();
110: String callbackPrefix = "";
111:
112: if (callback != null) {
113: callbackPrefix = "var reply = ";
114: }
115:
116: script.appendCall(callbackPrefix + getContextPath() + "get",
117: strKey);
118:
119: if (callback != null) {
120: String key = org.directwebremoting.extend.CallbackHelper
121: .saveCallback(callback, String.class);
122: script
123: .appendCall("__System.activateCallback", key,
124: "reply");
125: }
126:
127: getScriptProxy().addScript(script);
128: }
129:
130: /**
131: * Returns a stored setting value as the raw XML node.
132: * @param strKey the setting key.
133: */
134: @SuppressWarnings("unchecked")
135: public jsx3.xml.Node getNode(String strKey) {
136: String extension = "getNode(\"" + strKey + "\").";
137: try {
138: java.lang.reflect.Constructor<jsx3.xml.Node> ctor = jsx3.xml.Node.class
139: .getConstructor(Context.class, String.class,
140: ScriptProxy.class);
141: return ctor.newInstance(this , extension, getScriptProxy());
142: } catch (Exception ex) {
143: throw new IllegalArgumentException("Unsupported type: "
144: + jsx3.xml.Node.class.getName());
145: }
146: }
147:
148: }
|