RepositoryResourceLoader implements ResourceLoader { public ResourceKey deriveKey( final ResourceKey parent, String path, final Map data ) throws ResourceKeyCreationException { if ( !path.startsWith( getSchema() + SCHEMA_SEPARATOR ) ) { final int winindex = ( (String) parent.getIdentifier() ).lastIndexOf( WIN_PATH_SEPARATOR ); final int regindex = ( (String) parent.getIdentifier() ).lastIndexOf( PATH_SEPARATOR ); int dirindex = 0; if ( winindex > regindex ) { dirindex = winindex + WIN_PATH_SEPARATOR.length(); } else { dirindex = regindex + PATH_SEPARATOR.length(); } path = ( (String) parent.getIdentifier() ).substring( 0, dirindex ) + path; } final Map derivedValues = new HashMap( parent.getFactoryParameters() ); if ( data != null ) { derivedValues.putAll( data ); } return new ResourceKey( getSchema(), path, derivedValues ); } RepositoryResourceLoader(); void setResourceManager( final ResourceManager manager ); ResourceManager getManager(); String getSchema(); ResourceData load( final ResourceKey key ); boolean isSupportedKey( final ResourceKey key ); ResourceKey createKey( final Object value, final Map factoryKeys ); ResourceKey deriveKey( final ResourceKey parent, String path, final Map data ); ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ); String serialize( final ResourceKey bundleKey, final ResourceKey key ); URL toURL( final ResourceKey key ); boolean isSupportedDeserializer( final String data ); static final String SOLUTION_SCHEMA_NAME; static final String SCHEMA_SEPARATOR; static final String PATH_SEPARATOR; static final String WIN_PATH_SEPARATOR; }
@Test public void testDeriveKey() throws Exception { ResourceKey key = new ResourceKey( "", "", null ); Map<String, Object> keys = new HashMap<String, Object>() {{ put( "key", "value" ); }}; ResourceKey derivedKey = rrl.deriveKey( key, "", keys ); assertEquals( rrl.SOLUTION_SCHEMA_NAME, derivedKey.getSchema() ); assertEquals( "", derivedKey.getIdentifierAsString() ); String path = rrl.SOLUTION_SCHEMA_NAME + rrl.SCHEMA_SEPARATOR; key = new ResourceKey( rrl.SOLUTION_SCHEMA_NAME + rrl.SCHEMA_SEPARATOR, "/", null ); derivedKey = rrl.deriveKey( key, path, keys ); assertEquals( rrl.SOLUTION_SCHEMA_NAME, derivedKey.getSchema() ); assertEquals( rrl.SOLUTION_SCHEMA_NAME + rrl.SCHEMA_SEPARATOR, derivedKey.getIdentifierAsString() ); }