use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.
the class BootTest method testBoot.
@Test
public void testBoot() throws Exception {
PentahoSystemBoot boot = new PentahoSystemBoot();
boot.setFilePath("solution");
IPentahoObjectFactory factory = boot.getFactory();
assertNotNull("object factory is null", factory);
assertTrue("object factory not definable", factory instanceof IPentahoDefinableObjectFactory);
boot.define(ISolutionEngine.class.getSimpleName(), Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
boot.define("MyObject", Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
boot.define("MyObject", Object2.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
assertFalse(boot.isInitialized());
boolean ok = boot.start();
assertNull(boot.getSettingsProvider());
assertTrue(boot.isInitialized());
assertTrue(ok);
factory = boot.getFactory();
Object2 object = factory.get(Object2.class, "MyObject", null);
assertNotNull("object get failed", object);
assertEquals("file path is wrong", "solution", boot.getFilePath());
boot.stop();
assertFalse(boot.isInitialized());
}
use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.
the class PluginManagerNotConfiguredIT method setUp.
public void setUp() {
List<?> messages = TestManager.getMessagesList();
if (messages == null) {
messages = new ArrayList<String>();
}
if (initOk) {
return;
}
PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
if (PentahoSystem.getApplicationContext() == null) {
// $NON-NLS-1$
StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
// $NON-NLS-1$ //$NON-NLS-2$
String inContainer = System.getProperty("incontainer", "false");
if (inContainer.equalsIgnoreCase("false")) {
// $NON-NLS-1$
// Setup simple-jndi for datasources
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("org.osjava.sj.root", getSolutionPath() + "/system/simple-jndi");
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("org.osjava.sj.delimiter", "/");
}
ApplicationContext springApplicationContext = getSpringApplicationContext();
IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
pentahoObjectFactory.init(null, springApplicationContext);
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
// force Spring to populate PentahoSystem
// $NON-NLS-1$
springApplicationContext.getBean("pentahoSystemProxy");
initOk = PentahoSystem.init(applicationContext);
} else {
initOk = true;
}
initOk = true;
}
use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testCannotCreateCache.
public void testCannotCreateCache() throws Exception {
SimpleObjectFactory factory = new SimpleObjectFactory();
// $NON-NLS-1$
factory.defineObject("ICacheManager", MockDisabledCacheManager.class.getName());
// Swap in an object factory with a cache manager that doesn't allow creating new caches
Set<IPentahoObjectFactory> facts = ((AggregateObjectFactory) PentahoSystem.getObjectFactory()).getFactories();
PentahoSystem.clearObjectFactory();
PentahoSystem.registerObjectFactory(factory);
try {
try {
new SessionCachingMetadataDomainRepository(new MockSessionAwareMetadataDomainRepository());
// $NON-NLS-1$
fail("Should not be able to create a Session Caching Repository without an enabled cache");
} catch (IllegalStateException ex) {
// $NON-NLS-1$
assertTrue(ex.getMessage().contains("cannot be initialized"));
// expected
}
} finally {
// Replace the original object factory so the rest of the tests work
PentahoSystem.clearObjectFactory();
for (IPentahoObjectFactory fact : facts) {
PentahoSystem.registerObjectFactory(fact);
}
}
}
use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project data-access by pentaho.
the class DebugModelerService method getSession.
private IPentahoSession getSession() {
IPentahoSession session = null;
IPentahoObjectFactory pentahoObjectFactory = PentahoSystem.getObjectFactory();
if (pentahoObjectFactory != null) {
try {
// $NON-NLS-1$
session = pentahoObjectFactory.get(IPentahoSession.class, "systemStartupSession", null);
} catch (ObjectFactoryException e) {
e.printStackTrace();
}
}
return session;
}
use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project data-access by pentaho.
the class PentahoSystemHelper method init.
public static void init() {
if (PentahoSystem.getInitializedOK()) {
return;
}
try {
PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
if (PentahoSystem.getApplicationContext() == null) {
StandaloneApplicationContext applicationContext = // $NON-NLS-1$
new StandaloneApplicationContext(getSolutionPath(), "");
// set the base url assuming there is a running server on port 8080
if (PentahoRequestContextHolder.getRequestContext() != null) {
applicationContext.setFullyQualifiedServerURL(PentahoRequestContextHolder.getRequestContext().getContextPath());
}
// $NON-NLS-1$ //$NON-NLS-2$
String inContainer = System.getProperty("incontainer", "false");
if (inContainer.equalsIgnoreCase("false")) {
// $NON-NLS-1$
// Setup simple-jndi for datasources
System.setProperty("java.naming.factory.initial", // $NON-NLS-1$ //$NON-NLS-2$
"org.osjava.sj.SimpleContextFactory");
System.setProperty("org.osjava.sj.root", // $NON-NLS-1$ //$NON-NLS-2$
getSolutionPath() + "/system/simple-jndi");
// $NON-NLS-1$ //$NON-NLS-2$
System.setProperty("org.osjava.sj.delimiter", "/");
}
ApplicationContext springApplicationContext = getSpringApplicationContext();
IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
pentahoObjectFactory.init(null, springApplicationContext);
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
// force Spring to inject PentahoSystem, there has got to be a better way than this,
// perhaps an alternate way of initting spring's app context
// $NON-NLS-1$
springApplicationContext.getBean("pentahoSystemProxy");
PentahoSystem.init(applicationContext);
}
} catch (Exception e) {
logger.error(e);
}
}
Aggregations