View Javadoc

1   /*
2    * ----------------------------------------------------------------------
3    * Copyright (C) 2009 Enrique Lara (k957@68k.org)
4    *
5    * TinLizard is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public License
7    * as published by the Free Software Foundation; either version 3.0
8    * of the License, or (at your option) any later version.
9    *
10   * TinLizard is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with TinLizard. If not, see http://www.gnu.org/licenses/.
17   * ----------------------------------------------------------------------
18   */
19  package tinlizard.model;
20  
21  import tinlizard.dao.MashDao;
22  import tinlizard.dao.ScmDao;
23  
24  import tinlizard.dao.jpa.JpaDao;
25  
26  import tinlizard.util.Messages;
27  
28  import java.lang.management.ManagementFactory;
29  import java.util.Date;
30  
31  import javax.management.MBeanServer;
32  import javax.management.ObjectName;
33  
34  import org.apache.log4j.Logger;
35  
36  /***
37   * The Object Model entry point.
38   */
39  public final class TinLizard implements TinLizardMBean {
40      private static final Logger LOG = Logger.getLogger(TinLizard.class);
41      private static TinLizard instance = null;
42      private Integer id = 1;
43      private String name = Messages.AppName();
44      private final TinLizardConfig config;
45  
46      private TinLizard(final TinLizardConfig config) {
47          this.config = config;
48      }
49  
50      public Integer getId() {
51          return this.id;
52      }
53  
54      public String getName() {
55          return this.name;
56      }
57  
58      public Date getCreated() {
59          return this.config.getCreated();
60      }
61  
62      public String getCreatedBy() {
63          return "k957";
64      }
65  
66      public Date getLastModified() {
67          return this.config.getLastModified();
68      }
69  
70      public String getLastModifiedBy() {
71          return getName();
72      }
73  
74      public String getVersion() {
75          return this.config.getVersion();
76      }
77  
78      public static TinLizard getInstance() {
79          return instance;
80      }
81  
82      public static synchronized void initialize(final TinLizardConfig config) {
83          if (instance == null) {
84              instance = new TinLizard(config);
85              JpaDao.initialize(config);
86  
87              if (System.getProperties().containsKey("com.sun.management.jmxremote")) {
88                  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
89  
90                  try {
91                      ObjectName appName = new ObjectName(instance.getName() + ":name=" + Messages.mbean_app());
92                      mbs.registerMBean(instance, appName);
93  
94                      ObjectName configName = new ObjectName(instance.getName() + ":name=" + Messages.mbean_config());
95                      mbs.registerMBean(config, configName);
96                  } catch (Exception e) {
97                      throw new RuntimeException(Messages.error_0400(), e);
98                  }
99              }
100 
101             if (config.isIndexOnStartUp()) {
102                 LOG.debug("Index on Startup.");
103                 instance.indexAll();
104             }
105         }
106     }
107 
108     public MashDao getMashDao() {
109         return config.getMashDao();
110     }
111 
112     public ScmDao getScmDao() {
113         return config.getScmDao();
114     }
115 
116     public void indexAll() {
117         Codeline.indexAll();
118         Dependency.indexAll();
119         Dependency.indexAll();
120         Project.indexAll();
121         User.indexAll();
122         View.indexAll();
123     }
124 }