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.digester;
018
019 import java.util.Set;
020
021 import org.apache.commons.betwixt.XMLIntrospector;
022 import org.apache.commons.digester.Rule;
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025
026 /** <p><code>RuleSupport</code> is an abstract base class containing useful
027 * helper methods.</p>
028 *
029 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
030 * @version $Revision: 493795 $
031 */
032 public class RuleSupport extends Rule {
033
034 /** Logger */
035 private static final Log log = LogFactory.getLog( RuleSupport.class );
036 /** Base constructor */
037 public RuleSupport() {
038 }
039
040
041
042 // Implementation methods
043 //-------------------------------------------------------------------------
044 /**
045 * Gets <code>XMLBeanInfoDigester</code> using this rule.
046 *
047 * @return <code>XMLBeanInfoDigester</code> for this rule
048 */
049 protected XMLBeanInfoDigester getXMLInfoDigester() {
050 return (XMLBeanInfoDigester) getDigester();
051 }
052
053 /**
054 * Gets <code>XMLIntrospector</code> to be used for introspection
055 *
056 * @return <code>XMLIntrospector</code> to use
057 */
058 protected XMLIntrospector getXMLIntrospector() {
059 return getXMLInfoDigester().getXMLIntrospector();
060 }
061
062 /**
063 * Gets the class of the bean whose .betwixt file is being digested
064 *
065 * @return the <code>Class</code> of the bean being processed
066 */
067 protected Class getBeanClass() {
068 return getXMLInfoDigester().getBeanClass();
069 }
070
071 /**
072 * Gets the property names already processed
073 *
074 * @return the set of property names that have been processed so far
075 */
076 protected Set getProcessedPropertyNameSet() {
077 return getXMLInfoDigester().getProcessedPropertyNameSet();
078 }
079
080
081
082 /**
083 * Loads the given class using an appropriate <code>ClassLoader</code>.
084 * Uses {@link org.apache.commons.digester.Digester#getClassLoader()}.
085 * @param className names the class to be loaded
086 * @return <code>Class</code> loaded, not null
087 * @throws ClassNotFoundException
088 */
089 protected Class loadClass(String className) throws ClassNotFoundException {
090 ClassLoader classloader = digester.getClassLoader();
091 Class clazz = null;
092 if (classloader == null) {
093 clazz = Class.forName(className);
094 } else {
095 clazz = classloader.loadClass(className);
096 }
097 return clazz;
098 }
099 }