use of groovy.lang.GroovyObject in project groovy by apache.
the class Demo method compile.
protected GroovyObject compile(String fileName) throws Exception {
Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
GroovyObject object = (GroovyObject) groovyClass.newInstance();
assertTrue(object != null);
return object;
}
use of groovy.lang.GroovyObject in project groovy by apache.
the class GPathResult method getBody.
/**
* Creates a Closure representing the body of this GPathResult.
*
* @return the body of this GPathResult, converted to a <code>Closure</code>
*/
public Closure getBody() {
return new Closure(this.parent, this) {
public void doCall(Object[] args) {
final GroovyObject delegate = (GroovyObject) getDelegate();
final GPathResult thisObject = (GPathResult) getThisObject();
Node node = (Node) thisObject.getAt(0);
List children = node.children();
for (Object child : children) {
delegate.getProperty("mkp");
if (child instanceof Node) {
delegate.invokeMethod("yield", new Object[] { new NodeChild((Node) child, thisObject, "*", null) });
} else {
delegate.invokeMethod("yield", new Object[] { child });
}
}
}
};
}
use of groovy.lang.GroovyObject in project groovy by apache.
the class Node method build.
public void build(final GroovyObject builder, final Map namespaceMap, final Map<String, String> namespaceTagHints) {
if (this.replacementNodeStack.empty()) {
final Closure rest = new Closure(null) {
public Object doCall(final Object o) {
buildChildren(builder, namespaceMap, namespaceTagHints);
return null;
}
};
if (this.namespaceURI.length() == 0 && this.attributeNamespaces.isEmpty()) {
builder.invokeMethod(this.name, new Object[] { this.attributes, rest });
} else {
final List newTags = new LinkedList();
builder.getProperty("mkp");
final List namespaces = (List) builder.invokeMethod("getNamespaces", new Object[] {});
final Map current = (Map) namespaces.get(0);
final Map pending = (Map) namespaces.get(1);
if (this.attributeNamespaces.isEmpty()) {
builder.getProperty(getTagFor(this.namespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder));
builder.invokeMethod(this.name, new Object[] { this.attributes, rest });
} else {
final Map attributesWithNamespaces = new HashMap(this.attributes);
for (Object key : this.attributes.keySet()) {
final Object attributeNamespaceURI = this.attributeNamespaces.get(key);
if (attributeNamespaceURI != null) {
attributesWithNamespaces.put(getTagFor(attributeNamespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder) + "$" + key, attributesWithNamespaces.remove(key));
}
}
builder.getProperty(getTagFor(this.namespaceURI, current, pending, namespaceMap, namespaceTagHints, newTags, builder));
builder.invokeMethod(this.name, new Object[] { attributesWithNamespaces, rest });
}
// remove the new tags we had to define for this element
if (!newTags.isEmpty()) {
final Iterator iter = newTags.iterator();
do {
pending.remove(iter.next());
} while (iter.hasNext());
}
}
} else {
((ReplacementNode) this.replacementNodeStack.peek()).build(builder, namespaceMap, namespaceTagHints);
}
}
use of groovy.lang.GroovyObject in project cucumber-jvm by cucumber.
the class GroovyWorld method findWorldWithMethod.
private GroovyObject findWorldWithMethod(String methodName, Object arguments) {
Object[] args = unwrapMethodArguments(arguments);
if (worlds.isEmpty()) {
throw new MissingMethodException(methodName, this.getClass(), args);
}
if (worlds.size() == 1) {
return worlds.get(0);
}
GroovyObject worldWithMethod = null;
for (GroovyObject world : worlds) {
if (world.getMetaClass().getMetaMethod(methodName, args) != null) {
if (worldWithMethod == null) {
worldWithMethod = world;
} else {
throw new RuntimeException("Multiple method call: " + methodName);
}
}
}
if (worldWithMethod == null) {
throw new MissingMethodException(methodName, this.getClass(), args);
}
return worldWithMethod;
}
use of groovy.lang.GroovyObject in project runesource by PureCS.
the class PluginHandler method loadPlugins.
/**
* Loads all plugins.
*
* @param pluginsFile a text file containing a list of plugins to load
* @throws Exception
*/
public static void loadPlugins(String pluginsFile) throws Exception {
loadedPluginFile = pluginsFile;
File file = new File(pluginsFile);
BufferedReader reader = new BufferedReader(new FileReader(file));
String pluginName;
while ((pluginName = reader.readLine()) != null) {
if (pluginName.trim().length() == 0)
continue;
// Loading the plugin instance
Class cls = classLoader.parseClass(new File(PLUGIN_DIRECTORY + pluginName + ".groovy"));
GroovyObject obj = (GroovyObject) cls.newInstance();
Plugin plugin = (Plugin) obj;
plugin.setInstance(obj);
register(pluginName.replace('/', '.'), plugin);
}
}
Aggregations