001    // Copyright 2011 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    // http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.kaptcha.services;
016    
017    import org.apache.tapestry5.internal.InternalConstants;
018    import org.apache.tapestry5.ioc.Configuration;
019    import org.apache.tapestry5.ioc.OrderedConfiguration;
020    import org.apache.tapestry5.ioc.Resource;
021    import org.apache.tapestry5.ioc.ServiceBinder;
022    import org.apache.tapestry5.ioc.annotations.Contribute;
023    import org.apache.tapestry5.ioc.annotations.Value;
024    import org.apache.tapestry5.kaptcha.internal.services.KaptchaDataTypeAnalyzer;
025    import org.apache.tapestry5.kaptcha.internal.services.KaptchaProducerImpl;
026    import org.apache.tapestry5.services.BeanBlockContribution;
027    import org.apache.tapestry5.services.BeanBlockSource;
028    import org.apache.tapestry5.services.ComponentClassResolver;
029    import org.apache.tapestry5.services.DataTypeAnalyzer;
030    import org.apache.tapestry5.services.EditBlockContribution;
031    import org.apache.tapestry5.services.LibraryMapping;
032    import org.apache.tapestry5.services.messages.ComponentMessagesSource;
033    
034    /**
035     * Defines core services for Kaptcha support.
036     *
037     * @since 5.3
038     */
039    public class KaptchaModule
040    {
041        public static void bind(ServiceBinder binder)
042        {
043            binder.bind(KaptchaProducer.class, KaptchaProducerImpl.class);
044        }
045    
046        @Contribute(ComponentClassResolver.class)
047        public static void provideLibraryMapping(Configuration<LibraryMapping> configuration)
048        {
049            configuration.add(new LibraryMapping(InternalConstants.CORE_LIBRARY, "org.apache.tapestry5.kaptcha"));
050        }
051    
052        @Contribute(ComponentMessagesSource.class)
053        public static void provideLibrayMessages(
054                OrderedConfiguration<Resource> configuration,
055                @Value("classpath:org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties")
056                Resource coreCatalog)
057        {
058            configuration.add("TapestryKaptcha", coreCatalog, "before:AppCatalog");
059        }
060    
061        public static void contributeDataTypeAnalyzer(OrderedConfiguration<DataTypeAnalyzer> configuration)
062        {
063            configuration.add("Kaptcha", new KaptchaDataTypeAnalyzer(), "after:Annotation");
064        }
065    
066        @Contribute(BeanBlockSource.class)
067        public static void provideDefaultBeanBlocks(Configuration<BeanBlockContribution> configuration)
068        {
069            configuration.add(new EditBlockContribution("kaptcha", "KaptchaEditBlocks", "kaptcha"));
070    
071        }
072    }