Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8337419906 for ; Thu, 14 Apr 2016 06:13:08 +0000 (UTC) Received: (qmail 78678 invoked by uid 500); 14 Apr 2016 06:13:08 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 78631 invoked by uid 500); 14 Apr 2016 06:13:08 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 78159 invoked by uid 99); 14 Apr 2016 06:13:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Apr 2016 06:13:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E01DEEAB4D; Thu, 14 Apr 2016 06:13:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@zest.apache.org Date: Thu, 14 Apr 2016 06:13:25 -0000 Message-Id: <3d0f9b40f8574f0ca1fbd8afb51bc43e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [19/34] zest-java git commit: ZEST-136 - Massive changes to the Runtime, refactoring the Model and Instance relationship. http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java index 5d67aa2..02448d3 100644 --- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java +++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java @@ -33,14 +33,9 @@ import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.Set; -import java.util.function.BiFunction; import java.util.function.Function; import org.apache.zest.api.entity.EntityReference; -import org.apache.zest.api.injection.scope.Service; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.service.ServiceReference; -import org.apache.zest.api.structure.Application; -import org.apache.zest.api.structure.Module; +import org.apache.zest.api.structure.ModuleDescriptor; import org.apache.zest.api.type.CollectionType; import org.apache.zest.api.type.EnumType; import org.apache.zest.api.type.MapType; @@ -105,10 +100,6 @@ public abstract class ValueDeserializerAdapter private static final String UTF_8 = "UTF-8"; private final Map, Function> deserializers = new HashMap<>( 16 ); private final Map, ComplexDeserializer> complexDeserializers = new HashMap<>( 2 ); - private final Application application; - private final Module module; - private Function valuesModuleFinder; - private Module valuesModule; /** * Register a Plain Value type deserialization Function. @@ -131,24 +122,8 @@ public abstract class ValueDeserializerAdapter complexDeserializers.put( type, (ComplexDeserializer) deserializer ); } - @SuppressWarnings( "unchecked" ) - public ValueDeserializerAdapter( @Structure Application application, - @Structure Module module, - @Service ServiceReference serviceRef - ) + protected ValueDeserializerAdapter() { - this( application, module, serviceRef.metaInfo( Function.class ) ); - } - - protected ValueDeserializerAdapter( Application application, - Module module, - Function valuesModuleFinder - ) - { - - this.application = application; - this.module = module; - setValuesModuleFinder( valuesModuleFinder ); // Primitive Value types registerDeserializer( String.class, Object::toString ); @@ -189,84 +164,58 @@ public abstract class ValueDeserializerAdapter registerDeserializer( EntityReference.class, input -> EntityReference.parseEntityReference( input.toString() ) ); } - private void setValuesModuleFinder( Function valuesModuleFinder ) - { - this.valuesModuleFinder = valuesModuleFinder; - this.valuesModule = null; - } - - private Module valuesModule() - { - if( valuesModule == null ) - { - if( valuesModuleFinder == null ) - { - valuesModule = module; - } - else - { - valuesModule = valuesModuleFinder.apply( application ); - if( valuesModule == null ) - { - throw new ValueSerializationException( "Values Module provided by the finder Function was null." ); - } - } - } - return valuesModule; - } - @Override - public Function deserialize( Class type ) + public Function deserialize( ModuleDescriptor module, Class type ) { if( CollectionType.isCollection( type ) ) { ValueType objectValueType = new ValueType( Object.class ); - return deserialize( new CollectionType( type, objectValueType ) ); + return deserialize( module, new CollectionType( type, objectValueType ) ); } if( MapType.isMap( type ) ) { ValueType objectValueType = new ValueType( Object.class ); - return deserialize( new MapType( type, objectValueType, objectValueType ) ); + return deserialize( module, new MapType( type, objectValueType, objectValueType ) ); } - return deserialize( new ValueType( type ) ); + return deserialize( module, new ValueType( type ) ); } @Override - public final Function deserialize( final ValueType valueType ) + public final Function deserialize( ModuleDescriptor module, ValueType valueType ) { - return input -> deserialize( valueType, input ); + return input -> deserialize( module, valueType, input ); } - @Override - public final BiFunction deserialize() - { - return this::deserialize; - } +// @Override +// public final BiFunction deserialize() +// { +// return this::deserialize; +// } @Override - public final T deserialize( Class type, String input ) + public final T deserialize( ModuleDescriptor module, Class type, String input ) throws ValueSerializationException { if( CollectionType.isCollection( type ) ) { ValueType objectValueType = new ValueType( Object.class ); - return deserialize( new CollectionType( type, objectValueType ), input ); + return deserialize( module, new CollectionType( type, objectValueType ), input ); } if( MapType.isMap( type ) ) { ValueType objectValueType = new ValueType( Object.class ); - return deserialize( new MapType( type, objectValueType, objectValueType ), input ); + return deserialize( module, new MapType( type, objectValueType, objectValueType ), input ); } - return deserialize( new ValueType( type ), input ); + return deserialize( module, new ValueType( type ), input ); } @Override - public final T deserialize( ValueType valueType, String input ) + public final T deserialize( ModuleDescriptor module, ValueType valueType, String input ) throws ValueSerializationException { try { - return deserializeRoot( valueType, new ByteArrayInputStream( input.getBytes( UTF_8 ) ) ); + return deserializeRoot( module, valueType, new ByteArrayInputStream( input.getBytes( UTF_8 ) ) ); } catch( ValueSerializationException ex ) { @@ -279,29 +228,29 @@ public abstract class ValueDeserializerAdapter } @Override - public final T deserialize( Class type, InputStream input ) + public final T deserialize( ModuleDescriptor module, Class type, InputStream input ) throws ValueSerializationException { if( CollectionType.isCollection( type ) ) { ValueType objectValueType = new ValueType( Object.class ); - return deserialize( new CollectionType( type, objectValueType ), input ); + return deserialize( module, new CollectionType( type, objectValueType ), input ); } if( MapType.isMap( type ) ) { ValueType objectValueType = new ValueType( Object.class ); - return deserialize( new MapType( type, objectValueType, objectValueType ), input ); + return deserialize( module, new MapType( type, objectValueType, objectValueType ), input ); } - return deserialize( new ValueType( type ), input ); + return deserialize( module, new ValueType( type ), input ); } @Override - public final T deserialize( ValueType valueType, InputStream input ) + public final T deserialize( ModuleDescriptor module, ValueType valueType, InputStream input ) throws ValueSerializationException { try { - return deserializeRoot( valueType, input ); + return deserializeRoot( module, valueType, input ); } catch( ValueSerializationException ex ) { @@ -314,7 +263,7 @@ public abstract class ValueDeserializerAdapter } @SuppressWarnings( "unchecked" ) - private T deserializeRoot( ValueType valueType, InputStream input ) + private T deserializeRoot( ModuleDescriptor module, ValueType valueType, InputStream input ) throws Exception { final Class type = valueType.types().findFirst().orElse( null ); @@ -338,27 +287,27 @@ public abstract class ValueDeserializerAdapter return null; } String string = scanner.next(); - return (T) deserializeBase64Serialized( string ); + return (T) deserializeBase64Serialized( module, string ); } else // Complex ValueType { - InputType adaptedInput = adaptInput( input ); - onDeserializationStart( valueType, adaptedInput ); - T deserialized = doDeserialize( valueType, adaptedInput ); - onDeserializationEnd( valueType, adaptedInput ); + InputType adaptedInput = adaptInput( module, input ); + onDeserializationStart( module, valueType, adaptedInput ); + T deserialized = doDeserialize( module, valueType, adaptedInput ); + onDeserializationEnd( module, valueType, adaptedInput ); return deserialized; } } @SuppressWarnings( "unchecked" ) - private T doDeserialize( ValueType valueType, InputType input ) + private T doDeserialize( ModuleDescriptor module, ValueType valueType, InputType input ) throws Exception { final Class type = valueType.types().findFirst().orElse( null ); // Registered deserializers if( deserializers.get( type ) != null ) { - Object value = readPlainValue( input ); + Object value = readPlainValue( module, input ); if( value == null ) { return null; @@ -372,38 +321,38 @@ public abstract class ValueDeserializerAdapter else // Explicit ValueComposite if( ValueCompositeType.class.isAssignableFrom( valueType.getClass() ) ) { - return (T) deserializeValueComposite( valueType, input ); + return (T) deserializeValueComposite( module, valueType, input ); } else // Explicit Collections if( CollectionType.class.isAssignableFrom( valueType.getClass() ) ) { - return (T) deserializeCollection( (CollectionType) valueType, input ); + return (T) deserializeCollection( module, (CollectionType) valueType, input ); } else // Explicit Map if( MapType.class.isAssignableFrom( valueType.getClass() ) ) { - return (T) deserializeMap( (MapType) valueType, input ); + return (T) deserializeMap( module, (MapType) valueType, input ); } else // Enum if( EnumType.class.isAssignableFrom( valueType.getClass() ) || type.isEnum() ) { - return (T) Enum.valueOf( (Class) type, readPlainValue( input ).toString() ); + return (T) Enum.valueOf( (Class) type, readPlainValue( module, input ).toString() ); } else // Array if( type.isArray() ) { - return (T) deserializeBase64Serialized( readPlainValue( input ).toString() ); + return (T) deserializeBase64Serialized( module, readPlainValue( module, input ).toString() ); } // Guessed Deserialization - return (T) deserializeGuessed( valueType, input ); + return (T) deserializeGuessed( module, valueType, input ); } - private Function buildDeserializeInputFunction( final ValueType valueType ) + private Function buildDeserializeInputFunction( ModuleDescriptor module, ValueType valueType ) { return input -> { try { - return doDeserialize( valueType, input ); + return doDeserialize( module, valueType, input ); } catch( ValueSerializationException ex ) { @@ -416,7 +365,7 @@ public abstract class ValueDeserializerAdapter }; } - private Collection deserializeCollection( CollectionType collectionType, InputType input ) + private Collection deserializeCollection( ModuleDescriptor module, CollectionType collectionType, InputType input ) throws Exception { Collection collection; @@ -429,43 +378,46 @@ public abstract class ValueDeserializerAdapter { collection = new ArrayList<>(); } - return readArrayInCollection( input, - this.buildDeserializeInputFunction( collectionType.collectedType() ), + return readArrayInCollection( module, + input, + this.buildDeserializeInputFunction( module, collectionType.collectedType() ), collection ); } - private Map deserializeMap( MapType mapType, InputType input ) + private Map deserializeMap( ModuleDescriptor module, MapType mapType, InputType input ) throws Exception { - return readMapInMap( input, - this.buildDeserializeInputFunction( mapType.keyType() ), - this.buildDeserializeInputFunction( mapType.valueType() ), + return readMapInMap( module, + input, + this.buildDeserializeInputFunction( module, mapType.keyType() ), + this.buildDeserializeInputFunction( module, mapType.valueType() ), new HashMap<>() ); } - private T deserializeValueComposite( ValueType valueType, InputType input ) + private T deserializeValueComposite( ModuleDescriptor module, ValueType valueType, InputType input ) throws Exception { - InputNodeType inputNode = readObjectTree( input ); + InputNodeType inputNode = readObjectTree( module, input ); if( inputNode == null ) { return null; } - return deserializeNodeValueComposite( valueType, inputNode ); + return deserializeNodeValueComposite( module, valueType, inputNode ); } - private T deserializeNodeValueComposite( ValueType valueType, InputNodeType inputNode ) + private T deserializeNodeValueComposite( ModuleDescriptor module, ValueType valueType, InputNodeType inputNode ) throws Exception { ValueCompositeType valueCompositeType = (ValueCompositeType) valueType; Class valueBuilderType = valueCompositeType.types().findFirst().orElse( null ); String typeInfo = this.getObjectFieldValue( + module, inputNode, "_type", - this.buildDeserializeInputNodeFunction( new ValueType( String.class ) ) ); + this.buildDeserializeInputNodeFunction( module, new ValueType( String.class ) ) ); if( typeInfo != null ) { - ValueDescriptor valueDescriptor = valuesModule().valueDescriptor( typeInfo ); + ValueDescriptor valueDescriptor = module.valueDescriptor( typeInfo ); if( valueDescriptor == null ) { throw new ValueSerializationException( "Specified value type could not be resolved: " + typeInfo ); @@ -473,11 +425,12 @@ public abstract class ValueDeserializerAdapter valueCompositeType = valueDescriptor.valueType(); valueBuilderType = Class.forName( typeInfo ); } - return deserializeValueComposite( valueCompositeType, valueBuilderType, inputNode ); + return deserializeValueComposite( module, valueCompositeType, valueBuilderType, inputNode ); } @SuppressWarnings( "unchecked" ) - private T deserializeValueComposite( ValueCompositeType valueCompositeType, + private T deserializeValueComposite( ModuleDescriptor module, + ValueCompositeType valueCompositeType, Class valueBuilderType, InputNodeType inputNode ) @@ -492,12 +445,13 @@ public abstract class ValueDeserializerAdapter try { propertyName = property.qualifiedName().name(); - if( objectHasField( inputNode, propertyName ) ) + if( objectHasField( module, inputNode, propertyName ) ) { value = getObjectFieldValue( + module, inputNode, propertyName, - buildDeserializeInputNodeFunction( property.valueType() ) ); + buildDeserializeInputNodeFunction( module, property.valueType() ) ); if( property.isImmutable() ) { if( value instanceof Set ) @@ -517,7 +471,7 @@ public abstract class ValueDeserializerAdapter else { // Serialized object does not contain the field, try to default it - value = property.initialValue( valuesModule() ); + value = property.initialValue( module ); } } catch( Exception e ) @@ -532,12 +486,13 @@ public abstract class ValueDeserializerAdapter try { String associationName = association.qualifiedName().name(); - if( objectHasField( inputNode, associationName ) ) + if( objectHasField( module, inputNode, associationName ) ) { Object value = getObjectFieldValue( + module, inputNode, associationName, - buildDeserializeInputNodeFunction( new ValueType( EntityReference.class ) ) ); + buildDeserializeInputNodeFunction( module, new ValueType( EntityReference.class ) ) ); stateMap.put( associationName, value ); } } @@ -552,14 +507,17 @@ public abstract class ValueDeserializerAdapter try { String manyAssociationName = manyAssociation.qualifiedName().name(); - if( objectHasField( inputNode, manyAssociationName ) ) + if( objectHasField( module, inputNode, manyAssociationName ) ) { Object value = getObjectFieldValue( + module, inputNode, manyAssociationName, - buildDeserializeInputNodeFunction( new CollectionType( - Collection.class, - new ValueType( EntityReference.class ) ) ) ); + buildDeserializeInputNodeFunction( + module, + new CollectionType( + Collection.class, + new ValueType( EntityReference.class ) ) ) ); stateMap.put( manyAssociationName, value ); } } @@ -574,12 +532,13 @@ public abstract class ValueDeserializerAdapter try { String namedAssociationName = namedAssociation.qualifiedName().name(); - if( objectHasField( inputNode, namedAssociationName ) ) + if( objectHasField( module, inputNode, namedAssociationName ) ) { Object value = getObjectFieldValue( + module, inputNode, namedAssociationName, - buildDeserializeInputNodeFunction( MapType.of( String.class, EntityReference.class, Serialization.Variant.object ) ) ); + buildDeserializeInputNodeFunction( module, MapType.of( String.class, EntityReference.class, Serialization.Variant.object ) ) ); stateMap.put( namedAssociationName, value ); } } @@ -589,16 +548,16 @@ public abstract class ValueDeserializerAdapter } } ); - ValueBuilder valueBuilder = buildNewValueBuilderWithState( valueBuilderType, stateMap ); + ValueBuilder valueBuilder = buildNewValueBuilderWithState( module, valueBuilderType, stateMap ); return (T) valueBuilder.newInstance(); // Unchecked cast because the builder could use a type != T } - private Function buildDeserializeInputNodeFunction( final ValueType valueType ) + private Function buildDeserializeInputNodeFunction( ModuleDescriptor module, final ValueType valueType ) { return inputNode -> { try { - return doDeserializeInputNodeValue( valueType, inputNode ); + return doDeserializeInputNodeValue( module, valueType, inputNode ); } catch( ValueSerializationException ex ) { @@ -612,7 +571,7 @@ public abstract class ValueDeserializerAdapter } @SuppressWarnings( "unchecked" ) - private T doDeserializeInputNodeValue( ValueType valueType, InputNodeType inputNode ) + private T doDeserializeInputNodeValue( ModuleDescriptor module, ValueType valueType, InputNodeType inputNode ) throws Exception { if( inputNode == null ) @@ -623,7 +582,7 @@ public abstract class ValueDeserializerAdapter // Registered deserializers if( deserializers.get( type ) != null ) { - Object value = asSimpleValue( inputNode ); + Object value = asSimpleValue( module, inputNode ); if( value == null ) { return null; @@ -637,12 +596,12 @@ public abstract class ValueDeserializerAdapter else // Explicit ValueComposite if( ValueCompositeType.class.isAssignableFrom( valueType.getClass() ) ) { - return (T) deserializeNodeValueComposite( valueType, inputNode ); + return (T) deserializeNodeValueComposite( module, valueType, inputNode ); } else // Explicit Collections if( CollectionType.class.isAssignableFrom( valueType.getClass() ) ) { - return (T) deserializeNodeCollection( (CollectionType) valueType, inputNode ); + return (T) deserializeNodeCollection( module, (CollectionType) valueType, inputNode ); } else // Explicit Map if( MapType.class.isAssignableFrom( valueType.getClass() ) ) @@ -650,17 +609,17 @@ public abstract class ValueDeserializerAdapter MapType mapType = (MapType) valueType; if( mapType.variant().equals( Serialization.Variant.entry ) ) { - return (T) deserializeNodeEntryMap( (MapType) valueType, inputNode ); + return (T) deserializeNodeEntryMap( module, (MapType) valueType, inputNode ); } else { - return (T) deserializeNodeObjectMap( (MapType) valueType, inputNode ); + return (T) deserializeNodeObjectMap( module, (MapType) valueType, inputNode ); } } else // Enum if( EnumType.class.isAssignableFrom( valueType.getClass() ) || type.isEnum() ) { - Object value = asSimpleValue( inputNode ); + Object value = asSimpleValue( module, inputNode ); if( value == null ) { return null; @@ -668,12 +627,15 @@ public abstract class ValueDeserializerAdapter return (T) Enum.valueOf( (Class) type, value.toString() ); } // Guessed deserialization - return (T) deserializeNodeGuessed( valueType, inputNode ); + return (T) deserializeNodeGuessed( module, valueType, inputNode ); } - private ValueBuilder buildNewValueBuilderWithState( Class type, final Map stateMap ) + private ValueBuilder buildNewValueBuilderWithState( ModuleDescriptor module, + Class type, + final Map stateMap + ) { - return valuesModule().newValueBuilderWithState( + return module.instance().newValueBuilderWithState( type, property -> stateMap.get( property.qualifiedName().name() ), association -> { @@ -705,18 +667,21 @@ public abstract class ValueDeserializerAdapter } @SuppressWarnings( "unchecked" ) - private T deserializeGuessed( ValueType valueType, InputType input ) + private T deserializeGuessed( ModuleDescriptor module, ValueType valueType, InputType input ) throws Exception { - InputNodeType inputNode = readObjectTree( input ); + InputNodeType inputNode = readObjectTree( module, input ); if( inputNode == null ) { return null; } - return deserializeNodeGuessed( valueType, inputNode ); + return deserializeNodeGuessed( module, valueType, inputNode ); } - private Collection deserializeNodeCollection( CollectionType collectionType, InputNodeType inputNode ) + private Collection deserializeNodeCollection( ModuleDescriptor module, + CollectionType collectionType, + InputNodeType inputNode + ) throws Exception { Collection collection; @@ -729,48 +694,52 @@ public abstract class ValueDeserializerAdapter { collection = new ArrayList<>(); } - putArrayNodeInCollection( inputNode, - this.buildDeserializeInputNodeFunction( collectionType.collectedType() ), + putArrayNodeInCollection( module, + inputNode, + this.buildDeserializeInputNodeFunction( module, collectionType.collectedType() ), collection ); return collection; } - private Map deserializeNodeEntryMap( MapType mapType, InputNodeType inputNode ) + private Map deserializeNodeEntryMap( ModuleDescriptor module, MapType mapType, InputNodeType inputNode ) throws Exception { Map map = new HashMap<>(); - putArrayNodeInMap( inputNode, - this.buildDeserializeInputNodeFunction( mapType.keyType() ), - this.buildDeserializeInputNodeFunction( mapType.valueType() ), + putArrayNodeInMap( module, + inputNode, + this.buildDeserializeInputNodeFunction( module, mapType.keyType() ), + this.buildDeserializeInputNodeFunction( module, mapType.valueType() ), map ); return map; } - private Map deserializeNodeObjectMap( MapType mapType, InputNodeType inputNode ) + private Map deserializeNodeObjectMap( ModuleDescriptor module, MapType mapType, InputNodeType inputNode ) throws Exception { Map map = new HashMap<>(); - putObjectNodeInMap( inputNode, - this.buildDeserializeInputNodeFunction( mapType.valueType() ), + putObjectNodeInMap( module, + inputNode, + this.buildDeserializeInputNodeFunction( module, mapType.valueType() ), map ); return map; } @SuppressWarnings( "unchecked" ) - private T deserializeNodeGuessed( ValueType valueType, InputNodeType inputNode ) + private T deserializeNodeGuessed( ModuleDescriptor module, ValueType valueType, InputNodeType inputNode ) throws Exception { - if( isObjectValue( inputNode ) ) + if( isObjectValue( module, inputNode ) ) { // Attempt ValueComposite deserialization ValueCompositeType valueCompositeType; - if( objectHasField( inputNode, "_type" ) ) // with _type info + if( objectHasField( module, inputNode, "_type" ) ) // with _type info { String typeInfo = this.getObjectFieldValue( + module, inputNode, "_type", - this.buildDeserializeInputNodeFunction( new ValueType( String.class ) ) ); - ValueDescriptor valueDescriptor = valuesModule().valueDescriptor( typeInfo ); + this.buildDeserializeInputNodeFunction( module, new ValueType( String.class ) ) ); + ValueDescriptor valueDescriptor = module.valueDescriptor( typeInfo ); if( valueDescriptor == null ) { throw new ValueSerializationException( "Specified value type could not be resolved: " + typeInfo ); @@ -779,10 +748,10 @@ public abstract class ValueDeserializerAdapter } else // without _type info { - ValueDescriptor valueDescriptor = valuesModule().valueDescriptor( valueType.types() - .findFirst() - .get() - .getName() ); + ValueDescriptor valueDescriptor = module.valueDescriptor( valueType.types() + .findFirst() + .get() + .getName() ); if( valueDescriptor == null ) { throw new ValueSerializationException( "Don't know how to deserialize " + inputNode ); @@ -790,27 +759,27 @@ public abstract class ValueDeserializerAdapter valueCompositeType = valueDescriptor.valueType(); } Class valueBuilderType = valueCompositeType.types().findFirst().orElse( null ); - return deserializeValueComposite( valueCompositeType, valueBuilderType, inputNode ); + return deserializeValueComposite( module, valueCompositeType, valueBuilderType, inputNode ); } // Last resort : base64 java deserialization - return (T) deserializeBase64Serialized( inputNode ); + return (T) deserializeBase64Serialized( module, inputNode ); } @SuppressWarnings( "unchecked" ) - private T deserializeBase64Serialized( InputNodeType inputNode ) + private T deserializeBase64Serialized( ModuleDescriptor module, InputNodeType inputNode ) throws Exception { - Object value = asSimpleValue( inputNode ); + Object value = asSimpleValue( module, inputNode ); if( value == null ) { return null; } String base64 = value.toString(); - return deserializeBase64Serialized( base64 ); + return deserializeBase64Serialized( module, base64 ); } @SuppressWarnings( "unchecked" ) - private T deserializeBase64Serialized( String inputString ) + private T deserializeBase64Serialized( ModuleDescriptor module, String inputString ) throws Exception { byte[] bytes = inputString.getBytes( UTF_8 ); @@ -828,7 +797,7 @@ public abstract class ValueDeserializerAdapter // /** - * Called by the adapter on deserialization start, after {@link #adaptInput(java.io.InputStream)}. + * Called by the adapter on deserialization start, after {@link #adaptInput(ModuleDescriptor, java.io.InputStream)}. * * @param valueType ValueType * @param input Input @@ -836,7 +805,7 @@ public abstract class ValueDeserializerAdapter * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ @SuppressWarnings( "UnusedParameters" ) - protected void onDeserializationStart( ValueType valueType, InputType input ) + protected void onDeserializationStart( ModuleDescriptor module, ValueType valueType, InputType input ) throws Exception { // NOOP @@ -850,7 +819,7 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected void onDeserializationEnd( ValueType valueType, InputType input ) + protected void onDeserializationEnd( ModuleDescriptor module, ValueType valueType, InputType input ) throws Exception { // NOOP @@ -869,7 +838,7 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected abstract InputType adaptInput( InputStream input ) + protected abstract InputType adaptInput( ModuleDescriptor module, InputStream input ) throws Exception; /** @@ -879,7 +848,7 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected abstract Object readPlainValue( InputType input ) + protected abstract Object readPlainValue( ModuleDescriptor module, InputType input ) throws Exception; /** @@ -892,7 +861,8 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected abstract Collection readArrayInCollection( InputType input, + protected abstract Collection readArrayInCollection( ModuleDescriptor module, + InputType input, Function deserializer, Collection collection ) @@ -926,7 +896,8 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected abstract Map readMapInMap( InputType input, + protected abstract Map readMapInMap( ModuleDescriptor module, + InputType input, Function keyDeserializer, Function valueDeserializer, Map map @@ -940,19 +911,19 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected abstract InputNodeType readObjectTree( InputType input ) + protected abstract InputNodeType readObjectTree( ModuleDescriptor module, InputType input ) throws Exception; // // Tree Parsing Deserialization // - protected abstract Object asSimpleValue( InputNodeType inputNode ) + protected abstract Object asSimpleValue( ModuleDescriptor module, InputNodeType inputNode ) throws Exception; - protected abstract boolean isObjectValue( InputNodeType inputNode ) + protected abstract boolean isObjectValue( ModuleDescriptor module, InputNodeType inputNode ) throws Exception; - protected abstract boolean objectHasField( InputNodeType inputNode, String key ) + protected abstract boolean objectHasField( ModuleDescriptor module, InputNodeType inputNode, String key ) throws Exception; /** @@ -967,26 +938,30 @@ public abstract class ValueDeserializerAdapter * * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ - protected abstract T getObjectFieldValue( InputNodeType inputNode, + protected abstract T getObjectFieldValue( ModuleDescriptor module, + InputNodeType inputNode, String key, Function valueDeserializer ) throws Exception; - protected abstract void putArrayNodeInCollection( InputNodeType inputNode, + protected abstract void putArrayNodeInCollection( ModuleDescriptor module, + InputNodeType inputNode, Function deserializer, Collection collection ) throws Exception; - protected abstract void putArrayNodeInMap( InputNodeType inputNode, + protected abstract void putArrayNodeInMap( ModuleDescriptor module, + InputNodeType inputNode, Function keyDeserializer, Function valueDeserializer, Map map ) throws Exception; - protected abstract void putObjectNodeInMap( InputNodeType inputNode, + protected abstract void putObjectNodeInMap( ModuleDescriptor module, + InputNodeType inputNode, Function valueDeserializer, Map map ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java b/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java index 6dd152e..f74c5f4 100644 --- a/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java +++ b/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java @@ -23,17 +23,12 @@ import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.function.Function; +import org.apache.zest.api.structure.ModuleDescriptor; +import org.apache.zest.api.value.ValueSerializationException; +import org.apache.zest.spi.value.ValueDeserializerAdapter; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; -import org.apache.zest.api.injection.scope.Service; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.service.ServiceReference; -import org.apache.zest.api.structure.Application; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.value.ValueDeserializer; -import org.apache.zest.api.value.ValueSerializationException; -import org.apache.zest.spi.value.ValueDeserializerAdapter; /** * ValueDeserializer reading Values from JSON documents using org.json. @@ -42,31 +37,15 @@ public class OrgJsonValueDeserializer extends ValueDeserializerAdapter { - public OrgJsonValueDeserializer( - @Structure Application application, - @Structure Module module, - @Service ServiceReference serviceRef ) - { - super( application, module, serviceRef ); - } - - /* package */ OrgJsonValueDeserializer( - Application application, - Module module, - Function valuesModuleFinder ) - { - super( application, module, valuesModuleFinder ); - } - @Override - protected JSONTokener adaptInput( InputStream input ) + protected JSONTokener adaptInput( ModuleDescriptor module, InputStream input ) throws Exception { return new JSONTokener( new InputStreamReader( input, "UTF-8" ) ); } @Override - protected Object readPlainValue( JSONTokener input ) + protected Object readPlainValue( ModuleDescriptor module, JSONTokener input ) throws Exception { Object nextValue = input.nextValue(); @@ -75,18 +54,20 @@ public class OrgJsonValueDeserializer return null; } else // Object or Array - if( JSONObject.class.isAssignableFrom( nextValue.getClass() ) - || JSONArray.class.isAssignableFrom( nextValue.getClass() ) ) - { - throw new ValueSerializationException( "Asked for a Value but found an Object or an Array." ); - } + if( JSONObject.class.isAssignableFrom( nextValue.getClass() ) + || JSONArray.class.isAssignableFrom( nextValue.getClass() ) ) + { + throw new ValueSerializationException( "Asked for a Value but found an Object or an Array." ); + } return nextValue; } @Override - protected Collection readArrayInCollection( JSONTokener input, + protected Collection readArrayInCollection( ModuleDescriptor module, + JSONTokener input, Function deserializer, - Collection collection ) + Collection collection + ) throws Exception { char c = input.nextClean(); @@ -129,7 +110,7 @@ public class OrgJsonValueDeserializer return collection; } input.back(); - for( ;; ) + for(; ; ) { if( input.nextClean() == ',' ) { @@ -144,32 +125,34 @@ public class OrgJsonValueDeserializer c = input.nextClean(); switch( c ) { - case ';': - case ',': - if( input.nextClean() == ']' ) - { - return collection; - } - input.back(); - break; - case ']': - case ')': - if( q != c ) - { - throw input.syntaxError( "Expected a '" + Character.valueOf( q ) + "'" ); - } + case ';': + case ',': + if( input.nextClean() == ']' ) + { return collection; - default: - throw input.syntaxError( "Expected a ',' or ']'" ); + } + input.back(); + break; + case ']': + case ')': + if( q != c ) + { + throw input.syntaxError( "Expected a '" + Character.valueOf( q ) + "'" ); + } + return collection; + default: + throw input.syntaxError( "Expected a ',' or ']'" ); } } } @Override - protected Map readMapInMap( JSONTokener input, + protected Map readMapInMap( ModuleDescriptor module, + JSONTokener input, Function keyDeserializer, Function valueDeserializer, - Map map ) + Map map + ) throws Exception { char c = input.nextClean(); @@ -213,7 +196,7 @@ public class OrgJsonValueDeserializer } input.back(); - for( ;; ) + for(; ; ) { if( input.nextClean() == ',' ) { @@ -238,14 +221,14 @@ public class OrgJsonValueDeserializer c = input.nextClean(); switch( c ) { - case 0: - throw input.syntaxError( "A JSONObject text must end with '}'" ); - case '}': - breakIteration = true; - continue; - default: - input.back(); - objectKey = input.nextValue().toString(); + case 0: + throw input.syntaxError( "A JSONObject text must end with '}'" ); + case '}': + breakIteration = true; + continue; + default: + input.back(); + objectKey = input.nextValue().toString(); } /* @@ -282,20 +265,20 @@ public class OrgJsonValueDeserializer */ switch( input.nextClean() ) { - case ';': - case ',': - if( input.nextClean() == '}' ) - { - breakIteration = true; - continue; - } - input.back(); - continue; - case '}': + case ';': + case ',': + if( input.nextClean() == '}' ) + { breakIteration = true; continue; - default: - throw input.syntaxError( "Expected a ',' or '}'" ); + } + input.back(); + continue; + case '}': + breakIteration = true; + continue; + default: + throw input.syntaxError( "Expected a ',' or '}'" ); } } if( key != null ) @@ -306,23 +289,23 @@ public class OrgJsonValueDeserializer c = input.nextClean(); switch( c ) { - case ';': - case ',': - if( input.nextClean() == ']' ) - { - return map; - } - input.back(); - break; - case ']': - case ')': - if( q != c ) - { - throw input.syntaxError( "Expected a '" + Character.valueOf( q ) + "'" ); - } + case ';': + case ',': + if( input.nextClean() == ']' ) + { return map; - default: - throw input.syntaxError( "Expected a ',' or ']'" ); + } + input.back(); + break; + case ']': + case ')': + if( q != c ) + { + throw input.syntaxError( "Expected a '" + Character.valueOf( q ) + "'" ); + } + return map; + default: + throw input.syntaxError( "Expected a ',' or ']'" ); } } } @@ -331,7 +314,9 @@ public class OrgJsonValueDeserializer // Deserialization - Tree parsing // @Override - protected JSONObject readObjectTree( JSONTokener input ) + protected JSONObject readObjectTree( ModuleDescriptor module, + JSONTokener input + ) throws Exception { Object objectTree = input.nextValue(); @@ -343,7 +328,7 @@ public class OrgJsonValueDeserializer } @Override - protected Object asSimpleValue( Object inputNode ) + protected Object asSimpleValue( ModuleDescriptor module, Object inputNode ) throws Exception { if( JSONObject.NULL.equals( inputNode ) ) @@ -358,7 +343,7 @@ public class OrgJsonValueDeserializer } @Override - protected boolean isObjectValue( Object inputNode ) + protected boolean isObjectValue( ModuleDescriptor module, Object inputNode ) throws Exception { if( JSONObject.NULL.equals( inputNode ) ) @@ -369,7 +354,7 @@ public class OrgJsonValueDeserializer } @Override - protected boolean objectHasField( Object inputNode, String key ) + protected boolean objectHasField( ModuleDescriptor module, Object inputNode, String key ) throws Exception { if( JSONObject.NULL.equals( inputNode ) ) @@ -385,7 +370,11 @@ public class OrgJsonValueDeserializer } @Override - protected T getObjectFieldValue( Object inputNode, String key, Function valueDeserializer ) + protected T getObjectFieldValue( ModuleDescriptor module, + Object inputNode, + String key, + Function valueDeserializer + ) throws Exception { JSONObject json = (JSONObject) inputNode; @@ -399,7 +388,11 @@ public class OrgJsonValueDeserializer } @Override - protected void putArrayNodeInCollection( Object inputNode, Function deserializer, Collection collection ) + protected void putArrayNodeInCollection( ModuleDescriptor module, + Object inputNode, + Function deserializer, + Collection collection + ) throws Exception { if( JSONObject.NULL.equals( inputNode ) ) @@ -420,7 +413,12 @@ public class OrgJsonValueDeserializer } @Override - protected void putArrayNodeInMap( Object inputNode, Function keyDeserializer, Function valueDeserializer, Map map ) + protected void putArrayNodeInMap( ModuleDescriptor module, + Object inputNode, + Function keyDeserializer, + Function valueDeserializer, + Map map + ) throws Exception { if( JSONObject.NULL.equals( inputNode ) ) @@ -452,7 +450,11 @@ public class OrgJsonValueDeserializer } @Override - protected void putObjectNodeInMap( Object inputNode, Function valueDeserializer, Map map ) + protected void putObjectNodeInMap( ModuleDescriptor module, + Object inputNode, + Function valueDeserializer, + Map map + ) throws Exception { if( JSONObject.NULL.equals( inputNode ) ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueSerialization.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueSerialization.java b/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueSerialization.java deleted file mode 100644 index 9ce1892..0000000 --- a/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueSerialization.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2012, Paul Merlin. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.zest.valueserialization.orgjson; - -import java.io.InputStream; -import java.io.OutputStream; -import java.util.function.BiFunction; -import java.util.function.Function; -import org.apache.zest.api.structure.Application; -import org.apache.zest.api.structure.Module; -import org.apache.zest.api.type.ValueType; -import org.apache.zest.api.value.ValueSerialization; -import org.apache.zest.api.value.ValueSerializationException; - -/** - * ValueSerialization producing and consuming JSON documents using org.json. - * - *

