Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 338494b9f859cb6203803d81ba3b345357147e3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2007 Intel Corporation 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:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.internal.buildproperties;

import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyType;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;

public class BuildProperty implements IBuildProperty{
	private IBuildPropertyType fType;
	private IBuildPropertyValue fValue;

	BuildProperty(String property) throws CoreException {
		int index = property.indexOf(BuildPropertyManager.PROPERTY_VALUE_SEPARATOR);
		String type, value;
		if(index != -1){
			type = property.substring(0, index);
			value = property.substring(index + 1);
		} else {
			type = property;
			value = null;
		}
		
		fType = BuildPropertyManager.getInstance().getPropertyType(type);
		if(fType == null){
			throw new CoreException(new Status(IStatus.ERROR,
					ManagedBuilderCorePlugin.getUniqueIdentifier(),
					BuildPropertiesMessages.getString("BuildProperty.0"))); //$NON-NLS-1$
		}
		setValue(value);
	}
	
	BuildProperty(IBuildPropertyType type, String valueId) throws CoreException {
		fType = type;
		setValue(valueId);
	}
	
	public IBuildPropertyType getPropertyType(){
		return fType;
	}
	
	private void setValue(String id) throws CoreException {
		IBuildPropertyValue value = fType.getSupportedValue(id);
		
		if(value == null)
			throw new CoreException(new Status(IStatus.ERROR,
				ManagedBuilderCorePlugin.getUniqueIdentifier(),
				BuildPropertiesMessages.getString("BuildProperty.1"))); //$NON-NLS-1$

		setValue(value);
	}
	
	private void setValue(IBuildPropertyValue value){
		fValue = value;
	}
	
	public IBuildPropertyValue getValue(){
		return fValue;
	}
	
	public String toString(){
		return toString(fType.toString(), fValue.toString());
	}
	
	public static String toString(String type, String value){
		StringBuffer buf = new StringBuffer();
		buf.append(type).append(BuildPropertyManager.PROPERTY_VALUE_SEPARATOR).append(value);
		return buf.toString();
	
	}

/*	public Object clone() {
		try {
			return super.clone();
		} catch (CloneNotSupportedException e) {
		}
		return null;
	}
*/
}

Back to the top