use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.
the class StandaloneSpringPentahoObjectFactoryTest method testInitFromXml.
public void testInitFromXml() throws Exception {
StandaloneSession session = new StandaloneSession();
StandaloneSession session2 = new StandaloneSession();
StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
GoodObject goodObject = factory.get(GoodObject.class, session);
assertNotNull(goodObject);
try {
factory.get(BadObject.class, null);
assertFalse(true);
} catch (ObjectFactoryException e) {
// ignored
}
GoodObject goodObject1 = factory.get(GoodObject.class, session);
GoodObject goodObject2 = factory.get(GoodObject.class, session);
assertEquals(goodObject1, goodObject2);
assertEquals(session, goodObject1.initSession);
GoodObject goodObject3 = factory.get(GoodObject.class, session2);
assertNotSame(goodObject1, goodObject3);
assertEquals(session2, goodObject3.initSession);
}
use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.
the class StandaloneSpringPentahoObjectFactoryTest method testBadInit.
public void testBadInit() throws Exception {
StandaloneSession session = new StandaloneSession();
StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
try {
factory.init(null, "bogus");
assertFalse(true);
} catch (IllegalArgumentException e) {
assertTrue(true);
}
try {
GoodObject obj = factory.get(GoodObject.class, session);
assertNotNull(obj);
assertFalse(true);
} catch (ObjectFactoryException e) {
assertTrue(true);
}
}
use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.
the class MondrianCatalogHelper method addToCatalog.
public static int addToCatalog(String baseUrl, boolean enableXmla, String schemaSolutionPath, IPentahoSession session, String jndiName, boolean overwrite) {
IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", session);
String dsUrl = baseUrl;
if (!dsUrl.endsWith("/")) {
// $NON-NLS-1$
// $NON-NLS-1$
dsUrl += "/";
}
// $NON-NLS-1$
dsUrl += "Xmla";
// $NON-NLS-1$
String catDef = "solution:" + schemaSolutionPath;
MondrianSchema mondrianSchema = mondrianCatalogService.loadMondrianSchema(catDef, session);
String catName = mondrianSchema.getName();
String[] roleNames = mondrianSchema.getRoleNames();
// verify JNDI
try {
IDBDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
datasourceService.getDSBoundName(jndiName);
} catch (ObjectFactoryException objface) {
Logger.error("MondrianCatalogHelper", Messages.getInstance().getErrorString("MondrianCatalogPublisher.ERROR_0006_UNABLE_TO_FACTORY_OBJECT", jndiName), objface);
} catch (DBDatasourceServiceException dse) {
Logger.error("MondrianCatalogHelper", Messages.getInstance().getErrorString("MondrianCatalogPublisher.ERROR_0001_JNDI_NAMING_ERROR", jndiName), dse);
return -1;
}
// used in both the catalog and the catalog datasource
// Note: we use the unbound JNDI name here, the PentahoXmlaServlet resolves the JNDI name
// $NON-NLS-1$
String catConnectStr = "Provider=mondrian;DataSource=" + jndiName;
// MB - 12/2009 - TODO: Figure out the empty list
// Curious why we aren't adding the cubes from the read schema into the created schema.
MondrianCatalog cat = new MondrianCatalog(catName, catConnectStr, catDef, new MondrianSchema(catName, new ArrayList<MondrianCube>(), roleNames));
try {
mondrianCatalogService.addCatalog(cat, overwrite, session);
} catch (MondrianCatalogServiceException e) {
Logger.error("MondrianCatalogHelper", Messages.getInstance().getErrorString("MondrianCatalogPublisher.ERROR_0002_EXCEPTION_OCCURRED"), e);
return -1;
}
return 0;
}
use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.
the class BeanBuilder method getObject.
/*
* (non-Javadoc)
*
* @see org.springframework.beans.factory.FactoryBean#getObject()
*/
public Object getObject() {
try {
if (resolvingBean.get() == this) {
log.warn("Circular Reference detected in bean creation ( " + type + " : " + attributes + "). Very likely a published " + "pentaho bean is resolving itself. Ensure that the published attributes do not match that of the Pentaho " + "bean query. The system will attempt to find the next highest available bean, but at a performance " + "penilty");
// attempt to find a lower priority bean for them
Class cls = getClass().getClassLoader().loadClass(type.trim());
resolvingBean.set(this);
List<IPentahoObjectReference<?>> objectReferences = PentahoSystem.getObjectFactory().getObjectReferences(cls, PentahoSessionHolder.getSession(), attributes);
resolvingBean.set(null);
if (objectReferences.size() > 1) {
// we have more than one, return the second highest
return objectReferences.get(1).getObject();
} else {
// there's only one bean, this is a fatal situation
throw new IllegalStateException("Fatal Circular reference in Pentaho Bean ( " + type + " : " + attributes + ")");
}
} else {
final Class cls = getClass().getClassLoader().loadClass(type.trim());
resolvingBean.set(this);
Object val = null;
IPentahoObjectReference objectReference = PentahoSystem.getObjectFactory().getObjectReference(cls, PentahoSessionHolder.getSession(), attributes);
if (objectReference != null) {
val = objectReference.getObject();
}
resolvingBean.set(null);
if (val == null) {
log.debug("No object was found to satisfy pen:bean request [" + type + " : " + attributes + "]");
final int f_dampeningTimeout = getDampeningTimeout();
// send back a proxy
if (cls.isInterface() && dampeningTimeout > -1) {
log.debug("Request bean which wasn't found is interface-based. Instantiating a Proxy dampener");
val = Proxy.newProxyInstance(cls.getClassLoader(), new Class[] { cls }, new InvocationHandler() {
// class name to prevent locking somewhere else by the same string
String lock = "lock_" + getClass().getName();
Object target;
Thread watcher;
boolean dead = false;
private void startWatcherThread(final int millis) {
watcher = new Thread(new Runnable() {
@Override
public void run() {
int countdown = millis;
while (countdown > 0) {
IPentahoObjectReference objectReference;
try {
objectReference = PentahoSystem.getObjectFactory().getObjectReference(cls, PentahoSessionHolder.getSession(), attributes);
if (objectReference != null) {
target = objectReference.getObject();
}
} catch (ObjectFactoryException e) {
log.debug("Error fetching from PentahoSystem", e);
}
if (target != null) {
synchronized (lock) {
lock.notifyAll();
}
return;
}
countdown -= 100;
}
dead = true;
}
});
watcher.start();
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (target == null && f_dampeningTimeout > 0) {
synchronized (lock) {
if (watcher == null && !dead) {
startWatcherThread(f_dampeningTimeout);
lock.wait(f_dampeningTimeout);
}
}
}
if (target == null) {
// with the ID equal to the simple name of the class
if (attributes.isEmpty() || (attributes.size() == 1 && attributes.containsKey("id"))) {
target = getFallbackBySimpleName(cls, attributes);
}
if (target == null) {
throw new IllegalStateException("Target of Bean was never resolved: " + cls.getName());
}
}
return method.invoke(target, args);
}
});
} else if (!cls.isInterface() && (attributes.isEmpty() || (attributes.size() == 1 && attributes.containsKey("id")))) {
val = getFallbackBySimpleName(cls, attributes);
}
}
return val;
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (ObjectFactoryException e) {
throw new RuntimeException(e);
}
}
use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.
the class AbstractSpringPentahoObjectFactory method retrieveViaSpring.
private <T> T retrieveViaSpring(Class<T> interfaceClass, Map<String, String> props) throws ObjectFactoryException {
Object object = null;
try {
String beanName = interfaceClass.getSimpleName();
if (!beanFactory.getBeanFactory().containsBean(beanName)) {
throw new IllegalStateException("No bean found for given type");
}
object = beanFactory.getBean(beanName);
} catch (Throwable t) {
String msg = Messages.getInstance().getString("AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", // $NON-NLS-1$
interfaceClass.getSimpleName());
throw new ObjectFactoryException(msg, t);
}
// Sanity check
if (interfaceClass.isAssignableFrom(object.getClass()) == false) {
throw new IllegalStateException("Object retrived from Spring not expected type: " + interfaceClass.getSimpleName());
}
return (T) object;
}
Aggregations