UML Modeling Layer

com.ibm.xtools.uml.msl.internal.lang
Class UMLLanguageManager

java.lang.Object
  extended by com.ibm.xtools.uml.msl.internal.lang.UMLLanguageManager

public class UMLLanguageManager
extends Object

Singleton manager class which allows for basic queries about language types available in the system and some of the modeling dependencies that are needed to support a particular language.


Nested Class Summary
static interface UMLLanguageManager.IActiveLanguageObserver
           
 
Field Summary
protected  IUMLLanguageDescriptor activeLanguage
          Our currently active language
protected  Map<URI,Set<UMLLanguageManager.IActiveLanguageObserver>> observers
           
 
Constructor Summary
protected UMLLanguageManager()
          protected Constructor
 
Method Summary
 boolean addActiveLanguageListener(UMLLanguageManager.IActiveLanguageObserver observer, Resource filter)
          Adds a observer to the set of observers that wish to be notified about changes to the active language.
protected  void addElementImportToLanguageLibraries(Package pkg, Collection<URI> libraries)
          Add language specific imports
protected  void addLanguageSpecificProfileApplications(Package pkg, Collection<URI> profileURIs)
          Add language specific profiles
 IUMLLanguageDescriptor addUserDefinedLanguage(String langId)
          Add the given language to the list of user defined languages.
protected  LanguageChangeEvent createLanguageChangeEvent(IUMLLanguageDescriptor old, IUMLLanguageDescriptor newLang)
          Allow specialization of the LanguageChangeEvent if needed
protected  IUMLLanguageDescriptor findLanguageDescriptor(String languageId, boolean searchDerived)
          Null safe method that will find the language descriptor given the language Id.
protected  void fireLanguageChanged(LanguageChangeEvent event, EObject context)
          Determines the list of observers to notify, creates the Language Change Event, and delegates to fireNotificationJob.
protected  void fireNotificationJob(LanguageChangeEvent event, Set<UMLLanguageManager.IActiveLanguageObserver> list)
          Actually notify listeners.
 IUMLLanguageDescriptor getActiveDescriptor()
          Note: This API should be used with caution.
 IUMLLanguageDescriptor getActiveDescriptor(EObject context)
          Retrieves the language descriptor initialized with the given context.
 IUMLLanguageDescriptor getActiveDescriptor(EObject firstContext, EObject defaultContext)
          Retrieves the language descriptor initialized with the given context.
 IUMLLanguageDescriptor getActiveDescriptor(LanguageContext context)
          Set the active descriptor and initialize it with the given context
 String getActiveLanguage(EObject context)
          This is a utility method for getting the active language when the context for either the First or Model language will be the same.
 String getActiveLanguage(EObject firstLangContext, EObject modelLangContext)
          Determines the active language.
 String getActiveLanguage(LanguageContext context)
          Uses the active descriptor to extract the language from the given context.
 Collection<IUMLDerivedLanguageDescriptor> getAllDerivedLanguages()
           
 Collection<IUMLLanguageDescriptor> getAllDescriptors(boolean includeDerived)
          Returns all the currently loaded 'static' descriptors (predefined and user defined).
 List<String> getAllLanguageDisplayNames(boolean includeDerived)
          This method creates a sorted list of display names.
 Set<String> getAllLanguages()
           
 Collection<IUMLLanguageDescriptor> getAllPredefinedLanguages()
           
 Collection<IUMLLanguageDescriptor> getAllUserDefinedLanguages()
           
 IUMLLanguageDescriptor getDescriptor(String langId)
          Access to the descriptor for a given language.
 String getDescriptorID(IUMLLanguageDescriptor desc)
           
 String getFirstLanguage(EObject context)
          Utility method to get the first language.
static UMLLanguageManager getInstance()
           
 String getPersistedModelLanguage(EObject context)
          Utility method to get the persisted language in the model.
