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 ); } }
public void init( final StyleKeyRegistry styleKeyRegistry, final ResourceManager resourceManager, final ResourceKey source, final long version, final StyleRule parentRule ) { if ( styleKeyRegistry == null ) { throw new NullPointerException(); } if ( resourceManager == null ) { throw new NullPointerException(); } this.styleKeyRegistry = styleKeyRegistry; this.resourceManager = resourceManager; this.source = source; if ( source != null ) { this.dependencies = new DependencyCollector( source, version ); } this.parentRules.clear(); if ( parentRule != null ) { parentRules.push( parentRule ); } this.namespaces.clear(); }
public CompoundResource( final ResourceKey source, final DependencyCollector dependencies, final Object product, final Class targetType ) { if ( source == null ) { throw new NullPointerException( "Source must not be null" ); } if ( dependencies == null ) { throw new NullPointerException( "Dependecies must be given." ); } if ( targetType == null ) { throw new NullPointerException( "TargetType must not be null" ); } if ( product == null ) { throw new NullPointerException( "Product must not be null" ); } this.targetType = targetType; this.source = source; try { this.dependencies = (DependencyCollector) dependencies.clone(); } catch ( CloneNotSupportedException e ) { throw new IllegalStateException ( "Clone not supported? This should not happen." ); } this.product = product; }
public Resource create( final ResourceManager manager, final ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { final ResourceKey key = data.getKey(); final Map factoryParameters = key.getFactoryParameters(); final boolean embedded = Boolean.TRUE.equals( factoryParameters.get( BaseFontResourceFactory.EMBEDDED ) ); final String encoding = String.valueOf( factoryParameters.get( BaseFontResourceFactory.ENCODING ) ); final String fontType = String.valueOf( factoryParameters.get( BaseFontResourceFactory.FONTNAME ) ); final DependencyCollector dc = new DependencyCollector( key, data.getVersion( manager ) ); final byte[] ttfAfm = data.getResource( manager ); byte[] pfb = null; if ( embedded && ( fontType.endsWith( ".afm" ) || fontType.endsWith( ".pfm" ) ) ) { final String pfbFileName = fontType.substring( 0, fontType.length() - 4 ) + ".pfb"; try { final ResourceKey pfbKey = manager.deriveKey( key, pfbFileName ); final ResourceData res = manager.load( pfbKey ); pfb = res.getResource( manager ); dc.add( pfbKey, res.getVersion( manager ) ); } catch ( ResourceException e ) { // ignore .. } } try { final BaseFont baseFont = BaseFont.createFont( fontType, encoding, embedded, false, ttfAfm, pfb ); return new CompoundResource( key, dc, baseFont, getFactoryType() ); } catch ( Exception e ) { throw new ResourceCreationException( "Failed to create the font " + fontType, e ); } }
/** * The primary source is also included in this set. The dependencies are given as ResourceKey objects. The keys itself * do not hold any state information. * <p/> * The dependencies do not track deep dependencies. So if Resource A depends on Resource B which depends on Resource * C, then A only knows about B, not C. * * @return */ public ResourceKey[] getDependencies() { return dependencies.getDependencies(); }
public long getVersion( final ResourceKey key ) { return dependencies.getVersion( key ); }
handler.getDependencyCollector().add( targetKey, data.getVersion( manager ) ); return createResource( targetKey, handler, createdProduct, getFactoryType() ); } catch ( ParserConfigurationException e ) {
/** * Creates a new root-handler using the given versioning information and resource-manager. * * @param manager the resource manager that loaded this xml-file. * @param source the source-key that identifies from where the file was loaded. * @param context the key that should be used to resolve relative paths. * @param version the versioning information for the root-file. */ public RootXmlReadHandler( final ResourceManager manager, final ResourceKey source, final ResourceKey context, final long version ) { if ( manager == null ) { throw new NullPointerException(); } if ( source == null ) { throw new NullPointerException(); } this.firstCall = true; this.manager = manager; this.source = source; this.context = context; this.dependencyCollector = new DependencyCollector( source, version ); this.objectRegistry = new HashMap<String, Object>(); this.parserConfiguration = new DefaultConfiguration(); this.commentHandler = new CommentHandler(); this.namespaces = new FastStack<String>(); }
/** * Parses an external file using LibLoader and returns the parsed result as an object of type * <code>targetClass</code>. The file is given as relative pathname (relative to the current source file). The current * helper-methods are used as parse-parameters for the external parsing. * * @param file the file to be parsed. * @param targetClass the target type of the parse operation. * @param map the map of parse parameters. * @return the result, never null. * @throws ParseException if parsing the result failed for some reason. * @throws ResourceLoadingException if there was an IO error loading the resource. * @see #deriveParseParameters() */ protected Object performExternalParsing( final String file, final Class targetClass, final Map map ) throws ParseException, ResourceLoadingException { try { final ResourceManager resourceManager = rootHandler.getResourceManager(); final ResourceKey source = rootHandler.getSource(); final ResourceKey target = resourceManager.deriveKey( source, file, map ); final DependencyCollector dc = rootHandler.getDependencyCollector(); final Resource resource = resourceManager.create( target, rootHandler.getContext(), targetClass ); dc.add( resource ); return resource.getResource(); } catch ( ResourceLoadingException rle ) { throw rle; } catch ( ResourceException e ) { throw new ParseException( "Failure while loading data: " + file, e, getLocator() ); } }
dc.add( resource );
final ResourceKey derivedKey = manager.deriveKey( key, href ); final Resource resource = manager.create( derivedKey, null, DataFactory.class ); getRootHandler().getDependencyCollector().add( resource ); dataFactory = (DataFactory) resource.getResource(); } catch ( ResourceKeyCreationException e ) {
dependencies.add( data.getKey(), data.getVersion( manager ) );
dependencies.add( data.getKey(), data.getVersion( manager ) );