@Override public Object getProperty(String property) { if (this.definitionWrapper.isReadableProperty(property)) { return this.definitionWrapper.getPropertyValue(property); } else if (dynamicProperties.contains(property)) { return null; } return super.getProperty(property); }
public Object invokeMethod(String name, Object args) { Object value = get(); if (value != null) { try { return InvokerHelper.invokeMethod(value, name, args); } catch (Exception e) { return super.invokeMethod(name, args); } } else { return super.invokeMethod(name, args); } }
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public void setProperty(String property, Object newValue) { /** @todo we should check if we have the property with the metaClass instead of try/catch */ try { super.setProperty(property, newValue); } catch (MissingPropertyException e) { setVariable(property, newValue); } }
public Object invokeMethod(String name, Object args) { return getMetaClass().invokeMethod(this, name, args); }
/** * Replaces the MetaClass of this GPathResult. * * @param metaClass the new MetaClass */ @Override public void setMetaClass(final MetaClass metaClass) { final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) { @Override public Object getAttribute(final Object object, final String attribute) { return GPathResult.this.getProperty("@" + attribute); } @Override public void setAttribute(final Object object, final String attribute, final Object newValue) { GPathResult.this.setProperty("@" + attribute, newValue); } }; super.setMetaClass(newMetaClass); }
public Object getProperty(String property) { return getMetaClass().getProperty(this, property); }
public void setMetaClass(final MetaClass metaClass) { final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) { /* (non-Javadoc) * @see groovy.lang.DelegatingMetaClass#getAttribute(java.lang.Object, java.lang.String) */ public Object getAttribute(final Object object, final String attribute) { return GPathResult.this.getProperty("@" + attribute); } public void setAttribute(final Object object, final String attribute, final Object newValue) { GPathResult.this.setProperty("@" + attribute, newValue); } }; super.setMetaClass(newMetaClass); }
public Object invokeMethod(String name, Object args) { try { return super.invokeMethod(name, args); } catch (MissingMethodException e) { return InvokerHelper.invokeMethod(adaptee, name, args); } }
public void setProperty(String property, Object newValue) { getMetaClass().setProperty(this, property, newValue); }
public Object getProperty(String property) { Object answer = getVariable(property); if (answer == null) { answer = super.getProperty(property); } return answer; }
public void setProperty(String property, Object newValue) { Object value = get(); if (value != null) { InvokerHelper.setProperty(value, property, newValue); } else { super.setProperty(property, newValue); } }
@Override public void setMetaClass(final MetaClass metaClass) { final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) { @Override public Object getAttribute(final Object object, final String attribute) { return GPathResult.this.getProperty("@" + attribute); } @Override public void setAttribute(final Object object, final String attribute, final Object newValue) { GPathResult.this.setProperty("@" + attribute, newValue); } }; super.setMetaClass(newMetaClass); }
/** * Overloaded to implement duck typing for Strings * so that any method that can't be evaluated on this * object will be forwarded to the toString() object instead. */ @Override public Object invokeMethod(String name, Object args) { try { return super.invokeMethod(name, args); } catch (MissingMethodException e) { // lets try invoke the method on the real String return InvokerHelper.invokeMethod(toString(), name, args); } }
public Object invokeMethod(String name, Object args) { return getMetaClass().invokeMethod(this, name, args); }
public Object getProperty(String property) { // always use the expando properties first Object result = getProperties().get(property); if (result != null) return result; try { return super.getProperty(property); } catch (MissingPropertyException e) { // IGNORE } return null; }
public void setProperty(String property, Object newValue) { setVariable(property, newValue); try { super.setProperty(property, newValue); } catch (GroovyRuntimeException e) { // ignore, was probably a dynamic property } }
@Override public void setMetaClass(final MetaClass metaClass) { final MetaClass newMetaClass = new DelegatingMetaClass(metaClass) { @Override public Object getAttribute(final Object object, final String attribute) { return GPathResult.this.getProperty("@" + attribute); } @Override public void setAttribute(final Object object, final String attribute, final Object newValue) { GPathResult.this.setProperty("@" + attribute, newValue); } }; super.setMetaClass(newMetaClass); }
/** * Invoke a method (or closure in the binding) defined. * * @param name method to call * @param args arguments to pass to the method * @return value */ public Object invokeMethod(String name, Object args) { try { return super.invokeMethod(name, args); } // if the method was not found in the current scope (the script's methods) // let's try to see if there's a method closure with the same name in the binding catch (MissingMethodException mme) { try { if (name.equals(mme.getMethod())) { Object boundClosure = getProperty(name); if (boundClosure instanceof Closure) { return ((Closure) boundClosure).call((Object[])args); } else { throw mme; } } else { throw mme; } } catch (MissingPropertyException mpe) { throw mme; } } }
public Object invokeMethod(String name, Object args) { return getMetaClass().invokeMethod(this, name, args); }
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public Object getProperty(String property) { /** @todo we should check if we have the property with the metaClass instead of try/catch */ try { return super.getProperty(property); } catch (MissingPropertyException e) { return getVariable(property); } }