public static MasterReport loadMasterReport( String sourceFilename ) throws Exception { ResourceManager manager = new ResourceManager(); manager.registerDefaults(); FileObject fileObject = KettleVFS.getFileObject( sourceFilename ); URL url = new URL( fileObject.getName().getURI() ); Resource resource = manager.createDirectly( url, MasterReport.class ); MasterReport report = (MasterReport) resource.getResource(); return report; }
private boolean isResourceCacheable( final Resource newResource ) { final ResourceKey source = newResource.getSource(); if ( newResource.isTemporaryResult() ) { return false; } if ( newResource.getVersion( source ) == -1 ) { return false; } final ResourceKey[] keys = newResource.getDependencies(); for ( int i = 0; i < keys.length; i++ ) { if ( newResource.getVersion( keys[ i ] ) == -1 ) { return false; } } return true; }
public Class getTargetType() { return parent.getTargetType(); }
public ResourceKey[] getDependencies() { final ResourceKey[] resourceKeys = parent.getDependencies(); final ResourceKey[] target = new ResourceKey[ resourceKeys.length + 1 ]; target[ 0 ] = parent.getSource(); System.arraycopy( resourceKeys, 0, target, 1, resourceKeys.length ); return target; }
public long getVersion( final ResourceKey key ) { if ( ObjectUtilities.equal( key, outsideKey ) ) { return parent.getVersion( parent.getSource() ); } return parent.getVersion( key ); }
public DefaultImageReference( final Resource imageResource ) throws ResourceException { if ( imageResource == null ) { throw new NullPointerException(); } final Object o = imageResource.getResource(); if ( o instanceof Image == false ) { throw new ResourceException( "ImageResource does not contain a java.awt.Image object." ); } final ResourceKey resKey = imageResource.getSource(); final Object identifier = resKey.getIdentifier(); if ( identifier instanceof URL ) { this.url = (URL) identifier; } this.resourceKey = resKey; this.image = (Image) o; final WaitingImageObserver obs = new WaitingImageObserver( image ); obs.waitImageLoaded(); if ( obs.isError() ) { throw new ResourceException( "Failed to load the image. ImageObserver signaled an error." ); } this.width = image.getWidth( null ); this.height = image.getHeight( null ); }
public void put( final Resource resource ) { final Object source = new CompoundCacheKey( resource.getSource(), resource.getTargetType() ); try { factoryCache.put( new Element( source, (Object) resource ) ); } catch ( Exception e ) { if ( logger.isDebugEnabled() ) { logger.debug( "Failed to store resource for key " + source, e ); } // ignore ... the object is not serializable .. } }
public void add( final Resource dependentResource ) { if ( dependentResource == null ) { throw new NullPointerException(); } final ResourceKey[] depKeys = dependentResource.getDependencies(); for ( int i = 0; i < depKeys.length; i++ ) { final ResourceKey depKey = depKeys[ i ]; final long version = dependentResource.getVersion( depKey ); add( depKey, version ); } }
if ( key != newResource.getSource() ) { factoryCache.put( new BundleCacheResourceWrapper( newResource, key ) );
public void remove( final Resource resource ) { final Object source = new CompoundCacheKey( resource.getSource(), resource.getTargetType() ); factoryCache.remove( source ); }
public boolean isResourceUnchanged( final ResourceManager frontEnd, final Resource resource ) throws ResourceLoadingException { if ( frontEnd == null ) { throw new NullPointerException(); } if ( resource == null ) { throw new NullPointerException(); } final ResourceKey[] deps = resource.getDependencies(); for ( int i = 0; i < deps.length; i++ ) { final ResourceKey dep = deps[ i ]; final long version = resource.getVersion( dep ); if ( version == -1 ) { // non-versioning key, ignore it. continue; } final ResourceData data = frontEnd.load( dep ); if ( data.getVersion( frontEnd ) != version ) { // oh, my bad, an outdated or changed entry. // We have to re-read the whole thing. return false; } } // all versions have been confirmed to be valid. Nice, we can use the // cached product. return true; }
public Object getRaw() { try { return content.getResource(); } catch ( ResourceException e ) { return null; } }
public Object getResource() throws ResourceException { return parent.getResource(); }
private StyleSheet parseStyleSheet( final ResourceKey key, final ResourceKey context ) { try { final Resource resource = resourceManager.create ( key, context, StyleSheet.class ); return (StyleSheet) resource.getResource(); } catch ( ResourceException e ) { // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage()); } return null; }
private ElementStyleDefinition parseStyleSheet( final ResourceKey key, final ResourceKey context ) { try { final Resource resource = resourceManager.create( key, context, ElementStyleDefinition.class ); return (ElementStyleDefinition) resource.getResource(); } catch ( ResourceException e ) { // Log.info("Unable to parse StyleSheet: " + e.getLocalizedMessage()); } return null; }
public static DocumentBundle getBundle( final File file ) throws ResourceException { if ( file == null ) { throw new NullPointerException(); } final ResourceManager resManager = new ResourceManager(); final Resource directly = resManager.createDirectly( file, DocumentBundle.class ); return (DocumentBundle) directly.getResource(); }
public void registerFromXml( final URL metaDataSource ) throws IOException { if ( metaDataSource == null ) { throw new NullPointerException( "Error: Could not find the element meta-data description file" ); } try { final Resource resource = resourceManager.createDirectly( metaDataSource, ElementTypeCollection.class ); final ElementTypeCollection typeCollection = (ElementTypeCollection) resource.getResource(); final ElementMetaData[] types = typeCollection.getElementTypes(); for ( int i = 0; i < types.length; i++ ) { final ElementMetaData metaData = types[i]; registerElement( metaData ); } } catch ( Exception e ) { logger.debug( "Error: Could not parse the element meta-data description file: " + metaDataSource, e ); throw new IOException( "Error: Could not parse the element meta-data description file: " + metaDataSource ); } }
public void registerFromXml( final URL dataFactoryMetaSource ) throws IOException { if ( dataFactoryMetaSource == null ) { throw new NullPointerException( "Error: Could not find the data-factory meta-data description file" ); } try { final Resource resource = resourceManager.createDirectly( dataFactoryMetaSource, DataFactoryMetaDataCollection.class ); final DataFactoryMetaDataCollection typeCollection = (DataFactoryMetaDataCollection) resource.getResource(); final DataFactoryMetaData[] types = typeCollection.getFactoryMetaData(); for ( int i = 0; i < types.length; i++ ) { final DataFactoryMetaData metaData = types[i]; if ( metaData != null ) { register( metaData ); } } } catch ( Exception e ) { DataFactoryRegistry.logger.error( "Failed:", e ); throw new IOException( "Error: Could not parse the element meta-data description file" ); } }
public void registerFromXml( final URL expressionMetaSource ) throws IOException { if ( expressionMetaSource == null ) { throw new NullPointerException( "Error: Could not find the expression meta-data description file" ); } try { final Resource resource = resourceManager.createDirectly( expressionMetaSource, ExpressionMetaDataCollection.class ); final ExpressionMetaDataCollection typeCollection = (ExpressionMetaDataCollection) resource.getResource(); final ExpressionMetaData[] types = typeCollection.getExpressionMetaData(); for ( int i = 0; i < types.length; i++ ) { final ExpressionMetaData metaData = types[i]; if ( metaData != null ) { registerExpression( metaData ); } } } catch ( Exception e ) { throw new IOException( "Error: Could not parse the element meta-data description file", e ); } }
public void registerFromXml( final URL expressionMetaSource ) throws IOException { if ( expressionMetaSource == null ) { throw new NullPointerException( "Error: Could not find the report-preprocessor meta-data description file" ); } try { final Resource resource = resourceManager.createDirectly( expressionMetaSource, ReportPreProcessorMetaDataCollection.class ); final ReportPreProcessorMetaDataCollection typeCollection = (ReportPreProcessorMetaDataCollection) resource.getResource(); final ReportPreProcessorMetaData[] types = typeCollection.getReportPreProcessorMetaData(); for ( int i = 0; i < types.length; i++ ) { final ReportPreProcessorMetaData metaData = types[i]; if ( metaData != null ) { registerReportPreProcessor( metaData ); } } } catch ( Exception e ) { ReportPreProcessorRegistry.logger.error( "Failed:", e ); throw new IOException( "Error: Could not parse the element meta-data description file" ); } }