groovy.lang.MissingPropertyException Java Examples

The following examples show how to use groovy.lang.MissingPropertyException. 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 Project: arcusplatform   Author: arcus-smart-home   File: GroovyCommandDefinition.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object getProperty(String property) {
   try {
      return super.getProperty(property);
   }
   catch(MissingPropertyException e) {
      if(isValidInstance(property)) {
         return instance(property);
      }
      else {
     	 if(this.constants != null) {
     		Object value = this.constants.get(property);
          	if(value != null) {
          		return value;
          	}
     	 }        	
     	 throw e;
      }
   }
}
 
Example #2
Source Project: arcusplatform   Author: arcus-smart-home   File: DriverScriptMetaClass.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setProperty(
      Class sender, Object object, String name, Object newValue,
      boolean useSuper, boolean fromInsideClass) {
   if(!frozen) {
      super.setProperty(sender, object, name, newValue, useSuper, fromInsideClass);
   }
   else {
      if(hasProperty(object, name) == null) {
         throw new MissingPropertyException(name);
      }
      else {
         throw new ReadOnlyPropertyException(name, getTheClass());
      }

   }
}
 
Example #3
private void addPropertiesToProject(Project project) {
    Properties projectProperties = new Properties();
    File projectPropertiesFile = new File(project.getProjectDir(), Project.GRADLE_PROPERTIES);
    LOGGER.debug("Looking for project properties from: {}", projectPropertiesFile);
    if (projectPropertiesFile.isFile()) {
        projectProperties = GUtil.loadProperties(projectPropertiesFile);
        LOGGER.debug("Adding project properties (if not overwritten by user properties): {}",
                projectProperties.keySet());
    } else {
        LOGGER.debug("project property file does not exists. We continue!");
    }
    
    Map<String, String> mergedProperties = propertiesLoader.mergeProperties(new HashMap(projectProperties));
    ExtraPropertiesExtension extraProperties = new DslObject(project).getExtensions().getExtraProperties();
    for (Map.Entry<String, String> entry: mergedProperties.entrySet()) {
        try {
            project.setProperty(entry.getKey(), entry.getValue());
        } catch (MissingPropertyException e) {
            if (!entry.getKey().equals(e.getProperty())) {
                throw e;
            }
            // Ignore and define as an extra property
            extraProperties.set(entry.getKey(), entry.getValue());
        }
    }
}
 
Example #4
Source Project: tinkerpop   Author: apache   File: GremlinGroovyScriptEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPromoteDefinedVarsInInterpreterModeWithNoBindings() throws Exception {
    final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer());
    engine.eval("def addItUp = { x, y -> x + y }");
    engine.eval("class A { def sub(int x, int y) {x - y}}");
    assertEquals(3, engine.eval("int xxx = 1 + 2"));
    assertEquals(4, engine.eval("yyy = xxx + 1"));
    assertEquals(7, engine.eval("def zzz = yyy + xxx"));
    assertEquals(4, engine.eval("zzz - xxx"));
    assertEquals("accessible-globally", engine.eval("if (yyy > 0) { def inner = 'should-stay-local'; outer = 'accessible-globally' }\n outer"));
    assertEquals("accessible-globally", engine.eval("outer"));

    try {
        engine.eval("inner");
        fail("Should not have been able to access 'inner'");
    } catch (Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        assertThat(root, instanceOf(MissingPropertyException.class));
    }

    assertEquals(9, engine.eval("new A().sub(10, 1)"));
    assertEquals(10, engine.eval("addItUp(zzz,xxx)"));
}
 
