blob: 266900b7e3b85fab2a1c4fb89f536c5e1ecb7f62 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 Chase Technology Ltd - http://www.chasetechnology.co.uk
* 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:
* Doug Satchwell (Chase Technology Ltd) - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.xsl.internal.launching;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.wst.xsl.launching.IFeature;
public class Feature implements IFeature, Comparable<Object>
{
private final String uri;
private final String description;
private final String type;
public Feature(String uri, String type, String description)
{
this.uri = uri;
this.type = type;
this.description = description;
}
public String getDescription()
{
return description;
}
public String getType()
{
return type;
}
public String getURI()
{
return uri;
}
public IStatus validateValue(String value)
{
IStatus status = null;
if (TYPE_BOOLEAN.equals(type))
{
boolean valid = "true".equals(value) || "false".equals(value); //$NON-NLS-1$ //$NON-NLS-2$
if (!valid)
status = new Status(IStatus.ERROR, LaunchingPlugin.PLUGIN_ID, 0, Messages.getString("Feature.2"), null); //$NON-NLS-1$
}
else if (TYPE_INT.equals(type))
{
try
{
Integer.parseInt(value);
}
catch (NumberFormatException e)
{
status = new Status(IStatus.ERROR, LaunchingPlugin.PLUGIN_ID, 0, Messages.getString("Feature.1"), null); //$NON-NLS-1$
}
}
else if (TYPE_DOUBLE.equals(type))
{
try
{
Double.parseDouble(value);
}
catch (NumberFormatException e)
{
status = new Status(IStatus.ERROR, LaunchingPlugin.PLUGIN_ID, 0, Messages.getString("Feature.0"), null); //$NON-NLS-1$
}
}
else if (TYPE_FLOAT.equals(type))
{
try
{
Float.parseFloat(value);
}
catch (NumberFormatException e)
{
status = new Status(IStatus.ERROR, LaunchingPlugin.PLUGIN_ID, 0, Messages.getString("Feature.5"), null); //$NON-NLS-1$
}
}
else if (TYPE_CLASS.equals(type) || TYPE_OBJECT.equals(type))
{
status = JavaConventions.validateJavaTypeName(value);
}
return status;
}
public int compareTo(Object o)
{
if (o instanceof IFeature)
{
IFeature f = (IFeature) o;
return f.getURI().compareTo(getURI());
}
return 0;
}
}