1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.betwixt.strategy;
18
19 /**
20 * <p>Class normalization strategy.</p>
21 *
22 * <p>
23 * The normalized Class is the Class that Betwixt should
24 * introspect.
25 * This strategy class allows the introspected Class to be
26 * varied.
27 * This implementation simply returns the Class given.
28 * </p>
29 *
30 * <p>
31 * Used by Betwixt to allow superclasses or interfaces to be subsittuted
32 * before an object is introspected.
33 * This allows users to feed in logical interfaces and make Betwixt ignore
34 * properties other than those in the interface.
35 * It also allows support for <code>Proxy</code>'s.
36 * Together, these features allow Betwixt to deal with Entity Beans
37 * properly by viewing them through their remote interfaces.
38 * </p>
39 * @author Robert Burrell Donkin
40 * @since 0.5
41 */
42 public class ClassNormalizer {
43
44 /**
45 * Gets the normalized class for the given Object.
46 * The normalized Class is the Class that Betwixt should
47 * introspect.
48 * This strategy class allows the introspected Class to be
49 * varied.
50 *
51 * @param object the <code>Object</code>
52 * for which the normalized Class is to be returned.
53 * @return the normalized Class
54 */
55 public Class getNormalizedClass( Object object ) {
56 if ( object == null ) {
57 throw new IllegalArgumentException("Cannot get class for null object.");
58 }
59 return normalize( object.getClass() );
60 }
61
62 /**
63 * Normalize given class.
64 * The normalized Class is the Class that Betwixt should
65 * introspect.
66 * This strategy class allows the introspected Class to be
67 * varied.
68 *
69 * @param clazz the class to normalize, not null
70 * @return this implementation the same clazz,
71 * subclasses may return any compatible class.
72 */
73 public Class normalize( Class clazz ) {
74 return clazz;
75 }
76 }