@Override public void setProperty(String name, Object value) { throw new MissingPropertyException("configurations cannot be set directly"); }
private String getPropertyGetterName(String prop) { if (prop == null || prop.length() < 1) { throw new MissingPropertyException(prop, target.getClass()); } return "get" + prop.substring(0, 1).toUpperCase() + prop.substring(1); }
/** * @param name the name of the variable to lookup * @return the variable value */ public Object getVariable(String name) { if (variables == null) throw new MissingPropertyException(name, this.getClass()); Object result = variables.get(name); if (result == null && !variables.containsKey(name)) { throw new MissingPropertyException(name, this.getClass()); } return result; }
/** * Retrieve the value of the property by its (case-insensitive) name. * * @param property is the name of the property to look at * @return the value of the property */ public Object getProperty(String property) { try { Object key = lookupKeyIgnoringCase(property); if (key != null) { return result.get(key); } throw new MissingPropertyException(property, GroovyRowResult.class); } catch (Exception e) { throw new MissingPropertyException(property, GroovyRowResult.class, e); } }
@Override public Object getProperty(String name) { Object config = configurationRegistry.getConfigurationByName(name); if (config == null) throw new MissingPropertyException("configuration not found"); return config; }
/** * Gets the value of the designated column in the current row * of as an <code>Object</code>. * * @param columnName the SQL name of the column * @return the returned column value * @throws MissingPropertyException if an SQLException happens while getting the object * @see groovy.lang.GroovyObject#getProperty(java.lang.String) * @see ResultSet#getObject(java.lang.String) */ public Object getProperty(String columnName) { try { return getResultSet().getObject(columnName); } catch (SQLException e) { throw new MissingPropertyException(columnName, GroovyResultSetProxy.class, e); } }
/** * 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 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); } }
public static void checkPropNames(Object instance, Map<String, Object> args) { final MetaClass metaClass = InvokerHelper.getMetaClass(instance); for (String k : args.keySet()) { if (metaClass.hasProperty(instance, k) == null) throw new MissingPropertyException(k, instance.getClass()); } }
public Object getProperty(String property) { if (STATIC_QUALIFIER.equals(property)) return new StaticDefiningClosure(); if (definition) return new ExpandoMetaProperty(property); else throw new MissingPropertyException(property, getClass()); } }
private void doSetProperty(String property, Object newValue) { Closure[] accessors = resolveExplicitProperty(property); if (accessors != null) { if (accessors[1] == null) { // read only property throw new MissingPropertyException(property + " is declared as read only"); } else { accessors[1].call(newValue); } } else { super.setProperty(property, newValue); } }
private Object doGetProperty(String property) { Closure[] accessors = resolveExplicitProperty(property); if (accessors != null) { if (accessors[0] == null) { // write only property throw new MissingPropertyException(property + " is declared as write only"); } else { return accessors[0].call(); } } else { return super.getProperty(property); } }
private static List getAtIterable(Iterable coll, String property, List<Object> answer) { for (Object item : coll) { if (item == null) continue; Object value; try { value = InvokerHelper.getProperty(item, property); } catch (MissingPropertyExceptionNoStack mpe) { String causeString = new MissingPropertyException(mpe.getProperty(), mpe.getType()).toString(); throw new MissingPropertyException("Exception evaluating property '" + property + "' for " + coll.getClass().getName() + ", Reason: " + causeString); } answer.add(value); } return answer; }
/** * Updates the designated column with an <code>Object</code> value. * * @param columnName the SQL name of the column * @param newValue the updated value * @throws MissingPropertyException if an SQLException happens while setting the new value * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object) * @see ResultSet#updateObject(java.lang.String, java.lang.Object) */ public void setProperty(String columnName, Object newValue) { try { getResultSet().updateObject(columnName, newValue); updated = true; } catch (SQLException e) { throw new MissingPropertyException(columnName, GroovyResultSetProxy.class, e); } }
/** * Hook to deal with the case of MissingProperty for static properties. The method will look attempt to look up * "propertyMissing" handlers and invoke them otherwise thrown a MissingPropertyException * * @param instance The instance * @param propertyName The name of the property * @param optionalValue The value in the case of a setter * @param isGetter True if its a getter * @return The value in the case of a getter or a MissingPropertyException */ protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) { MetaClass mc = instance instanceof Class ? registry.getMetaClass((Class) instance) : this; if (isGetter) { MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, GETTER_MISSING_ARGS); if (propertyMissing != null) { return propertyMissing.invoke(instance, new Object[]{propertyName}); } } else { MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, SETTER_MISSING_ARGS); if (propertyMissing != null) { return propertyMissing.invoke(instance, new Object[]{propertyName, optionalValue}); } } if (instance instanceof Class) { throw new MissingPropertyException(propertyName, (Class) instance); } throw new MissingPropertyException(propertyName, theClass); }
public static Throwable unwrap(GroovyRuntimeException gre) { if (gre.getCause()==null) { if (gre instanceof MissingPropertyExceptionNoStack) { MissingPropertyExceptionNoStack noStack = (MissingPropertyExceptionNoStack) gre; return new MissingPropertyException(noStack.getProperty(), noStack.getType()); } if (gre instanceof MissingMethodExceptionNoStack) { MissingMethodExceptionNoStack noStack = (MissingMethodExceptionNoStack) gre; return new MissingMethodException(noStack.getMethod(), noStack.getType(), noStack.getArguments(), noStack.isStatic()); } } Throwable th = gre; if (th.getCause() != null && th.getCause() != gre) th = th.getCause(); if (th != gre && (th instanceof GroovyRuntimeException)) return unwrap((GroovyRuntimeException) th); return th; }
@Override public Object getVariable(String name) { try { return super.getVariable(name); } catch (MissingPropertyException e) { // Original {@link Binding} doesn't have 'variable' for the given 'name'. // Try to resolve it as 'bean' from the given <code>beanFactory</code>. } if (GroovyScriptExecutingMessageProcessor.this.beanFactory == null) { throw new MissingPropertyException(name, this.getClass()); } try { return GroovyScriptExecutingMessageProcessor.this.beanFactory.getBean(name); } catch (NoSuchBeanDefinitionException e) { throw new MissingPropertyException(name, this.getClass(), e); } }
throw new MissingPropertyException((String) normalizedArgs[0], mockConfiguration.getType());
/** * Groovy override to provide usage hints with missing properties. * @param name The name of the missing property * @return The (simulated) property value. */ public Object propertyMissing(String name) { if (Character.isUpperCase(name.charAt(0))) { logger.error("unresolved class or property {}, missing import?", name); Set<String> packages = delegate.getConfigLoader().getDirectory().getPackages(name); logger.debug("found {} packages with classes named {}", packages.size(), name); if (packages.isEmpty()) { throw new MissingPropertyException(name, getClass()); } String message = "Unresolved property in evaluation script: " + name; RecommenderConfigurationException ex = new RecommenderConfigurationException(message); for (String pkg: packages) { logger.info("consider importing {}.{}", pkg, name); ex.addHint("consider importing %s.%s", pkg, name); } throw ex; } else { logger.error("unresolved property {} in configuration script", name); throw new MissingPropertyException(name, getClass()); } }
@Override public Object getVariable(String name) { synchronized (context) { int scope = context.getAttributesScope(name); if (scope != -1) { return context.getAttribute(name, scope); } // Redirect script output to context writer, if out var is not already provided if ("out".equals(name)) { final Writer writer = context.getWriter(); if (writer != null) { return (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer, true); } } // Provide access to engine context, if context var is not already provided if ("context".equals(name)) { return context; } } throw new MissingPropertyException(name, getClass()); }
@Override public Object getVariable(String name) { synchronized (ctx) { int scope = ctx.getAttributesScope(name); if (scope != -1) { return ctx.getAttribute(name, scope); } // Redirect script output to context writer, if out var is not already provided if ("out".equals(name)) { Writer writer = ctx.getWriter(); if (writer != null) { return (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer, true); } } // Provide access to engine context, if context var is not already provided if ("context".equals(name)) { return ctx; } } throw new MissingPropertyException(name, getClass()); }