- * This class is used internally by the Zest Runtime to provide default ValueSerialization when no - * ValueSerialization Service is available. - *

- *

- * In application code, prefer the use of {@link OrgJsonValueSerializationService}. - *

- */ -public class OrgJsonValueSerialization - implements ValueSerialization -{ - - private final OrgJsonValueSerializer serializer; - private final OrgJsonValueDeserializer deserializer; - - public OrgJsonValueSerialization( Application application, Module module, final Module valuesModule ) - { - this.serializer = new OrgJsonValueSerializer(); - this.deserializer = new OrgJsonValueDeserializer( application, module, from -> valuesModule ); - } - - @Override - public Function serialize() - { - return serializer.serialize(); - } - - @Override - public Function serialize( Options options ) - { - return serializer.serialize( options ); - } - - @Override - @Deprecated - public Function serialize( boolean includeTypeInfo ) - { - return serializer.serialize( includeTypeInfo ); - } - - @Override - public String serialize( Object object ) - throws ValueSerializationException - { - return serializer.serialize( object ); - } - - @Override - public String serialize( Options options, Object object ) - throws ValueSerializationException - { - return serializer.serialize( options, object ); - } - - @Override - @Deprecated - public String serialize( Object object, boolean includeTypeInfo ) - throws ValueSerializationException - { - return serializer.serialize( object, includeTypeInfo ); - } - - @Override - public void serialize( Object object, OutputStream output ) - throws ValueSerializationException - { - serializer.serialize( object, output ); - } - - @Override - public void serialize( Options options, Object object, OutputStream output ) - throws ValueSerializationException - { - serializer.serialize( options, object, output ); - } - - @Override - @Deprecated - public void serialize( Object object, OutputStream output, boolean includeTypeInfo ) - throws ValueSerializationException - { - serializer.serialize( object, output, includeTypeInfo ); - } - - @Override - public Function deserialize( Class type ) - { - return deserializer.deserialize( type ); - } - - @Override - public Function deserialize( ValueType valueType ) - { - return deserializer.deserialize( valueType ); - } - - @Override - public BiFunction deserialize() - { - return deserializer.deserialize(); - } - - @Override - public T deserialize( Class type, String input ) - throws ValueSerializationException - { - return deserializer.deserialize( type, input ); - } - - @Override - public T deserialize( ValueType type, String input ) - throws ValueSerializationException - { - return deserializer.deserialize( type, input ); - } - - @Override - public T deserialize( Class type, InputStream input ) - throws ValueSerializationException - { - return deserializer.deserialize( new ValueType( type ), input ); - } - - @Override - public T deserialize( ValueType type, InputStream input ) - throws ValueSerializationException - { - return deserializer.deserialize( type, input ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/spi/src/test/java/org/apache/zest/spi/entitystore/helpers/JSONManyAssociationStateTest.java ---------------------------------------------------------------------- diff --git a/core/spi/src/test/java/org/apache/zest/spi/entitystore/helpers/JSONManyAssociationStateTest.java b/core/spi/src/test/java/org/apache/zest/spi/entitystore/helpers/JSONManyAssociationStateTest.java index 4d7dec3..1cbce1d 100644 --- a/core/spi/src/test/java/org/apache/zest/spi/entitystore/helpers/JSONManyAssociationStateTest.java +++ b/core/spi/src/test/java/org/apache/zest/spi/entitystore/helpers/JSONManyAssociationStateTest.java @@ -45,6 +45,7 @@ public class JSONManyAssociationStateTest state.put( JSONKeys.MANY_ASSOCIATIONS, new JSONObject() ); state.put( JSONKeys.NAMED_ASSOCIATIONS, new JSONObject() ); JSONEntityState entityState = new JSONEntityState( null, + null, "0", System.currentTimeMillis(), EntityReference.parseEntityReference( "123" ), @@ -70,6 +71,7 @@ public class JSONManyAssociationStateTest state.put( JSONKeys.MANY_ASSOCIATIONS, new JSONObject() ); state.put( JSONKeys.NAMED_ASSOCIATIONS, new JSONObject() ); JSONEntityState entityState = new JSONEntityState( null, + null, "0", System.currentTimeMillis(), EntityReference.parseEntityReference( "123" ), http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java index 29c27aa..6254de9 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/AbstractZestTest.java @@ -14,18 +14,24 @@ package org.apache.zest.test; +import org.apache.zest.api.composite.TransientBuilderFactory; import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; -import org.junit.After; -import org.junit.Before; +import org.apache.zest.api.object.ObjectFactory; +import org.apache.zest.api.query.QueryBuilderFactory; +import org.apache.zest.api.service.ServiceFinder; +import org.apache.zest.api.structure.Module; +import org.apache.zest.api.structure.ModuleDescriptor; import org.apache.zest.api.unitofwork.UnitOfWork; +import org.apache.zest.api.unitofwork.UnitOfWorkFactory; +import org.apache.zest.api.value.ValueBuilderFactory; import org.apache.zest.bootstrap.ApplicationAssembly; import org.apache.zest.bootstrap.Assembler; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.LayerAssembly; import org.apache.zest.bootstrap.ModuleAssembly; -import org.apache.zest.spi.module.ModuleSpi; +import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; +import org.junit.After; +import org.junit.Before; /** * Base class for Composite tests. @@ -36,7 +42,23 @@ public abstract class AbstractZestTest extends AbstractZestBaseTest @Structure protected UnitOfWorkFactory uowf; - protected ModuleSpi module; + @Structure + protected TransientBuilderFactory transientBuilderFactory; + + @Structure + protected ValueBuilderFactory valueBuilderFactory; + + @Structure + protected ServiceFinder serviceFinder; + + @Structure + protected ObjectFactory objectFactory; + + @Structure + protected QueryBuilderFactory queryBuilderFactory; + + @Structure + protected ModuleDescriptor module; @Before @Override @@ -48,7 +70,7 @@ public abstract class AbstractZestTest extends AbstractZestBaseTest { return; // failure in Assembly. } - module = (ModuleSpi) application.findModule( "Layer 1", "Module 1" ); + Module module = application.findModule( "Layer 1", "Module 1" ); module.injectTo( this ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/cache/AbstractCachePoolTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/cache/AbstractCachePoolTest.java b/core/testsupport/src/main/java/org/apache/zest/test/cache/AbstractCachePoolTest.java index e697375..ebacb42 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/cache/AbstractCachePoolTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/cache/AbstractCachePoolTest.java @@ -45,7 +45,7 @@ public abstract class AbstractCachePoolTest throws Exception { super.setUp(); - cachePool = module.findService( CachePool.class ).get(); + cachePool = module.instance().findService( CachePool.class ).get(); cache = cachePool.fetchCache( "1", String.class ); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractConfigurationDeserializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractConfigurationDeserializationTest.java b/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractConfigurationDeserializationTest.java index 8712911..a6fff82 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractConfigurationDeserializationTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractConfigurationDeserializationTest.java @@ -45,6 +45,7 @@ public abstract class AbstractConfigurationDeserializationTest extends AbstractZ throws AssemblyException { // ModuleAssembly storageModule = module.layer().module( "storage" ); + @SuppressWarnings( "UnnecessaryLocalVariable" ) ModuleAssembly storageModule = module; // Disable the more complex set up. The entire value serialization has gotten the deserialization type lookup problem wrong. module.configurations( ConfigSerializationConfig.class ); module.values( Host.class ); @@ -57,7 +58,7 @@ public abstract class AbstractConfigurationDeserializationTest extends AbstractZ @Test public void givenServiceWhenInitializingExpectCorrectDeserialization() { - ServiceReference ref = module.findService( MyService.class ); + ServiceReference ref = module.instance().findService( MyService.class ); assertThat( ref, notNullValue() ); assertThat( ref.isAvailable(), equalTo( true ) ); MyService myService = ref.get(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java b/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java index de6956d..ad7a116 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java @@ -25,11 +25,12 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.zest.api.injection.scope.Structure; +import org.apache.zest.api.structure.Module; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.apache.zest.api.association.Association; import org.apache.zest.api.association.ManyAssociation; @@ -69,6 +70,9 @@ public abstract class AbstractEntityStoreTest @Service private EntityStore store; + @Structure + private Module moduleInstance; + @Override public void assemble( ModuleAssembly module ) throws AssemblyException @@ -79,12 +83,6 @@ public abstract class AbstractEntityStoreTest module.objects( getClass() ); } - @Before - public void init() - { - module.injectTo( this ); - } - @Override @After public void tearDown() @@ -115,23 +113,23 @@ public abstract class AbstractEntityStoreTest instance.localDateValue().set( new LocalDate( "2020-03-04" ) ); instance.association().set( instance ); - ValueBuilder valueBuilder4 = module.newValueBuilder( Tjabba.class ); + ValueBuilder valueBuilder4 = moduleInstance.newValueBuilder( Tjabba.class ); final Tjabba prototype4 = valueBuilder4.prototype(); prototype4.bling().set( "BlinkLjus" ); // Set value - ValueBuilder valueBuilder2 = module.newValueBuilder( TestValue2.class ); + ValueBuilder valueBuilder2 = moduleInstance.newValueBuilder( TestValue2.class ); TestValue2 prototype2 = valueBuilder2.prototype(); prototype2.stringValue().set( "Bar" ); Tjabba newValue = valueBuilder4.newInstance(); prototype2.anotherValue().set( newValue ); prototype2.anotherValue().set( newValue ); - ValueBuilder valueBuilder3 = module.newValueBuilder( Tjabba.class ); + ValueBuilder valueBuilder3 = moduleInstance.newValueBuilder( Tjabba.class ); final Tjabba prototype3 = valueBuilder3.prototype(); prototype3.bling().set( "Brakfis" ); - ValueBuilder valueBuilder1 = module.newValueBuilder( TestValue.class ); + ValueBuilder valueBuilder1 = moduleInstance.newValueBuilder( TestValue.class ); TestValue prototype = valueBuilder1.prototype(); prototype.enumProperty().set( TestEnum.VALUE3 ); prototype.listProperty().get().add( "Foo" ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractAnyQueryTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractAnyQueryTest.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractAnyQueryTest.java index e9c18b5..527b4bf 100755 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractAnyQueryTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractAnyQueryTest.java @@ -80,9 +80,9 @@ public class AbstractAnyQueryTest throws Exception { super.setUp(); - TestData.populate( module ); + TestData.populate( module.instance() ); - this.unitOfWork = this.module.unitOfWorkFactory().newUnitOfWork(); + this.unitOfWork = this.module.instance().unitOfWorkFactory().newUnitOfWork(); } http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractComplexQueryTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractComplexQueryTest.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractComplexQueryTest.java index 4698753..d9704ce 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractComplexQueryTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractComplexQueryTest.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.zest.api.injection.scope.Structure; +import org.apache.zest.api.structure.Module; import org.junit.Test; import org.apache.zest.api.property.Property; import org.apache.zest.api.query.Query; @@ -52,24 +54,28 @@ public abstract class AbstractComplexQueryTest private static final String JOE = "Joe Doe"; private static final String JACK = "Jack Doe"; + @Structure + Module moduleInstance; + + @Test public void showNetwork() throws IOException { - IndexExporter indexerExporter = module.findService( IndexExporter.class ).get(); + IndexExporter indexerExporter = moduleInstance.findService( IndexExporter.class ).get(); indexerExporter.exportReadableToStream( System.out ); } @Test public void script01() { - ValueBuilder
addressBuilder = this.module.newValueBuilder( Address.class ); + ValueBuilder
addressBuilder = this.moduleInstance.newValueBuilder( Address.class ); Address address = addressBuilder.prototype(); address.line1().set( "Qi Street 4j" ); address.line2().set( "Off main Java Street" ); address.zipcode().set( "12345" ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property
addressProp = templateFor( Person.class ).address(); qb = qb.where( eq( addressProp, addressBuilder.newInstance() ) ); Query query = unitOfWork.newQuery( qb ); @@ -81,13 +87,13 @@ public abstract class AbstractComplexQueryTest @Test public void script02() { - ValueBuilder
addressBuilder = this.module.newValueBuilder( Address.class ); + ValueBuilder
addressBuilder = this.moduleInstance.newValueBuilder( Address.class ); Address address = addressBuilder.prototype(); address.line1().set( "Qi Street 4j" ); address.line2().set( "Off main Java Street" ); address.zipcode().set( "12345" ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property
addressProp = templateFor( Person.class ).address(); qb = qb.where( not( eq( addressProp, addressBuilder.newInstance() ) ) ); Query query = unitOfWork.newQuery( qb ); @@ -99,20 +105,20 @@ public abstract class AbstractComplexQueryTest @Test public void script03() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); List queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( eq( paramsProp, queryParams ) ); Query query = unitOfWork.newQuery( qb ); @@ -124,7 +130,7 @@ public abstract class AbstractComplexQueryTest @Test public void script04() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); List queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); // Different order @@ -132,13 +138,13 @@ public abstract class AbstractComplexQueryTest param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( eq( paramsProp, queryParams ) ); Query query = unitOfWork.newQuery( qb ); @@ -150,20 +156,20 @@ public abstract class AbstractComplexQueryTest @Test public void script05() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); List queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( not( eq( paramsProp, queryParams ) ) ); Query query = unitOfWork.newQuery( qb ); @@ -175,9 +181,9 @@ public abstract class AbstractComplexQueryTest @Test public void script06() { - ValueBuilder urlBuilder = this.module.newValueBuilder( URL.class ); - ValueBuilder protocolBuilder = this.module.newValueBuilder( Protocol.class ); - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder urlBuilder = this.moduleInstance.newValueBuilder( URL.class ); + ValueBuilder protocolBuilder = this.moduleInstance.newValueBuilder( Protocol.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); Protocol protocol = protocolBuilder.prototype(); protocol.value().set( "http" ); @@ -188,7 +194,7 @@ public abstract class AbstractComplexQueryTest param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); @@ -198,7 +204,7 @@ public abstract class AbstractComplexQueryTest url.protocol().set( protocolBuilder.newInstance() ); url.queryParams().set( queryParams ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property websiteProp = templateFor( Person.class ).personalWebsite(); qb = qb.where( eq( websiteProp, urlBuilder.newInstance() ) ); Query query = unitOfWork.newQuery( qb ); @@ -210,9 +216,9 @@ public abstract class AbstractComplexQueryTest @Test public void script07() { - ValueBuilder urlBuilder = this.module.newValueBuilder( URL.class ); - ValueBuilder protocolBuilder = this.module.newValueBuilder( Protocol.class ); - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder urlBuilder = this.moduleInstance.newValueBuilder( URL.class ); + ValueBuilder protocolBuilder = this.moduleInstance.newValueBuilder( Protocol.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); Protocol protocol = protocolBuilder.prototype(); protocol.value().set( "http" ); @@ -223,7 +229,7 @@ public abstract class AbstractComplexQueryTest param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); @@ -233,7 +239,7 @@ public abstract class AbstractComplexQueryTest url.protocol().set( protocolBuilder.newInstance() ); url.queryParams().set( queryParams ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property websiteProp = templateFor( Person.class ).personalWebsite(); qb = qb.where( not( eq( websiteProp, urlBuilder.newInstance() ) ) ); Query query = unitOfWork.newQuery( qb ); @@ -245,12 +251,12 @@ public abstract class AbstractComplexQueryTest @Test public void script08() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( contains( paramsProp, queryParamBuilder.newInstance() ) ); Query query = unitOfWork.newQuery( qb ); @@ -261,13 +267,13 @@ public abstract class AbstractComplexQueryTest @Test public void script09() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); QueryParam param = queryParamBuilder.prototype(); param.name().set( "user" ); param.value().set( "jackdoe" ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( not( contains( paramsProp, queryParamBuilder.newInstance() ) ) ); Query query = unitOfWork.newQuery( qb ); @@ -278,7 +284,7 @@ public abstract class AbstractComplexQueryTest @Test public void script10() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); List queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); @@ -286,13 +292,13 @@ public abstract class AbstractComplexQueryTest param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( containsAll( paramsProp, queryParams ) ); Query query = unitOfWork.newQuery( qb ); @@ -303,7 +309,7 @@ public abstract class AbstractComplexQueryTest @Test public void script11() { - ValueBuilder queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + ValueBuilder queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); List queryParams = new ArrayList<>( 2 ); QueryParam param = queryParamBuilder.prototype(); @@ -311,13 +317,13 @@ public abstract class AbstractComplexQueryTest param.value().set( "jackdoe" ); queryParams.add( queryParamBuilder.newInstance() ); - queryParamBuilder = this.module.newValueBuilder( QueryParam.class ); + queryParamBuilder = this.moduleInstance.newValueBuilder( QueryParam.class ); param = queryParamBuilder.prototype(); param.name().set( "password" ); param.value().set( "somepassword" ); queryParams.add( queryParamBuilder.newInstance() ); - QueryBuilder qb = this.module.newQueryBuilder( Person.class ); + QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Property> paramsProp = templateFor( Person.class ).personalWebsite().get().queryParams(); qb = qb.where( not( containsAll( paramsProp, queryParams ) ) ); Query query = unitOfWork.newQuery( qb ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/dedb068e/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractEntityFinderTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractEntityFinderTest.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractEntityFinderTest.java index f02c0f9..1c5a4c0 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractEntityFinderTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractEntityFinderTest.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Predicate; +import org.apache.zest.api.injection.scope.Structure; +import org.apache.zest.api.structure.Module; import org.junit.Before; import org.junit.Test; import org.apache.zest.api.composite.Composite; @@ -81,6 +83,10 @@ public abstract class AbstractEntityFinderTest private static final String ANN = "Ann Doe"; + @Structure + Module moduleInstance; + + private EntityFinder entityFinder; @Before @@ -89,14 +95,14 @@ public abstract class AbstractEntityFinderTest throws Exception { super.setUp(); - entityFinder = this.module.findService( EntityFinder.class ).get(); + entityFinder = this.moduleInstance.findService( EntityFinder.class ).get(); } @Test public void showNetwork() throws IOException { - final ServiceReference indexerService = this.module.findService( IndexExporter.class ); + final ServiceReference indexerService = this.moduleInstance.findService( IndexExporter.class ); final IndexExporter exporter = indexerService.get(); exporter.exportReadableToStream( System.out ); // todo asserts