| 1 | |
package org.jtheque.core.managers.core; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.Managers; |
| 20 | |
import org.jtheque.core.managers.core.application.Application; |
| 21 | |
import org.jtheque.core.managers.core.io.Files; |
| 22 | |
import org.jtheque.core.managers.core.io.Folders; |
| 23 | |
import org.jtheque.core.managers.core.io.IFilesContainer; |
| 24 | |
import org.jtheque.core.managers.core.io.IFoldersContainer; |
| 25 | |
import org.jtheque.core.managers.error.IErrorManager; |
| 26 | |
import org.jtheque.core.managers.error.InternationalizedError; |
| 27 | |
import org.jtheque.core.managers.lifecycle.ILifeCycleManager; |
| 28 | |
import org.jtheque.core.managers.lifecycle.JThequeCoreTimer; |
| 29 | |
import org.jtheque.core.managers.lifecycle.LifeCycleManager; |
| 30 | |
import org.jtheque.core.managers.log.ILoggingManager; |
| 31 | |
import org.jtheque.core.managers.state.IStateManager; |
| 32 | |
import org.jtheque.core.managers.state.StateException; |
| 33 | |
import org.jtheque.utils.bean.Version; |
| 34 | |
|
| 35 | |
import java.util.ArrayList; |
| 36 | |
import java.util.Collection; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public final class Core implements ICore { |
| 44 | |
private static final String CORE_MESSAGES_FILE = "http://jtheque.developpez.com/public/messages/core.message"; |
| 45 | 0 | private static final Version VERSION = new Version("2.0.3.1"); |
| 46 | |
|
| 47 | 0 | private static final ICore CORE = new Core(); |
| 48 | |
|
| 49 | |
private final Collection<String> creditsMessage; |
| 50 | |
|
| 51 | |
private ILifeCycleManager lifeCycleManager; |
| 52 | |
|
| 53 | |
private Application application; |
| 54 | |
|
| 55 | |
private final IFoldersContainer foldersContainer; |
| 56 | |
private final IFilesContainer filesContainer; |
| 57 | |
|
| 58 | |
private CoreConfiguration configuration; |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
private Core() { |
| 64 | 0 | super(); |
| 65 | |
|
| 66 | 0 | foldersContainer = new Folders(); |
| 67 | 0 | filesContainer = new Files(); |
| 68 | |
|
| 69 | 0 | creditsMessage = new ArrayList<String>(5); |
| 70 | |
|
| 71 | 0 | creditsMessage.add("about.view.copyright"); |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
@Override |
| 75 | |
public Version getCoreCurrentVersion() { |
| 76 | 0 | return VERSION; |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public static ICore getInstance() { |
| 85 | 0 | return CORE; |
| 86 | |
} |
| 87 | |
|
| 88 | |
@Override |
| 89 | |
public void launchJThequeCore(Application application) { |
| 90 | 0 | this.application = application; |
| 91 | |
|
| 92 | 0 | JThequeCoreTimer.start(); |
| 93 | |
|
| 94 | 0 | Thread.currentThread().setName("JTheque Main Thread"); |
| 95 | |
|
| 96 | 0 | lifeCycleManager = new LifeCycleManager(); |
| 97 | 0 | lifeCycleManager.initCycles(); |
| 98 | 0 | lifeCycleManager.launchNextPhase(); |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
@Override |
| 102 | |
public String getCoreMessageFileURL() { |
| 103 | 0 | return CORE_MESSAGES_FILE; |
| 104 | |
} |
| 105 | |
|
| 106 | |
@Override |
| 107 | |
public void addCreditsMessage(String key) { |
| 108 | 0 | creditsMessage.add(key); |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public Collection<String> getCreditsMessage() { |
| 113 | 0 | return creditsMessage; |
| 114 | |
} |
| 115 | |
|
| 116 | |
@Override |
| 117 | |
public boolean isNotCompatibleWith(Version version) { |
| 118 | |
|
| 119 | 0 | Version version202 = new Version("2.0.2"); |
| 120 | 0 | return !(version.equals(version202) || version.isGreaterThan(version202)); |
| 121 | |
} |
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public Application getApplication() { |
| 125 | 0 | return application; |
| 126 | |
} |
| 127 | |
|
| 128 | |
@Override |
| 129 | |
public IFoldersContainer getFolders() { |
| 130 | 0 | return foldersContainer; |
| 131 | |
} |
| 132 | |
|
| 133 | |
@Override |
| 134 | |
public IFilesContainer getFiles() { |
| 135 | 0 | return filesContainer; |
| 136 | |
} |
| 137 | |
|
| 138 | |
@Override |
| 139 | |
public ILifeCycleManager getLifeCycleManager() { |
| 140 | 0 | return lifeCycleManager; |
| 141 | |
} |
| 142 | |
|
| 143 | |
@Override |
| 144 | |
public CoreConfiguration getConfiguration() { |
| 145 | 0 | if (configuration == null) { |
| 146 | 0 | configuration = Managers.getManager(IStateManager.class).getState(CoreConfiguration.class); |
| 147 | |
|
| 148 | 0 | if (configuration == null) { |
| 149 | 0 | initConfiguration(); |
| 150 | |
} |
| 151 | |
} |
| 152 | |
|
| 153 | 0 | return configuration; |
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
private void initConfiguration() { |
| 160 | |
try { |
| 161 | 0 | configuration = Managers.getManager(IStateManager.class).createState(CoreConfiguration.class); |
| 162 | 0 | } catch (StateException e) { |
| 163 | 0 | Managers.getManager(ILoggingManager.class).getLogger(getClass()).error(e); |
| 164 | 0 | configuration = new CoreConfiguration(); |
| 165 | 0 | Managers.getManager(IErrorManager.class).addError(new InternationalizedError("error.loading.configuration")); |
| 166 | 0 | } |
| 167 | |
|
| 168 | 0 | configuration.setDefaults(); |
| 169 | 0 | } |
| 170 | |
} |