protected  void internalSetActiveLanguage(IUMLLanguageDescriptor desc)
          Set the active language
 boolean isActive(IUMLLanguageDescriptor language)
          Determines if the given descriptor is currently active.
 boolean isFirstDescriptorActive()
          Utility method for determining if the 'First' language descriptor is active
 boolean isModelDescriptorActive()
          Utility method for determining if the 'Model' language descriptor is active
 void persistLanguageInRootPackage(EObject context, IUMLLanguageDescriptor descriptor, boolean loadLanguageDefaults)
          Persists the language id of the given descriptor in to the root package that owns the given context.
 boolean removeActiveLanguageListener(UMLLanguageManager.IActiveLanguageObserver observer)
          Removes the observer from the set of observers that wish to be notified about changes to the active language.
 IUMLLanguageDescriptor removeUserDefinedLanguage(String langId)
          Provides API to remove a language from the list of user defined languages
 void setActiveDescriptor(IUMLLanguageDescriptor desc)
          Sets the new active descriptor and notifies listeners
 IUMLLanguageDescriptor setActiveLanguage(String languageId)
          Set the active language.
 void setActiveLanguageAsFirst()
          Sets the active language to be 'First'
 void setActiveLanguageAsModel()
          Sets the active language to be 'Model'
protected  void setupRootPackageForLanguage(Package pkg, IUMLLanguageDescriptor descriptor)
          Does the setup on the root package to enable language specific elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeLanguage

protected IUMLLanguageDescriptor activeLanguage
Our currently active language


observers

protected Map<URI,Set<UMLLanguageManager.IActiveLanguageObserver>> observers
Constructor Detail

UMLLanguageManager

protected UMLLanguageManager()
protected Constructor

Method Detail

getInstance

public static UMLLanguageManager getInstance()

getActiveDescriptor

public IUMLLanguageDescriptor getActiveDescriptor()
Note: This API should be used with caution. Calling the getLanguageID on the result of this method may not return the correct result if the descriptor needs a context to determine the language. This API could return the FirstLanguageDescriptor or ModelLanguageDescriptorif it is currently active. If you have a context object to base your query on, use one of the following APIs:

Returns:
The currently active descriptor
See Also:
UMLLanguageManager.getActiveDescriptor(EObject), UMLLanguageManager.getActiveDescriptor(EObject, EObject)

getActiveDescriptor

public IUMLLanguageDescriptor getActiveDescriptor(EObject context)
Retrieves the language descriptor initialized with the given context. This means that calls to getLanguageID (given the First or Model descriptor is active) will result in the appropriate language given the context being returned. If the active language is a static language descriptor, than the context is silently ignored.

Parameters:
context - The semantic object to initialize the descriptor with

getActiveDescriptor

public IUMLLanguageDescriptor getActiveDescriptor(EObject firstContext,
                                                  EObject defaultContext)
Retrieves the language descriptor initialized with the given context. This means that calls to getLanguageID (given the First or Model descriptor is active) will result in the appropriate language given the context being returned. If the active language is a static language descriptor, than the context is silently ignored.

Parameters:
firstContext - The context to be used to determine the first language
defaultContext - The context to be used to determine the default language
Returns:
The Predefined or UserDefined language descriptor

getActiveDescriptor

public IUMLLanguageDescriptor getActiveDescriptor(LanguageContext context)
Set the active descriptor and initialize it with the given context

Parameters:
context -
Returns:

getActiveLanguage

public String getActiveLanguage(EObject context)
This is a utility method for getting the active language when the context for either the First or Model language will be the same.

Parameters:
context - The element to use as the context for the first or default language
Returns:
the String identifier for the language that is currently designated as "active" in the tooling environment.

getActiveLanguage

public String getActiveLanguage(EObject firstLangContext,
                                EObject modelLangContext)
Determines the active language. If the active language is First, the firstLangContext will be used to find the 'first' language. If the active language is Model, then the modelLanguageContext will be used to determine the persisted model language. In all other cases, the active language descriptor's ID will be returned. Example: In some cases, the semantic object could be defined in one project (P1), but is redefined and being viewed in another project (P2). In this case the root project, P1, may have one defined model language, and the redefining project, P2, may have another. In this case we want to pass the semantic element as the firstLangContext, and we want to pass the element's View as the modelLanguageContext. This way the View's hierarchy is properly traversed to find the P2 project to use for the model language context.

