View Javadoc

1   /*
2    * $Id: TranslatorDescriptor.java,v 1.3 2005/05/31 20:25:08 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.tools.translator;
10  
11  import java.util.HashMap;
12  import java.util.Map;
13  
14  import org.eclipse.core.runtime.IConfigurationElement;
15  
16  /***
17   * A class that represents a translator as defined by the translator 
18   * extension point.  This class provides accessor methods to get information 
19   * about a given translator.  This class is instantiated exclusively by the 
20   * {@link TranslatorPlugin} class and is relevant only within the scope of 
21   * SWeDE translators.  
22   * 
23   * @author aperezlo
24   */
25  public class TranslatorDescriptor
26  {
27     private static final String INPUT_EXTENSION_STR = "input-extension";
28     private static final String OUTPUT_EXTENSION_STR = "output-extension";
29     private static final String NAME_STR = "name";
30     private static final String ID_STR = "id";
31     private static final String TOOLTIP_STR = "tooltip";
32     private static final String GROUP_ID_STR = "group-id";
33     private static final String GROUP_NAME_STR = "group-name";
34     private static final String CLASS_STR = "class";
35     
36     private ITranslator _translator;
37     private Map _properties;
38     
39     /***
40      * Creates a translator descriptor for an extender of 
41      * com.bbn.swede.tools.translator.
42      * @param ice A configuration element for an extension of the translator
43      *            extension point.  Must specify an implementation of
44      *            ITranslator.
45      * @throws Exception if there is an error creating an executable extension
46      *                   for the translator.
47      */
48     TranslatorDescriptor(IConfigurationElement ice) throws Exception
49     {
50        _properties = new HashMap();
51        _translator = null;
52        String[] attrNames = ice.getAttributeNames();
53        for(int i = 0; i < attrNames.length; i++)
54        {
55           _properties.put(attrNames[i], ice.getAttributeAsIs(attrNames[i]));
56           if(attrNames[i].equals(CLASS_STR))
57           {
58              _translator = (ITranslator) ice.createExecutableExtension(attrNames[i]);
59           }
60        }
61     }
62     
63     /***
64      * Retrieves the <code>input-extension</code> of this translator.
65      * @return The input extension
66      */
67     public String getInputExtension()
68     {
69        return (String) _properties.get(INPUT_EXTENSION_STR);
70     }
71     
72     /***
73      * Retrieves the <code>output-extension</code> of this translator.
74      * @return The output extension
75      */
76     public String getOutputExtension()
77     {
78        return (String) _properties.get(OUTPUT_EXTENSION_STR);
79     }
80     
81     /***
82      * Retrieves the translator represented by this descriptor.
83      * @return the translator
84      */
85     public ITranslator getTranslator()
86     {
87        return _translator;
88     }
89     
90     /***
91      * Retrieves the <code>name</code> of this translator.  
92      * @return The name
93      */
94     public String getName()
95     {
96        return (String) _properties.get(NAME_STR);
97     }
98     
99     /***
100     * Retrieves the <code>group-name</code> of this translator, if one exists.  
101     * @return The group name
102     */
103    public String getGroupName()   
104    {
105       return (String) _properties.get(GROUP_NAME_STR);
106    }
107    
108    /***
109     * Retrieves the <code>group-id</code> of this translator, if one exists.
110     * @return The group ID
111     */
112    public String getGroupID()
113    {
114       return (String) _properties.get(GROUP_ID_STR);
115    }
116 }