从一个Java类创建另一个Java类POJO

问题描述

我有一个xml文件,我正在使用Java代码读取对象。

在读取该对象之后,我需要编写一个代码,该代码将从该对象创建文件(POJO)类,以便为该对象创建getter和setter方法

我已经编写了一个从xml文件读取变量和变量类型的代码,但是我不知道如何创建一个新的java文件,其中将包含该对象和getter setter方法

这是我从中读取xml的代码

package xmlRead;


import javax.xml.parsers.DocumentBuilderFactory;  
import javax.xml.parsers.DocumentBuilder;  
import org.w3c.dom.Document;  
import org.w3c.dom.NodeList;  
import org.w3c.dom.Node;  
import org.w3c.dom.Element;  
import java.io.File;  

public class readxmlFile  
{  
public static void main(String argv[])   
{  
try   
{  
//creating a constructor of file class and parsing an XML file  
String fileName = "C:\\Users\\AcnTUSR\\Downloads\\QiwkIdentityChangeHisotry.qdd";
//File file = new File(fileName);  

File inputHBMFile = new File(fileName);
DocumentBuilderFactory dbInputXMLFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dInputXMLBuilder = dbInputXMLFactory.newDocumentBuilder();
Document docInputXML = dInputXMLBuilder.parse(inputHBMFile);
docInputXML.getDocumentElement().normalize();

System.out.println("Root element :" + docInputXML.getDocumentElement().getNodeName());

Element classElementFromInputXML = (Element) docInputXML.getElementsByTagName("class").item(0);
String className = classElementFromInputXML.getAttribute("name");
String tableName = classElementFromInputXML.getAttribute("table");
System.out.println("className::" + className + " -- tableName::" + tableName);

NodeList propNodeList = docInputXML.getElementsByTagName("property");
for (int temp = 0; temp < propNodeList.getLength(); temp++) {
    Node propNode = propNodeList.item(temp);
    System.out.println("\nCurrent Element :" + propNode.getNodeName());
    if (propNode.getNodeType() == Node.ELEMENT_NODE) {
        String propName = "";
        String propType = "";
        String propLength = "";
        String aliasName = "";

        Element propElement = (Element) propNode;

        propName = propElement.getAttribute("name");
        propType = propElement.getAttribute("type");
        if (propElement.hasAttribute("length")) {
            propLength = propElement.getAttribute("length");
        }
        aliasName = propElement.getAttribute("alias");

        System.out.println("Prop Name::" + propName);
        System.out.println("Prop Type::" + propType);
        System.out.println("Prop Length::" + propLength);
        System.out.println("Prop aliasName::" + aliasName);
    }
}


}   
catch (Exception e)   
{  
e.printstacktrace();  
}  
}  
}  

有人可以帮助我如何创建另一个Java文件并在该Java文件中创建这些POJO吗?

预先感谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)