Parameters:
firstLangContext - - the context to determine the first language from
modelLangContext - - The context to determine the default language from
Returns:
the String identifier for the language that is currently designated as "active" in the tooling environment.

getActiveLanguage

public String getActiveLanguage(LanguageContext context)
Uses the active descriptor to extract the language from the given context.

Parameters:
context - A LanguageContext object that contains the elements to used to determine the language if needed.
Returns:
the currently active language based on the active descriptor and the context.

getAllDescriptors

public Collection<IUMLLanguageDescriptor> getAllDescriptors(boolean includeDerived)
Returns all the currently loaded 'static' descriptors (predefined and user defined).

Parameters:
includeDerived - whether to include derived descriptors.

getDescriptor

public IUMLLanguageDescriptor getDescriptor(String langId)
Access to the descriptor for a given language. Note: If no descriptor exists for the given name, a custom descriptor will be created and returned.

Parameters:
lang - The language id to find
Returns:
The descriptor for the given name.

isModelDescriptorActive

public boolean isModelDescriptorActive()
Utility method for determining if the 'Model' language descriptor is active

Returns:
true if Default is active

isFirstDescriptorActive

public boolean isFirstDescriptorActive()
Utility method for determining if the 'First' language descriptor is active

Returns:
true if First is active

addUserDefinedLanguage

public IUMLLanguageDescriptor addUserDefinedLanguage(String langId)
Add the given language to the list of user defined languages. If the given language already exists in either the user defined or predefined collections, then it will not be added.

Parameters:
lang - The language ID to try and add
Returns:
an IUMLLanguageDescriptor of the new language created, or null if it already existed

removeUserDefinedLanguage

public IUMLLanguageDescriptor removeUserDefinedLanguage(String langId)
Provides API to remove a language from the list of user defined languages

Parameters:
lang - the language id to remove
Returns:
the IUMLLanguageDescriptor being removed, or null if one did not exist

isActive

public boolean isActive(IUMLLanguageDescriptor language)
Determines if the given descriptor is currently active. Note: If the descriptor is currently First or Model, than that descriptor will be compared against the parameter. If you wish to know about the underlying active language, then use the alternate API.

Parameters:
language -
Returns:
See Also:
UMLLanguageManager#isActive(String)

getPersistedModelLanguage

public String getPersistedModelLanguage(EObject context)
Utility method to get the persisted language in the model.

Parameters:
context - The context to find the root package from
Returns:
The persisted language or "" if none exists

getFirstLanguage

public String getFirstLanguage(EObject context)
Utility method to get the first language.

Parameters:
context - The context to try and extract the first language from
Returns:

getAllLanguages

public Set<String> getAllLanguages()
Returns:
the Collection of predefined or user defined languages that are available for use.

getAllLanguageDisplayNames

public List<String> getAllLanguageDisplayNames(boolean includeDerived)
This method creates a sorted list of display names. The list is sorted alphabetically and puts the 'None' at the end. The sorting only applies to predefined or user defined static languages. If the derived descriptor are included, they will be prefixed at the top of the list.

Returns:
a sorted list of language display names.

getAllDerivedLanguages

public Collection<IUMLDerivedLanguageDescriptor> getAllDerivedLanguages()
Returns:
all predefined (plugged in) languages

getAllPredefinedLanguages

public Collection<IUMLLanguageDescriptor> getAllPredefinedLanguages()
Returns:
all predefined (plugged in) languages

getAllUserDefinedLanguages

public Collection<IUMLLanguageDescriptor> getAllUserDefinedLanguages()
Returns:
all user defined (created by user) languages

setActiveLanguageAsModel

public void setActiveLanguageAsModel()
Sets the active language to be 'Model'


setActiveLanguageAsFirst

public void setActiveLanguageAsFirst()
Sets the active language to be 'First'


setActiveLanguage

public IUMLLanguageDescriptor setActiveLanguage(String languageId)
Set the active language.

