View Javadoc
1   /*  This file is part of the aspect4log  project.
2    This program is free software; you can redistribute it and/or
3    modify it under the terms of the GNU Lesser General Public License
4    as published by the Free Software Foundation; version 2.1
5    of the License.
6    This program is distributed in the hope that it will be useful,
7    but WITHOUT ANY WARRANTY; without even the implied warranty of
8    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    GNU Lesser General Public License for more details.
10   You should have received a copy of the GNU Lesser General Public License
11   along with this program; if not, write to the Free Software
12   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
13  
14   Copyright 2007-2014 Semochkin Vitaliy Evgenevich aka Yilativs
15    
16   */
17  package net.sf.aspect4log.conf;
18  
19  import java.lang.reflect.InvocationTargetException;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlAnyElement;
26  import javax.xml.bind.annotation.XmlAttribute;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlRootElement;
29  import javax.xml.bind.annotation.XmlTransient;
30  
31  import net.sf.aspect4log.text.CustomisableMessageBuilderFactory;
32  import net.sf.aspect4log.text.MessageBuilderFactory;
33  
34  import org.apache.commons.beanutils.BeanUtils;
35  import org.w3c.dom.DOMException;
36  import org.w3c.dom.Element;
37  
38  /**
39   * This class is responsible for holding log format configuration.
40   * 
41   * @author yilativs
42   *
43   */
44  @XmlRootElement(name="aspect4logConfiguration")
45  @XmlAccessorType(XmlAccessType.PROPERTY)
46  public class LogFormatConfiguration {
47  	
48  	private MessageBuilderFactory messageBuilderFactory = new CustomisableMessageBuilderFactory();
49  
50  	@XmlTransient
51  	public void setMessageBuilderFactory(MessageBuilderFactory messageBuilderFactory) {
52  		this.messageBuilderFactory = messageBuilderFactory;
53  	}
54  
55  	public MessageBuilderFactory getMessageBuilderFactory()  {
56  		return messageBuilderFactory;
57  	}
58  
59  	@XmlElement
60  	public void setMessageBuilderFactoryConfiguration(MessageBuilderFactoryConfiguration messageBuilderFactoryConfiguration) throws InstantiationException, IllegalAccessException, InvocationTargetException, DOMException {
61  		messageBuilderFactory = messageBuilderFactoryConfiguration.getClazz().newInstance();
62  		for (Element element : messageBuilderFactoryConfiguration.getProperties()) {
63  			BeanUtils.setProperty(messageBuilderFactory, element.getTagName(), element.getTextContent());
64  		}
65  	}
66  }
67  
68  @XmlAccessorType(XmlAccessType.FIELD)
69  class MessageBuilderFactoryConfiguration {
70  	@XmlAnyElement
71  	private final List<Element> properties = new ArrayList<Element>();
72  
73  	@XmlAttribute(name = "class")
74  	private Class<? extends MessageBuilderFactory> clazz;
75  
76  	protected List<Element> getProperties() {
77  		return properties;
78  	}
79  
80  	protected Class<? extends MessageBuilderFactory> getClazz() {
81  		return clazz;
82  	}
83  
84  }