01: /* Copyright 2007 David N. Welton - DedaSys LLC - http://www.dedasys.com
02:
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14: */
15:
16: package org.hecl.java;
17:
18: import java.util.Enumeration;
19: import java.util.Vector;
20:
21: import org.hecl.HeclException;
22: import org.hecl.IntThing;
23: import org.hecl.Interp;
24: import org.hecl.Properties;
25: import org.hecl.Thing;
26:
27: /**
28: * The <code>MethodProps</code> class is utilized during the
29: * instantiation of classes, where it's possible to do things like:
30: * foo -new $bar -text "blah" -color red, where the keys are
31: * transformed into methods like setText and setColor, and run with
32: * the provided values. This is sort of hackey, but it works, given
33: * that setters with that naming convention are ubiquitous in the Java
34: * world.
35: *
36: * @author <a href="mailto:davidw@dedasys.com">David N. Welton</a>
37: * @version 1.0
38: */
39: public class MethodProps extends Properties {
40:
41: public MethodProps() {
42: super ();
43: }
44:
45: public void evalProps(Interp interp, Object target, Reflector ref)
46: throws HeclException {
47:
48: Enumeration names = props.keys();
49: while (names.hasMoreElements()) {
50: String name = (String) names.nextElement();
51: String methodname = "set" + name.substring(1);
52: /* First two need to be null to replace cmdname and subcmdname. */
53: Thing[] argv = { null, null, getProp(name) };
54: ref.evaluate(target, methodname, argv);
55: }
56: }
57: }
|