Constructors Summary |
---|
public AttributeNameMapperImpl()Create a new instance which will map nothing by default.
this( null, null);
|
public AttributeNameMapperImpl(String[] originalNames)Create a new instance which will map (as necessary) the specified
Attribute names.
Same as AttributeNameMapperImpl( originalNames, new AttributeNameManglerImpl() )
this( originalNames, new AttributeNameManglerImpl( true, null ) );
|
public AttributeNameMapperImpl(AttributeNameMangler mangler)Create a new instance which will map (as necessary) the specified
Attribute names
this( null, mangler );
|
public AttributeNameMapperImpl(String[] originalNames, AttributeNameMangler mangler)Create a new instance which will map (as necessary) the specified
Attribute names
mDebug = null;
mDerivedToOriginal = new HashMap<String,String>();
mOriginalToDerived = new HashMap<String,String>();
mAllNames = new HashSet<String>();
mMangler = mangler == null ? new AttributeNameManglerImpl( true, null ) : mangler ;
if ( originalNames != null )
{
deriveAll( originalNames );
}
|
Methods Summary |
---|
public void | addMapping(java.lang.String originalName, java.lang.String derivedName)
mDerivedToOriginal.put( derivedName, originalName );
mOriginalToDerived.put( originalName, derivedName );
mAllNames.add( derivedName );
|
protected final void | debug(java.lang.Object o)
if ( mDebug != null )
{
mDebug.println( o );
}
|
public void | deriveAll(java.lang.String[] originalNames)
final Set<String> notRequired = new HashSet<String>();
final Set<String> required = new HashSet<String>();
// first determine all names we (a) need to map and (b) don't need to map.
// we must not generate any mapped names that conflict with names
// that don't require mapping
for( final String originalName : originalNames )
{
if ( mOriginalToDerived.containsKey( originalName ) )
{
// continue; already present (explicit mapping)
}
else if ( ! requiresMapping( originalName ) )
{
notRequired.add( originalName );
}
else
{
required.add( originalName );
}
}
// add all ones that don't require mapping to map to themselves
for ( final String name : notRequired )
{
addMapping( name, name );
}
// now create a mapped name for each one that requires it.
for( final String originalName : required )
{
// our preferred derivation
final String preferredDerivation = originalToDerived( originalName );
// ensure that the derived name is not already used
String derivedName = preferredDerivation;
int id = 0;
while ( mAllNames.contains( derivedName ) ||
required.contains( derivedName ) )
{
derivedName = preferredDerivation + "_" + id;
++id;
}
addMapping( originalName, derivedName );
}
|
public boolean | derivedSameAsOriginal(java.lang.String derivedName)
final String original = derivedToOriginal( derivedName );
final boolean theSame = original != null && derivedName.equals( original );
return( theSame );
|
public java.lang.String | derivedToOriginal(java.lang.String derivedName)
String original = (String)mDerivedToOriginal.get( derivedName );
if ( original == null )
{
original = derivedName;
}
return( original );
|
public void | dontMap(java.lang.String originalName)
debug( "dontMap: " + originalName );
addMapping( originalName, originalName );
|
public java.util.Set | getAttributeNames()
return( mAllNames );
|
public java.lang.String | matchName(java.lang.String derivedName, java.lang.String[] candidates)
throw new UnsupportedOperationException( "matchName" );
|
public java.lang.String | originalToDerived(java.lang.String originalName)
String derivedName = (String)mOriginalToDerived.get( originalName );
if ( derivedName == null )
{
derivedName = mMangler.mangleAttributeName( originalName );
}
return( derivedName );
|
public boolean | requiresMapping(java.lang.String originalName)
boolean requiresMapping = true ;
// must start with upper-case first-letter
final char firstChar = originalName.charAt( 0 );
if ( Character.isUpperCase( firstChar ) )
{
if ( Character.isJavaIdentifierStart( firstChar ) )
{
final int length = originalName.length();
requiresMapping = false;
for( int i = 1; i < length; ++i )
{
if ( ! Character.isJavaIdentifierPart( originalName.charAt( i ) ) )
{
requiresMapping = true;
break;
}
}
}
}
return( requiresMapping );
|
public void | setDebugOutput(com.sun.appserv.management.util.misc.Output debugOutput)
mDebug = debugOutput;
|
public java.lang.String | toString()
final StringBuffer buf = new StringBuffer();
buf.append( "AttributeNameMapperImpl mappings:\n" );
final Iterator iter = getAttributeNames().iterator();
while ( iter.hasNext() )
{
final String name = (String)iter.next();
buf.append( name );
buf.append( " => " );
buf.append( derivedToOriginal( name ) + "\n" );
}
return( buf.toString() );
|