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