Java tutorial
/* * Copyright 2012 Nabeel Mukhtar * * 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 com.appspot.socialinquirer.server.service.mapper; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.beanutils.PropertyUtils; import com.appspot.socialinquirer.server.model.Entity; import com.appspot.socialinquirer.shared.dto.DataTransferObject; /** * The Class AbstractMapper. * * @param <SOURCE> the * @param <TARGET> the */ public abstract class AbstractMapper<SOURCE extends DataTransferObject, TARGET extends Entity> implements Mapper<SOURCE, TARGET> { /** The logger. */ protected final Logger logger = Logger.getLogger(getClass().getCanonicalName()); /* * (non-Javadoc) * * @see com.appspot.everscribe.server.service.mapper.Mapper#copyProperties(com.appspot.everscribe.shared.dto.DataTransferObject, * com.appspot.everscribe.server.model.Entity) */ public void copyProperties(SOURCE source, TARGET target) { try { PropertyUtils.copyProperties(target, source); } catch (Exception e) { logger.log(Level.SEVERE, "An error occurred while copying properties from '" + source.getClass().getName() + "' to '" + target.getClass().getName(), e); } } /* * (non-Javadoc) * * @see com.appspot.everscribe.server.service.mapper.Mapper#copyProperties(com.appspot.everscribe.server.model.Entity, * com.appspot.everscribe.shared.dto.DataTransferObject) */ public void copyProperties(TARGET source, SOURCE target) { try { PropertyUtils.copyProperties(target, source); } catch (Exception e) { logger.log(Level.SEVERE, "An error occurred while copying properties from '" + target.getClass().getName() + "' to '" + source.getClass().getName(), e); } } }