trace/tracebuilder/com.nokia.tracebuilder/src/com/nokia/tracebuilder/utils/DocumentFactory.java
changeset 10 ed1c9f64298a
equal deleted inserted replaced
9:14dc2103a631 10:ed1c9f64298a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 * Factory class to create document interfaces
       
    17 *
       
    18 */
       
    19 package com.nokia.tracebuilder.utils;
       
    20 
       
    21 import com.nokia.tracebuilder.engine.TraceBuilderErrorCodes.TraceBuilderErrorCode;
       
    22 import com.nokia.tracebuilder.model.TraceBuilderException;
       
    23 import com.nokia.tracebuilder.source.SourceDocumentFactory;
       
    24 import com.nokia.tracebuilder.source.SourceDocumentMonitor;
       
    25 
       
    26 /**
       
    27  * Factory class to create document interfaces
       
    28  * 
       
    29  */
       
    30 public final class DocumentFactory {
       
    31 
       
    32 	/**
       
    33 	 * Document monitor
       
    34 	 */
       
    35 	private static SourceDocumentMonitor monitor;
       
    36 
       
    37 	/**
       
    38 	 * Document factory class
       
    39 	 */
       
    40 	private static Class<? extends SourceDocumentFactory> factoryClass;
       
    41 
       
    42 	/**
       
    43 	 * Registers a document framework to be used by the engine
       
    44 	 * 
       
    45 	 * @param monitor
       
    46 	 *            the document monitor
       
    47 	 * @param factoryClass
       
    48 	 *            the document factory class
       
    49 	 */
       
    50 	public static void registerDocumentFramework(SourceDocumentMonitor monitor,
       
    51 			Class<? extends SourceDocumentFactory> factoryClass) {
       
    52 		DocumentFactory.monitor = monitor;
       
    53 		DocumentFactory.factoryClass = factoryClass;
       
    54 	}
       
    55 
       
    56 	/**
       
    57 	 * Gets the document monitor
       
    58 	 * 
       
    59 	 * @return the monitor
       
    60 	 */
       
    61 	public static final SourceDocumentMonitor getDocumentMonitor() {
       
    62 		return monitor;
       
    63 	}
       
    64 
       
    65 	/**
       
    66 	 * Creates a document factory, which is not associated to a document monitor
       
    67 	 * 
       
    68 	 * @return the factory
       
    69 	 * @throws TraceBuilderException
       
    70 	 *             if factory cannot be created
       
    71 	 */
       
    72 	public static final SourceDocumentFactory createDocumentFactory()
       
    73 			throws TraceBuilderException {
       
    74 		SourceDocumentFactory retval = null;
       
    75 		try {
       
    76 			retval = factoryClass.newInstance();
       
    77 		} catch (Exception e) {
       
    78 			throw new TraceBuilderException(
       
    79 					TraceBuilderErrorCode.UNEXPECTED_EXCEPTION, e);
       
    80 		}
       
    81 		return retval;
       
    82 	}
       
    83 
       
    84 }