Example #5
Source Project: tinkerpop   Author: apache   File: GremlinGroovyScriptEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPromoteDefinedVarsInInterpreterModeWithBindings() throws Exception {
    final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine(new InterpreterModeGroovyCustomizer());
    final Bindings b = new SimpleBindings();
    b.put("x", 2);
    engine.eval("def addItUp = { x, y -> x + y }", b);
    assertEquals(3, engine.eval("int xxx = 1 + x", b));
    assertEquals(4, engine.eval("yyy = xxx + 1", b));
    assertEquals(7, engine.eval("def zzz = yyy + xxx", b));
    assertEquals(4, engine.eval("zzz - xxx", b));
    assertEquals("accessible-globally", engine.eval("if (yyy > 0) { def inner = 'should-stay-local'; outer = 'accessible-globally' }\n outer", b));
    assertEquals("accessible-globally", engine.eval("outer", b));

    try {
        engine.eval("inner", b);
        fail("Should not have been able to access 'inner'");
    } catch (Exception ex) {
        final Throwable root = ExceptionUtils.getRootCause(ex);
        assertThat(root, instanceOf(MissingPropertyException.class));
    }

    assertEquals(10, engine.eval("addItUp(zzz,xxx)", b));
}
 
Example #6
Source Project: sqoop-on-spark   Author: vybs   File: ThrowableDisplayer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Error hook installed to Groovy shell.
 *
 * Will display exception that appeared during executing command. In most
 * cases we will simply delegate the call to printing throwable method,
 * however in case that we've received ClientError.CLIENT_0006 (server
 * exception), we will unwrap server issue and view only that as local
 * context shouldn't make any difference.
 *
 * @param t Throwable to be displayed
 */
public static void errorHook(Throwable t) {
  // Based on the kind of exception we are dealing with, let's provide different user experince
  if(t instanceof SqoopException && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0006) {
    println("@|red Server has returned exception: |@");
    printThrowable(t.getCause(), isVerbose());
  } else if(t instanceof SqoopException && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0003) {
    print("@|red Invalid command invocation: |@");
    // In most cases the cause will be actual parsing error, so let's print that alone
    if (t.getCause() != null) {
      println(t.getCause().getMessage());
    } else {
      println(t.getMessage());
    }
  } else if(t.getClass() == MissingPropertyException.class) {
    print("@|red Unknown command: |@");
    println(t.getMessage());
  } else {
    println("@|red Exception has occurred during processing command |@");
    printThrowable(t, isVerbose());
  }
}
 
Example #7
Source Project: groovy   Author: apache   File: GroovyRowResult.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the value of the property by its index.
 * A negative index will count backwards from the last column.
 *
 * @param index is the number of the column to look at
 * @return the value of the property
 */
public Object getAt(int index) {
    try {
        // a negative index will count backwards from the last column.
        if (index < 0)
            index += result.size();
        Iterator<Object> it = result.values().iterator();
        int i = 0;
        Object obj = null;
        while ((obj == null) && (it.hasNext())) {
            if (i == index)
                obj = it.next();
            else
                it.next();
            i++;
        }
        return obj;
    }
    catch (Exception e) {
        throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.class, e);
    }
}
 
Example #8
Source Project: groovy   Author: apache   File: BindPath.java    License: Apache License 2.0 6 votes vote down vote up
private Object extractNewValue(Object newObject) {
    Object newValue;
    try {
        newValue = InvokerHelper.getProperty(newObject, propertyName);

    } catch (MissingPropertyException mpe) {
        //todo we should flag this when the path is created that this is a field not a prop...
        // try direct method...
        try {
            newValue = InvokerHelper.getAttribute(newObject, propertyName);
            if (newValue instanceof Reference) {
                newValue = ((Reference) newValue).get();
            }
        } catch (Exception e) {
            //LOGME?
            newValue = null;
        }
    }
    return newValue;
}
 
Example #9
Source Project: groovy   Author: apache   File: FactoryBuilderSupport.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Overloaded to make variables appear as bean properties or via the subscript operator
 */
public Object getProperty(String property) {
    try {
        return getProxyBuilder().doGetProperty(property);
    } catch (MissingPropertyException mpe) {
        if ((getContext() != null) && (getContext().containsKey(property))) {
            return getContext().get(property);
        } else {
            try {
                return getMetaClass().getProperty(this, property);
            } catch(MissingPropertyException mpe2) {
                if(mpe2.getProperty().equals(property) && propertyMissingDelegate != null) {
                    return propertyMissingDelegate.call(new Object[]{property});
                }
                throw mpe2;
            }
        }
    }
}
 
