/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Converts aribitrary strings into Java identifiers.
*
* @author
* <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
*/
public interface NameConverter
{
/**
* converts a string into an identifier suitable for classes.
*
* In general, this operation should generate "NamesLikeThis".
*/
/**
* converts a string into an identifier suitable for interfaces.
*
* In general, this operation should generate "NamesLikeThis".
* But for example, it can prepend every interface with 'I'.
*/
/**
* converts a string into an identifier suitable for properties.
*
* In general, this operation should generate "NamesLikeThis",
* which will be used with known prefixes like "get" or "set".
*/
/**
* converts a string into an identifier suitable for constants.
*
* In the standard Java naming convention, this operation should
* generate "NAMES_LIKE_THIS".
*/
/**
* Converts a string into an identifier suitable for variables.
*
* In general it should generate "namesLikeThis".
*/
/**
* Converts a namespace URI into a package name.
* This method should expect strings like
* "http://foo.bar.zot/org", "urn:abc:def:ghi" "", or even "###"
* (basically anything) and expected to return a package name,
* liks "org.acme.foo".
*
*/
/**
* The name converter implemented by Code Model.
*
* This is the standard name conversion for JAXB.
*/
return toMixedCaseName(toWordList(s), true);
}
return toMixedCaseName(toWordList(s), false);
}
return toClassName(token);
}
// property name "Class" with collide with Object.getClass,
// so escape this.
prop = "Clazz";
return prop;
}
return super.toConstantName(token);
}
/**
* Computes a Java package name from a namespace URI,
* as specified in the spec.
*
* @return
* null if it fails to derive a package name.
*/
// remove scheme and :, if present
// spec only requires us to remove 'http' and 'urn'...
if(idx>=0) {
}
// issue 709; s/(.*)#(.*)/\1/
if(idx >= 0)
// tokenize string
return null;
}
// remove trailing file type, if necessary
// for uri's like "www.foo.com" and "foo.com", there is no trailing
// file, so there's no need to look at the last '.' and substring
// otherwise, we loose the "com" (which would be wrong)
if( idx > 0 ) {
}
}
// tokenize domain name and reverse. Also remove :port if it exists
// remove leading www
}
// replace the domain name with tokenized items
// iterate through the tokens and apply xml->java name algorithm
// get the token and remove illegal chars
// this will check for reserved keywords
}
}
// concat all the pieces and return it
}
// prefix an '_' if the first char is illegal
} else if( !Character.isJavaIdentifierPart( c ) ) {
// replace the char with an '_' if it is illegal
} else {
// add the legal char
}
}
}
while(tokens.hasMoreTokens())
return r;
}
return r;
}
for( int i=1; i<r.size(); i++ ) {
}
}
}
/**
* JAX-PRC compatible name converter implementation.
*
* The only difference is that we treat '_' as a valid character
* and not as a word separator.
*/
protected boolean isPunct(char c) {
return (c == '.' || c == '-' || c == ';' /*|| c == '_'*/ || c == '\u00b7'
|| c == '\u0387' || c == '\u06dd' || c == '\u06de');
}
protected boolean isLetter(char c) {
return super.isLetter(c) || c=='_';
}
}
};
/**
* Smarter converter used for RELAX NG support.
*/
return name;
else
return '_'+name;
}
};
}