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.digester; 18 19 import java.util.Set; 20 21 import org.apache.commons.betwixt.XMLIntrospector; 22 import org.apache.commons.digester.Rule; 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 /** <p><code>RuleSupport</code> is an abstract base class containing useful 27 * helper methods.</p> 28 * 29 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> 30 * @version $Revision: 493795 $ 31 */ 32 public class RuleSupport extends Rule { 33 34 /** Logger */ 35 private static final Log log = LogFactory.getLog( RuleSupport.class ); 36 /** Base constructor */ 37 public RuleSupport() { 38 } 39 40 41 42 // Implementation methods 43 //------------------------------------------------------------------------- 44 /** 45 * Gets <code>XMLBeanInfoDigester</code> using this rule. 46 * 47 * @return <code>XMLBeanInfoDigester</code> for this rule 48 */ 49 protected XMLBeanInfoDigester getXMLInfoDigester() { 50 return (XMLBeanInfoDigester) getDigester(); 51 } 52 53 /** 54 * Gets <code>XMLIntrospector</code> to be used for introspection 55 * 56 * @return <code>XMLIntrospector</code> to use 57 */ 58 protected XMLIntrospector getXMLIntrospector() { 59 return getXMLInfoDigester().getXMLIntrospector(); 60 } 61 62 /** 63 * Gets the class of the bean whose .betwixt file is being digested 64 * 65 * @return the <code>Class</code> of the bean being processed 66 */ 67 protected Class getBeanClass() { 68 return getXMLInfoDigester().getBeanClass(); 69 } 70 71 /** 72 * Gets the property names already processed 73 * 74 * @return the set of property names that have been processed so far 75 */ 76 protected Set getProcessedPropertyNameSet() { 77 return getXMLInfoDigester().getProcessedPropertyNameSet(); 78 } 79 80 81 82 /** 83 * Loads the given class using an appropriate <code>ClassLoader</code>. 84 * Uses {@link org.apache.commons.digester.Digester#getClassLoader()}. 85 * @param className names the class to be loaded 86 * @return <code>Class</code> loaded, not null 87 * @throws ClassNotFoundException 88 */ 89 protected Class loadClass(String className) throws ClassNotFoundException { 90 ClassLoader classloader = digester.getClassLoader(); 91 Class clazz = null; 92 if (classloader == null) { 93 clazz = Class.forName(className); 94 } else { 95 clazz = classloader.loadClass(className); 96 } 97 return clazz; 98 } 99 }