4170 |
07 Mar 08 |
nicklas |
1 |
/** |
4479 |
05 Sep 08 |
jari |
$Id$ |
4170 |
07 Mar 08 |
nicklas |
3 |
|
4170 |
07 Mar 08 |
nicklas |
Copyright (C) Authors contributing to this file. |
4170 |
07 Mar 08 |
nicklas |
5 |
|
4170 |
07 Mar 08 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4170 |
07 Mar 08 |
nicklas |
Available at http://base.thep.lu.se/ |
4170 |
07 Mar 08 |
nicklas |
8 |
|
4170 |
07 Mar 08 |
nicklas |
BASE is free software; you can redistribute it and/or |
4170 |
07 Mar 08 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
4170 |
07 Mar 08 |
nicklas |
of the License, or (at your option) any later version. |
4170 |
07 Mar 08 |
nicklas |
13 |
|
4170 |
07 Mar 08 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4170 |
07 Mar 08 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4170 |
07 Mar 08 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4170 |
07 Mar 08 |
nicklas |
GNU General Public License for more details. |
4170 |
07 Mar 08 |
nicklas |
18 |
|
4170 |
07 Mar 08 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4170 |
07 Mar 08 |
nicklas |
21 |
*/ |
4170 |
07 Mar 08 |
nicklas |
22 |
package net.sf.basedb.util.extensions.xml; |
4170 |
07 Mar 08 |
nicklas |
23 |
|
4170 |
07 Mar 08 |
nicklas |
24 |
import java.lang.reflect.Method; |
4170 |
07 Mar 08 |
nicklas |
25 |
|
4170 |
07 Mar 08 |
nicklas |
26 |
/** |
4170 |
07 Mar 08 |
nicklas |
Interface for classes that wants to inspect/convert |
4170 |
07 Mar 08 |
nicklas |
parameters from the XML file before they are passed |
4170 |
07 Mar 08 |
nicklas |
to factory setter methods. |
4170 |
07 Mar 08 |
nicklas |
30 |
|
4170 |
07 Mar 08 |
nicklas |
<p> |
4170 |
07 Mar 08 |
nicklas |
Instances of this class are registered with an XML loader |
4170 |
07 Mar 08 |
nicklas |
with the {@link XmlLoader#addValueConverter(ValueConverter)} method. |
4170 |
07 Mar 08 |
nicklas |
Before a factory setter method is called, all registered |
4198 |
28 Mar 08 |
nicklas |
converters will get the chance to {@link #convert(String, Method)} |
4170 |
07 Mar 08 |
nicklas |
the parameter value from the XML file. The converters are |
4170 |
07 Mar 08 |
nicklas |
called in the order they are registered. |
4170 |
07 Mar 08 |
nicklas |
38 |
|
4170 |
07 Mar 08 |
nicklas |
<p> |
4170 |
07 Mar 08 |
nicklas |
A typical implementation of a converter is to check if the |
4170 |
07 Mar 08 |
nicklas |
setter method has been annotated with some specific annotation. |
4170 |
07 Mar 08 |
nicklas |
If, so the value is converted, otherwise it is returned without |
4170 |
07 Mar 08 |
nicklas |
modification. |
4170 |
07 Mar 08 |
nicklas |
44 |
|
4170 |
07 Mar 08 |
nicklas |
<pre class="code"> |
4170 |
07 Mar 08 |
nicklas |
// Add a prefix to all strings. |
4208 |
07 Apr 08 |
nicklas |
@Override |
4170 |
07 Mar 08 |
nicklas |
public String convert(String in, Method method) |
4170 |
07 Mar 08 |
nicklas |
49 |
{ |
4170 |
07 Mar 08 |
nicklas |
if (!method.isAnnotationPresent(AddPrefix.class)) return in; |
4170 |
07 Mar 08 |
nicklas |
return in == null ? PREFIX : PREFIX + in; |
4170 |
07 Mar 08 |
nicklas |
52 |
} |
4170 |
07 Mar 08 |
nicklas |
</pre> |
4170 |
07 Mar 08 |
nicklas |
54 |
|
4170 |
07 Mar 08 |
nicklas |
<p> |
4170 |
07 Mar 08 |
nicklas |
Note! Since each registered converter is invoked everytime a |
4170 |
07 Mar 08 |
nicklas |
factory setter method is about to be called, we recommend that |
4170 |
07 Mar 08 |
nicklas |
the {@link #convert(String, Method)} method is kept as quick |
4170 |
07 Mar 08 |
nicklas |
as possible. |
4170 |
07 Mar 08 |
nicklas |
60 |
|
4170 |
07 Mar 08 |
nicklas |
@author nicklas |
4170 |
07 Mar 08 |
nicklas |
@version 2.7 |
4198 |
28 Mar 08 |
nicklas |
@base.modified $Date:2008-03-20 12:15:25 +0100 (Thu, 20 Mar 2008) $ |
4170 |
07 Mar 08 |
nicklas |
64 |
*/ |
4170 |
07 Mar 08 |
nicklas |
65 |
public interface ValueConverter |
4170 |
07 Mar 08 |
nicklas |
66 |
{ |
4170 |
07 Mar 08 |
nicklas |
67 |
/** |
4208 |
07 Apr 08 |
nicklas |
Convert a value. |
4170 |
07 Mar 08 |
nicklas |
69 |
|
4170 |
07 Mar 08 |
nicklas |
@param in The value to convert |
4170 |
07 Mar 08 |
nicklas |
@param method The factory setter method |
4170 |
07 Mar 08 |
nicklas |
@return The converted or original value |
4170 |
07 Mar 08 |
nicklas |
73 |
*/ |
4170 |
07 Mar 08 |
nicklas |
74 |
public String convert(String in, Method method); |
4170 |
07 Mar 08 |
nicklas |
75 |
|
4170 |
07 Mar 08 |
nicklas |
76 |
} |