スポンサーサイト

(--/--/-- --:--)

上記の広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書く事で広告が消せます。
【 permalink 】 | | page top↑ | edit
Javaでドメイン名から一意なパッケージ名を生成するルールのまとめ。

(2009/05/01 17:07)

Java言語仕様 第3版7.7 Unique Package Names に、以下の記述があります。

In some cases, the internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations:

  • If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.
  • If any of the resulting package name components are keywords (§3.9) then append underscore to them.
  • If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.

というわけで、ドメイン名の要素を逆順にしつつ、

  1. ドメイン名にハイフンのような識別子に使えない文字が含まれる場合は、それらをアンダーバーに置き換える。
  2. さらに、パッケージ名の要素が予約語になってしまう場合には、その要素にアンダーバーを後置する。(append)
  3. さらに、パッケージ名の要素が数字(や、そのほか識別子の先頭に使えない文字)からはじまる場合、その要素にアンダーバーを前置する。(prefixed)
【 permalink 】 | java | トラックバック(0) | コメント(0) | page top↑ | edit
<<Java 6で、HttpURLConnectionをクッキーに対応させる手軽な方法。 | ホーム | 文字列をWikipediaのアンカー名風にエンコードする。Javaで。>>
コメント

※コメント大歓迎です。いただいたコメントに対してこちらから返答することは原則ありませんが、必要な場合には記事本文で回答します。

コメントの投稿














管理者にだけ表示を許可する

トラックバック
トラックバックURL
→http://0xc000013a.blog96.fc2.com/tb.php/90-a582d62c
この記事にトラックバックする(FC2ブログユーザー)
| ホーム |