View Javadoc

1   /**
2    * This file Copyright (c) 2008-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.module.samples;
35  
36  import java.util.ArrayList;
37  import java.util.HashMap;
38  import java.util.List;
39  import java.util.Map;
40  
41  import org.slf4j.Logger;
42  import org.slf4j.LoggerFactory;
43  
44  import info.magnolia.module.ModuleLifecycle;
45  import info.magnolia.module.ModuleLifecycleContext;
46  
47  /**
48   * This is the configuration class of the samples module, it can implement ModuleLifecycle it there
49   * are some tasks to perform when starting/stopping the module.
50   * This class is loaded with what you have defined in the configuration in modules/samples/config
51   * nodedata get loaded into class variables (modules/samples/config/propertySample)
52   * content into list object (modules/samples/config/sampleList)
53   * contentnode into map object (modules/samples/config/sampleMap)
54   *
55   * by using nodedata 'class' you can specify the class it will turn into (see in this
56   * sample the list of dummy clases we have created: modules/samples/config/sampleList/ each item is an instance
57   * of Dummy class)
58   *
59   * @author tmiyar
60   *
61   */
62  public class SamplesModule implements ModuleLifecycle {
63  
64      final private static Logger log = LoggerFactory.getLogger(SamplesModule.class);
65  
66      private List items = new ArrayList();
67  
68      private Map sampleMap = new HashMap();
69  
70      private String sampleProperty;
71  
72      public void start(ModuleLifecycleContext moduleLifecycleContext) {
73          log.info("Samples module is starting");
74  
75      }
76  
77      public void stop(ModuleLifecycleContext moduleLifecycleContext) {
78          log.info("Samples module is stopping");
79  
80      }
81  
82      public List getItems() {
83          log.info("this is a node of type content");
84          return items;
85      }
86  
87      public void setItems(List items) {
88          this.items = items;
89      }
90  
91      public void addItem(Dummy dummy) {
92          log.info("Adds the items to the list, a 'Dummy' class:" + dummy.getName());
93          this.items.add(dummy);
94      }
95  
96      public Map getSampleMap() {
97          log.info("This is a node of type content node");
98          return sampleMap;
99      }
100 
101     public void setSampleMap(Map sampleMap) {
102         this.sampleMap = sampleMap;
103     }
104 
105     public String getSampleProperty() {
106         log.info("This is a node of type node data: " + sampleProperty);
107         return sampleProperty;
108     }
109 
110     public void setSampleProperty(String sampleProperty) {
111         this.sampleProperty = sampleProperty;
112     }
113 
114 }