参考のスクリプト
シェルスクリプト conv2java.sh
#!/bin/sh if [ $# -ne 1 ] then echo "ファイル名がありません。" echo "使用法:conv2java.sh ファイル名(.xmlは省略してください。)" exit fi nkf -s $1".xml" | sed -f preconv | awk -f cache2java > $1".java"
sedファイル preconv
/^<Class name=\"/ s/\".*\./\"/ s/=\"/ / s/\"/ / s/>/ / s/<\/Type/ / s/<\/Description/ \/Description/ s/%String/String/ s/%Date/Date/
awkファイル cache2java
/^<Class name/ {
print "class "$3"{"
inClass = 1
}
/^<\/Class/ {
print "}"
inClass = 0
}
/^<Property name/ {
propName = $3
inProperty = 1
}
/^<\/Property/ {
printf ("\tpublic %s %s;\n",propType , propName)
inProperty = 0
}
inProperty == 1 && /^<Type/ { propType = $2 }
スクリプトの実行結果 Simple.java
class withProperty{
public String name;
}
このスクリプトでは、プロパティだけを考慮していますが、メソッドなどの処理も同様の方法で処理できそうです。
このスクリプトを書きながら、閃いた事があります。