/******************************************************************************* * Copyright (c) 2010 Eteration A.S. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation * - This code is based on WTP SDK frameworks and Tomcat Server Adapters * org.eclipse.jst.server.core * org.eclipse.jst.server.ui * * Naci Dai and Murat Yener, Eteration A.S. *******************************************************************************/ package org.eclipse.libra.framework.core; import java.util.HashMap; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.launching.IVMInstall; import org.eclipse.jdt.launching.IVMInstallType; import org.eclipse.jdt.launching.JavaRuntime; import org.eclipse.wst.server.core.IRuntimeType; public abstract class FrameworkDelegate extends org.eclipse.wst.server.core.model.RuntimeDelegate { protected static final String PROP_VM_INSTALL_TYPE_ID = "vm-install-type-id"; protected static final String PROP_VM_INSTALL_ID = "vm-install-id"; protected static Map<Object, Object> sdkMap = new HashMap<Object, Object>(2); public FrameworkDelegate() { super(); } protected String getVMInstallTypeId() { return getAttribute(PROP_VM_INSTALL_TYPE_ID, (String) null); } protected String getVMInstallId() { return getAttribute(PROP_VM_INSTALL_ID, (String) null); } public boolean isUsingDefaultJRE() { return getVMInstallTypeId() == null; } public IVMInstall getVMInstall() { if (getVMInstallTypeId() == null) return JavaRuntime.getDefaultVMInstall(); try { IVMInstallType vmInstallType = JavaRuntime .getVMInstallType(getVMInstallTypeId()); IVMInstall[] vmInstalls = vmInstallType.getVMInstalls(); int size = vmInstalls.length; String id = getVMInstallId(); for (int i = 0; i < size; i++) { if (id.equals(vmInstalls[i].getId())) return vmInstalls[i]; } } catch (Exception e) { // ignore } return null; } public abstract IStatus verifyLocation() ; //public abstract IStatus validate(); @Override public void setDefaults(IProgressMonitor monitor) { IRuntimeType type = getRuntimeWorkingCopy().getRuntimeType(); getRuntimeWorkingCopy() .setLocation( new Path(FrameworkCorePlugin.getPreference("location"+ type.getId()))); } public void setVMInstall(IVMInstall vmInstall) { if (vmInstall == null) { setVMInstall(null, null); } else setVMInstall(vmInstall.getVMInstallType().getId(), vmInstall.getId()); } protected void setVMInstall(String typeId, String id) { if (typeId == null) setAttribute(PROP_VM_INSTALL_TYPE_ID, (String) null); else setAttribute(PROP_VM_INSTALL_TYPE_ID, typeId); if (id == null) setAttribute(PROP_VM_INSTALL_ID, (String) null); else setAttribute(PROP_VM_INSTALL_ID, id); } }