Example #10
Source Project: tinkerpop   Author: apache   File: GremlinGroovyScriptEngineOverGraphTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldClearBindingsBetweenEvals() throws Exception {
    final Graph graph = TinkerFactory.createModern();
    final GraphTraversalSource g = graph.traversal();
    final ScriptEngine engine = new GremlinGroovyScriptEngine();
    engine.put("g", g);
    engine.put("marko", convertToVertexId(graph, "marko"));
    assertEquals(g.V(convertToVertexId(graph, "marko")).next(), engine.eval("g.V(marko).next()"));

    final Bindings bindings = engine.createBindings();
    bindings.put("g", g);
    bindings.put("s", "marko");

    assertEquals(engine.eval("g.V().has('name',s).next()", bindings), g.V(convertToVertexId(graph, "marko")).next());

    try {
        engine.eval("g.V().has('name',s).next()");
        fail("This should have failed because s is no longer bound");
    } catch (Exception ex) {
        final Throwable t = ExceptionUtils.getRootCause(ex);
        assertEquals(MissingPropertyException.class, t.getClass());
        assertTrue(t.getMessage().startsWith("No such property: s for class"));
    }

}
 
Example #11
Source Project: arcusplatform   Author: arcus-smart-home   File: ZigbeeCommandBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CommandBuilder addProtocolMessageData(String parameterName, String parameterValue) {
	try {
		 logger.trace("Add ZCL Data {}", parameterName);
		this.addZclData(parameterName, parameterValue);
	} catch (MissingPropertyException e) {
		 logger.trace("Add ProtocMessage Data {}",parameterName);
		this.addProtocMessageData(parameterName, parameterValue);
	}
	return this;
}
 
Example #12
Source Project: arcusplatform   Author: arcus-smart-home   File: GroovyAttributeDefinition.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object getProperty(String property) {
   try {
      return super.getProperty(property);
   }
   catch(MissingPropertyException e) {
      if(isValidInstance(property)) {
         return instance(property);
      }
      else {
         throw e;
      }
   }
}
 
Example #13
Source Project: arcusplatform   Author: arcus-smart-home   File: GroovyAttributeDefinition.java    License: Apache License 2.0 5 votes vote down vote up
public Object get(String key) {
   if(!isMapType()) {
      throw new MissingPropertyException("May only call get(key) on a Map attribute");
   }
   Object curValue = get();
   if(curValue != null) {
      return ((Map<?, ?>) curValue).get(key);
   }else{
      return null;
   }
}
 
Example #14
Source Project: arcusplatform   Author: arcus-smart-home   File: AttributesContext.java    License: Apache License 2.0 5 votes vote down vote up
public Object setAttribute(AttributeKey<?> key, Object value) {
   DeviceDriverContext context = GroovyContextObject.getContext();
   if(!supportedAttributes.containsKey(key.getName())) {
      throw new MissingPropertyException("The attribute [" + key + "] is not supported by this driver, please check your spelling and capability definitions");
   }
   return context.setAttributeValue(key.coerceToValue(value));
}
 
Example #15
Source Project: arcusplatform   Author: arcus-smart-home   File: AttributesContext.java    License: Apache License 2.0 5 votes vote down vote up
public Object setAttribute(String name, Object value) {
   NamespacedKey attribute = NamespacedKey.parse(name);
   AttributeDefinition definition = supportedAttributes.get(name);
   if(definition == null) {
      throw new MissingPropertyException("The attribute [" + name + "] is not supported by this driver, please check your spelling and capability definitions");
   }

   if(attribute.isInstanced()) {
      return setAttribute(definition.getKey().instance(attribute.getInstance()), value);
   }
   return setAttribute(definition.getKey(), value);
}
 
