private ClassBinder buildClassBinder()

in lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractSerializerDefinition.java [201:280]


    private <T> ClassBinder<T> buildClassBinder( final Class<T> clazz )
    {
        return new ClassBinder<T>()
        {

            @Override
            public AnnotatedBinder attributes()
            {
                return buildAnnotatedBinder( this, attributeAnnotation );
            }

            @Override
            public AnnotatedBinder attributes( Class<? extends Annotation> annotation )
            {
                return buildAnnotatedBinder( this, annotation );
            }

            @Override
            public Class<T> getType()
            {
                return clazz;
            }

            @Override
            @SuppressWarnings( "unchecked" )
            public void using( Class<?> clazz )
            {
                if ( Marshaller.class.isAssignableFrom( clazz ) )
                {
                    try
                    {
                        using( ( (Class<Marshaller>) clazz ).newInstance() );
                    }
                    catch ( Exception e )
                    {
                        throw new SerializerDefinitionException( "Marshaller class " + clazz.getCanonicalName()
                            + " could not be instantiated. Is there a standard (public) constructor?", e );
                    }
                }

            }

            @Override
            public void using( Marshaller marshaller )
            {
                if ( marshaller instanceof AbstractObjectMarshaller )
                {
                    marshallerContext.bindMarshaller( clazz,
                                                      new ObjenesisDelegatingMarshaller(
                                                                                         (AbstractObjectMarshaller) marshaller,
                                                                                         objectInstantiatorFactory ) );
                }
                else
                {
                    marshallerContext.bindMarshaller( clazz, marshaller );
                }
            }

            @Override
            public void using( TypeIntrospector typeIntrospector )
            {
                // TODO Auto-generated method stub

            }

            @Override
            public void attributes( AttributeBinder<?>... attributes )
            {
                for ( AttributeBinder<?> attribute : attributes )
                {
                    if ( attribute instanceof DefinedAttributeBinder )
                    {
                        DefinedAttributeBinder<?> binder = (DefinedAttributeBinder<?>) attribute;
                        binder.setDeclaringClass( getType() );
                        binder.build();
                    }
                }
            }
        };
    }