
support.ActionSupportHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tropo-webapi-java Show documentation
Show all versions of tropo-webapi-java Show documentation
WebApi Java implementation for the Tropo Cloud platform
The newest version!
package support;
import java.lang.reflect.Constructor;
import com.voxeo.tropo.Key;
import com.voxeo.tropo.TropoException;
import com.voxeo.tropo.actions.Action;
import com.voxeo.tropo.actions.ArrayBackedJsonAction;
import com.voxeo.tropo.actions.JsonAction;
public class ActionSupportHandler {
private Class clazz;
public ActionSupportHandler(Class clazz) {
this.clazz = clazz;
}
public E build(Action action, Key... keys) throws TropoException {
return build(action, null, keys);
}
public E build(Action action, String name, Key... keys) throws TropoException {
try {
Constructor c = clazz.getConstructor(Key[].class);
E instanceAction = c.newInstance(new Object[]{keys});
if (action instanceof ArrayBackedJsonAction) {
action.addToArray(name, instanceAction.getName(), instanceAction);
} else if (action instanceof JsonAction) {
action.put(instanceAction.getName(),instanceAction);
} else {
action.put(instanceAction.getName(),instanceAction);
}
return instanceAction;
} catch (TropoException te) {
throw te;
} catch (Exception e) {
if (e.getCause() != null && e.getCause() instanceof TropoException) {
throw (TropoException)e.getCause();
}
e.printStackTrace();
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy