java/sql-dk/src/info/globalcode/sql/dk/configuration/FormatterDefinition.java
branchv_0
changeset 29 d66858b4b563
parent 26 4ec8e5534eb9
child 30 b7ea47b2d4ca
equal deleted inserted replaced
28:57c44a6baedb 29:d66858b4b563
    15  * You should have received a copy of the GNU General Public License
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    17  */
    18 package info.globalcode.sql.dk.configuration;
    18 package info.globalcode.sql.dk.configuration;
    19 
    19 
       
    20 import static info.globalcode.sql.dk.Constants.XMLNS_CONFIGURATION;
    20 import info.globalcode.sql.dk.DKException;
    21 import info.globalcode.sql.dk.DKException;
    21 import info.globalcode.sql.dk.formatting.Formatter;
    22 import info.globalcode.sql.dk.formatting.Formatter;
    22 import info.globalcode.sql.dk.formatting.FormatterContext;
    23 import info.globalcode.sql.dk.formatting.FormatterContext;
    23 import java.lang.reflect.Constructor;
    24 import java.lang.reflect.Constructor;
    24 import java.lang.reflect.InvocationTargetException;
    25 import java.lang.reflect.InvocationTargetException;
    25 import javax.xml.bind.annotation.XmlElement;
    26 import javax.xml.bind.annotation.XmlElement;
    26 import javax.xml.bind.annotation.XmlTransient;
       
    27 
    27 
    28 /**
    28 /**
    29  *
    29  *
    30  * @author Ing. František Kučera (frantovo.cz)
    30  * @author Ing. František Kučera (frantovo.cz)
    31  */
    31  */
    32 public class FormatterDefinition implements NameIdentified {
    32 public class FormatterDefinition implements NameIdentified {
    33 
    33 
    34 	private String name;
    34 	private String name;
    35 	private String className;
    35 	private String className;
    36 
    36 
    37 	@XmlElement(name = "name")
    37 	public FormatterDefinition() {
       
    38 	}
       
    39 
       
    40 	public FormatterDefinition(String name, String className) {
       
    41 		this.name = name;
       
    42 		this.className = className;
       
    43 	}
       
    44 
       
    45 	@XmlElement(name = "name", namespace = XMLNS_CONFIGURATION)
    38 	@Override
    46 	@Override
    39 	public String getName() {
    47 	public String getName() {
    40 		return name;
    48 		return name;
    41 	}
    49 	}
    42 
    50 
    52 	 * The constructor must accept one parameter:
    60 	 * The constructor must accept one parameter:
    53 	 * <code>info.globalcode.sql.dk.formatting.FormatterContext</code>
    61 	 * <code>info.globalcode.sql.dk.formatting.FormatterContext</code>
    54 	 *
    62 	 *
    55 	 * @return fully qualified class name
    63 	 * @return fully qualified class name
    56 	 */
    64 	 */
    57 	@XmlElement(name = "class")
    65 	@XmlElement(name = "class", namespace = XMLNS_CONFIGURATION)
    58 	public String getClassName() {
    66 	public String getClassName() {
    59 		return className;
    67 		return className;
    60 	}
    68 	}
    61 
    69 
    62 	public void setClassName(String className) {
    70 	public void setClassName(String className) {
    66 	/**
    74 	/**
    67 	 * @param context
    75 	 * @param context
    68 	 * @return
    76 	 * @return
    69 	 * @throws DKException
    77 	 * @throws DKException
    70 	 */
    78 	 */
    71 	@XmlTransient
       
    72 	public Formatter getInstance(FormatterContext context) throws DKException {
    79 	public Formatter getInstance(FormatterContext context) throws DKException {
    73 		try {
    80 		try {
    74 			Constructor constructor = Class.forName(className).getConstructor(context.getClass());
    81 			Constructor constructor = Class.forName(className).getConstructor(context.getClass());
    75 
    82 
    76 			Object instance = constructor.newInstance(context);
    83 			Object instance = constructor.newInstance(context);