001: /** ===================================================================
002: *
003: * L2FProd.com Common Components 7.3 License.
004: *
005: * Copyright (c) 2005-2007 L2FProd.com. All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution, if
020: * any, must include the following acknowlegement:
021: * "This product includes software developed by L2FProd.com
022: * (http://www.L2FProd.com/)."
023: * Alternately, this acknowlegement may appear in the software itself,
024: * if and wherever such third-party acknowlegements normally appear.
025: *
026: * 4. The names "L2FProd.com Common Components", "l2fprod-common" and "L2FProd.com" must not
027: * be used to endorse or promote products derived from this software
028: * without prior written permission. For written permission, please
029: * contact info@L2FProd.com.
030: *
031: * 5. Products derived from this software may not be called "l2fprod-common"
032: * nor may "l2fprod-common" appear in their names without prior written
033: * permission of L2FProd.com.
034: *
035: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
036: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
037: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
038: * DISCLAIMED. IN NO EVENT SHALL L2FPROD.COM OR ITS CONTRIBUTORS BE
039: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
040: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
041: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
042: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
043: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
044: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
045: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
046: * ====================================================================
047: */package com.l2fprod.common.model;
048:
049: import com.l2fprod.common.beans.BeanInfoResolver;
050:
051: import java.beans.BeanInfo;
052:
053: /**
054: * DefaultBeanInfoResolver. <br>
055: *
056: */
057: public class DefaultBeanInfoResolver implements BeanInfoResolver {
058:
059: public DefaultBeanInfoResolver() {
060: super ();
061: }
062:
063: public BeanInfo getBeanInfo(Object object) {
064: if (object == null) {
065: return null;
066: }
067:
068: return getBeanInfo(object.getClass());
069: }
070:
071: public BeanInfo getBeanInfo(Class clazz) {
072: if (clazz == null) {
073: return null;
074: }
075:
076: String classname = clazz.getName();
077:
078: // look for .impl.basic., remove it and call getBeanInfo(class)
079: int index = classname.indexOf(".impl.basic");
080: if (index != -1 && classname.endsWith("Basic")) {
081: classname = classname.substring(0, index)
082: + classname.substring(index
083: + ".impl.basic".length(), classname
084: .lastIndexOf("Basic"));
085: try {
086: return getBeanInfo(Class.forName(classname));
087: } catch (ClassNotFoundException e) {
088: return null;
089: }
090: } else {
091: try {
092: BeanInfo beanInfo = (BeanInfo) Class.forName(
093: classname + "BeanInfo").newInstance();
094: return beanInfo;
095: } catch (Exception e) {
096: return null;
097: }
098: }
099: }
100:
101: }
|