View Javadoc
1   /*
2    * #%L
3    * EUGene :: Java templates
4    * %%
5    * Copyright (C) 2004 - 2011 CodeLutin, Tony Chemit
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  package org.nuiton.eugene.java;
23  
24  
25  /*{generator option: parentheses = false}*/
26  /*{generator option: writeString = +}*/
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  import org.codehaus.plexus.component.annotations.Component;
31  import org.nuiton.eugene.EugeneCoreTagValues;
32  import org.nuiton.eugene.Template;
33  import org.nuiton.eugene.models.object.ObjectModelEnumeration;
34  import org.nuiton.eugene.models.object.ObjectModelPackage;
35  
36  import java.util.Collection;
37  
38  /**
39   * JavaEnumerationTransformer generates a enumeration for enuration with
40   * stereotype enumeration.
41   *
42   * @author Tony Chemit - chemit@codelutin.com
43   * @since 2.5
44   */
45  @Component(role = Template.class, hint = "org.nuiton.eugene.java.JavaEnumerationTransformer")
46  public class JavaEnumerationTransformer extends ObjectModelTransformerToJava {
47  
48      private static final Log log =
49              LogFactory.getLog(JavaEnumerationTransformer.class);
50  
51      @Override
52      public void transformFromEnumeration(ObjectModelEnumeration input) {
53          if (!canGenerate(input)) {
54  
55              if (log.isDebugEnabled()) {
56                  log.debug("Skip generation for " + input.getQualifiedName());
57              }
58              return;
59          }
60  
61          ObjectModelEnumeration output =
62                  createEnumeration(input.getName(), input.getPackageName());
63  
64          if (log.isDebugEnabled()) {
65              log.debug("will generate " + output.getQualifiedName());
66          }
67  
68          Collection<String> literals = input.getLiterals();
69  
70          for (String literal : literals) {
71              addLiteral(output, literal);
72          }
73      }
74  
75      protected boolean canGenerate(ObjectModelEnumeration input) {
76          ObjectModelPackage aPackage = getPackage(input);
77          boolean b = !EugeneCoreTagValues.isSkip(input, aPackage);
78          if (b) {
79  
80              // check if not found in class-path
81              b = !getResourcesHelper().isJavaFileInClassPath(input.getQualifiedName());
82          }
83          return b;
84      }
85  }