use of groovy.lang.MissingPropertyException in project groovy by apache.
the class GroovyResultSetExtension method setProperty.
/**
* 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);
}
}
use of groovy.lang.MissingPropertyException in project groovy by apache.
the class GroovyRowResult method getAt.
/**
* 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);
}
}
use of groovy.lang.MissingPropertyException in project groovy by apache.
the class GroovyScriptEngineImpl method eval.
// package-privates
Object eval(Class<?> scriptClass, final ScriptContext ctx) throws ScriptException {
/*
* We use the following Binding instance so that global variable lookup
* will be done in the current ScriptContext instance.
*/
Binding binding = new Binding(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) {
@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());
}
@Override
public void setVariable(String name, Object value) {
synchronized (ctx) {
int scope = ctx.getAttributesScope(name);
if (scope == -1) {
scope = ScriptContext.ENGINE_SCOPE;
}
ctx.setAttribute(name, value, scope);
}
}
};
try {
// then simply return that class
if (!Script.class.isAssignableFrom(scriptClass)) {
return scriptClass;
} else {
// it's a script
Script scriptObject = InvokerHelper.createScript(scriptClass, binding);
// save all current closures into global closures map
Method[] methods = scriptClass.getMethods();
for (Method m : methods) {
String name = m.getName();
globalClosures.put(name, new MethodClosure(scriptObject, name));
}
MetaClass oldMetaClass = scriptObject.getMetaClass();
/*
* We override the MetaClass of this script object so that we can
* forward calls to global closures (of previous or future "eval" calls)
* This gives the illusion of working on the same "global" scope.
*/
scriptObject.setMetaClass(new DelegatingMetaClass(oldMetaClass) {
@Override
public Object invokeMethod(Object object, String name, Object args) {
if (args == null) {
return invokeMethod(object, name, MetaClassHelper.EMPTY_ARRAY);
}
if (args instanceof Tuple) {
return invokeMethod(object, name, ((Tuple) args).toArray());
}
if (args instanceof Object[]) {
return invokeMethod(object, name, (Object[]) args);
} else {
return invokeMethod(object, name, new Object[] { args });
}
}
@Override
public Object invokeMethod(Object object, String name, Object[] args) {
try {
return super.invokeMethod(object, name, args);
} catch (MissingMethodException mme) {
return callGlobal(name, args, ctx);
}
}
@Override
public Object invokeStaticMethod(Object object, String name, Object[] args) {
try {
return super.invokeStaticMethod(object, name, args);
} catch (MissingMethodException mme) {
return callGlobal(name, args, ctx);
}
}
});
return scriptObject.run();
}
} catch (Exception e) {
throw new ScriptException(e);
}
}
use of groovy.lang.MissingPropertyException in project gradle by gradle.
the class AbstractDynamicObject method getMissingProperty.
public MissingPropertyException getMissingProperty(String name) {
Class<?> publicType = getPublicType();
boolean includeDisplayName = hasUsefulDisplayName();
if (publicType != null && includeDisplayName) {
return new MissingPropertyException(String.format("Could not get unknown property '%s' for %s of type %s.", name, getDisplayName(), publicType.getName()), name, publicType);
} else if (publicType != null) {
return new MissingPropertyException(String.format("Could not get unknown property '%s' for object of type %s.", name, publicType.getName()), name, publicType);
} else {
// Use the display name anyway
return new MissingPropertyException(String.format("Could not get unknown property '%s' for %s.", name, getDisplayName()), name, null);
}
}
use of groovy.lang.MissingPropertyException in project gradle by gradle.
the class AbstractDynamicObject method setMissingProperty.
public MissingPropertyException setMissingProperty(String name) {
Class<?> publicType = getPublicType();
boolean includeDisplayName = hasUsefulDisplayName();
if (publicType != null && includeDisplayName) {
return new MissingPropertyException(String.format("Could not set unknown property '%s' for %s of type %s.", name, getDisplayName(), publicType.getName()), name, publicType);
} else if (publicType != null) {
return new MissingPropertyException(String.format("Could not set unknown property '%s' for object of type %s.", name, publicType.getName()), name, publicType);
} else {
// Use the display name anyway
return new MissingPropertyException(String.format("Could not set unknown property '%s' for %s.", name, getDisplayName()), name, null);
}
}
Aggregations