Skip to main content
summaryrefslogtreecommitdiffstats
blob: c140b4fdfeb5723838cc017217922f6c86730ebc (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
/*******************************************************************************
 * Copyright (c) 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.core.internal.content;

import java.io.*;
import java.util.*;
import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.core.internal.runtime.Policy;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.content.*;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;

public final class ContentType implements IContentType {

	/* A placeholder for missing/invalid binary/text describers. */
	private class InvalidDescriber implements IContentDescriber, ITextContentDescriber {
		public int describe(InputStream contents, IContentDescription description) throws IOException {
			return INVALID;
		}

		public int describe(Reader contents, IContentDescription description) throws IOException {
			return INVALID;
		}

		public QualifiedName[] getSupportedOptions() {
			return new QualifiedName[0];
		}
	}

	final static byte ASSOCIATED_BY_EXTENSION = 2;
	final static byte ASSOCIATED_BY_NAME = 1;
	private static final String DESCRIBER_ELEMENT = "describer"; //$NON-NLS-1$
	final static byte NOT_ASSOCIATED = 0;

	public final static String PREF_DEFAULT_CHARSET = "charset"; //$NON-NLS-1$	
	public final static String PREF_FILE_EXTENSIONS = "file-extensions"; //$NON-NLS-1$
	public final static String PREF_FILE_NAMES = "file-names"; //$NON-NLS-1$
	final static byte PRIORITY_HIGH = 1;
	final static byte PRIORITY_LOW = -1;
	final static byte PRIORITY_NORMAL = 0;
	final static int SPEC_PRE_DEFINED = IGNORE_PRE_DEFINED;
	final static int SPEC_USER_DEFINED = IGNORE_USER_DEFINED;
	final static byte STATUS_INVALID = 2;
	final static byte STATUS_UNKNOWN = 3;
	final static byte STATUS_VALID = 1;
	private ContentType aliasTarget;
	private String baseTypeId;
	private IContentType[] children;
	private IConfigurationElement contentTypeElement;
	private String defaultCharset;
	private String userCharset;
	private IContentDescription defaultDescription;
	private IContentDescriber describer;
	private List fileSpecs;
	private ContentTypeManager manager;
	private String name;
	private String namespace;
	private byte priority;
	private String simpleId;
	private byte validation;

	public static ContentType createContentType(ContentTypeManager manager, String namespace, String simpleId, String name, byte priority, String[] fileExtensions, String[] fileNames, String baseTypeId, String defaultCharset, IConfigurationElement contentTypeElement) {
		ContentType contentType = new ContentType(manager);
		contentType.defaultDescription = new DefaultDescription(contentType);
		contentType.simpleId = simpleId;
		contentType.namespace = namespace;
		contentType.name = name;
		contentType.priority = priority;
		if ((fileExtensions != null && fileExtensions.length > 0) || (fileNames != null && fileNames.length > 0)) {
			contentType.fileSpecs = new ArrayList(fileExtensions.length + fileNames.length);
			for (int i = 0; i < fileNames.length; i++)
				contentType.fileSpecs.add(createFileSpec(fileNames[i], FILE_NAME_SPEC | SPEC_PRE_DEFINED));
			for (int i = 0; i < fileExtensions.length; i++)
				contentType.fileSpecs.add(createFileSpec(fileExtensions[i], FILE_EXTENSION_SPEC | SPEC_PRE_DEFINED));
		}
		contentType.defaultCharset = defaultCharset;
		contentType.contentTypeElement = contentTypeElement;
		contentType.baseTypeId = baseTypeId;
		contentType.processPreferences();
		return contentType;
	}

	private void processPreferences() {
		Preferences contentTypeNode = manager.getPreferences().node(getId());
		// user set default charset
		this.userCharset = contentTypeNode.get(PREF_DEFAULT_CHARSET, null);
		// user set file names 
		String userSetFileNames = contentTypeNode.get(PREF_FILE_NAMES, null);
		String[] fileNames = parseItems(userSetFileNames);
		for (int i = 0; i < fileNames.length; i++)
			internalAddFileSpec(fileNames[i], FILE_NAME_SPEC | SPEC_USER_DEFINED);
		// user set file extensions
		String userSetFileExtensions = contentTypeNode.get(PREF_FILE_EXTENSIONS, null);
		String[] fileExtensions = parseItems(userSetFileExtensions);
		for (int i = 0; i < fileExtensions.length; i++)
			internalAddFileSpec(fileExtensions[i], FILE_EXTENSION_SPEC | SPEC_USER_DEFINED);
	}

	static FileSpec createFileSpec(String fileSpec, int type) {
		return new FileSpec(fileSpec, type);
	}

	private static String getPreferenceKey(int flags) {
		if ((flags & FILE_EXTENSION_SPEC) != 0)
			return PREF_FILE_EXTENSIONS;
		if ((flags & FILE_NAME_SPEC) != 0)
			return PREF_FILE_NAMES;
		throw new IllegalArgumentException("Unknown type: " + flags); //$NON-NLS-1$
	}

	static String[] parseItems(String string) {
		if (string == null)
			return new String[0];
		StringTokenizer tokenizer = new StringTokenizer(string, ","); //$NON-NLS-1$
		if (!tokenizer.hasMoreTokens())
			return new String[0];
		String first = tokenizer.nextToken();
		if (!tokenizer.hasMoreTokens())
			return new String[] {first};
		ArrayList items = new ArrayList();
		items.add(first);
		do {
			items.add(tokenizer.nextToken());
		} while (tokenizer.hasMoreTokens());
		return (String[]) items.toArray(new String[items.size()]);
	}

	static String toListString(List list) {
		if (list.isEmpty())
			return ""; //$NON-NLS-1$
		StringBuffer result = new StringBuffer();
		for (Iterator i = list.iterator(); i.hasNext();) {
			result.append(i.next());
			result.append(',');
		}
		// ignore last comma
		return result.substring(0, result.length() - 1);
	}

	static String toListString(Object[] list) {
		if (list.length == 0)
			return ""; //$NON-NLS-1$
		StringBuffer result = new StringBuffer();
		for (int i = 0; i < list.length; i++) {
			result.append(list[i]);
			result.append(',');
		}
		// ignore last comma
		return result.substring(0, result.length() - 1);
	}

	public ContentType(ContentTypeManager manager) {
		this.manager = manager;
	}

	public synchronized void addFileSpec(String fileSpec, int type) throws CoreException {
		if (aliasTarget != null) {
			getTarget().addFileSpec(fileSpec, type);
			return;
		}
		if (type != FILE_EXTENSION_SPEC && type != FILE_NAME_SPEC)
			throw new IllegalArgumentException("Unknown type: " + type); //$NON-NLS-1$		
		if (!internalAddFileSpec(fileSpec, type | SPEC_USER_DEFINED))
			// the entry was already there, nothing to do...
			return;
		// notify listeners
		manager.fireContentTypeChangeEvent(this);
		// update preferences
		String key = getPreferenceKey(type);
		Preferences contentTypeNode = manager.getPreferences().node(getId());
		final String[] userSet = internalGetFileSpecs(type | IGNORE_PRE_DEFINED);
		contentTypeNode.put(key, toListString(userSet));
		// persist preferences
		try {
			contentTypeNode.flush();
		} catch (BackingStoreException bse) {
			String message = Policy.bind("content.errorSavingSettings", getId()); //$NON-NLS-1$
			IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, 0, message, bse);
			throw new CoreException(status);
		}
	}

	int describe(IContentDescriber selectedDescriber, InputStream contents, ContentDescription description) {
		try {
			return selectedDescriber.describe(contents, description);
		} catch (IOException ioe) {
			if (ContentTypeManager.DEBUGGING) {
				String message = Policy.bind("content.errorReadingContents", getId()); //$NON-NLS-1$ 
				log(message, ioe);
			}
			return IContentDescriber.INVALID;
		} catch (RuntimeException re) {
			// describer seems to be buggy. just disable it (logging the reason)
			invalidateDescriber(re);
			return IContentDescriber.INVALID;
		} catch (Error e) {
			// describer got some serious problem. disable it (logging the reason) and throw the error again 
			invalidateDescriber(e);
			throw e;
		} finally {
			((LazyInputStream) contents).rewind();
		}
	}

	int describe(ITextContentDescriber selectedDescriber, Reader contents, ContentDescription description) {
		try {
			return selectedDescriber.describe(contents, description);
		} catch (IOException ioe) {
			if (ContentTypeManager.DEBUGGING) {
				String message = Policy.bind("content.errorReadingContents", getId()); //$NON-NLS-1$
				log(message, ioe);
			}
			return IContentDescriber.INVALID;
		} catch (RuntimeException re) {
			// describer seems to be buggy. just disable it (logging the reason)
			invalidateDescriber(re);
			return IContentDescriber.INVALID;
		} catch (Error e) {
			// describer got some serious problem. disable it (logging the reason) and throw the error again			
			invalidateDescriber(e);
			throw e;
		} finally {
			((LazyReader) contents).rewind();
		}
	}

	public IContentType getBaseType() {
		if (aliasTarget != null)
			return getTarget().getBaseType();
		if (baseTypeId == null)
			return null;
		ContentType originalBaseType = manager.internalGetContentType(baseTypeId);
		return originalBaseType != null ? originalBaseType.getTarget() : null;
	}

	String getBaseTypeId() {
		return baseTypeId;
	}

	IContentType[] getChildren() {
		if (children == null)
			children = manager.getChildren(this);
		return children;
	}

	/**
	 * @see IContentType
	 */
	public String getDefaultCharset() {
		if (aliasTarget != null)
			return getTarget().getDefaultCharset();
		String currentCharset = userCharset != null ? userCharset : internalGetDefaultCharset();
		// an empty string as charset means: no default charset
		return "".equals(currentCharset) ? null : currentCharset; //$NON-NLS-1$
	}

	public IContentDescription getDefaultDescription() {
		if (aliasTarget != null)
			return getTarget().getDefaultDescription();
		return defaultDescription;
	}

	public int getDepth() {
		ContentType baseType = (ContentType) getBaseType();
		if (baseType == null)
			return 0;
		return 1 + baseType.getDepth();
	}

	public IContentDescriber getDescriber() {
		if (aliasTarget != null)
			return getTarget().getDescriber();
		// if "" is specified no describer should be created
		if ("".equals(contentTypeElement.getAttributeAsIs(DESCRIBER_ELEMENT))) //$NON-NLS-1$
			return null;
		synchronized (this) {
			if (describer != null)
				return describer;
			if (contentTypeElement.getChildren(DESCRIBER_ELEMENT).length > 0 || contentTypeElement.getAttributeAsIs(DESCRIBER_ELEMENT) != null)
				try {
					return describer = (IContentDescriber) contentTypeElement.createExecutableExtension(DESCRIBER_ELEMENT);
				} catch (CoreException ce) {
					// the content type definition was invalid. Ensure we don't
					// try again, and this content type does not accept any
					// contents
					return invalidateDescriber(ce);
				}
		}
		ContentType baseType = (ContentType) getBaseType();
		return baseType == null ? null : baseType.getDescriber();
	}

	/**
	 * @see IContentType
	 */
	public IContentDescription getDescriptionFor(InputStream contents, QualifiedName[] options) throws IOException {
		InputStream buffer = ContentTypeManager.readBuffer(contents);
		if (buffer == null)
			return defaultDescription;
		return internalGetDescriptionFor(buffer, options);
	}

	/**
	 * @see IContentType
	 */
	public IContentDescription getDescriptionFor(Reader contents, QualifiedName[] options) throws IOException {
		Reader buffer = ContentTypeManager.readBuffer(contents);
		if (buffer == null)
			return defaultDescription;
		return internalGetDescriptionFor(buffer, options);
	}

	public String[] getFileSpecs(int typeMask) {
		if (aliasTarget != null)
			return getTarget().getFileSpecs(typeMask);
		return internalGetFileSpecs(typeMask);
	}

	private String[] internalGetFileSpecs(int typeMask) {
		if (fileSpecs == null)
			return new String[0];
		// invert the last two bits so it is easier to compare
		typeMask ^= (IGNORE_PRE_DEFINED | IGNORE_USER_DEFINED);
		List result = new ArrayList(fileSpecs.size());
		for (Iterator i = fileSpecs.iterator(); i.hasNext();) {
			FileSpec spec = (FileSpec) i.next();
			if ((spec.getType() & typeMask) == spec.getType())
				result.add(spec.getText());
		}
		return (String[]) result.toArray(new String[result.size()]);
	}

	public String getId() {
		return namespace + '.' + simpleId;
	}

	public String getName() {
		return name;
	}

	byte getPriority() {
		return priority;
	}

	String getSimpleId() {
		return simpleId;
	}

	/*
	 * Returns the alias target, if one is found, or this object otherwise.
	 */
	ContentType getTarget() {
		if (aliasTarget == null)
			return this;
		return aliasTarget.getTarget();
	}

	byte getValidation() {
		return validation;
	}

	/**
	 * @param text the file spec string
	 * @param typeMask FILE_NAME_SPEC or FILE_EXTENSION_SPEC
	 * @return true if this file spec has already been added, false otherwise
	 */
	private boolean hasFileSpec(String text, int typeMask) {
		if (fileSpecs == null)
			return false;
		for (Iterator i = fileSpecs.iterator(); i.hasNext();) {
			FileSpec spec = (FileSpec) i.next();
			if (spec.equals(text, typeMask))
				return true;
		}
		return false;
	}

	boolean internalAddFileSpec(String fileSpec, int typeMask) {
		if (hasFileSpec(fileSpec, typeMask))
			return false;
		if (aliasTarget != null)
			return aliasTarget.internalAddFileSpec(fileSpec, typeMask);
		if (fileSpecs == null)
			fileSpecs = new ArrayList(3);
		fileSpecs.add(createFileSpec(fileSpec, typeMask));
		return true;
	}

	private String internalGetDefaultCharset() {
		if (defaultCharset == null) {
			ContentType baseType = (ContentType) getBaseType();
			return baseType == null ? null : baseType.getDefaultCharset();
		}
		return defaultCharset;
	}

	IContentDescription internalGetDescriptionFor(InputStream buffer, QualifiedName[] options) {
		if (aliasTarget != null)
			return getTarget().internalGetDescriptionFor(buffer, options);
		if (buffer == null)
			return defaultDescription;
		IContentDescriber describer = this.getDescriber();
		// no describer - just return the default description
		if (describer == null)
			return defaultDescription;
		ContentDescription description = new ContentDescription(options);
		describe(describer, buffer, description);
		// if the describer didn't add any details, just return the default
		// description
		if (!description.isSet())
			return defaultDescription;
		// check if any of the defaults need to be applied
		if (description.isRequested(IContentDescription.CHARSET) && description.getProperty(IContentDescription.CHARSET) == null)
			description.setProperty(IContentDescription.CHARSET, getDefaultCharset());
		description.setContentType(this);
		return description;
	}

	IContentDescription internalGetDescriptionFor(Reader buffer, QualifiedName[] options) {
		if (aliasTarget != null)
			return getTarget().internalGetDescriptionFor(buffer, options);
		if (buffer == null)
			return defaultDescription;
		IContentDescriber describer = this.getDescriber();
		// no describer - just return the default description
		if (describer == null)
			return defaultDescription;
		ContentDescription description = new ContentDescription(options);
		if (!(describer instanceof ITextContentDescriber))
			throw new UnsupportedOperationException();
		describe((ITextContentDescriber) describer, buffer, description);
		// if the describer didn't add any details, just return the default description
		if (!description.isSet())
			return defaultDescription;
		// check if any of the defaults need to be applied
		if (description.isRequested(IContentDescription.CHARSET) && description.getProperty(IContentDescription.CHARSET) == null)
			description.setProperty(IContentDescription.CHARSET, getDefaultCharset());
		description.setContentType(this);
		return description;
	}

	public byte internalIsAssociatedWith(String fileName) {
		if (aliasTarget != null)
			return getTarget().internalIsAssociatedWith(fileName);
		if (hasFileSpec(fileName, FILE_NAME_SPEC))
			return ASSOCIATED_BY_NAME;
		String fileExtension = ContentTypeManager.getFileExtension(fileName);
		if (hasFileSpec(fileExtension, FILE_EXTENSION_SPEC))
			return ASSOCIATED_BY_EXTENSION;
		// if does not have *built-in* file specs, delegate to parent (if any)
		if (!hasAnyFileSpec(SPEC_PRE_DEFINED)) {
			IContentType baseType = getBaseType();
			if (baseType != null)
				return ((ContentType) baseType).internalIsAssociatedWith(fileName);
		}
		return NOT_ASSOCIATED;
	}

	private boolean hasAnyFileSpec(int typeMask) {
		if (fileSpecs == null || fileSpecs.isEmpty())
			return false;
		for (Iterator i = fileSpecs.iterator(); i.hasNext();) {
			FileSpec spec = (FileSpec) i.next();
			if ((spec.getType() & typeMask) == typeMask)
				return true;
		}
		return false;
	}

	boolean internalRemoveFileSpec(String fileSpec, int typeMask) {
		if (aliasTarget != null)
			return aliasTarget.internalRemoveFileSpec(fileSpec, typeMask);
		if (fileSpecs == null)
			return false;
		for (Iterator i = fileSpecs.iterator(); i.hasNext();) {
			FileSpec spec = (FileSpec) i.next();
			if ((spec.getType() == typeMask) && fileSpec.equals(spec.getText())) {
				i.remove();
				return true;
			}
		}
		return false;
	}

	private IContentDescriber invalidateDescriber(Throwable reason) {
		setValidation(STATUS_INVALID);
		String message = Policy.bind("content.invalidContentDescriber", getId()); //$NON-NLS-1$ 
		log(message, reason);
		return describer = new InvalidDescriber();
	}

	public boolean isAssociatedWith(String fileName) {
		return internalIsAssociatedWith(fileName) != NOT_ASSOCIATED;
	}

	public boolean isKindOf(IContentType another) {
		if (another == null)
			return false;
		if (aliasTarget != null)
			return getTarget().isKindOf(another);
		if (this == another)
			return true;
		if (getDepth() <= ((ContentType) another).getDepth())
			return false;
		IContentType baseType = getBaseType();
		return baseType != null && baseType.isKindOf(another);
	}

	public boolean isText() {
		return isKindOf(manager.getContentType(IContentTypeManager.CT_TEXT));
	}

	boolean isValid() {
		return validation == STATUS_VALID;
	}

	private void log(String message, Throwable reason) {
		// don't log CoreExceptions again
		IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, 0, message, reason instanceof CoreException ? null : reason);
		InternalPlatform.getDefault().log(status);
	}

	public synchronized void removeFileSpec(String fileSpec, int type) throws CoreException {
		if (aliasTarget != null) {
			getTarget().removeFileSpec(fileSpec, type);
			return;
		}
		if (type != FILE_EXTENSION_SPEC && type != FILE_NAME_SPEC)
			throw new IllegalArgumentException("Unknown type: " + type); //$NON-NLS-1$
		if (!internalRemoveFileSpec(fileSpec, type | SPEC_USER_DEFINED))
			// the entry was not there... nothing to do
			return;
		// notify listeners
		manager.fireContentTypeChangeEvent(this);
		// update preferences
		String key = getPreferenceKey(type);
		Preferences contentTypeNode = manager.getPreferences().node(getId());
		final String[] userSet = internalGetFileSpecs(type | IGNORE_PRE_DEFINED);
		if (userSet.length == 0)
			contentTypeNode.remove(key);
		else
			contentTypeNode.put(key, toListString(userSet));
		// persist using preferences
		try {
			contentTypeNode.flush();
		} catch (BackingStoreException bse) {
			String message = Policy.bind("content.errorSavingSettings", getId()); //$NON-NLS-1$
			IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, 0, message, bse);
			throw new CoreException(status);
		}
	}

	void setAliasTarget(ContentType newTarget) {
		// when changing the target, it must be cleared first
		if (aliasTarget != null && newTarget != null)
			return;
		// don't allow a sub-type to be made into an alias to the base type
		if (aliasTarget == null && isKindOf(newTarget))
			return;
		if (ContentTypeManager.DEBUGGING)
			Policy.debug("Setting alias target for " + this + " -> " + newTarget); //$NON-NLS-1$ //$NON-NLS-2$		
		aliasTarget = newTarget;
	}

	/*
	 * (non-Javadoc) 
	 * @see org.eclipse.core.runtime.content.IContentType#setDefaultCharset(java.lang.String)
	 */
	public void setDefaultCharset(String newCharset) throws CoreException {
		if (userCharset == null) {
			if (newCharset == null)
				return;
		} else if (userCharset.equals(newCharset))
			return;
		userCharset = newCharset;
		// notify listeners
		manager.fireContentTypeChangeEvent(this);
		// update preferences
		Preferences contentTypeNode = manager.getPreferences().node(getId());
		if (userCharset == null)
			contentTypeNode.remove(PREF_DEFAULT_CHARSET);
		else
			contentTypeNode.put(PREF_DEFAULT_CHARSET, userCharset);
		// persist preferences
		try {
			contentTypeNode.flush();
		} catch (BackingStoreException bse) {
			String message = Policy.bind("content.errorSavingSettings", getId()); //$NON-NLS-1$
			IStatus status = new Status(IStatus.ERROR, Platform.PI_RUNTIME, 0, message, bse);
			throw new CoreException(status);
		}
	}

	void setValidation(byte validation) {
		this.validation = validation;
		if (ContentTypeManager.DEBUGGING)
			Policy.debug("Validating " + this + ": " + getValidationString(validation)); //$NON-NLS-1$ //$NON-NLS-2$
	}

	private static String getValidationString(byte validation) {
		return validation == STATUS_VALID ? "VALID" : (validation == STATUS_INVALID ? "INVALID" : "UNKNOWN"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}

	public String toString() {
		return getId();
	}

	public boolean isAlias() {
		return aliasTarget != null;
	}
}

Back to the top