View Javadoc
1   /*
2    * Copyright (c) 2002-2014, 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.myportal.business;
35  
36  import fr.paris.lutece.plugins.myportal.service.MyPortalPlugin;
37  import fr.paris.lutece.portal.service.plugin.Plugin;
38  import fr.paris.lutece.portal.service.plugin.PluginService;
39  import fr.paris.lutece.portal.service.spring.SpringContextService;
40  import fr.paris.lutece.util.ReferenceList;
41  
42  import java.util.List;
43  
44  /**
45   *
46   * This class provides instances management methods (create, find, ...) for Style objects
47   *
48   */
49  public final class ColumnStyleHome
50  {
51      // Static variable pointed at the DAO instance
52      private static final String BEAN_MYPORTAL_COLUMNSTYLEDAO = "myportal.columnStyleDAO";
53      private static Plugin _plugin = PluginService.getPlugin( MyPortalPlugin.PLUGIN_NAME );
54      private static IWidgetStyleDAO./../../../fr/paris/lutece/plugins/myportal/business/IWidgetStyleDAO.html#IWidgetStyleDAO">IWidgetStyleDAO _dao = (IWidgetStyleDAO) SpringContextService.getPluginBean( MyPortalPlugin.PLUGIN_NAME, BEAN_MYPORTAL_COLUMNSTYLEDAO );
55  
56      /**
57       * Private constructor - this class need not be instantiated
58       */
59      private ColumnStyleHome( )
60      {
61      }
62  
63      /**
64       * Generates a new primary key
65       * 
66       * @return The new primary key
67       */
68      public static int newPrimaryKey( )
69      {
70          return _dao.newPrimaryKey( _plugin );
71      }
72  
73      /**
74       * Create an instance of the style class
75       * 
76       * @param style
77       *            The instance of the Style which contains the informations to store
78       * @return The instance of style which has been created with its primary key.
79       */
80      public static Stylef="../../../../../../fr/paris/lutece/plugins/myportal/business/Style.html#Style">Style create( Style style )
81      {
82          _dao.insert( style, _plugin );
83  
84          return style;
85      }
86  
87      /**
88       * Update of the style which is specified in parameter
89       * 
90       * @param style
91       *            The instance of the Style which contains the data to store
92       * @return The instance of the style which has been updated
93       */
94      public static Stylef="../../../../../../fr/paris/lutece/plugins/myportal/business/Style.html#Style">Style update( Style style )
95      {
96          _dao.store( style, _plugin );
97  
98          return style;
99      }
100 
101     /**
102      * Remove the style whose identifier is specified in parameter
103      * 
104      * @param nStyleId
105      *            The style Id
106      */
107     public static void remove( int nStyleId )
108     {
109         _dao.delete( nStyleId, _plugin );
110     }
111 
112     // /////////////////////////////////////////////////////////////////////////
113     // Finders
114 
115     /**
116      * Returns an instance of a style whose identifier is specified in parameter
117      * 
118      * @param nKey
119      *            The style primary key
120      * @return an instance of Style
121      */
122     public static Style findByPrimaryKey( int nKey )
123     {
124         return _dao.load( nKey, _plugin );
125     }
126 
127     /**
128      * Load the data of all the style objects and returns them in form of a list
129      * 
130      * @return the list which contains the data of all the style objects
131      */
132     public static List<Style> getStylesList( )
133     {
134         return _dao.selectStylesList( _plugin );
135     }
136 
137     /**
138      * Load the data of all the style objects and returns them in form of a list
139      * 
140      * @return the list which contains the data of all the style objects
141      */
142     public static ReferenceList getStyles( )
143     {
144         ReferenceList list = new ReferenceList( );
145 
146         for ( Style style : _dao.selectStylesList( _plugin ) )
147         {
148             list.addItem( style.getId( ), style.getName( ) );
149         }
150 
151         return list;
152     }
153 }