001    package net.sourceforge.retroweaver.translator;
002    
003    public class NameSpace {
004    
005            public NameSpace(String oldPrefix, String newPrefix) {
006                    if (oldPrefix == null || newPrefix == null) {
007                            throw new IllegalArgumentException();
008                    }
009    
010                    this.oldPrefix = oldPrefix.replace('.', '/');
011                    this.newPrefix = newPrefix.replace('.', '/');
012            }
013    
014            private final String oldPrefix;
015    
016            private final String newPrefix;
017    
018            public String getOldPrefix() {
019                    return oldPrefix;
020            }
021    
022            public String getNewPrefix() {
023                    return newPrefix;
024            }
025    
026            public String toString() {
027                    return "[" + oldPrefix + ", " + newPrefix + "]";
028            }
029    
030            /**
031             * Returns the translated mirror class name for <code>class_</code> or
032             * null if the namespace is not applicable
033             * 
034             * @param class_ the class name to translate
035             * @return the translated name or null
036             */
037            public String getMirrorClassName(final String class_) {
038                    if (oldPrefix.length() == 0) {
039                            return newPrefix + '/' + class_;
040                    }
041    
042                    if (!class_.startsWith(oldPrefix)) {
043                            return null;
044                    }
045    
046                    return class_.replaceFirst(oldPrefix, newPrefix);
047            }
048    
049    }