001 /*
002 * ----------------------------------------------------------------------
003 * Copyright (C) 2009 Enrique Lara (k957@68k.org)
004 *
005 * TinLizard is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public License
007 * as published by the Free Software Foundation; either version 3.0
008 * of the License, or (at your option) any later version.
009 *
010 * TinLizard is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with TinLizard. If not, see http://www.gnu.org/licenses/.
017 * ----------------------------------------------------------------------
018 */
019 package tinlizard.model;
020
021 import tinlizard.dao.MashDao;
022 import tinlizard.dao.ScmDao;
023
024 import tinlizard.dao.jpa.JpaDao;
025
026 import tinlizard.util.Messages;
027
028 import java.lang.management.ManagementFactory;
029 import java.util.Date;
030
031 import javax.management.MBeanServer;
032 import javax.management.ObjectName;
033
034 import org.apache.log4j.Logger;
035
036 /**
037 * The Object Model entry point.
038 */
039 public final class TinLizard implements TinLizardMBean {
040 private static final Logger LOG = Logger.getLogger(TinLizard.class);
041 private static TinLizard instance = null;
042 private Integer id = 1;
043 private String name = Messages.AppName();
044 private final TinLizardConfig config;
045
046 private TinLizard(final TinLizardConfig config) {
047 this.config = config;
048 }
049
050 public Integer getId() {
051 return this.id;
052 }
053
054 public String getName() {
055 return this.name;
056 }
057
058 public Date getCreated() {
059 return this.config.getCreated();
060 }
061
062 public String getCreatedBy() {
063 return "k957";
064 }
065
066 public Date getLastModified() {
067 return this.config.getLastModified();
068 }
069
070 public String getLastModifiedBy() {
071 return getName();
072 }
073
074 public String getVersion() {
075 return this.config.getVersion();
076 }
077
078 public static TinLizard getInstance() {
079 return instance;
080 }
081
082 public static synchronized void initialize(final TinLizardConfig config) {
083 if (instance == null) {
084 instance = new TinLizard(config);
085 JpaDao.initialize(config);
086
087 if (System.getProperties().containsKey("com.sun.management.jmxremote")) {
088 MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
089
090 try {
091 ObjectName appName = new ObjectName(instance.getName() + ":name=" + Messages.mbean_app());
092 mbs.registerMBean(instance, appName);
093
094 ObjectName configName = new ObjectName(instance.getName() + ":name=" + Messages.mbean_config());
095 mbs.registerMBean(config, configName);
096 } catch (Exception e) {
097 throw new RuntimeException(Messages.error_0400(), e);
098 }
099 }
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 }