net.sourceforge.nrl.parser.type
Class TypeMapping

java.lang.Object
  extended by net.sourceforge.nrl.parser.type.TypeMapping
All Implemented Interfaces:
ITypeMapping
Direct Known Subclasses:
XmlTypeMapping

public class TypeMapping
extends Object
implements ITypeMapping

A default type mapping implementation. The type mapping is completely empty and can be populated using the add methods before use.

Alternatively, a subclass with a serializer/deserializer method can be used to load and save the mapping to a file, for example XmlTypeMapping.


Constructor Summary
TypeMapping()
           
 
Method Summary
 void addAll(TypeMapping other)
          Add all entries from another mapping to this one.
 TypeMappingEntry addMapping(String packageName, String typeName, NRLDataType type)
          Add a mapping from a type name, in a particular package, to an internal type.
 void clear()
          Empty the mapping.
 boolean contains(String packageName, String typeName)
          Return true if this contains a mapping for a particular package and type name.
 List<TypeMappingEntry> getMapping()
          Return the type mapping entries, in order.
static String getStringForType(NRLDataType type)
          Return a serializable string for the integer constant from NRLDataType.
 NRLDataType getType(IAttribute attr)
          Map the type of an attribute to an internal abstract type.
 NRLDataType getType(IModelElement element)
          Map a model element to an internal, abstract type.
static NRLDataType getTypeFromString(String type)
          Convert a string representation of a type back to an integer number.
 void remove(String packageName, String typeName)
          Remove a particular mapping
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeMapping

public TypeMapping()
Method Detail

addAll

public void addAll(TypeMapping other)
Add all entries from another mapping to this one.

Parameters:
other - the mapping to add

addMapping

public TypeMappingEntry addMapping(String packageName,
                                   String typeName,
                                   NRLDataType type)
Add a mapping from a type name, in a particular package, to an internal type. The package can be passed as "*" to indicate that the type is always mapped, no matter where it occurs.

Parameters:
packageName - the package name or "*"
typeName - the type (class/data type) name
type - the target type

clear

public void clear()
Empty the mapping.


contains

public boolean contains(String packageName,
                        String typeName)
Return true if this contains a mapping for a particular package and type name.

Parameters:
packageName - the package
typeName - the type
Returns:
true if found

getMapping

public List<TypeMappingEntry> getMapping()
Return the type mapping entries, in order.

Returns:
the entries

getStringForType

public static String getStringForType(NRLDataType type)
Return a serializable string for the integer constant from NRLDataType. If it is not one of the constants, returns "Unknown".

Parameters:
type - the type value
Returns:
a string value

getTypeFromString

public static NRLDataType getTypeFromString(String type)
Convert a string representation of a type back to an integer number. The string representation is as produced by getStringForType(NRLDataType). If it is not one of this, returns NRLDataType.UNKNOWN.

Parameters:
type - the string
Returns:
the type

getType

public NRLDataType getType(IAttribute attr)
Description copied from interface: ITypeMapping
Map the type of an attribute to an internal abstract type.

Specified by:
getType in interface ITypeMapping
Parameters:
attr - the attribute
Returns:
an NRL type

getType

public NRLDataType getType(IModelElement element)
Description copied from interface: ITypeMapping
Map a model element to an internal, abstract type. If the element is a classifier and not otherwise mapped, it maps to NRLDataType.ELEMENT.

Specified by:
getType in interface ITypeMapping
Parameters:
element - the element
Returns:
an NRL type

remove

public void remove(String packageName,
                   String typeName)
Remove a particular mapping

Parameters:
packageName - the package name
typeName - the type name


Copyright © 2006-2010 Christian Nentwich and others