Parameters:
languageId - The new language to be set as active
Returns:
the newly active descriptor

setActiveDescriptor

public void setActiveDescriptor(IUMLLanguageDescriptor desc)
Sets the new active descriptor and notifies listeners

Parameters:
desc - the new descriptor to make active

internalSetActiveLanguage

protected void internalSetActiveLanguage(IUMLLanguageDescriptor desc)
Set the active language

Parameters:
desc -

setupRootPackageForLanguage

protected void setupRootPackageForLanguage(Package pkg,
                                           IUMLLanguageDescriptor descriptor)
Does the setup on the root package to enable language specific elements. Adds:
  • element imports
  • language specific profiles
  • sets language specific capabilities
  • sets the default language
  • Parameters:
    pkg -
    descriptor -

    persistLanguageInRootPackage

    public void persistLanguageInRootPackage(EObject context,
                                             IUMLLanguageDescriptor descriptor,
                                             boolean loadLanguageDefaults)
    Persists the language id of the given descriptor in to the root package that owns the given context.

    Parameters:
    context - The context to find the root package from
    descriptor - The language descriptor that defines the language to persist. Or null if the persisted language should be removed from the root package.
    loadLanguageDefaults - true if the given discriptor's Libraries, profiles, etc should be applied to the root model false if just the language should be persisted

    addElementImportToLanguageLibraries

    protected void addElementImportToLanguageLibraries(Package pkg,
                                                       Collection<URI> libraries)
    Add language specific imports

    Parameters:
    pkg -
    libraries -

    addLanguageSpecificProfileApplications

    protected void addLanguageSpecificProfileApplications(Package pkg,
                                                          Collection<URI> profileURIs)
    Add language specific profiles

    Parameters:
    pkg -
    profileURIs -

    fireLanguageChanged

    protected void fireLanguageChanged(LanguageChangeEvent event,
                                       EObject context)
    Determines the list of observers to notify, creates the Language Change Event, and delegates to fireNotificationJob.

    Parameters:
    old -
    newlang -
    context -
    contextChanged -

    createLanguageChangeEvent

    protected LanguageChangeEvent createLanguageChangeEvent(IUMLLanguageDescriptor old,
                                                            IUMLLanguageDescriptor newLang)
    Allow specialization of the LanguageChangeEvent if needed

    Parameters:
    old -
    newLang -
    contextChanged -
    Returns:

    fireNotificationJob

    protected void fireNotificationJob(LanguageChangeEvent event,
                                       Set<UMLLanguageManager.IActiveLanguageObserver> list)
    Actually notify listeners.

    Parameters:
    event -
    list -

    findLanguageDescriptor

    protected IUMLLanguageDescriptor findLanguageDescriptor(String languageId,
                                                            boolean searchDerived)
    Null safe method that will find the language descriptor given the language Id. If the descriptor does not yet exist (e.g. custom language), then it will be created and stored for next time.

    Parameters:
    languageId -
    searchDerived - whether to search the derived language list
    Returns:
    The language descriptor associated with the given language id

    addActiveLanguageListener

    public boolean addActiveLanguageListener(UMLLanguageManager.IActiveLanguageObserver observer,
                                             Resource filter)
    Adds a observer to the set of observers that wish to be notified about changes to the active language. Active language listeners will be notified about all active language changes. The active language could be changed based on selection if 'Default' or 'First', thus to avoid notifications to listeners who would not be affect

    Parameters:
    observer - The object to be notified of a change
    filter - the resource to use as a filter for 'default' language changes
    Returns:
    true if the observer was successfully added. false otherwise

    removeActiveLanguageListener

    public boolean removeActiveLanguageListener(UMLLanguageManager.IActiveLanguageObserver observer)
    Removes the observer from the set of observers that wish to be notified about changes to the active language.

    Parameters:
    observer - The object no longer wanting to be notified
    Returns:
    true if the observer was successfully removed. false otherwise

    getDescriptorID

    public String getDescriptorID(IUMLLanguageDescriptor desc)

    UML Modeling Layer

    © Copyright IBM Corp. 2009. All rights reserved.