Java语言规范基于JavaSE9 第七章 包和模块(三)

7.2 Host Support for Modules and Packages

7.2主机对模块和包的支持

Each host system determines how modules, packages, and compilation units are created and stored.

每一个主机系统都确定了模块、包和编译单元是如何创建和存储的。

Each host system determines which compilation units are observable in a particular compilation (§7.3). Each host system also determines which observable compilation units are associated with a module. The observability of compilation units associated with a module determines which modules are observable (§7.7.3) and which packages are visible within those modules (§7.4.3).

每一个主机系统都确定了哪些编译单元在特定的编译中是可观察的(第7.3节)。每一个主机系统还确定了哪些可观察的编译单元与模块相关联。这些与模块相关联的编译单元的可观察性决定了哪些模块是可观察的(第7.7.3节),以及哪些包在这些模块中是可见的(第7.4.3节)。

The host system is free to determine that a compilation unit which contains a module declaration is not, in fact, observable, and thus is not associated with the module declared therein. This enables a compiler to choose which directory on a modulesourcepath is “really” the embodiment of a given module. However, if the host system determines that a compilation unit which contains a module declaration is observable, then §7.4.3 mandates that the compilation unit must be associated with the module declared therein, and not with any other module.

主机系统可以自主确定包含模块声明的编译单元实际上是不可观察的,因此不与其中声明的模块相关联。这使得编译器能够选择模块资源路径上的哪个目录是“真正”给定模块的实例。但是,如果主机系统确定包含模块声明的编译单元是可观察的,则按照第7.4.3节中要求的,编译单元必须与其中声明的模块关联,而不是与其他任何模块关联。

The host system is free to determine that a compilation unit which contains a type declaration is (first) observable and (second) associated with an unnamed module or an automatic module - despite no declaration of an unnamed or automatic module existing in any compilation unit, observable or otherwise.

主机系统可以自由地确定包含类型声明的编译单元(第一)是可观察的,(第二)与未命名模块或自动模块相关联——尽管没有声明任何编译单元中存在可观察或其他的未命名或自动模块。

In simple implementations of the Java SE Platform, packages and compilation units may be stored in a local file system. Other implementations may store them using a distributed file system or some form of database.

在Java SE平台的简单实现中,包和编译单元可以存储在本地文件系统中。其他实现可以用分布式文件系统或某种形式的数据库来存储它们。

If a host system stores packages and compilation units in a database, then the database must not impose the optional restrictions (§7.6) on compilation units permissible in file-based implementations.

如果主机系统将包和编译单元存储在数据库中,那么数据库不能对在基于文件的实现中所允许的编译单元上强加任何可能的限制条件(第7.6节)。

For example, a system that uses a database to store packages may not enforce a maximum of one public class or interface per compilation unit.

例如,使用数据库来存储包的系统不能对每个编译单元中公共类或接口的数量强加最大值限制。

Systems that use a database must, however, provide an option to convert a program to a form that obeys the restrictions, for purposes of export to file-based implementations.

但是,考虑到需要导出到基于文件的实现系统中,对于使用数据库的系统,必须提供可选项,将程序转换为遵循某种限制的形式。

As an extremely simple example of storing packages in a file system, all the packages and source and binary code in a project might be stored in a single directory and its subdirectories. Each immediate subdirectory of this directory would represent a top level package, that is, one whose fully qualified name consists of a single simple name. Each further level of subdirectory would represent a subpackage of the package represented by the containing directory, and so on.

作为将包存储在文件系统中的一个极其简单的例子,项目中所有的包、源代码和二进制码可以都存储在单个目录及其子目录中。该目录的直接子目录可以表示顶层包,即完全限定名由单个简单名构成的包。每个更深层的子目录级别表示由包含它的目录所表示的包的子包,以此类推。

The directory might contain the following immediate subdirectories:

该目录可以包含下面这些直接目录:

com
gls
jag
java
wnj

where directory java would contain the Java SE Platform packages; the directories jag, gls, and wnj might contain packages that three of the authors of this specification created for their personal use and to share with each other within this small group; and the directory com would contain packages procured from companies that used the conventions described in §6.1 to generate unique names for their packages.

其中java目录包Java SE平台包;jag、gls和wnj可以包含本规范的三个作者创建的用于个人使用的包,并且在这个小组中彼此共享;com目录将包含从其他公司获取的包,这些公司使用 了第6. l节描述的惯用法为他们的包产生唯一的名字。

Continuing the example, the directory java would contain, among others, the following subdirectories:

继续看这个例子,上述子目录中的java目录将包含下面的子目 录:

applet
awt
io
lang
net
util

corresponding to the packages java.applet, java.awt, java.io, java.lang, java.net, and java.util that are defined as part of the Java SE Platform API.

对应的包为:java.applet、java.awt、java.io、java.lang、java.net、 java.util,它们 是作为Java SE平台API的一部分而定义的。

Still continuing the example, if we were to look inside the directory util, we might see the following files:

再继续看这个例子,在util目录的内部可以看到下面的文件:

BitSet.java Observable.java
BitSet.class Observable.class
Date.java Observer.java
Date.class Observer.class

where each of the .java files contains the source for a compilation unit (§7.3) that contains the definition of a class or interface whose binary compiled form is contained in the corresponding .class file.

其中每个.java文件都包含用于某个编译单元(第7.3节)的源 码,该编译单元包含某个类或接口的定义,而该定义的二进制编译形式则包含在该文件对应的.class文件中。

Under this simple organization of packages, an implementation of the Java SE Platform would transform a package name into a pathname by concatenating the components of the package name, placing a file name separator (directory indicator) between adjacent components.

在这个包的简单组织结构下,Java SE平台的某种实现可以将包名转换为目录名,方法是将包名的各个部分连接在一起,并在两个相邻部分之间放置一个文件名分隔符(路径指示符)。

For example, if this simple organization were used on an operating system where the file name separator is /, the package name:

例如,如果这个简单的组织结构用于文件名分隔符为“/”的操作系统上,下面的包名:

jag.scrabble.board

would be transformed into the directory name:

就将被转换为下面的目录名:

jag/scrabble/board

A package name component or class name might contain a character that cannot correctly appear in a host file system’s ordinary directory name, such as a Unicode character on a system that allows only ASCII characters in file names. As a convention, the character can be escaped by using, say, the @ character followed by four hexadecimal digits giving the numeric value of the character, as in the \uxxxx escape (§3.3).

包名的组成部分或类名可以包含不能在主机文件系统的普通目录名中正确显示的字符,例如在只允许在文件名中出现ASCII字符的系统上使用Unicode字符。作为一种惯用法,该字符可以用@字符后面跟着四个表示该字符的十六进制数字值来转义,就像在\uxxxx转义中的做法一样(第3.3节)。

Under this convention, the package name:

在这个惯用法之下,下面的包名:

children.activities.crafts.papierM\u00e2ch\u00e9

which can also be written using full Unicode as:

也可以全部由Unicode来编写:

children.activities.crafts.papierMâché

might be mapped to the directory name:

它可以映射成下面的目录名:

children/activities/crafts/papierM@00e2ch@00e9

If the @ character is not a valid character in a file name for some given host file system, then some other character that is not valid in a identifier could be used instead.

如果@字符在用于某些主机文件系统的文件名中不是有效字符时,那么可以用其他在标识符中无效的字符来代替。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值