View Javadoc

1   package org.codehaus.modello.plugins.xml.metadata;
2   
3   /*
4    * Copyright (c) 2004, Codehaus.org
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  
25  import java.util.Map;
26  
27  import org.codehaus.modello.metadata.AbstractMetadataPlugin;
28  import org.codehaus.modello.metadata.AssociationMetadata;
29  import org.codehaus.modello.metadata.ClassMetadata;
30  import org.codehaus.modello.metadata.FieldMetadata;
31  import org.codehaus.modello.metadata.InterfaceMetadata;
32  import org.codehaus.modello.metadata.MetadataPlugin;
33  import org.codehaus.modello.metadata.ModelMetadata;
34  import org.codehaus.modello.model.Model;
35  import org.codehaus.modello.model.ModelAssociation;
36  import org.codehaus.modello.model.ModelClass;
37  import org.codehaus.modello.model.ModelField;
38  import org.codehaus.modello.model.ModelInterface;
39  
40  /**
41   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
42   * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
43   */
44  public class XmlMetadataPlugin
45      extends AbstractMetadataPlugin
46      implements MetadataPlugin
47  {
48      public static final String XML_ATTRIBUTE = "xml.attribute";
49  
50      public static final String XML_CONTENT = "xml.content";
51  
52      public static final String XML_FORMAT = "xml.format";
53  
54      public static final String XML_ITEMS_STYLE = "xml.itemsStyle";
55  
56      public static final String XML_MAP_STYLE = "xml.mapStyle";
57  
58      public static final String XML_NAMESPACE = "xml.namespace";
59  
60      public static final String XML_REFERENCE = "xml.reference";
61  
62      public static final String XML_SCHEMA_LOCATION = "xml.schemaLocation";
63  
64      public static final String XML_TAG_NAME = "xml.tagName";
65  
66      public static final String XML_STANDALONE_READ = "xml.standaloneRead";
67  
68      public static final String XML_TRIM = "xml.trim";
69  
70      public static final String XML_TRANSIENT = "xml.transient";
71  
72      public static final String XML_INSERT_PARENT_FIELDS_UP_TO = "xml.insertParentFieldsUpTo";
73  
74      // ----------------------------------------------------------------------
75      // Map to Metadata
76      // ----------------------------------------------------------------------
77  
78      public ModelMetadata getModelMetadata( Model model, Map<String, String> data )
79      {
80          XmlModelMetadata metadata = new XmlModelMetadata();
81  
82          metadata.setNamespace( getString( data, XML_NAMESPACE ) );
83  
84          metadata.setSchemaLocation( getString( data, XML_SCHEMA_LOCATION ) );
85  
86          return metadata;
87      }
88  
89      public ClassMetadata getClassMetadata( ModelClass clazz, Map<String, String> data )
90      {
91          XmlClassMetadata metadata = new XmlClassMetadata();
92  
93          metadata.setTagName( getString( data, XML_TAG_NAME ) );
94  
95          metadata.setStandaloneRead( getBoolean( data, XML_STANDALONE_READ, false ) );
96  
97          return metadata;
98      }
99  
100     public InterfaceMetadata getInterfaceMetadata( ModelInterface iface, Map<String, String> data )
101     {
102         return new XmlInterfaceMetadata();
103     }
104 
105     public FieldMetadata getFieldMetadata( ModelField field, Map<String, String> data )
106     {
107         XmlFieldMetadata metadata = new XmlFieldMetadata();
108 
109         metadata.setAttribute( getBoolean( data, XML_ATTRIBUTE, false ) );
110 
111         metadata.setContent( getBoolean( data, XML_CONTENT, false ) );
112 
113         metadata.setTrim( getBoolean( data, XML_TRIM, true ) );
114 
115         metadata.setTagName( getString( data, XML_TAG_NAME ) );
116 
117         metadata.setFormat( getString( data, XML_FORMAT ) );
118 
119         metadata.setTransient( getBoolean( data, XML_TRANSIENT, false ) );
120 
121         metadata.setInsertParentFieldsUpTo( getString( data, XML_INSERT_PARENT_FIELDS_UP_TO ) );
122 
123         return metadata;
124     }
125 
126     public AssociationMetadata getAssociationMetadata( ModelAssociation association, Map<String, String> data )
127     {
128         XmlAssociationMetadata metadata = new XmlAssociationMetadata();
129 
130         metadata.setTagName( getString( data, XML_TAG_NAME ) );
131 
132         metadata.setItemsStyle( getString( data, XML_ITEMS_STYLE ) );
133 
134         metadata.setMapStyle( getString( data, XML_MAP_STYLE ) );
135 
136         metadata.setReference( getBoolean( data, XML_REFERENCE, false ) );
137 
138         return metadata;
139     }
140 }