扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:键者天行 来源:csdn 2007年11月4日
关键字:
public void generateClasses(URL schemaURL) throws IOException { /** * Create builder to generate JDOM representation of XML Schema, * without validation and using Apache Xerces. */ SAXBuilder builder = new SAXBuilder(); try { Document schemaDoc = builder.build(schemaURL); // Handle complex types List complexTypes = schemaDoc.getRootElement().getChildren("complexType", schemaNamespace); for (Iterator i = complexTypes.iterator(); i.hasNext(); ) { // Iterate and handle Element complexType = (Element)i.next(); handleComplexType(complexType); } } catch (JDOMException e) { throw new IOException(e.getMessage()); } } |
String type = null; // Handle extension, if needed String baseType = null; try { // Assume that we are dealing with an explicit type type = complexType.getAttribute("name").getValue(); } catch (NoSuchAttributeException e) { /* * It is safe with an implicit type to assume that the parent * is of type "element", has no "type" attribute, and that we * can derive the type as the value of the element's "name" * attribute with the word "Type" appended to it. */ try { type = new StringBuffer().append(BindingUtils.initialCaps(complexType.getParent() .getAttribute("name") .getValue())) .append("Type") .toString(); } catch (NoSuchAttributeException nsae) { // Shouldn't happen in schema-valid documents throw new IOException("All elements must at have a name."); } } |
StringBuffer interfaceCode = new StringBuffer(); StringBuffer implementationCode = new StringBuffer(); /* * Start writing out the interface and implementation class * definitions. */ interfaceCode.append("public interface ") .append(interfaceName); // Add in extension if appropriate if (baseType != null) { interfaceCode.append(" extends ") .append(baseType); } interfaceCode.append(" {\n"); implementationCode.append("public class ") .append(implementationName); // Add in extension if appropriate if (baseType != null) { implementationCode.append(" extends ") .append(baseType) .append("Impl"); } implementationCode.append(" implements ") .append(interfaceName) .append(" {\n"); // Add in properties and methods // Close up interface and implementation classes interfaceCode.append("}"); implementationCode.append("}"); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者