com.ibm.commons.Platform Maven / Gradle / Ivy
The newest version!
/*
* © Copyright IBM Corp. 2012-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.ibm.commons;
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import com.ibm.commons.extension.ExtensionManager;
import com.ibm.commons.log.LogMgrFactory;
import com.ibm.commons.platform.GenericEclipsePlatform;
import com.ibm.commons.platform.GenericPlatform;
import com.ibm.commons.platform.GenericWebAppServerPlatform;
import com.ibm.commons.platform.IPlatformFactory;
import com.ibm.commons.util.StringUtil;
import com.ibm.commons.util.io.StreamUtil;
/**
* Access to platform specific services.
*
* There is one platform object (singleton) for the JVM. It encapsulate the services for the
* underlying platform.
* This platform object is automatically instantiated when necessary.
*
* @ibm-api
*/
public abstract class Platform {
private static Platform instance; //singleton
// static {
// instance = createPlatform();
// instance.initialize();
// //System.out.println("Platform: '" + instance.getName() + "'"); // $NON-NLS-1$
// }
/**
* Return the platform singleton.
* @return the Platform singleton
* @ibm-api
*/
public static Platform getInstance() {
if(instance == null) {
synchronized (Platform.class) {
if(instance == null) {
instance = createPlatform();
instance.initialize();
//System.out.println("Platform: '" + instance.getName() + "'"); // $NON-NLS-1$
}
}
}
return instance;
}
// --------------------------------------------------------------------
public static final String FACTORY_CLASS = "com.ibm.commons.platform.Factory"; // $NON-NLS-1$
// Server side platform classes
public static final String PORTAL6_PLATFORM_CLASS = "com.ibm.xsp.portlet.platform.PortalPlatform"; // $NON-NLS-1$
// public static final String TOMCAT_PLATFORM_CLASS = "com.ibm.xfaces.platform.TomcatPlatform"; // $NON-NLS-1$
// public static final String WASCE_PLATFORM_CLASS = "com.ibm.xfaces.platform.WasCEPlatform"; // $NON-NLS-1$
// Entry if needed is the System properties
public static final String PLATFORM_PROPERTY_KEY = "com.ibm.commons.platform"; // $NON-NLS-1$
// Properties file storing meta info
private static final String PLATFORM_PROPERTIES = "META-INF/com.ibm.commons.Platform.properties"; // $NON-NLS-1$
// In order to force the platform in some specific cases
// Must be called before the first access to the platform
public static void initPlatform(Platform platform) {
synchronized (Platform.class) {
if(instance!=null) {
throw new IllegalStateException("Platform Object has already been set"); // $NON-NLS-1$
}
instance = platform;
instance.initialize();
//System.out.println("Platform forced to: '" + instance.getName() + "'"); // $NLS-Platform.Platform-1$
}
}
private static Platform createPlatform() {
// 1- Use the property to find the Platform
String prop = System.getProperty(PLATFORM_PROPERTY_KEY);
if(StringUtil.isNotEmpty(prop)) {
Platform platform = loadPlatform(prop);
if(platform!=null) {
return platform;
}
}
// 2- Use an extension point
try {
List