Exemplo n.º 1
0
    public void setProperty(final String name, Object value) throws MissingPropertyException {
      if (!includeProperties) {
        throw propertyMissingException(name);
      }

      MetaClass metaClass = getMetaClass();
      MetaProperty property = metaClass.hasProperty(bean, name);
      if (property == null) {
        if (property == null) {
          getMetaClass().invokeMissingProperty(bean, name, null, false);
        }
      }

      if (property instanceof MetaBeanProperty
          && ((MetaBeanProperty) property).getSetter() == null) {
        throw new ReadOnlyPropertyException(name, bean.getClass()) {
          @Override
          public String getMessage() {
            return String.format(
                "Cannot set the value of read-only property '%s' on %s.", name, getDisplayName());
          }
        };
      }
      try {
        metaClass.setProperty(bean, name, value);
      } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
          throw (RuntimeException) e.getCause();
        }
        throw e;
      }
    }
Exemplo n.º 2
0
    public Object getProperty(String name) throws MissingPropertyException {
      if (!includeProperties) {
        throw propertyMissingException(name);
      }

      MetaProperty property = getMetaClass().hasProperty(bean, name);
      if (property == null) {
        return getMetaClass().invokeMissingProperty(bean, name, null, true);
      }
      if (property instanceof MetaBeanProperty
          && ((MetaBeanProperty) property).getGetter() == null) {
        throw new GroovyRuntimeException(
            String.format(
                "Cannot get the value of write-only property '%s' on %s.", name, getDisplayName()));
      }

      try {
        return property.getProperty(bean);
      } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
          throw (RuntimeException) e.getCause();
        }
        throw e;
      }
    }
Exemplo n.º 3
0
 /** Run the script. */
 private boolean run() {
   try {
     if (processSockets) {
       processSockets();
     } else if (processFiles) {
       processFiles();
     } else {
       processOnce();
     }
     return true;
   } catch (CompilationFailedException e) {
     System.err.println(e);
     return false;
   } catch (Throwable e) {
     if (e instanceof InvokerInvocationException) {
       InvokerInvocationException iie = (InvokerInvocationException) e;
       e = iie.getCause();
     }
     System.err.println("Caught: " + e);
     if (!debug) {
       StackTraceUtils.deepSanitize(e);
     }
     e.printStackTrace();
     return false;
   }
 }
Exemplo n.º 4
0
 @Override
 public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
   try {
     return groovyObject.invokeMethod(name, arguments);
   } catch (InvokerInvocationException e) {
     if (e.getCause() instanceof RuntimeException) {
       throw (RuntimeException) e.getCause();
     }
     throw e;
   }
 }
Exemplo n.º 5
0
 @SuppressWarnings("unchecked")
 public V call(Object... args) {
   try {
     return (V) getMetaClass().invokeMethod(this, "doCall", args);
   } catch (InvokerInvocationException e) {
     ExceptionUtils.sneakyThrow(e.getCause());
     return null; // unreachable statement
   } catch (Exception e) {
     return (V) throwRuntimeException(e);
   }
 }
Exemplo n.º 6
0
 public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
   try {
     return getMetaClass().invokeMethod(bean, name, arguments);
   } catch (InvokerInvocationException e) {
     if (e.getCause() instanceof RuntimeException) {
       throw (RuntimeException) e.getCause();
     }
     throw e;
   } catch (MissingMethodException e) {
     throw methodMissingException(name, arguments);
   }
 }