View Javadoc

1   /*
2    * Copyright (c) 2001-2005,
3    * RedVerst Group, ISP RAS http://www.ispras.ru
4    * All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions are met:
8    *
9    * 1. Redistributions of source code must retain the above copyright notice, this
10   *    list of conditions and the following disclaimer.
11   *
12   * 2. Redistributions in binary form must reproduce the above copyright notice,
13   *    this list of conditions and the following disclaimer in the documentation
14   *    and/or other materials provided with the distribution.
15   *
16   * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS"
17   *    may not be used to endorse or promote products derived from this software
18   *    without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24   * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   */
31  
32  package com.unitesk.atp.treedl;
33  
34  import com.unitesk.atp.tool.Plugin;
35  import com.unitesk.atp.messages.*;
36  
37  public class CreatorAction extends FileGeneratorAction
38  {
39      /***
40       * {@inheritDoc}
41       */
42      public String getVersion()
43      {
44          return getRevision( "$Revision: 1.7 $" );
45      }
46  
47      public void process( com.unitesk.atp.tree.tool.Tree tree )
48      {
49          setCurrentTree( tree );
50  
51          process( getProperty( "check.action", "check" ) );
52  
53          // TODO: Factory can be generated only for tree description module
54          
55          String output_dir = getProperty( "output.dir", "." );
56  
57          boolean update_mode = getProperty( "update", "true" ).equals( "true" );
58  
59          String action_name = getName();
60          String language_name = ((TDL_Module)tree).getLanguage().getName();
61          String generator_name = language_name + "_" + action_name + "_interface";
62  
63          String interfaceCreatorName = getProperty( "interface.name" );
64  
65          if( interfaceCreatorName != null )
66          {
67              TextGenerator interfaceCreatorGenerator
68                  = (TextGenerator)getPlugin( generator_name );
69  
70              if( interfaceCreatorGenerator == null )
71              {
72                  mbox.error( new NameNotFoundMessage( null
73                                                     , null
74                                                     ,  mbox
75                                                       .getStringManager()
76                                                       .getString( TextGenerator.class
77                                                                 , "message.generator"
78                                                                 )
79                                                     , generator_name
80                                                     )
81                            );
82                  return;
83              }
84  
85              interfaceCreatorGenerator.setOutClassName( interfaceCreatorName );
86              interfaceCreatorGenerator.setOutDir( output_dir );
87              interfaceCreatorGenerator.setActionName( action_name );
88              
89              generateFile( interfaceCreatorGenerator.getOutFile() 
90                          , update_mode
91                          , interfaceCreatorGenerator
92                          );
93          }
94  
95          generator_name = language_name + "_" + action_name + "_null";
96  
97          String nullCreatorName = getProperty( "null.name" );
98  
99          if( nullCreatorName != null )
100         {
101             if( interfaceCreatorName == null )
102             {
103                 mbox.error( new NameNotFoundMessage( null
104                                                    , null
105                                                    ,  mbox
106                                                      .getStringManager()
107                                                      .getString( Plugin.class
108                                                                , "message.plugin_property"
109                                                                )
110                                                    , "interface.name"
111                                                    )
112                           );
113                 return;
114             }
115             TextGenerator nullCreatorGenerator
116                 = (TextGenerator)getPlugin( generator_name );
117             if( nullCreatorGenerator == null )
118             {
119                 mbox.error( new NameNotFoundMessage( null
120                                                    , null
121                                                    ,  mbox
122                                                      .getStringManager()
123                                                      .getString( TextGenerator.class
124                                                                , "message.generator"
125                                                                )
126                                                    , generator_name
127                                                    )
128                           );
129                 return;
130             }
131             nullCreatorGenerator.setOutClassName( nullCreatorName );
132             nullCreatorGenerator.addImplementedInterface( interfaceCreatorName );
133             nullCreatorGenerator.setOutDir( output_dir );
134             nullCreatorGenerator.setActionName( action_name );
135 
136             generateFile( nullCreatorGenerator.getOutFile()
137                         , update_mode
138                         , nullCreatorGenerator
139                         );
140         }
141 
142         generator_name = language_name + "_" + action_name + "_node";
143         String nodeCreatorName = getProperty( "node.name" );
144 
145         if( nodeCreatorName != null )
146         {
147             if( interfaceCreatorName == null )
148             {
149                 mbox.error( new NameNotFoundMessage( null
150                                                    , null
151                                                    ,  mbox
152                                                      .getStringManager()
153                                                      .getString( Plugin.class
154                                                                , "message.plugin_property"
155                                                                )
156                                                    , "interface.name"
157                                                    )
158                           );
159                 return;
160             }
161             TextGenerator nodeCreatorGenerator
162                 = (TextGenerator)getPlugin( generator_name );
163             if( nodeCreatorGenerator == null )
164             {
165                 mbox.error( new NameNotFoundMessage( null
166                                                    , null
167                                                    ,  mbox
168                                                      .getStringManager()
169                                                      .getString( TextGenerator.class
170                                                                , "message.generator"
171                                                                )
172                                                    , generator_name
173                                                    )
174                           );
175                 return;
176             }
177             nodeCreatorGenerator.setOutClassName( nodeCreatorName );
178             nodeCreatorGenerator.addImplementedInterface( interfaceCreatorName );
179             nodeCreatorGenerator.setOutDir( output_dir );
180             nodeCreatorGenerator.setActionName( action_name );
181             
182             generateFile( nodeCreatorGenerator.getOutFile()
183                         , update_mode
184                         , nodeCreatorGenerator
185                         );
186         }
187     }
188 }