Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2005 The Apache Software Foundation.
*
* 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 net.sf.beanlib.hibernate3;
import static net.sf.beanlib.hibernate.UnEnhancer.unenhance;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.sf.beanlib.CollectionPropertyName;
import net.sf.beanlib.ProtectedSetterMethodCollector;
import net.sf.beanlib.api.BeanPopulatable;
import net.sf.beanlib.api.DetailedBeanPopulatable;
import net.sf.beanlib.hibernate.HibernateBeanReplicator;
import org.apache.commons.lang.ArrayUtils;
/**
* Convenient class for converting application specific
* Hibernate 3 persistence object to DTO.
*
* @author Joe D. Velopar
*/
public class Hibernate3DtoCopier
{
/**
* Factory for {@link Hibernate3DtoCopier}.
*
* @author Joe D. Velopar
*/
public static class Factory
{
public static Hibernate3DtoCopier getInstance(String applicationPackagePrefix, Class applicationSampleClass) {
return new Hibernate3DtoCopier().init(applicationPackagePrefix, applicationSampleClass);
}
public static Hibernate3DtoCopier getInstance(String applicationPackagePrefix) {
return new Hibernate3DtoCopier().init(applicationPackagePrefix, null);
}
}
// private static final Logger log = Logger.getLogger(Hibernate3DtoCopier.class);
private String applicationPackagePrefix = "#"; // By default no application package is specified.
/** Must be constructed only via the factory. */
private Hibernate3DtoCopier() {
}
protected Hibernate3BeanReplicator createHibernateBeanReplicator() {
return new Hibernate3BeanReplicator();
}
/**
* Used to specify the application package prefix, with a sample application class for verification purposes.
*/
protected Hibernate3DtoCopier init(String applicationPackagePrefix, Class applicationSampleClass) {
this.applicationPackagePrefix = applicationPackagePrefix;
if (applicationSampleClass != null) {
String thisPackageName = org.apache.commons.lang.ClassUtils.getPackageName(applicationSampleClass);
if (!thisPackageName.startsWith(applicationPackagePrefix)) {
throw new IllegalStateException(
"The specified application package prefix " + applicationPackagePrefix
+ " is not consistent with the given sample application class " + applicationSampleClass);
}
}
return this;
}
/** Returns a DTO by deep cloning the given Hibernate bean. */
public T hibernate2dtoFully(T entityBean) {
return entityBean == null
? null
: createHibernateBeanReplicator()
.initBeanPopulatable(new Hibernate3DtoPopulator()
.init(this))
.copy(entityBean);
}
/** Returns a list of DTO's by deep cloning the given collection of Hibernate beans. */
public List hibernate2dtoFully(Collection hibernateBeans) {
if (hibernateBeans == null)
return null;
List