KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > datatype > convertor > BeanConvertorBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.forms.datatype.convertor;
17
18 import org.apache.cocoon.forms.FormsConstants;
19 import org.apache.cocoon.forms.util.DomHelper;
20
21 import org.w3c.dom.Element JavaDoc;
22
23
24 /**
25  * Creates {@link BeanConvertor}s
26  *
27  * <p>
28  * The optional &lt;fd:bean&gt;FQCN&lt;/fd:bean&gt; attribute is used to give
29  * this convertor a hint of which concrete bean class we are going to work with.
30  * If this attribute is not specified java.lang.Object is used.
31  * <p>
32  * Sometimes the toString() method doesn't give a good representation of a
33  * Java Bean suited for selection list IDs. For this an optional
34  * &lt;fd:id-path&gt;jx-path&lt;/fd:id-path&gt; attribute can be specified to
35  * have this convertor to use a different string representation.
36  * </p>
37  *
38  * @author <a HREF="mailto:giacomo@apache.org">Giacomo Pati</a>
39  * @version $Id$
40  */

41 public class BeanConvertorBuilder
42     implements ConvertorBuilder
43 {
44     //~ Methods ----------------------------------------------------------------
45

46     /**
47      * Build a {@link BeanConvertor}
48      *
49      * @param configElement The configuration element
50      *
51      * @return An initialized {@link Convertor}
52      *
53      * @throws Exception In case of failure
54      */

55     public Convertor build( final Element JavaDoc configElement )
56         throws Exception JavaDoc
57     {
58         if( configElement == null )
59         {
60             return null;
61         }
62
63         final Element JavaDoc beanEl =
64             DomHelper.getChildElement( configElement, FormsConstants.DEFINITION_NS,
65                                        "bean", false );
66         final String JavaDoc clazz =
67             ( ( beanEl == null ) ? Object JavaDoc.class.getName( )
68               : beanEl.getFirstChild( ).getNodeValue( ) );
69         final Element JavaDoc idPathEl =
70             DomHelper.getChildElement( configElement, FormsConstants.DEFINITION_NS,
71                                        "id-path", false );
72         final String JavaDoc idPath =
73             ( ( idPathEl != null )
74               ? idPathEl.getFirstChild( ).getNodeValue( ) : null );
75         final BeanConvertor convertor = new BeanConvertor( clazz, idPath );
76
77         return convertor;
78     }
79 }
80
Popular Tags