Java jaxb att auto-generated

Source: Internet
Author: User
Tags readfile

Package code;

Import Java.io.FileReader;
Import Java.io.FileWriter;
Import Java.io.LineNumberReader;
Import java.util.ArrayList;
Import java.util.List;

Import Javax.xml.bind.annotation.XmlAttribute;



public class Codexmlattr {

private static list<string> ReadFile (String filename)
{
list<string> fileline = new arraylist<string> ();

try {

FileReader in = new FileReader (filename);
LineNumberReader reader = new LineNumberReader (in);

String s = reader.readline ();
while (s! = null)
{
if (!s.startswith ("#"))
{
Fileline.add (s);
}
s = Reader.readline ();
}

Reader.close ();
In.close ();
}catch (Exception e)
{
E.printstacktrace ();
}

return fileline;
}

public static void Genaratecode (list<string> line)
{
String cr= "\ r \ n";

try{

String [] data = Line.get (1). Split (",");
FileWriter FW = new FileWriter (data[1]+ ". Java");
Fw.write (CR);
data = Line.get (0). Split (",");
Fw.write ("package" +DATA[1]+CR);
Fw.write (CR);
Fw.write (CR);
Fw.write ("Import javax.xml.bind.annotation.XmlAccessType;" +CR);
Fw.write ("Import javax.xml.bind.annotation.XmlAccessorType;" +CR);
Fw.write ("Import javax.xml.bind.annotation.XmlAttribute;" +CR);
Fw.write (CR);
Fw.write (CR);
Fw.write ("@XmlRootElement" +CR);
Fw.write ("@XmlAccessorType (Xmlaccesstype.field)" +CR);
data = Line.get (1). Split (",");
Fw.write ("public class" +data[1]+ "{" +CR);
Fw.write (CR);
for (int i = 2;i < Line.size (); i++)
{
data = Line.get (i). Split (",");
if (Data[1].trim (). Equalsignorecase ("int"))
{
Fw.write ("@XmlAttribute (name = \" "+data[0]+" \ ")" +CR);
Fw.write ("Private Integer" +tolowercasefirst (data[0]) + ";" +CR);
}
else if (Data[1].trim (). Equalsignorecase ("string"))
{
Fw.write ("@XmlAttribute (name = \" "+data[0]+" \ ")" +CR);
Fw.write ("Private String" +tolowercasefirst (data[0]) + ";" +CR);
}
Else
{
Fw.write ("@XmlAttribute (name = \" "+data[0]+" \ ")" +CR);
Fw.write ("Private" + data[1]+ "" +tolowercasefirst (Data[0]) + ";" +CR);
}
}

Fw.write (CR);
Fw.write (CR);

for (int i = 2;i < Line.size (); i++)
{
data = Line.get (i). Split (",");
if (Data[1].trim (). Equalsignorecase ("int"))
{
Fw.write ("public void Set" +data[0]+ "(Integer value)" +CR);
Fw.write ("{" +CR);
Fw.write ("+tolowercasefirst (data[0]) +" = "+" value; " +CR);
Fw.write ("}" +CR);

Fw.write ("Public Integer Get" +data[0]+ "()" +CR);
Fw.write ("{" +CR);
Fw.write ("Return" +tolowercasefirst (Data[0]) + ";" +CR);
Fw.write ("}" +CR);
}
else if (Data[1].trim (). Equalsignorecase ("string"))
{
Fw.write ("public void Set" +data[0]+ "(String value)" +CR);
Fw.write ("{" +CR);
Fw.write ("+tolowercasefirst (data[0]) +" = "+" value; " +CR);
Fw.write ("}" +CR);

Fw.write ("Public String Get" +data[0]+ "()" +CR);
Fw.write ("{" +CR);
Fw.write ("Return" +tolowercasefirst (Data[0]) + ";" +CR);
Fw.write ("}" +CR);
}
Else
{
Fw.write ("public void Set" +data[0]+ "(" +data[1]+ "value)" +CR);
Fw.write ("{" +CR);
Fw.write ("+tolowercasefirst (data[0]) +" = "+" value; " +CR);
Fw.write ("}" +CR);

Fw.write ("Public" +data[1]+ "Get" +data[0]+ "()" +CR);
Fw.write ("{" +CR);
Fw.write ("Return" +tolowercasefirst (Data[0]) + ";" +CR);
Fw.write ("}" +CR);
}
}
Fw.write (CR+CR);
Fw.write ("}" +CR);
Fw.close ();
}catch (Exception e)
{

}
}

public static string Tolowercasefirst (String str)
{
StringBuilder sb = new StringBuilder (str);
Sb.setcharat (0, Character.tolowercase (Sb.charat (0)));
str = sb.tostring ();
return str;
}

public static void Main (String args[])
{

list<string> fileline = ReadFile ("Field.txt");

Genaratecode (Fileline);
System.out.println ("success!");

}

}

Java jaxb att auto-generated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.