📄 defaultmodelreader.java
字号:
/* ========================================================================
* JCommon : a free general purpose class library for the Java(tm) platform
* ========================================================================
*
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jcommon/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -----------------------
* DefaultModelReader.java
* -----------------------
* (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Object Refinery Limited);
*
* $Id: DefaultModelReader.java,v 1.2 2005/10/18 13:32:20 mungady Exp $
*
* Changes
* -------
* 12-Nov-2003 : Initial version (TM);
* 26-Nov-2003 : Updated header and Javadocs (DG);
*
*/
package org.jfree.xml.generator;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import org.jfree.io.IOUtils;
import org.jfree.xml.generator.model.ClassDescription;
import org.jfree.xml.generator.model.Comments;
import org.jfree.xml.generator.model.DescriptionModel;
import org.jfree.xml.generator.model.IgnoredPropertyInfo;
import org.jfree.xml.generator.model.ManualMappingInfo;
import org.jfree.xml.generator.model.MultiplexMappingInfo;
import org.jfree.xml.generator.model.PropertyInfo;
import org.jfree.xml.generator.model.PropertyType;
import org.jfree.xml.generator.model.TypeInfo;
import org.jfree.xml.util.AbstractModelReader;
import org.jfree.xml.util.ObjectDescriptionException;
/**
* A reader for the class model.
*/
public class DefaultModelReader extends AbstractModelReader {
/** A model containing classes and the corresponding class descriptions. */
private DescriptionModel model;
/** The class description under construction. */
private ClassDescription currentClassDescription;
/** Information about the class being processed. */
private BeanInfo currentBeanInfo;
/** The base URL. */
private URL baseURL;
/** The source. */
private String source;
/** The multiplex mapping info. */
private MultiplexMappingInfo multiplexInfo;
/** The multiplex type info.*/
private ArrayList multiplexTypeInfos;
/** Storage for the properties of the current class. */
private ArrayList propertyList;
/** Storage for the constructors of the current class. */
private ArrayList constructorList;
/**
* Creates a new model reader.
*/
public DefaultModelReader() {
super();
}
/**
* Loads a description model.
*
* @param file the file name.
*
* @return A description model.
*
* @throws IOException if there is an I/O problem.
* @throws ObjectDescriptionException if there is a problem reading the object descriptions.
*/
public synchronized DescriptionModel load(final String file) throws IOException,
ObjectDescriptionException {
this.model = new DescriptionModel();
this.baseURL = new File (file).toURL();
parseXml(this.baseURL);
fillSuperClasses();
return this.model;
}
/**
* Iterates through all the class descriptions in the model, setting the superclass
* attribute in all cases where the superclass definitions are contained in the model.
*/
protected void fillSuperClasses() {
for (int i = 0; i < this.model.size(); i++) {
final ClassDescription cd = this.model.get(i);
final Class parent = cd.getObjectClass().getSuperclass();
if (parent == null) {
continue;
}
final ClassDescription superCD = this.model.get(parent);
if (superCD != null) {
cd.setSuperClass(superCD.getObjectClass());
}
}
}
/**
* Begin processing an object definition element.
*
* @param className the class name.
* @param register the register name (<code>null</code> permitted).
* @param ignore ??
*
* @return <code>true</code> if the class is available, and <code>false</code> otherwise.
*/
protected boolean startObjectDefinition(final String className, final String register, final boolean ignore) {
final Class c = loadClass(className);
if (c == null) {
return false;
}
this.currentClassDescription = new ClassDescription(c);
this.currentClassDescription.setPreserve(ignore);
this.currentClassDescription.setRegisterKey(register);
try {
this.currentBeanInfo = Introspector.getBeanInfo(c, Object.class);
}
catch (IntrospectionException ie) {
return false;
}
this.propertyList = new java.util.ArrayList();
this.constructorList = new java.util.ArrayList();
return true;
}
/**
* Finishes processing an object definition (sets the constructor and property info for the
* class description, and adds the class description to the model).
*
* @throws ObjectDescriptionException if there is a problem with the object description.
*/
protected void endObjectDefinition() throws ObjectDescriptionException {
final PropertyInfo[] pis = (PropertyInfo[])
this.propertyList.toArray(new PropertyInfo[this.propertyList.size()]);
this.currentClassDescription.setProperties(pis);
final TypeInfo[] tis = (TypeInfo[])
this.constructorList.toArray(new TypeInfo[this.constructorList.size()]);
this.currentClassDescription.setConstructorDescription(tis);
this.currentClassDescription.setComments
(new Comments(getOpenComment(), getCloseComment()));
this.currentClassDescription.setSource(this.source);
this.model.addClassDescription(this.currentClassDescription);
this.propertyList = null;
this.currentBeanInfo = null;
this.currentClassDescription = null;
}
/**
* Handles the description of an attribute within an object definition.
*
* @param name the name.
* @param attribName the attribute name.
* @param handlerClass the fully qualified class name for the attribute handler.
*
* @throws ObjectDescriptionException if there is a problem with the object description.
*/
protected void handleAttributeDefinition(final String name, final String attribName, final String handlerClass)
throws ObjectDescriptionException {
final PropertyInfo propertyInfo = ModelBuilder.getInstance().createSimplePropertyInfo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -