polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [36/48] polygene-java git commit: Favor Initializable over ServiceActivation
Date Mon, 13 Mar 2017 15:28:59 GMT
Favor Initializable over ServiceActivation

POLYGENE-231


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/37792b2f
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/37792b2f
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/37792b2f

Branch: refs/heads/serialization-3.0
Commit: 37792b2fbdfc429750dfb15b09ec6ecaf859161d
Parents: 0e089cf
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Mar 13 15:04:55 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Mar 13 16:27:47 2017 +0100

----------------------------------------------------------------------
 .../DefaultSerializationAssembler.java          |   4 +-
 .../javaxjson/JavaxJsonAdapters.java            | 296 +++++++++++++++-
 .../JavaxJsonSerializationService.java          | 347 -------------------
 .../JavaxJsonSerializationAssembler.java        |   2 +-
 .../javaxxml/JavaxXmlAdapters.java              | 165 ++++++++-
 .../JavaxXmlSerializationAssembler.java         |   2 +-
 .../javaxxml/JavaxXmlSerializationService.java  | 214 ------------
 .../javaxxml/JavaxXmlAdaptersTest.java          |   2 +-
 .../msgpack/MessagePackAdapters.java            | 207 ++++++++++-
 .../MessagePackSerializationAssembler.java      |   2 +-
 .../MessagePackSerializationService.java        | 256 --------------
 11 files changed, 671 insertions(+), 826 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java
----------------------------------------------------------------------
diff --git a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java
index a4bcc0c..4a6f4b8 100644
--- a/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java
+++ b/core/bootstrap/src/main/java/org/apache/polygene/bootstrap/serialization/DefaultSerializationAssembler.java
@@ -23,7 +23,7 @@ import org.apache.polygene.api.serialization.Serializer;
 import org.apache.polygene.bootstrap.Assembler;
 import org.apache.polygene.bootstrap.AssemblyException;
 import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.serialization.javaxjson.JavaxJsonSerializationService;
+import org.apache.polygene.serialization.javaxjson.JavaxJsonSerialization;
 import org.apache.polygene.spi.serialization.JsonDeserializer;
 import org.apache.polygene.spi.serialization.JsonSerialization;
 import org.apache.polygene.spi.serialization.JsonSerializer;
@@ -34,7 +34,7 @@ public class DefaultSerializationAssembler
     @Override
     public void assemble( ModuleAssembly module ) throws AssemblyException
     {
-        module.services( JavaxJsonSerializationService.class )
+        module.services( JavaxJsonSerialization.class )
               .withTypes( Serialization.class, Serializer.class, Deserializer.class,
                           JsonSerialization.class, JsonSerializer.class, JsonDeserializer.class )
               .taggedWith( Serialization.Format.JSON );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapters.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapters.java b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapters.java
index a46accd..a6c7933 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapters.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonAdapters.java
@@ -19,10 +19,24 @@ package org.apache.polygene.serialization.javaxjson;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import javax.json.Json;
+import javax.json.JsonNumber;
+import javax.json.JsonString;
+import javax.json.JsonValue;
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.api.mixin.Initializable;
 import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.serialization.Converters;
+import org.apache.polygene.api.serialization.SerializationException;
+import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.serialization.BuiltInConverters;
 
 import static org.apache.polygene.api.type.HasTypesCollectors.closestType;
+import static org.apache.polygene.serialization.javaxjson.JavaxJsonSettings.orDefault;
 
 @Mixins( JavaxJsonAdapters.Mixin.class )
 public interface JavaxJsonAdapters
@@ -36,10 +50,30 @@ public interface JavaxJsonAdapters
         return adapterFor( ValueType.of( type ) );
     }
 
