protected Class createClass() throws ObjectFactoryException { try { return loader.loadClass( className ); } catch ( Exception e ) { if ( e instanceof RuntimeException ) { throw (RuntimeException) e; } throw new ObjectFactoryException( e ); } }
private IPentahoSession getSession() { IPentahoSession session = null; IPentahoObjectFactory pentahoObjectFactory = PentahoSystem.getObjectFactory(); if ( pentahoObjectFactory != null ) { try { session = pentahoObjectFactory.get( IPentahoSession.class, "systemStartupSession", null ); //$NON-NLS-1$ } catch ( ObjectFactoryException e ) { e.printStackTrace(); } } return session; }
protected Object createObject() throws ObjectFactoryException { Object instance = null; Class<?> classObject = createClass(); try { instance = classObject.newInstance(); } catch ( Exception e ) { if ( e instanceof RuntimeException ) { throw (RuntimeException) e; } throw new ObjectFactoryException( e ); } return instance; }
"roleAuthorizationPolicyRoleBindingDaoTarget", PentahoSessionHolder.getSession() ); } catch ( ObjectFactoryException e ) { e.printStackTrace();
protected Object retrieveViaSpring( String beanId ) throws ObjectFactoryException { Object object; try { object = beanFactory.getBean( beanId ); } catch ( Throwable t ) { String msg = Messages.getInstance() .getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", beanId ); //$NON-NLS-1$ throw new ObjectFactoryException( msg, t ); } return object; }
@Override protected T createObject() throws ObjectFactoryException { final IPentahoSession session = PentahoSessionHolder.getSession(); try { return creator.create( session ); } catch ( Exception e ) { throw new ObjectFactoryException( "Error creating instance", e ); } }
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", interfaceClass.getSimpleName() ); //$NON-NLS-1$ 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; }
public void afterPropertiesSet() throws ObjectFactoryException { if ( ( saltString == null ) || ( algorithm == null ) || ( encryptionKey == null ) ) { throw new ObjectFactoryException( "Required properties not set - need Salt, algorithm and encryption key" ); } if ( saltString.length() != this.saltLength ) { // Make sure that the salt length is 8 bytes - the PBEParameterSpec doesn't anything but if ( saltString.length() < saltLength ) { saltString = ( saltString + "!@#$%^&*" ).substring( 0, saltLength ); // postfix bytes to pad it out } else if ( saltString.length() > saltLength ) { saltString = saltString.substring( 0, saltLength ); // Trim off longer than 8-bytes } } byte[] saltBytes = saltString.getBytes(); paramSpec = new PBEParameterSpec( saltBytes, getIterations() ); PBEKeySpec skeySpec = new PBEKeySpec( getEncryptionKey().toCharArray(), saltBytes, getIterations() ); try { secretKey = SecretKeyFactory.getInstance( getAlgorithm() ).generateSecret( skeySpec ); } catch ( Exception ex ) { ex.printStackTrace(); throw new ObjectFactoryException( "Encryption requested not available" ); } }
protected Object retreiveObject( String key, IPentahoSession session ) throws ObjectFactoryException { Object o = instanceMap.get( key ); if ( o != null ) { return o; } ObjectCreator creator = creators.get( key ); if ( creator == null ) { String msg = Messages.getInstance() .getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_CREATE_OBJECT", key ); //$NON-NLS-1$ throw new ObjectFactoryException( msg ); } Object instance = creator.getInstance( key, session ); return instance; }
protected Object instanceClass( Class<?> interfaceClass, String key ) throws ObjectFactoryException { Object object = null; try { if ( key != null ) { object = beanFactory.getType( key ).newInstance(); } else { // No published beans by this type, try the interface simplename itself as the key (legacy behavior) object = beanFactory.getType( interfaceClass.getSimpleName() ).newInstance(); } } catch ( Exception e ) { String msg = Messages.getInstance() .getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_CREATE_OBJECT", key ); //$NON-NLS-1$ throw new ObjectFactoryException( msg, e ); } return object; }
@SuppressWarnings( "unchecked" ) public <T> T get( Class<T> interfaceClass, String key, IPentahoSession session ) throws ObjectFactoryException { String classname = classnamesMap.get( key ); try { Class implClass = Class.forName( classname ); T t = (T) implClass.newInstance(); if ( t instanceof IPentahoInitializer ) { ( (IPentahoInitializer) t ).init( session ); } return t; } catch ( Throwable th ) { throw new ObjectFactoryException( "Could not create instance for class " + classname, th ); } }
protected Object instanceClass( String simpleName, String key ) throws ObjectFactoryException { Object object = null; try { if ( beanFactory.containsBean( simpleName ) ) { object = beanFactory.getType( simpleName ).newInstance(); } else if ( key != null ) { object = beanFactory.getType( key ).newInstance(); } } catch ( Exception e ) { String msg = Messages.getInstance() .getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_CREATE_OBJECT", key ); //$NON-NLS-1$ throw new ObjectFactoryException( msg, e ); } return object; }
@Override public <T> T get( Class<T> clazz, IPentahoSession session, Map<String, String> properties ) throws ObjectFactoryException { IPentahoObjectReference<T> highestRef = this.getObjectReference( clazz, session, properties ); if ( highestRef != null ) { return highestRef.getObject(); } readLock.lock(); try { for ( IPentahoObjectFactory fact : factories ) { if ( fact.objectDefined( clazz.getSimpleName() ) ) { T object = fact.get( clazz, clazz.getSimpleName(), session ); return object; } } } finally { readLock.unlock(); } String msg = Messages.getInstance().getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", clazz.getSimpleName() ); throw new ObjectFactoryException( msg ); }
@Override public <T> T get( Class<T> interfaceClass, String key, IPentahoSession session ) throws ObjectFactoryException { // if they want it by id, check for that first if ( key != null ) { readLock.lock(); try { for ( IPentahoObjectFactory fact : factories ) { if ( fact.objectDefined( key ) ) { T object = fact.get( interfaceClass, key, session ); logger.debug( MessageFormat.format( "Found object for key: {0} in factory: {1}", key, fact.getName() ) ); return object; } } } finally { readLock.unlock(); } } T fromType = get( interfaceClass, session, null ); if ( fromType != null ) { return fromType; } String msg = Messages.getInstance().getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", interfaceClass.getSimpleName() ); throw new ObjectFactoryException( msg ); }
Messages.getInstance().getString( "AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", throw new ObjectFactoryException( msg, tt );