View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.codewizard.business;
35  
36  import fr.paris.lutece.plugins.codewizard.service.JavaTypeService;
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  /**
41   * This class provide the Business Object object
42   */
43  public class BusinessObject
44  {
45      // Constants
46      private String _strPackageName;
47      private String _strClassName;
48      private String _strTable;
49      private String _strIdColumnName;
50      private String _strPluginName;
51      private List<ObjectAttribute> _attributes = new ArrayList<ObjectAttribute>( );
52  
53      /**
54       * Sets the PackageName
55       *
56       * @param strPackageName
57       *            The PackageName
58       */
59      public void setPackageName( String strPackageName )
60      {
61          _strPackageName = strPackageName;
62      }
63  
64      /**
65       * Returns the PackageName
66       *
67       * @return The PackageName
68       */
69      public String getPackageName( )
70      {
71          return _strPackageName;
72      }
73  
74      /**
75       * Sets the ClassName
76       *
77       * @param strClassName
78       *            The ClassName
79       */
80      public void setClassName( String strClassName )
81      {
82          _strClassName = strClassName;
83      }
84  
85      /**
86       * Returns the ClassName
87       *
88       * @return The ClassName
89       */
90      public String getClassName( )
91      {
92          return _strClassName;
93      }
94  
95      /**
96       * Sets the Table
97       *
98       * @param strTable
99       *            The Table
100      */
101     public void setTable( String strTable )
102     {
103         _strTable = strTable;
104     }
105 
106     /**
107      * Returns the Table
108      *
109      * @return The Table
110      */
111     public String getTable( )
112     {
113         return _strTable;
114     }
115 
116     /**
117      * Sets the IdColumnName
118      *
119      * @param strIdColumnName
120      *            The IdColumnName
121      */
122     public void setIdColumnName( String strIdColumnName )
123     {
124         _strIdColumnName = strIdColumnName;
125     }
126 
127     /**
128      * Returns the IdColumnName
129      *
130      * @return The IdColumnName
131      */
132     public String getIdColumnName( )
133     {
134         return _strIdColumnName;
135     }
136 
137     /*
138      * Add Attributes
139      * 
140      * @param attribute The ObjectAttribute
141      */
142     public void addAttribute( ObjectAttribute attribute )
143     {
144         _attributes.add( attribute );
145     }
146 
147     /**
148      * Returns the select Sql request
149      * 
150      * @return null
151      */
152     public String getSelectSQLRequest( )
153     {
154         return null;
155     }
156 
157     /**
158      * Returns a list of attributes
159      * 
160      * @return _attributes
161      */
162     public List<ObjectAttribute> getAttributes( )
163     {
164         return _attributes;
165     }
166     
167     /**
168      * Return a valid list of attribute for DAO
169      * @return The list
170      */
171     public List<ObjectAttribute> getDaoAttributes( )
172     {
173         List<ObjectAttribute> list = new ArrayList<>();
174         for( ObjectAttribute attribute :  _attributes )
175         {
176             if( attribute.isDaoType() )
177             {
178                 list.add( attribute );
179             }
180         }
181         return list;
182     }
183 
184     /**
185      * The list of import needed by object's attributes
186      * @return The list of import
187      */
188     public List<String> getImports( )
189     {
190         List<String> list = new ArrayList<>();
191         for( ObjectAttribute attribute :  _attributes )
192         {
193             String strImport = JavaTypeService.getImport( attribute.getType() );
194             if( strImport != null )
195             {
196                 list.add( strImport );
197             }
198         }
199         return list;
200     }
201 
202     /**
203      * Returns the InstanceName
204      *
205      * @return The InstanceName
206      */
207     public String getInstanceName( )
208     {
209         String strInstanceName = _strClassName.substring( 0, 1 ).toLowerCase( ) + _strClassName.substring( 1, _strClassName.length( ) );
210 
211         return strInstanceName;
212     }
213 
214     /**
215      * Returns the PluginName
216      * 
217      * @return The PluginName
218      */
219     public String getPluginName( )
220     {
221         return _strPluginName;
222     }
223 
224     /**
225      * Sets the PluginName
226      * 
227      * @param strPluginName
228      *            The PluginName
229      */
230     public void setPluginName( String strPluginName )
231     {
232         _strPluginName = strPluginName;
233     }
234 }