001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.betwixt.strategy; 018 019 /** 020 * <p>Class normalization strategy.</p> 021 * 022 * <p> 023 * The normalized Class is the Class that Betwixt should 024 * introspect. 025 * This strategy class allows the introspected Class to be 026 * varied. 027 * This implementation simply returns the Class given. 028 * </p> 029 * 030 * <p> 031 * Used by Betwixt to allow superclasses or interfaces to be subsittuted 032 * before an object is introspected. 033 * This allows users to feed in logical interfaces and make Betwixt ignore 034 * properties other than those in the interface. 035 * It also allows support for <code>Proxy</code>'s. 036 * Together, these features allow Betwixt to deal with Entity Beans 037 * properly by viewing them through their remote interfaces. 038 * </p> 039 * @author Robert Burrell Donkin 040 * @since 0.5 041 */ 042 public class ClassNormalizer { 043 044 /** 045 * Gets the normalized class for the given Object. 046 * The normalized Class is the Class that Betwixt should 047 * introspect. 048 * This strategy class allows the introspected Class to be 049 * varied. 050 * 051 * @param object the <code>Object</code> 052 * for which the normalized Class is to be returned. 053 * @return the normalized Class 054 */ 055 public Class getNormalizedClass( Object object ) { 056 if ( object == null ) { 057 throw new IllegalArgumentException("Cannot get class for null object."); 058 } 059 return normalize( object.getClass() ); 060 } 061 062 /** 063 * Normalize given class. 064 * The normalized Class is the Class that Betwixt should 065 * introspect. 066 * This strategy class allows the introspected Class to be 067 * varied. 068 * 069 * @param clazz the class to normalize, not null 070 * @return this implementation the same clazz, 071 * subclasses may return any compatible class. 072 */ 073 public Class normalize( Class clazz ) { 074 return clazz; 075 } 076 }