-    class Mixin implements JavaxJsonAdapters
+    class Mixin implements JavaxJsonAdapters, Initializable
     {
         private final Map<ValueType, JavaxJsonAdapter<?>> adapters = new LinkedHashMap<>();
 
+        @Uses
+        private ServiceDescriptor descriptor;
+
+        @This
+        private BuiltInConverters builtInConverters;
+
+        @This
+        private Converters converters;
+
+        @Override
+        public void initialize()
+        {
+            JavaxJsonSettings settings = orDefault( descriptor.metaInfo( JavaxJsonSettings.class ) );
+            settings.getConverters()
+                    .forEach( ( type, converter ) -> converters.registerConverter( type, converter ) );
+            builtInConverters.registerBuiltInConverters( converters );
+            settings.getAdapters().forEach( adapters::put );
+            registerBaseJavaxJsonAdapters();
+        }
+
         @Override
         public void registerAdapter( ValueType valueType, JavaxJsonAdapter<?> adapter )
         {
@@ -60,5 +94,265 @@ public interface JavaxJsonAdapters
         {
             return (JavaxJsonAdapter<T>) adapter;
         }
+
+        private void registerBaseJavaxJsonAdapters()
+        {
+            // Primitive Value types
+            adapters.put( ValueType.STRING, new StringAdapter() );
+            adapters.put( ValueType.CHARACTER, new CharacterAdapter() );
+            adapters.put( ValueType.BOOLEAN, new BooleanAdapter() );
+            adapters.put( ValueType.INTEGER, new IntegerAdapter() );
+            adapters.put( ValueType.LONG, new LongAdapter() );
+            adapters.put( ValueType.SHORT, new ShortAdapter() );
+            adapters.put( ValueType.BYTE, new ByteAdapter() );
+            adapters.put( ValueType.FLOAT, new FloatAdapter() );
+            adapters.put( ValueType.DOUBLE, new DoubleAdapter() );
+        }
+
+        private static abstract class ToJsonStringAdapter<T> implements JavaxJsonAdapter<T>
+        {
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return JavaxJson.toJsonString( object );
+            }
+        }
+
+        private static class StringAdapter extends ToJsonStringAdapter<String>
+        {
+            @Override
+            public Class<String> type() { return String.class; }
+
+            @Override
+            public String deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                return JavaxJson.asString( json );
+            }
+        }
+
+        private static class CharacterAdapter extends ToJsonStringAdapter<Character>
+        {
+            @Override
+            public Class<Character> type() { return Character.class; }
+
+            @Override
+            public Character deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                String string = JavaxJson.asString( json );
+                return string.isEmpty() ? null : string.charAt( 0 );
+            }
+        }
+
+        private static class BooleanAdapter implements JavaxJsonAdapter<Boolean>
+        {
+            @Override
+            public Class<Boolean> type() { return Boolean.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return type().cast( object ) ? JsonValue.TRUE : JsonValue.FALSE;
+            }
+
+            @Override
+            public Boolean deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case TRUE:
+                        return true;
+                    case FALSE:
+                        return false;
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return ( (JsonNumber) json ).doubleValue() > 0;
+                    case STRING:
+                        return Boolean.valueOf( ( (JsonString) json ).getString() );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Boolean from " + json );
+                }
+            }
+        }
+
+        private static class IntegerAdapter implements JavaxJsonAdapter<Integer>
+        {
+            @Override
+            public Class<Integer> type() { return Integer.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
+                           .getJsonNumber( "value" );
+            }
+
+            @Override
+            public Integer deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return ( (JsonNumber) json ).intValueExact();
+                    case STRING:
+                        String string = ( (JsonString) json ).getString();
+                        return string.isEmpty() ? 0 : Integer.parseInt( string );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Integer from " + json );
+                }
+            }
+        }
+
+        private static class LongAdapter implements JavaxJsonAdapter<Long>
+        {
+            @Override
+            public Class<Long> type() { return Long.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build().getJsonNumber(
+                    "value" );
+            }
+
+            @Override
+            public Long deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return ( (JsonNumber) json ).longValueExact();
+                    case STRING:
+                        String string = ( (JsonString) json ).getString();
+                        return string.isEmpty() ? 0L : Long.parseLong( string );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Long from " + json );
+                }
+            }
+        }
+
+        private static class ShortAdapter implements JavaxJsonAdapter<Short>
+        {
+            @Override
+            public Class<Short> type() { return Short.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
+                           .getJsonNumber( "value" );
+            }
+
+            @Override
+            public Short deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return (short) ( (JsonNumber) json ).intValueExact();
+                    case STRING:
+                        String string = ( (JsonString) json ).getString();
+                        return string.isEmpty() ? 0 : Short.parseShort( string );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Short from " + json );
+                }
+            }
+        }
+
+        private static class ByteAdapter implements JavaxJsonAdapter<Byte>
+        {
+            @Override
+            public Class<Byte> type() { return Byte.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
+                           .getJsonNumber( "value" );
+            }
+
+            @Override
+            public Byte deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return (byte) ( (JsonNumber) json ).intValueExact();
+                    case STRING:
+                        String string = ( (JsonString) json ).getString();
+                        return string.isEmpty() ? 0 : Byte.parseByte( string );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Byte from " + json );
+                }
+            }
+        }
+
+        private static class FloatAdapter implements JavaxJsonAdapter<Float>
+        {
+            @Override
+            public Class<Float> type() { return Float.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
+                           .getJsonNumber( "value" );
+            }
+
+            @Override
+            public Float deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return (float) ( (JsonNumber) json ).doubleValue();
+                    case STRING:
+                        String string = ( (JsonString) json ).getString();
+                        return string.isEmpty() ? 0F : Float.parseFloat( string );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Float from " + json );
+                }
+            }
+        }
+
+        private static class DoubleAdapter implements JavaxJsonAdapter<Double>
+        {
+            @Override
+            public Class<Double> type() { return Double.class; }
+
+            @Override
+            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
+            {
+                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
+                           .getJsonNumber( "value" );
+            }
+
+            @Override
+            public Double deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
+            {
+                switch( json.getValueType() )
+                {
+                    case NULL:
+                        return null;
+                    case NUMBER:
+                        return ( (JsonNumber) json ).doubleValue();
+                    case STRING:
+                        String string = ( (JsonString) json ).getString();
+                        return string.isEmpty() ? 0D : Double.parseDouble( string );
+                    default:
+                        throw new SerializationException( "Don't know how to deserialize Double from " + json );
+                }
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
deleted file mode 100644
index 1968b92..0000000
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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.polygene.serialization.javaxjson;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import javax.json.Json;
-import javax.json.JsonNumber;
-import javax.json.JsonString;
-import javax.json.JsonValue;
-import org.apache.polygene.api.injection.scope.This;
-import org.apache.polygene.api.injection.scope.Uses;
-import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.serialization.Converters;
-import org.apache.polygene.api.serialization.SerializationException;
-import org.apache.polygene.api.service.ServiceActivation;
-import org.apache.polygene.api.service.ServiceDescriptor;
-import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.spi.serialization.BuiltInConverters;
-
-// TODO Move into JavaxJsonSerialization
-// TODO Do the same on XML & MessagePack
-@Mixins( JavaxJsonSerializationService.Activation.class )
-public interface JavaxJsonSerializationService extends JavaxJsonSerialization, ServiceActivation
-{
-    class Activation implements ServiceActivation
-    {
-        @Uses
-        private ServiceDescriptor descriptor;
-
-        @This
-        private BuiltInConverters builtInConverters;
-
-        @This
-        private Converters converters;
-
-        @This
-        private JavaxJsonAdapters adapters;
-
-        private boolean registrationDone = false;
-
-        @Override
-        public void activateService()
-        {
-            if( !registrationDone )
-            {
-                applySettings();
-                registerBuiltInConverters();
-                registerBaseJavaxJsonAdapters();
-                registrationDone = true;
-            }
-        }
-
-        @Override
-        public void passivateService() {}
-
-        private void applySettings()
-        {
-            JavaxJsonSettings settings
-                = JavaxJsonSettings.orDefault( descriptor.metaInfo( JavaxJsonSettings.class ) );
-            settings.getConverters()
-                    .forEach( ( type, converter ) -> converters.registerConverter( type, converter ) );
-            settings.getAdapters()
-                    .forEach( ( type, adapter ) -> adapters.registerAdapter( type, adapter ) );
-        }
-
-        private void registerBuiltInConverters()
-        {
-            builtInConverters.registerBuiltInConverters( converters );
-        }
-
-        private void registerBaseJavaxJsonAdapters()
-        {
-            // Primitive Value types
-            adapters.registerAdapter( ValueType.STRING, new StringAdapter() );
-            adapters.registerAdapter( ValueType.CHARACTER, new CharacterAdapter() );
-            adapters.registerAdapter( ValueType.BOOLEAN, new BooleanAdapter() );
-            adapters.registerAdapter( ValueType.INTEGER, new IntegerAdapter() );
-            adapters.registerAdapter( ValueType.LONG, new LongAdapter() );
-            adapters.registerAdapter( ValueType.SHORT, new ShortAdapter() );
-            adapters.registerAdapter( ValueType.BYTE, new ByteAdapter() );
-            adapters.registerAdapter( ValueType.FLOAT, new FloatAdapter() );
-            adapters.registerAdapter( ValueType.DOUBLE, new DoubleAdapter() );
-        }
-
-        private static abstract class ToJsonStringAdapter<T> implements JavaxJsonAdapter<T>
-        {
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return JavaxJson.toJsonString( object );
-            }
-        }
-
-        private static class StringAdapter extends ToJsonStringAdapter<String>
-        {
-            @Override
-            public Class<String> type() { return String.class; }
-
-            @Override
-            public String deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                return JavaxJson.asString( json );
-            }
-        }
-
-        private static class CharacterAdapter extends ToJsonStringAdapter<Character>
-        {
-            @Override
-            public Class<Character> type() { return Character.class; }
-
-            @Override
-            public Character deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                String string = JavaxJson.asString( json );
-                return string.isEmpty() ? null : string.charAt( 0 );
-            }
-        }
-
-        private static class BooleanAdapter implements JavaxJsonAdapter<Boolean>
-        {
-            @Override
-            public Class<Boolean> type() { return Boolean.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return type().cast( object ) ? JsonValue.TRUE : JsonValue.FALSE;
-            }
-
-            @Override
-            public Boolean deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case TRUE:
-                        return true;
-                    case FALSE:
-                        return false;
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return ( (JsonNumber) json ).doubleValue() > 0;
-                    case STRING:
-                        return Boolean.valueOf( ( (JsonString) json ).getString() );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Boolean from " + json );
-                }
-            }
-        }
-
-        private static class IntegerAdapter implements JavaxJsonAdapter<Integer>
-        {
-            @Override
-            public Class<Integer> type() { return Integer.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
-                           .getJsonNumber( "value" );
-            }
-
-            @Override
-            public Integer deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return ( (JsonNumber) json ).intValueExact();
-                    case STRING:
-                        String string = ( (JsonString) json ).getString();
-                        return string.isEmpty() ? 0 : Integer.parseInt( string );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Integer from " + json );
-                }
-            }
-        }
-
-        private static class LongAdapter implements JavaxJsonAdapter<Long>
-        {
-            @Override
-            public Class<Long> type() { return Long.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build().getJsonNumber(
-                    "value" );
-            }
-
-            @Override
-            public Long deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return ( (JsonNumber) json ).longValueExact();
-                    case STRING:
-                        String string = ( (JsonString) json ).getString();
-                        return string.isEmpty() ? 0L : Long.parseLong( string );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Long from " + json );
-                }
-            }
-        }
-
-        private static class ShortAdapter implements JavaxJsonAdapter<Short>
-        {
-            @Override
-            public Class<Short> type() { return Short.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
-                           .getJsonNumber( "value" );
-            }
-
-            @Override
-            public Short deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return (short) ( (JsonNumber) json ).intValueExact();
-                    case STRING:
-                        String string = ( (JsonString) json ).getString();
-                        return string.isEmpty() ? 0 : Short.parseShort( string );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Short from " + json );
-                }
-            }
-        }
-
-        private static class ByteAdapter implements JavaxJsonAdapter<Byte>
-        {
-            @Override
-            public Class<Byte> type() { return Byte.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
-                           .getJsonNumber( "value" );
-            }
-
-            @Override
-            public Byte deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return (byte) ( (JsonNumber) json ).intValueExact();
-                    case STRING:
-                        String string = ( (JsonString) json ).getString();
-                        return string.isEmpty() ? 0 : Byte.parseByte( string );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Byte from " + json );
-                }
-            }
-        }
-
-        private static class FloatAdapter implements JavaxJsonAdapter<Float>
-        {
-            @Override
-            public Class<Float> type() { return Float.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
-                           .getJsonNumber( "value" );
-            }
-
-            @Override
-            public Float deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return (float) ( (JsonNumber) json ).doubleValue();
-                    case STRING:
-                        String string = ( (JsonString) json ).getString();
-                        return string.isEmpty() ? 0F : Float.parseFloat( string );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Float from " + json );
-                }
-            }
-        }
-
-        private static class DoubleAdapter implements JavaxJsonAdapter<Double>
-        {
-            @Override
-            public Class<Double> type() { return Double.class; }
-
-            @Override
-            public JsonValue serialize( Object object, Function<Object, JsonValue> serialize )
-            {
-                return Json.createObjectBuilder().add( "value", type().cast( object ) ).build()
-                           .getJsonNumber( "value" );
-            }
-
-            @Override
-            public Double deserialize( JsonValue json, BiFunction<JsonValue, ValueType, Object> deserialize )
-            {
-                switch( json.getValueType() )
-                {
-                    case NULL:
-                        return null;
-                    case NUMBER:
-                        return ( (JsonNumber) json ).doubleValue();
-                    case STRING:
-                        String string = ( (JsonString) json ).getString();
-                        return string.isEmpty() ? 0D : Double.parseDouble( string );
-                    default:
-                        throw new SerializationException( "Don't know how to deserialize Double from " + json );
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-javaxjson/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxjson/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationAssembler.java b/extensions/serialization-javaxjson/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationAssembler.java
index 4a041dd..16e2029 100644
--- a/extensions/serialization-javaxjson/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationAssembler.java
+++ b/extensions/serialization-javaxjson/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationAssembler.java
@@ -40,7 +40,7 @@ public class JavaxJsonSerializationAssembler extends Assemblers.VisibilityIdenti
     @Override
     public void assemble( ModuleAssembly module )
     {
-        ServiceDeclaration declaration = module.services( JavaxJsonSerializationService.class )
+        ServiceDeclaration declaration = module.services( JavaxJsonSerialization.class )
                                                .withTypes( Serialization.class,
                                                            Serializer.class, Deserializer.class,
                                                            JsonSerialization.class,

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdapters.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdapters.java b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdapters.java
index 273789d..716be65 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdapters.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdapters.java
@@ -19,10 +19,21 @@ package org.apache.polygene.serialization.javaxxml;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.api.mixin.Initializable;
 import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.serialization.Converters;
+import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.serialization.BuiltInConverters;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
 
 import static org.apache.polygene.api.type.HasTypesCollectors.closestType;
+import static org.apache.polygene.serialization.javaxxml.JavaxXmlSettings.orDefault;
 
 @Mixins( JavaxXmlAdapters.Mixin.class )
 public interface JavaxXmlAdapters
@@ -36,10 +47,30 @@ public interface JavaxXmlAdapters
         return adapterFor( ValueType.of( type ) );
     }
 
-    class Mixin implements JavaxXmlAdapters
+    class Mixin implements JavaxXmlAdapters, Initializable
     {
         private Map<ValueType, JavaxXmlAdapter<?>> adapters = new LinkedHashMap<>();
 
+        @Uses
+        private ServiceDescriptor descriptor;
+
+        @This
+        private BuiltInConverters builtInConverters;
+
+        @This
+        private Converters converters;
+
+        @Override
+        public void initialize() throws Exception
+        {
+            JavaxXmlSettings settings = orDefault( descriptor.metaInfo( JavaxXmlSettings.class ) );
+            settings.getConverters()
+                    .forEach( ( type, converter ) -> converters.registerConverter( type, converter ) );
+            builtInConverters.registerBuiltInConverters( converters );
+            settings.getAdapters().forEach( adapters::put );
+            registerBaseJavaxXmlAdapters();
+        }
+
         @Override
         public void registerAdapter( final ValueType valueType, final JavaxXmlAdapter<?> adapter )
         {
@@ -60,5 +91,137 @@ public interface JavaxXmlAdapters
         {
             return (JavaxXmlAdapter<T>) adapter;
         }
+
+        private void registerBaseJavaxXmlAdapters()
+        {
+            // Primitive Value types
+            adapters.put( ValueType.STRING, new StringAdapter() );
+            adapters.put( ValueType.CHARACTER, new CharacterAdapter() );
+            adapters.put( ValueType.BOOLEAN, new BooleanAdapter() );
+            adapters.put( ValueType.INTEGER, new IntegerAdapter() );
+            adapters.put( ValueType.LONG, new LongAdapter() );
+            adapters.put( ValueType.SHORT, new ShortAdapter() );
+            adapters.put( ValueType.BYTE, new ByteAdapter() );
+            adapters.put( ValueType.FLOAT, new FloatAdapter() );
+            adapters.put( ValueType.DOUBLE, new DoubleAdapter() );
+        }
+
+        private static abstract class ToStringTextNodeAdapter<T> implements JavaxXmlAdapter<T>
+        {
+            @Override
+            public Node serialize( Document document, Object object, Function<Object, Node> serialize )
+            {
+                return document.createTextNode( object.toString() );
+            }
+        }
+
+        private static class StringAdapter extends ToStringTextNodeAdapter<String>
+        {
+            @Override
+            public Class<String> type() { return String.class; }
+
+            @Override
+            public String deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return node.getNodeValue();
+            }
+        }
+
+        private static class CharacterAdapter extends ToStringTextNodeAdapter<Character>
+        {
+            @Override
+            public Class<Character> type() { return Character.class; }
+
+            @Override
+            public Character deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                String string = node.getNodeValue();
+                return string.isEmpty() ? null : string.charAt( 0 );
+            }
+        }
+
+        private static class BooleanAdapter extends ToStringTextNodeAdapter<Boolean>
+        {
+            @Override
+            public Class<Boolean> type() { return Boolean.class; }
+
+            @Override
+            public Boolean deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Boolean.valueOf( node.getNodeValue() );
+            }
+        }
+
+        private static class IntegerAdapter extends ToStringTextNodeAdapter<Integer>
+        {
+            @Override
+            public Class<Integer> type() { return Integer.class; }
+
+            @Override
+            public Integer deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Integer.valueOf( node.getNodeValue() );
+            }
+        }
+
+        private static class LongAdapter extends ToStringTextNodeAdapter<Long>
+        {
+            @Override
+            public Class<Long> type() { return Long.class; }
+
+            @Override
+            public Long deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Long.valueOf( node.getNodeValue() );
+            }
+        }
+
+        private static class ShortAdapter extends ToStringTextNodeAdapter<Short>
+        {
+            @Override
+            public Class<Short> type() { return Short.class; }
+
+            @Override
+            public Short deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Short.valueOf( node.getNodeValue() );
+            }
+        }
+
+        private static class ByteAdapter extends ToStringTextNodeAdapter<Byte>
+        {
+            @Override
+            public Class<Byte> type() { return Byte.class; }
+
+            @Override
+            public Byte deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Byte.valueOf( node.getNodeValue() );
+            }
+        }
+
+        private static class FloatAdapter extends ToStringTextNodeAdapter<Float>
+        {
+            @Override
+            public Class<Float> type() { return Float.class; }
+
+            @Override
+            public Float deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Float.valueOf( node.getNodeValue() );
+            }
+        }
+
+        private static class DoubleAdapter extends ToStringTextNodeAdapter<Double>
+        {
+            @Override
+            public Class<Double> type() { return Double.class; }
+
+            @Override
+            public Double deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
+            {
+                return Double.valueOf( node.getNodeValue() );
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationAssembler.java b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationAssembler.java
index 63ed345..a543dce 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationAssembler.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationAssembler.java
@@ -40,7 +40,7 @@ public class JavaxXmlSerializationAssembler extends Assemblers.VisibilityIdentit
     @Override
     public void assemble( ModuleAssembly module )
     {
-        ServiceDeclaration declaration = module.services( JavaxXmlSerializationService.class )
+        ServiceDeclaration declaration = module.services( JavaxXmlSerialization.class )
                                                .withTypes( Serialization.class,
                                                            Serializer.class, Deserializer.class,
                                                            XmlSerialization.class,

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
deleted file mode 100644
index 4ff2e1c..0000000
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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.polygene.serialization.javaxxml;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import org.apache.polygene.api.injection.scope.This;
-import org.apache.polygene.api.injection.scope.Uses;
-import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.serialization.Converters;
-import org.apache.polygene.api.service.ServiceActivation;
-import org.apache.polygene.api.service.ServiceDescriptor;
-import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.spi.serialization.BuiltInConverters;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-@Mixins( JavaxXmlSerializationService.Activation.class )
-public interface JavaxXmlSerializationService extends JavaxXmlSerialization, ServiceActivation
-{
-    class Activation implements ServiceActivation
-    {
-        @Uses
-        private ServiceDescriptor descriptor;
-
-        @This
-        private BuiltInConverters builtInConverters;
-
-        @This
-        private Converters converters;
-
-        @This
-        private JavaxXmlAdapters adapters;
-
-        private boolean registrationDone = false;
-
-        @Override
-        public void activateService()
-        {
-            if( !registrationDone )
-            {
-                applySettings();
-                registerBuiltInConverters();
-                registerBaseJavaxXmlAdapters();
-                registrationDone = true;
-            }
-        }
-
-        @Override
-        public void passivateService() {}
-
-        private void applySettings()
-        {
-            JavaxXmlSettings settings
-                = JavaxXmlSettings.orDefault( descriptor.metaInfo( JavaxXmlSettings.class ) );
-            settings.getConverters()
-                    .forEach( ( type, converter ) -> converters.registerConverter( type, converter ) );
-            settings.getAdapters()
-                    .forEach( ( type, adapter ) -> adapters.registerAdapter( type, adapter ) );
-        }
-
-        private void registerBuiltInConverters()
-        {
-            builtInConverters.registerBuiltInConverters( converters );
-        }
-
-        private void registerBaseJavaxXmlAdapters()
-        {
-            // Primitive Value types
-            adapters.registerAdapter( ValueType.STRING, new StringAdapter() );
-            adapters.registerAdapter( ValueType.CHARACTER, new CharacterAdapter() );
-            adapters.registerAdapter( ValueType.BOOLEAN, new BooleanAdapter() );
-            adapters.registerAdapter( ValueType.INTEGER, new IntegerAdapter() );
-            adapters.registerAdapter( ValueType.LONG, new LongAdapter() );
-            adapters.registerAdapter( ValueType.SHORT, new ShortAdapter() );
-            adapters.registerAdapter( ValueType.BYTE, new ByteAdapter() );
-            adapters.registerAdapter( ValueType.FLOAT, new FloatAdapter() );
-            adapters.registerAdapter( ValueType.DOUBLE, new DoubleAdapter() );
-        }
-
-        private static abstract class ToStringTextNodeAdapter<T> implements JavaxXmlAdapter<T>
-        {
-            @Override
-            public Node serialize( Document document, Object object, Function<Object, Node> serialize )
-            {
-                return document.createTextNode( object.toString() );
-            }
-        }
-
-        private static class StringAdapter extends ToStringTextNodeAdapter<String>
-        {
-            @Override
-            public Class<String> type() { return String.class; }
-
-            @Override
-            public String deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return node.getNodeValue();
-            }
-        }
-
-        private static class CharacterAdapter extends ToStringTextNodeAdapter<Character>
-        {
-            @Override
-            public Class<Character> type() { return Character.class; }
-
-            @Override
-            public Character deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                String string = node.getNodeValue();
-                return string.isEmpty() ? null : string.charAt( 0 );
-            }
-        }
-
-        private static class BooleanAdapter extends ToStringTextNodeAdapter<Boolean>
-        {
-            @Override
-            public Class<Boolean> type() { return Boolean.class; }
-
-            @Override
-            public Boolean deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Boolean.valueOf( node.getNodeValue() );
-            }
-        }
-
-        private static class IntegerAdapter extends ToStringTextNodeAdapter<Integer>
-        {
-            @Override
-            public Class<Integer> type() { return Integer.class; }
-
-            @Override
-            public Integer deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Integer.valueOf( node.getNodeValue() );
-            }
-        }
-
-        private static class LongAdapter extends ToStringTextNodeAdapter<Long>
-        {
-            @Override
-            public Class<Long> type() { return Long.class; }
-
-            @Override
-            public Long deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Long.valueOf( node.getNodeValue() );
-            }
-        }
-
-        private static class ShortAdapter extends ToStringTextNodeAdapter<Short>
-        {
-            @Override
-            public Class<Short> type() { return Short.class; }
-
-            @Override
-            public Short deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Short.valueOf( node.getNodeValue() );
-            }
-        }
-
-        private static class ByteAdapter extends ToStringTextNodeAdapter<Byte>
-        {
-            @Override
-            public Class<Byte> type() { return Byte.class; }
-
-            @Override
-            public Byte deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Byte.valueOf( node.getNodeValue() );
-            }
-        }
-
-        private static class FloatAdapter extends ToStringTextNodeAdapter<Float>
-        {
-            @Override
-            public Class<Float> type() { return Float.class; }
-
-            @Override
-            public Float deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Float.valueOf( node.getNodeValue() );
-            }
-        }
-
-        private static class DoubleAdapter extends ToStringTextNodeAdapter<Double>
-        {
-            @Override
-            public Class<Double> type() { return Double.class; }
-
-            @Override
-            public Double deserialize( Node node, BiFunction<Node, ValueType, Object> deserialize )
-            {
-                return Double.valueOf( node.getNodeValue() );
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdaptersTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdaptersTest.java b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdaptersTest.java
index 16a2fb3..bf37395 100644
--- a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdaptersTest.java
+++ b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlAdaptersTest.java
@@ -18,7 +18,7 @@ public class JavaxXmlAdaptersTest extends AbstractPolygeneTest
     public void assemble( ModuleAssembly module )
     {
         new JavaxXmlSerializationAssembler().assemble( module );
-        module.services( JavaxXmlSerializationService.class )
+        module.services( JavaxXmlSerialization.class )
               .withTypes( JavaxXmlAdapters.class );
     }
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackAdapters.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackAdapters.java b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackAdapters.java
index 892b389..f87b9cd 100644
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackAdapters.java
+++ b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackAdapters.java
@@ -19,10 +19,21 @@ package org.apache.polygene.serialization.msgpack;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import org.apache.polygene.api.injection.scope.This;
+import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.api.mixin.Initializable;
 import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.serialization.Converters;
+import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.serialization.BuiltInConverters;
+import org.msgpack.value.Value;
+import org.msgpack.value.ValueFactory;
 
 import static org.apache.polygene.api.type.HasTypesCollectors.closestType;
+import static org.apache.polygene.serialization.msgpack.MessagePackSettings.orDefault;
 
 @Mixins( MessagePackAdapters.Mixin.class )
 public interface MessagePackAdapters
@@ -36,10 +47,30 @@ public interface MessagePackAdapters
         return adapterFor( ValueType.of( type ) );
     }
 
-    class Mixin implements MessagePackAdapters
+    class Mixin implements MessagePackAdapters, Initializable
     {
         private Map<ValueType, MessagePackAdapter<?>> adapters = new LinkedHashMap<>();
 
+        @Uses
+        private ServiceDescriptor descriptor;
+
+        @This
+        private BuiltInConverters builtInConverters;
+
+        @This
+        private Converters converters;
+
+        @Override
+        public void initialize()
+        {
+            MessagePackSettings settings = orDefault( descriptor.metaInfo( MessagePackSettings.class ) );
+            settings.getConverters()
+                    .forEach( ( type, converter ) -> converters.registerConverter( type, converter ) );
+            builtInConverters.registerBuiltInConverters( converters );
+            settings.getAdapters().forEach( adapters::put );
+            registerBaseMessagePackAdapters();
+        }
+
         @Override
         public void registerAdapter( ValueType valueType, MessagePackAdapter<?> adapter )
         {
@@ -60,5 +91,179 @@ public interface MessagePackAdapters
         {
             return (MessagePackAdapter<T>) adapter;
         }
+
+        private void registerBaseMessagePackAdapters()
+        {
+            // Primitive Value types
+            adapters.put( ValueType.STRING, new StringAdapter() );
+            adapters.put( ValueType.CHARACTER, new CharacterAdapter() );
+            adapters.put( ValueType.BOOLEAN, new BooleanAdapter() );
+            adapters.put( ValueType.INTEGER, new IntegerAdapter() );
+            adapters.put( ValueType.LONG, new LongAdapter() );
+            adapters.put( ValueType.SHORT, new ShortAdapter() );
+            adapters.put( ValueType.BYTE, new ByteAdapter() );
+            adapters.put( ValueType.FLOAT, new FloatAdapter() );
+            adapters.put( ValueType.DOUBLE, new DoubleAdapter() );
+        }
+
+        private static abstract class ToStringAdapter<T> implements MessagePackAdapter<T>
+        {
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newString( object.toString() );
+            }
+        }
+
+        private static class StringAdapter extends ToStringAdapter<String>
+        {
+            @Override
+            public Class<String> type() { return String.class; }
+
+            @Override
+            public String deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asStringValue().asString();
+            }
+        }
+
+        private static class CharacterAdapter extends ToStringAdapter<Character>
+        {
+            @Override
+            public Class<Character> type() { return Character.class; }
+
+            @Override
+            public Character deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                String string = value.asStringValue().asString();
+                return string.isEmpty() ? null : string.charAt( 0 );
+            }
+        }
+
+        private static class BooleanAdapter implements MessagePackAdapter<Boolean>
+        {
+            @Override
+            public Class<Boolean> type() { return Boolean.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newBoolean( (Boolean) object );
+            }
+
+            @Override
+            public Boolean deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asBooleanValue().getBoolean();
+            }
+        }
+
+        private static class IntegerAdapter implements MessagePackAdapter<Integer>
+        {
+            @Override
+            public Class<Integer> type() { return Integer.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newInteger( (Integer) object );
+            }
+
+            @Override
+            public Integer deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asIntegerValue().asInt();
+            }
+        }
+
+        private static class LongAdapter implements MessagePackAdapter<Long>
+        {
+            @Override
+            public Class<Long> type() { return Long.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newInteger( (Long) object );
+            }
+
+            @Override
+            public Long deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asIntegerValue().asLong();
+            }
+        }
+
+        private static class ShortAdapter implements MessagePackAdapter<Short>
+        {
+            @Override
+            public Class<Short> type() { return Short.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newInteger( (Short) object );
+            }
+
+            @Override
+            public Short deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asIntegerValue().asShort();
+            }
+        }
+
+        private static class ByteAdapter implements MessagePackAdapter<Byte>
+        {
+            @Override
+            public Class<Byte> type() { return Byte.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newInteger( (Byte) object );
+            }
+
+            @Override
+            public Byte deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asIntegerValue().asByte();
+            }
+        }
+
+        private static class FloatAdapter implements MessagePackAdapter<Float>
+        {
+            @Override
+            public Class<Float> type() { return Float.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newFloat( (Float) object );
+            }
+
+            @Override
+            public Float deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asFloatValue().toFloat();
+            }
+        }
+
+        private static class DoubleAdapter implements MessagePackAdapter<Double>
+        {
+            @Override
+            public Class<Double> type() { return Double.class; }
+
+            @Override
+            public Value serialize( Object object, Function<Object, Value> serialize )
+            {
+                return ValueFactory.newFloat( (Double) object );
+            }
+
+            @Override
+            public Double deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
+            {
+                return value.asFloatValue().toDouble();
+            }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationAssembler.java b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationAssembler.java
index 63536cc..1a576ce 100644
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationAssembler.java
+++ b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationAssembler.java
@@ -37,7 +37,7 @@ public class MessagePackSerializationAssembler extends Assemblers.VisibilityIden
     @Override
     public void assemble( ModuleAssembly module )
     {
-        ServiceDeclaration declaration = module.services( MessagePackSerializationService.class )
+        ServiceDeclaration declaration = module.services( MessagePackSerialization.class )
                                                .withTypes( Serialization.class, Serializer.class, Deserializer.class )
                                                .visibleIn( visibility() );
         if( hasIdentity() )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/37792b2f/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
deleted file mode 100644
index 43afb3e..0000000
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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.polygene.serialization.msgpack;
-
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import org.apache.polygene.api.injection.scope.This;
-import org.apache.polygene.api.injection.scope.Uses;
-import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.serialization.Converters;
-import org.apache.polygene.api.service.ServiceActivation;
-import org.apache.polygene.api.service.ServiceDescriptor;
-import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.spi.serialization.BuiltInConverters;
-import org.msgpack.value.Value;
-import org.msgpack.value.ValueFactory;
-
-@Mixins( MessagePackSerializationService.Activation.class )
-public interface MessagePackSerializationService extends MessagePackSerialization, ServiceActivation
-{
-    class Activation implements ServiceActivation
-    {
-        @Uses
-        private ServiceDescriptor descriptor;
-
-        @This
-        private BuiltInConverters builtInConverters;
-
-        @This
-        private Converters converters;
-
-        @This
-        private MessagePackAdapters adapters;
-
-        private boolean registrationDone = false;
-
-        @Override
-        public void activateService()
-        {
-            if( !registrationDone )
-            {
-                applySettings();
-                registerBuiltInConverters();
-                registerBaseMessagePackAdapters();
-                registrationDone = true;
-            }
-        }
-
-        @Override
-        public void passivateService() {}
-
-        private void applySettings()
-        {
-            MessagePackSettings settings
-                = MessagePackSettings.orDefault( descriptor.metaInfo( MessagePackSettings.class ) );
-            settings.getConverters()
-                    .forEach( ( type, converter ) -> converters.registerConverter( type, converter ) );
-            settings.getAdapters()
-                    .forEach( ( type, adapter ) -> adapters.registerAdapter( type, adapter ) );
-        }
-
-        private void registerBuiltInConverters()
-        {
-            builtInConverters.registerBuiltInConverters( converters );
-        }
-
-        private void registerBaseMessagePackAdapters()
-        {
-            // Primitive Value types
-            adapters.registerAdapter( ValueType.STRING, new StringAdapter() );
-            adapters.registerAdapter( ValueType.CHARACTER, new CharacterAdapter() );
-            adapters.registerAdapter( ValueType.BOOLEAN, new BooleanAdapter() );
-            adapters.registerAdapter( ValueType.INTEGER, new IntegerAdapter() );
-            adapters.registerAdapter( ValueType.LONG, new LongAdapter() );
-            adapters.registerAdapter( ValueType.SHORT, new ShortAdapter() );
-            adapters.registerAdapter( ValueType.BYTE, new ByteAdapter() );
-            adapters.registerAdapter( ValueType.FLOAT, new FloatAdapter() );
-            adapters.registerAdapter( ValueType.DOUBLE, new DoubleAdapter() );
-        }
-
-        private static abstract class ToStringAdapter<T> implements MessagePackAdapter<T>
-        {
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newString( object.toString() );
-            }
-        }
-
-        private static class StringAdapter extends ToStringAdapter<String>
-        {
-            @Override
-            public Class<String> type() { return String.class; }
-
-            @Override
-            public String deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asStringValue().asString();
-            }
-        }
-
-        private static class CharacterAdapter extends ToStringAdapter<Character>
-        {
-            @Override
-            public Class<Character> type() { return Character.class; }
-
-            @Override
-            public Character deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                String string = value.asStringValue().asString();
-                return string.isEmpty() ? null : string.charAt( 0 );
-            }
-        }
-
-        private static class BooleanAdapter implements MessagePackAdapter<Boolean>
-        {
-            @Override
-            public Class<Boolean> type() { return Boolean.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newBoolean( (Boolean) object );
-            }
-
-            @Override
-            public Boolean deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asBooleanValue().getBoolean();
-            }
-        }
-
-        private static class IntegerAdapter implements MessagePackAdapter<Integer>
-        {
-            @Override
-            public Class<Integer> type() { return Integer.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newInteger( (Integer) object );
-            }
-
-            @Override
-            public Integer deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asIntegerValue().asInt();
-            }
-        }
-
-        private static class LongAdapter implements MessagePackAdapter<Long>
-        {
-            @Override
-            public Class<Long> type() { return Long.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newInteger( (Long) object );
-            }
-
-            @Override
-            public Long deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asIntegerValue().asLong();
-            }
-        }
-
-        private static class ShortAdapter implements MessagePackAdapter<Short>
-        {
-            @Override
-            public Class<Short> type() { return Short.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newInteger( (Short) object );
-            }
-
-            @Override
-            public Short deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asIntegerValue().asShort();
-            }
-        }
-
-        private static class ByteAdapter implements MessagePackAdapter<Byte>
-        {
-            @Override
-            public Class<Byte> type() { return Byte.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newInteger( (Byte) object );
-            }
-
-            @Override
-            public Byte deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asIntegerValue().asByte();
-            }
-        }
-
-        private static class FloatAdapter implements MessagePackAdapter<Float>
-        {
-            @Override
-            public Class<Float> type() { return Float.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newFloat( (Float) object );
-            }
-
-            @Override
-            public Float deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asFloatValue().toFloat();
-            }
-        }
-
-        private static class DoubleAdapter implements MessagePackAdapter<Double>
-        {
-            @Override
-            public Class<Double> type() { return Double.class; }
-
-            @Override
-            public Value serialize( Object object, Function<Object, Value> serialize )
-            {
-                return ValueFactory.newFloat( (Double) object );
-            }
-
-            @Override
-            public Double deserialize( Value value, BiFunction<Value, ValueType, Object> deserialize )
-            {
-                return value.asFloatValue().toDouble();
-            }
-        }
-    }
-}


Mime
View raw message