Java Code Examples for groovy.lang.GroovyObject#getProperty()
The following examples show how to use
groovy.lang.GroovyObject#getProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GPathResult.java From groovy with Apache License 2.0 | 6 votes |
/** * 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}); } } } }; }
Example 2
Source File: Node.java From groovy with Apache License 2.0 | 5 votes |
private static String getTagFor(final Object namespaceURI, final Map current, final Map pending, final Map local, final Map tagHints, final List newTags, final GroovyObject builder) { String tag = findNamespaceTag(pending, namespaceURI); // look in the namespaces whose declaration has already been emitted if (tag == null) { tag = findNamespaceTag(current, namespaceURI); // look in the namespaces who will be declared at the next element if (tag == null) { // we have to declare the namespace - choose a tag tag = findNamespaceTag(local, namespaceURI); // If the namespace has been declared in the GPath expression use that tag if (tag == null || tag.length() == 0) { tag = findNamespaceTag(tagHints, namespaceURI); // If the namespace has been used in the parse document use that tag } if (tag == null || tag.length() == 0) { // otherwise make up a new tag and check it has not been used before int suffix = 0; do { final String possibleTag = "tag" + suffix++; if (!pending.containsKey(possibleTag) && !current.containsKey(possibleTag) && !local.containsKey(possibleTag)) { tag = possibleTag; } } while (tag == null); } final Map newNamespace = new HashMap(); newNamespace.put(tag, namespaceURI); builder.getProperty("mkp"); builder.invokeMethod("declareNamespace", new Object[]{newNamespace}); newTags.add(tag); } } return tag; }
Example 3
Source File: Node.java From groovy with Apache License 2.0 | 5 votes |
private void buildChildren(final GroovyObject builder, final Map namespaceMap, final Map<String, String> namespaceTagHints) { for (Object child : this.children) { if (child instanceof Node) { ((Node) child).build(builder, namespaceMap, namespaceTagHints); } else if (child instanceof Buildable) { ((Buildable) child).build(builder); } else { builder.getProperty("mkp"); builder.invokeMethod("yield", new Object[]{child}); } } }
Example 4
Source File: InvokerHelper.java From groovy with Apache License 2.0 | 5 votes |
public static Object getProperty(Object object, String property) { if (object == null) { object = NullObject.getNullObject(); } if (object instanceof GroovyObject) { GroovyObject pogo = (GroovyObject) object; return pogo.getProperty(property); } else if (object instanceof Class) { Class c = (Class) object; return metaRegistry.getMetaClass(c).getProperty(object, property); } else { return ((MetaClassRegistryImpl) metaRegistry).getMetaClass(object).getProperty(object, property); } }
Example 5
Source File: GetPropertyTest.java From groovy with Apache License 2.0 | 5 votes |
public void testProperty() throws Exception { GroovyObject object = compile("src/test/org/codehaus/groovy/classgen/MyBean.groovy"); System.out.println("Got object: " + object); Object value = object.getProperty("name"); assertEquals("name property", "James", value); object.setProperty("name", "Bob"); assertEquals("name property", "Bob", object.getProperty("name")); }
Example 6
Source File: GroovyCapabilityDefinition.java From arcusplatform with Apache License 2.0 | 4 votes |
public static CapabilityHandlerContext getContext(GroovyObject context) { return (CapabilityHandlerContext)context.getProperty("__capability_handler_context__"); }
Example 7
Source File: Attributes.java From groovy with Apache License 2.0 | 4 votes |
public void build(final GroovyObject builder) { builder.getProperty("mkp"); builder.invokeMethod("yield", new Object[]{text()}); }
Example 8
Source File: Attribute.java From groovy with Apache License 2.0 | 4 votes |
public void build(final GroovyObject builder) { builder.getProperty("mkp"); builder.invokeMethod("yield", new Object[]{this.value}); }
Example 9
Source File: Node.java From groovy with Apache License 2.0 | 4 votes |
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); } }
Example 10
Source File: ScriptBytecodeAdapter.java From groovy with Apache License 2.0 | 4 votes |
public static Object getGroovyObjectProperty(Class senderClass, GroovyObject receiver, String messageName) throws Throwable { return receiver.getProperty(messageName); }
Example 11
Source File: InvokerHelper.java From groovy with Apache License 2.0 | 4 votes |
public static Object getGroovyObjectProperty(GroovyObject object, String property) { return object.getProperty(property); }