Example #16
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultConvention.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setProperty(String name, Object value) {
    extensionsStorage.checkExtensionIsNotReassigned(name);
    for (Object object : plugins.values()) {
        BeanDynamicObject dynamicObject = new BeanDynamicObject(object);
        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
            return;
        }
    }
    throw new MissingPropertyException(name, Convention.class);
}
 
Example #17
public Object getProperty(String name) {
    if (name.equals("properties")) {
        return getProperties();
    }

    try {
        return get(name);
    } catch (UnknownPropertyException e) {
        throw new MissingPropertyException(e.getMessage(), name, null);
    }
}
 
Example #18
@Override
public T getProperty(String name) throws MissingPropertyException {
    T t = findByName(name);
    if (t == null) {
        return (T) super.getProperty(name);
    }
    return t;
}
 
Example #19
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultConvention.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setProperty(String name, Object value) {
    extensionsStorage.checkExtensionIsNotReassigned(name);
    for (Object object : plugins.values()) {
        BeanDynamicObject dynamicObject = new BeanDynamicObject(object);
        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
            return;
        }
    }
    throw new MissingPropertyException(name, Convention.class);
}
 
Example #20
Source Project: Pushjet-Android   Author: Pushjet   File: DefaultAntBuilder.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object propertyMissing(String name) {
    if (getProject().getProperties().containsKey(name)) {
        return getProject().getProperties().get(name);
    }

    throw new MissingPropertyException(name, getClass());
}
 
Example #21
Source Project: pushfish-android   Author: PushFish   File: ConventionAwareHelper.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void propertyMissing(String name, Object value) {
    if (value instanceof Closure) {
        map(name, (Closure) value);
    } else {
        throw new MissingPropertyException(name, getClass());
    }
}
 
Example #22
@Override
public Object getProperty(String name) throws MissingPropertyException {
    Object object = findByName(name);
    if (object == null) {
        return super.getProperty(name);
    }
    return object;
}
 
Example #23
Source Project: pushfish-android   Author: PushFish   File: DefaultConvention.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object getProperty(String name) throws MissingPropertyException {
    if (extensionsStorage.hasExtension(name)) {
        return extensionsStorage.getByName(name);
    }
    for (Object object : plugins.values()) {
        DynamicObject dynamicObject = new BeanDynamicObject(object);
        if (dynamicObject.hasProperty(name)) {
            return dynamicObject.getProperty(name);
        }
    }
    throw new MissingPropertyException(name, Convention.class);
}
 
Example #24
@Override
public Object getProperty(String name) throws MissingPropertyException {
    Object object = findByName(name);
    if (object == null) {
        return super.getProperty(name);
    }
    return object;
}
 
Example #25
@Override
public void setProperty(String name, Object value) throws MissingPropertyException {
    if (!hasProperty(name)) {
        throw new MissingPropertyException(name, delegateType);
    }

    super.setProperty(name, value);
}
 
Example #26
public Object getProperty(String name) {
    if (name.equals("properties")) {
        return getProperties();
    }

    try {
        return get(name);
    } catch (UnknownPropertyException e) {
        throw new MissingPropertyException(e.getMessage(), name, null);
    }
}
 
Example #27
Source Project: pushfish-android   Author: PushFish   File: DefaultAntBuilder.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object propertyMissing(String name) {
    if (getProject().getProperties().containsKey(name)) {
        return getProject().getProperties().get(name);
    }

    throw new MissingPropertyException(name, getClass());
}
 
Example #28
@Override
public T getProperty(String name) throws MissingPropertyException {
    T t = findByName(name);
    if (t == null) {
        return (T) super.getProperty(name);
    }
    return t;
}
 
Example #29
Source Project: pushfish-android   Author: PushFish   File: ConventionAwareHelper.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void propertyMissing(String name, Object value) {
    if (value instanceof Closure) {
        map(name, (Closure) value);
    } else {
        throw new MissingPropertyException(name, getClass());
    }
}
 
Example #30
@Override
public Object getProperty(String name) throws MissingPropertyException {
    Object object = findByName(name);
    if (object == null) {
        return super.getProperty(name);
    }
    return object;
}