public boolean isSupportedDeserializer( final String data ) throws ResourceKeyCreationException { final ResourceKeyData resourceKeyData = ResourceKeyUtils.parse( data ); // Validate the data return ( INNER_SCHEMA.equals( resourceKeyData.getSchema() ) ); }
public boolean isSupportedDeserializer( String data ) { return SCHEMA_NAME.equals( ResourceKeyUtils.readSchemaFromString( data ) ); } }
public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof File ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a File object" ); } // Log information logger.debug( "Serializing a File Resource Key..." ); if ( key.getParent() != null ) { throw new ResourceException ( "Unable to serialize a File-ResourceKey with a parent. This type is not expected to have a parent." ); } // Create a string version of the identifier try { final File file = (File) key.getIdentifier(); final String strIdentifier = file.getCanonicalPath(); final String result = ResourceKeyUtils.createStringResourceKey ( key.getSchema().toString(), strIdentifier, key.getFactoryParameters() ); logger.debug( "Serialized File Resource Key: [" + result + "]" ); return result; } catch ( IOException ioe ) { throw new IllegalArgumentException( "Could not determine cononical path to file specified in ResourceKey: " + ioe.getMessage() ); } }
/** * Returns a string representation of the ResourceKey based on the pieces that are passed as parameters * * @param schema the string representation of the schema * @param identifier the string representation of the identifier * @param factoryParameters the set of factory parameters (<code>null</code> allowed) * @return the string version with the pieces delimited and concatenated */ public static String createStringResourceKey( final String schema, final String identifier, final Map factoryParameters ) { final String factoryParamString = convertFactoryParametersToString( factoryParameters ); final CSVQuoter quoter = new CSVQuoter( ';' ); return quoter.doQuoting( SERIALIZATION_PREFIX + schema ) + DELIMITER + quoter.doQuoting( identifier ) + ( factoryParamString == null ? "" : DELIMITER + quoter.doQuoting( factoryParamString ) ); }
final Map parameters; if ( tokenizer.hasMoreElements() ) { parameters = parseFactoryParametersFromString( tokenizer.nextToken() ); } else { parameters = null;
try { final ResourceKey resourceKey = ResourceKeyUtils.embedResourceInKey( locateResourceManager(), key, key.getFactoryParameters() ); SerializerHelper.getInstance().writeObject( resourceKey, stream ); } catch ( ResourceException e ) {
/** * Creates a String version of the resource key that can be used to generate a new ResourceKey object via * deserialization * * @param bundleKey * @param key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof byte[] ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a byte[] object" ); } final byte[] data = (byte[]) key.getIdentifier(); final char[] cdata = new char[ data.length ]; for ( int i = 0; i < data.length; i++ ) { cdata[ i ] = (char) ( data[ i ] & 0xFF ); } return ResourceKeyUtils.createStringResourceKey ( String.valueOf( key.getSchema() ), new String( cdata ), key.getFactoryParameters() ); }
public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { // Parse the data final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } // Create a new file based on the path provided final File file = new File( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, file, keyData.getFactoryParameters() ); }
/** * Serializes the resource key to a String representation which can be recreated using the * <code>deserialize(ResourceKey)<code> method. * * @param bundleKey * @param key * @return a <code>String<code> which is a serialized version of the <code>ResourceKey</code> * @throws ResourceException indicates an error serializing the resource key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof String ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a byte[] object" ); } final String data = (String) key.getIdentifier(); return ResourceKeyUtils.createStringResourceKey ( String.valueOf( key.getSchema() ), data, key.getFactoryParameters() ); }
public boolean isSupportedDeserializer( String data ) { return SCHEMA_NAME.equals( ResourceKeyUtils.readSchemaFromString( data ) ); } }
/** * Parses the input string and returns a newly created ResourceKey based on the string data */ public ResourceKey deserialize( final ResourceKey bundleKey, String stringKey ) throws ResourceKeyCreationException { // Parse the data final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } final String identifier = keyData.getIdentifier(); final char[] chars = identifier.toCharArray(); final byte[] data = new byte[ chars.length ]; for ( int i = 0; i < chars.length; i++ ) { data[ i ] = (byte) chars[ i ]; } return createKey( data, keyData.getFactoryParameters() ); }
final String result = ResourceKeyUtils.createStringResourceKey ( key.getSchema().toString(), url.toExternalForm(), key.getFactoryParameters() ); logger.debug( "Serialized Classloader Resource Key: [" + result + "]" );
public boolean isSupportedDeserializer( final String data ) { return SCHEMA_NAME.equals( ResourceKeyUtils.readSchemaFromString( data ) ); } }
/** * Parses the input string and returns a newly created ResourceKey based on the string data */ public ResourceKey deserialize( final ResourceKey bundleKey, String stringKey ) throws ResourceKeyCreationException { // Parse the data final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } // Create and return a new key return createKey( keyData.getIdentifier(), keyData.getFactoryParameters() ); }
/** * Creates a String version of the resource key that can be used to generate a new ResourceKey object via * deserialization * * @param bundleKey * @param key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof String ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a String object" ); } // Log information logger.debug( "Serializing a Classloader Resource Key..." ); if ( key.getParent() != null ) { throw new ResourceException ( "Cannot serialize this key, it contains a parent, but should not contain one at all." ); } // Serialize the key final String result = ResourceKeyUtils.createStringResourceKey( key.getSchema().toString(), (String) key.getIdentifier(), key.getFactoryParameters() ); logger.debug( "Serialized Classloader Resource Key: [" + result + "]" ); return result; }
public boolean isSupportedDeserializer( final String data ) { return SCHEMA_NAME.equals( ResourceKeyUtils.readSchemaFromString( data ) ); } }
/** * Parses the input string and returns a newly created ResourceKey based on the string data */ public ResourceKey deserialize( final ResourceKey bundleKey, String stringKey ) throws ResourceKeyCreationException { // Parse the data ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } // Create and return a new key try { return createKey( new URL( keyData.getIdentifier() ), keyData.getFactoryParameters() ); } catch ( MalformedURLException mfue ) { throw new ResourceKeyCreationException( "Malformed value: " + keyData.getIdentifier() ); } }
public boolean isSupportedDeserializer( String data ) { return SCHEMA_NAME.equals( ResourceKeyUtils.readSchemaFromString( data ) ); } }
/** * Creates a <code>ResourceKey</code> based off the <code>String</code> representation of the key. The * <code>String</code> should have been created using the <code>serialize</code> method. * * @param bundleKey * @param stringKey the <code>String</code> representation of the <code>ResourceKey</code> @return a * <code>ResourceKey</code> which matches the <code>String</code> representation * @throws ResourceKeyCreationException indicates an error occurred in the creation or deserialization of the * <code>ResourceKey</code> */ public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData resourceKeyData = ResourceKeyUtils.parse( stringKey ); // Validate the data if ( INNER_SCHEMA.equals( resourceKeyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of key does not contain correct schema" ); } return new ResourceKey( bundleKey, resourceKeyData.getSchema(), resourceKeyData.getIdentifier(), resourceKeyData.getFactoryParameters() ); }