📄 xmlintrospector.java
字号:
package org.apache.commons.betwixt;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.betwixt.digester.XMLBeanInfoDigester;
import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
import org.apache.commons.betwixt.expression.EmptyExpression;
import org.apache.commons.betwixt.expression.IteratorExpression;
import org.apache.commons.betwixt.expression.MapEntryAdder;
import org.apache.commons.betwixt.expression.MethodUpdater;
import org.apache.commons.betwixt.expression.StringExpression;
import org.apache.commons.betwixt.registry.DefaultXMLBeanInfoRegistry;
import org.apache.commons.betwixt.registry.XMLBeanInfoRegistry;
import org.apache.commons.betwixt.strategy.ClassNormalizer;
import org.apache.commons.betwixt.strategy.DefaultNameMapper;
import org.apache.commons.betwixt.strategy.DefaultPluralStemmer;
import org.apache.commons.betwixt.strategy.NameMapper;
import org.apache.commons.betwixt.strategy.PluralStemmer;
import org.apache.commons.betwixt.strategy.TypeBindingStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p><code>XMLIntrospector</code> an introspector of beans to create a
* XMLBeanInfo instance.</p>
*
* <p>By default, <code>XMLBeanInfo</code> caching is switched on.
* This means that the first time that a request is made for a <code>XMLBeanInfo</code>
* for a particular class, the <code>XMLBeanInfo</code> is cached.
* Later requests for the same class will return the cached value.</p>
*
* <p>Note :</p>
* <p>This class makes use of the <code>java.bean.Introspector</code>
* class, which contains a BeanInfoSearchPath. To make sure betwixt can
* do his work correctly, this searchpath is completely ignored during
* processing. The original values will be restored after processing finished
* </p>
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
*/
public class XMLIntrospector {
/**
* Log used for logging (Doh!)
* @deprecated 0.6 use the {@link #getLog()} property instead
*/
protected Log log = LogFactory.getLog( XMLIntrospector.class );
/** Maps classes to <code>XMLBeanInfo</code>'s */
private XMLBeanInfoRegistry registry = new DefaultXMLBeanInfoRegistry();
/** Digester used to parse the XML descriptor files */
private XMLBeanInfoDigester digester;
/** Configuration to be used for introspection*/
private IntrospectionConfiguration configuration;
/** Base constructor */
public XMLIntrospector() {
this(new IntrospectionConfiguration());
}
/**
* Construct allows a custom configuration to be set on construction.
* This allows <code>IntrospectionConfiguration</code> subclasses
* to be easily used.
* @param configuration IntrospectionConfiguration, not null
*/
public XMLIntrospector(IntrospectionConfiguration configuration) {
setConfiguration(configuration);
}
// Properties
//-------------------------------------------------------------------------
/**
* <p>Gets the current logging implementation. </p>
* @return the Log implementation which this class logs to
*/
public Log getLog() {
return getConfiguration().getIntrospectionLog();
}
/**
* <p>Sets the current logging implementation.</p>
* @param log the Log implementation to use for logging
*/
public void setLog(Log log) {
getConfiguration().setIntrospectionLog(log);
}
/**
* <p>Gets the current registry implementation.
* The registry is checked to see if it has an <code>XMLBeanInfo</code> for a class
* before introspecting.
* After standard introspection is complete, the instance will be passed to the registry.</p>
*
* <p>This allows finely grained control over the caching strategy.
* It also allows the standard introspection mechanism
* to be overridden on a per class basis.</p>
*
* @return the XMLBeanInfoRegistry currently used
*/
public XMLBeanInfoRegistry getRegistry() {
return registry;
}
/**
* <p>Sets the <code>XMLBeanInfoRegistry</code> implementation.
* The registry is checked to see if it has an <code>XMLBeanInfo</code> for a class
* before introspecting.
* After standard introspection is complete, the instance will be passed to the registry.</p>
*
* <p>This allows finely grained control over the caching strategy.
* It also allows the standard introspection mechanism
* to be overridden on a per class basis.</p>
*
* @param registry the XMLBeanInfoRegistry to use
*/
public void setRegistry(XMLBeanInfoRegistry registry) {
this.registry = registry;
}
/**
* Gets the configuration to be used for introspection.
* The various introspection-time strategies
* and configuration variables have been consolidated as properties
* of this bean.
* This allows the configuration to be more easily shared.
* @return IntrospectionConfiguration, not null
*/
public IntrospectionConfiguration getConfiguration() {
return configuration;
}
/**
* Sets the configuration to be used for introspection.
* The various introspection-time strategies
* and configuration variables have been consolidated as properties
* of this bean.
* This allows the configuration to be more easily shared.
* @param configuration IntrospectionConfiguration, not null
*/
public void setConfiguration(IntrospectionConfiguration configuration) {
this.configuration = configuration;
}
/**
* Gets the <code>ClassNormalizer</code> strategy.
* This is used to determine the Class to be introspected
* (the normalized Class).
*
* @return the <code>ClassNormalizer</code> used to determine the Class to be introspected
* for a given Object.
* @deprecated 0.6 use getConfiguration().getClassNormalizer
* @since 0.5
*/
public ClassNormalizer getClassNormalizer() {
return getConfiguration().getClassNormalizer();
}
/**
* Sets the <code>ClassNormalizer</code> strategy.
* This is used to determine the Class to be introspected
* (the normalized Class).
*
* @param classNormalizer the <code>ClassNormalizer</code> to be used to determine
* the Class to be introspected for a given Object.
* @deprecated 0.6 use getConfiguration().setClassNormalizer
* @since 0.5
*
*/
public void setClassNormalizer(ClassNormalizer classNormalizer) {
getConfiguration().setClassNormalizer(classNormalizer);
}
/**
* Is <code>XMLBeanInfo</code> caching enabled?
*
* @deprecated 0.5 replaced by XMlBeanInfoRegistry
* @return true if caching is enabled
*/
public boolean isCachingEnabled() {
return true;
}
/**
* Set whether <code>XMLBeanInfo</code> caching should be enabled.
*
* @deprecated 0.5 replaced by XMlBeanInfoRegistry
* @param cachingEnabled ignored
*/
public void setCachingEnabled(boolean cachingEnabled) {
//
}
/**
* Should attributes (or elements) be used for primitive types.
* @return true if primitive types will be mapped to attributes in the introspection
* @deprecated 0.6 use getConfiguration().isAttributesForPrimitives
*/
public boolean isAttributesForPrimitives() {
return getConfiguration().isAttributesForPrimitives();
}
/**
* Set whether attributes (or elements) should be used for primitive types.
* @param attributesForPrimitives pass trus to map primitives to attributes,
* pass false to map primitives to elements
* @deprecated 0.6 use getConfiguration().setAttributesForPrimitives
*/
public void setAttributesForPrimitives(boolean attributesForPrimitives) {
getConfiguration().setAttributesForPrimitives(attributesForPrimitives);
}
/**
* Should collections be wrapped in an extra element?
*
* @return whether we should we wrap collections in an extra element?
* @deprecated 0.6 use getConfiguration().isWrapCollectionsInElement
*/
public boolean isWrapCollectionsInElement() {
return getConfiguration().isWrapCollectionsInElement();
}
/**
* Sets whether we should we wrap collections in an extra element.
*
* @param wrapCollectionsInElement pass true if collections should be wrapped in a
* parent element
* @deprecated 0.6 use getConfiguration().setWrapCollectionsInElement
*/
public void setWrapCollectionsInElement(boolean wrapCollectionsInElement) {
getConfiguration().setWrapCollectionsInElement(wrapCollectionsInElement);
}
/**
* Get singular and plural matching strategy.
*
* @return the strategy used to detect matching singular and plural properties
* @deprecated 0.6 use getConfiguration().getPluralStemmer
*/
public PluralStemmer getPluralStemmer() {
return getConfiguration().getPluralStemmer();
}
/**
* Sets the strategy used to detect matching singular and plural properties
*
* @param pluralStemmer the PluralStemmer used to match singular and plural
* @deprecated 0.6 use getConfiguration().setPluralStemmer
*/
public void setPluralStemmer(PluralStemmer pluralStemmer) {
getConfiguration().setPluralStemmer(pluralStemmer);
}
/**
* Gets the name mapper strategy.
*
* @return the strategy used to convert bean type names into element names
* @deprecated 0.5 getNameMapper is split up in
* {@link #getElementNameMapper()} and {@link #getAttributeNameMapper()}
*/
public NameMapper getNameMapper() {
return getElementNameMapper();
}
/**
* Sets the strategy used to convert bean type names into element names
* @param nameMapper the NameMapper strategy to be used
* @deprecated 0.5 setNameMapper is split up in
* {@link #setElementNameMapper(NameMapper)} and {@link #setAttributeNameMapper(NameMapper)}
*/
public void setNameMapper(NameMapper nameMapper) {
setElementNameMapper(nameMapper);
}
/**
* Gets the name mapping strategy used to convert bean names into elements.
*
* @return the strategy used to convert bean type names into element
* names. If no element mapper is currently defined then a default one is created.
* @deprecated 0.6 use getConfiguration().getElementNameMapper
*/
public NameMapper getElementNameMapper() {
return getConfiguration().getElementNameMapper();
}
/**
* Sets the strategy used to convert bean type names into element names
* @param nameMapper the NameMapper to use for the conversion
* @deprecated 0.6 use getConfiguration().setElementNameMapper
*/
public void setElementNameMapper(NameMapper nameMapper) {
getConfiguration().setElementNameMapper( nameMapper );
}
/**
* Gets the name mapping strategy used to convert bean names into attributes.
*
* @return the strategy used to convert bean type names into attribute
* names. If no attributeNamemapper is known, it will default to the ElementNameMapper
* @deprecated 0.6 getConfiguration().getAttributeNameMapper
*/
public NameMapper getAttributeNameMapper() {
return getConfiguration().getAttributeNameMapper();
}
/**
* Sets the strategy used to convert bean type names into attribute names
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -