/***************************************************************** * 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.cayenne.dbsync.reverse.configuration; import org.apache.cayenne.access.translator.batch.BatchTranslatorFactory; import org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory; import org.apache.cayenne.access.types.DefaultValueObjectTypeRegistry; import org.apache.cayenne.access.types.ValueObjectTypeRegistry; import org.apache.cayenne.configuration.Constants; import org.apache.cayenne.configuration.DefaultRuntimeProperties; import org.apache.cayenne.configuration.RuntimeProperties; import org.apache.cayenne.configuration.server.DataSourceFactory; import org.apache.cayenne.configuration.server.DbAdapterFactory; import org.apache.cayenne.configuration.server.DefaultDbAdapterFactory; import org.apache.cayenne.configuration.server.ServerModule; import org.apache.cayenne.dba.db2.DB2Sniffer; import org.apache.cayenne.dba.derby.DerbySniffer; import org.apache.cayenne.dba.firebird.FirebirdSniffer; import org.apache.cayenne.dba.frontbase.FrontBaseSniffer; import org.apache.cayenne.dba.h2.H2Sniffer; import org.apache.cayenne.dba.hsqldb.HSQLDBSniffer; import org.apache.cayenne.dba.ingres.IngresSniffer; import org.apache.cayenne.dba.mysql.MySQLSniffer; import org.apache.cayenne.dba.openbase.OpenBaseSniffer; import org.apache.cayenne.dba.oracle.OracleSniffer; import org.apache.cayenne.dba.postgres.PostgresSniffer; import org.apache.cayenne.dba.sqlite.SQLiteSniffer; import org.apache.cayenne.dba.sqlserver.SQLServerSniffer; import org.apache.cayenne.dba.sybase.SybaseSniffer; import org.apache.cayenne.di.AdhocObjectFactory; import org.apache.cayenne.di.Binder; import org.apache.cayenne.di.ClassLoaderManager; import org.apache.cayenne.di.Key; import org.apache.cayenne.di.Module; import org.apache.cayenne.di.spi.DefaultAdhocObjectFactory; import org.apache.cayenne.di.spi.DefaultClassLoaderManager; import org.apache.cayenne.log.Slf4jJdbcEventLogger; import org.apache.cayenne.log.JdbcEventLogger; import org.apache.cayenne.resource.ClassLoaderResourceLocator; import org.apache.cayenne.resource.ResourceLocator; import org.slf4j.Logger; /** * A DI module to bootstrap DI container for Cayenne Ant tasks and Maven * plugins. * * @since 4.0 */ public class ToolsModule implements Module { private Logger logger; public ToolsModule(Logger logger) { if (logger == null) { throw new NullPointerException("Null logger"); } this.logger = logger; } public void configure(Binder binder) { binder.bind(Logger.class).toInstance(logger); // configure empty global stack properties ServerModule.contributeProperties(binder); ServerModule.contributeDefaultTypes(binder); ServerModule.contributeUserTypes(binder); ServerModule.contributeTypeFactories(binder); ServerModule.contributeValueObjectTypes(binder); binder.bind(ValueObjectTypeRegistry.class).to(DefaultValueObjectTypeRegistry.class); binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class); binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class); binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class); binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(ClassLoaderResourceLocator.class); binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class); binder.bind(BatchTranslatorFactory.class).to(DefaultBatchTranslatorFactory.class); binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class); ServerModule.contributeAdapterDetectors(binder).add(FirebirdSniffer.class).add(OpenBaseSniffer.class) .add(FrontBaseSniffer.class).add(IngresSniffer.class).add(SQLiteSniffer.class).add(DB2Sniffer.class) .add(H2Sniffer.class).add(HSQLDBSniffer.class).add(SybaseSniffer.class).add(DerbySniffer.class) .add(SQLServerSniffer.class).add(OracleSniffer.class).add(PostgresSniffer.class) .add(MySQLSniffer.class); binder.bind(DbAdapterFactory.class).to(DefaultDbAdapterFactory.class); binder.bind(DataSourceFactory.class).to(DriverDataSourceFactory.class); } }