1 /*
2 * Copyright 2005 The Codehaus.
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.codehaus.mojo.castor;
17
18 import java.util.Iterator;
19 import java.util.Map;
20
21 import org.apache.maven.plugin.MojoExecutionException;
22 import org.apache.maven.plugin.MojoFailureException;
23 import org.apache.maven.plugins.annotations.Parameter;
24
25 /**
26 * A mojo that uses Castor MappingTool to generate mapping files from a set of Classes. <a
27 * href="http://castor.codehaus.org/javadoc/org/exolab/castor/tools/MappingTool.html"> MappingTool</a>.
28 *
29 * @goal mappings
30 * @phase process-classes
31 * @author nicolas <nicolas@apache.org>
32 */
33 public class MappingsMojo
34 extends AbstractMappingMojo
35 {
36 /**
37 * A set of Java classes for which a mapping file should be generated.
38 */
39 @Parameter(property = "classes", required = true)
40 private Map<String, String> classes;
41
42 /**
43 * A Java class name.
44 */
45 private String className;
46
47 /**
48 * Name of the mapping file to be generated.
49 */
50 private String mappingName;
51
52 /**
53 * {@inheritDoc}
54 *
55 * @see org.apache.maven.plugin.Mojo#execute()
56 */
57 public void execute()
58 throws MojoExecutionException, MojoFailureException
59 {
60 if ( classes.isEmpty() )
61 {
62 getLog().warn( "No mapping set" );
63 }
64
65 for ( Iterator<Map.Entry<String, String>> iterator = classes.entrySet().iterator(); iterator.hasNext(); )
66 {
67 Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
68 className = (String) entry.getKey();
69 mappingName = (String) entry.getValue();
70 super.execute();
71 }
72 }
73
74 /**
75 * Returns the class name.
76 *
77 * @return the classname
78 */
79 protected String getClassName()
80 {
81 return className;
82 }
83
84 /**
85 * Returns the mapping file name.
86 *
87 * @return the mappingName
88 */
89 protected String getMappingName()
90 {
91 return mappingName;
92 }
93 }