開頭,接著是

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

XMLEncoder生成的xml文檔的schema分析

系統(tǒng) 2408 0

以下文為基礎(chǔ),進(jìn)行分析

Long Term Persistence of JavaBeans Components: XML Schema

http://java.sun.com/products/jfc/tsc/articles/persistence3/

1Basic Elements

每個(gè)xml以一個(gè)可選的

<?xml version="1.0" encoding="UTF-8" ?>

開頭,接著是

<java version="1.4.0" class="java.beans.XMLDecoder">
...objects go here...
</java>

其中,version,class這個(gè)兩個(gè)屬性似乎已經(jīng)不使用了。

<java>..</java>中間填充的是組成xml文檔的objects,以被解碼器readObject的順序出現(xiàn)。

2Objects

每個(gè)object由創(chuàng)建它的一系列方法,按序排列來代表。

每個(gè)xml元素都代表一個(gè)方法調(diào)用。這些方法:一,創(chuàng)建了object(對應(yīng)一個(gè)表達(dá)式expression);二,影響了object(對應(yīng)一個(gè)語句statement)。

strings被看作特殊的expressions,標(biāo)識符(identifiers)用來在object創(chuàng)建之后再引用object時(shí)使用的。

3Strings

xml中的原子表達(dá)式,

<string>Hello, World</string>

The '<' and '&' characters are represented by the &lt; and &amp; escape sequences.

4Expressions and Statements

expression是有返回值的方法調(diào)用,表示為:<object>

statement是沒有返回值的方法調(diào)用。表示為:<void>

兩個(gè)元素都有一個(gè)method屬性,表示調(diào)用的方法。

<object>的class 屬性指定作為一個(gè)靜態(tài)方法的目標(biāo)的class,構(gòu)造函數(shù)表示為:一個(gè)名為new的靜態(tài)方法。

當(dāng)expression,statement進(jìn)一步還包含expressions,則這些expressions作為前兩者所代表的方法的參數(shù)。

所以,

<object class="javax.swing.JButton" method="new">
<string>Press me</string>
</object>

代表的java 語句是

new JButton("Press me");

還可以表示為:

<object class="javax.swing.JButton">
<string>Press me</string>
</object>

因?yàn)椋琻ew是默認(rèn)的方法。

將影響一個(gè)object(由expression產(chǎn)生)的方法(一個(gè)statement)放到這個(gè)object里去,如下:

<object class="javax.swing.JButton">
<void method="setText">
<string>Hello, world</string>
</void>
</object>

即為:

JButton b = new JButton();
b.setText("Hello, world");

If an expression should not be used as an argument to the enclosing method, it should be represented with the <void> tag. The result of an expression in a <void> tag is still evaluated and used by any objects it encloses.(待考)

嵌套expression,statement的能力減少了描述圖形時(shí)使用的identifier的數(shù)目。

5標(biāo)識符

有時(shí),用<object>聲明了一個(gè)對象之后,可能會在其他地方再次用到該對象,所以要定義identifier:

<object id="button1" class="javax.swing.JButton"/>

id是全局的,從聲明起。

例子:

<object class="javax.swing.JPanel">
<void method="add">
<object id="button1" class="javax.swing.JButton"/>
</void>
<void method="add">
<object class="javax.swing.JLabel">
<void method="setLabelFor">
<object idref="button1"/>
</void>
</object>
</void>
</object>

即為:

JPanel panel1 = new JPanel();
JButton button1 = new JButton();
JLabel label1 = new JLabel();
panel1.add(button1);
panel1.add(label1);
label1.setLabelFor(button1);

id還可以這樣用:

<object class="java.util.Date">
<void id="now" method="getTime"/>
</object>

It allows an expression to be evaluated in the context of the enclosing instance, in this case defining the variable now as the value of the expression. It corresponds to the following Java code: (待考)

long now = new Date().getTime();

6縮寫詞Abbreviation

上述知識,足夠使用XMLEncoder,下面是高級知識,可以讓xml更簡單:

primitives

The following tags represent both the primitive types and their corresponding wrapper classes:
<boolean>
<byte>
<char>
<short>
<int>
<long>
<float>
<double>

例如:

<object class="java.lang.Integer">
<string>123</string>
</object>

可簡寫為:

<int>123</int>

null

<null/>

class

The <class> tag can be used to represent an instance of Class. For example,

<object class="java.lang.Class method="forName">
<string>java.awt.event.ActionListener</string>
</object>
is shortened to

<class>java.awt.event.ActionListener</class>

which is equivalent to ActionListener.class.

Static Constants
(only in releases after 1.4.0 beta) (待考)

As of the release following 1.4.0 beta, the values of static constants may be written using the class and field attributes to specify the declaring class and field name of the constant, respectively. Thus

<void class="javax.swing.JTable" method="getField">
<string>AUTO_RESIZE_OFF</string>
<void id="Integer0" method="get">
<null/>
</void>
</void>
<object idref="Integer0"/>

is shortened to

<object class="javax.swing.JTable" field="AUTO_RESIZE_OFF"/>

property

以get,set開頭的方法可以簡寫:

如,<void method="getText"/>
is shortened to:

<void property="text"/>

如,

<void method="setText">
<string>Hello, world</string>
</void>
is shortened to:

<void property="text">
<string>Hello, world</string>
</void>

Index

繼承于java.util,list接口的get,set方法可以簡寫為:

<void method="get">
<int>3</int>
<void>
is shortened to

<void index="3"/>
which corresponds to the following Java code:

Object o = aList.get(3);

又,

<void index="3">
<string>Hello, world</string>
</void>
is equivalent to

<void method="set">
<int>3</int>
<string>Hello, world</string>
</void>
which corresponds to the following Java code:

aList.set(3, "Hello, world")

array

用<array>來表示數(shù)組,

<array class="java.awt.Component" length="3"/>
It corresponds to the following Java code:

Component[] a = new Component[3];

version1。4之后,還可以:

<array class="int">
<int>123</int>
<int>456</int>
</array>
represents the following Java code fragment:

int[] intArray = {123, 456};

which represents JTable.AUTO_RESIZE_OFF.

The Top Level environment

定義在<java></java>這個(gè)層次的一些高級屬性,涉及到XMLDecoder(待考)

7DTD

http://java.sun.com/products/jfc/tsc/articles/persistence3/javabeans.dtd

一個(gè)例子:

http://java.sun.com/products/jfc/tsc/articles/persistence3/Browse.xml

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.0" class="java.beans.XMLDecoder">
<object class="javax.swing.JFrame">
<void id="JPanel0" property="contentPane">
<void method="add">
<object id="JLabel0" class="javax.swing.JLabel">
<void property="text">
<string>URL:</string>
</void>
<void property="location">
<object class="java.awt.Point">
<int>10</int>
<int>10</int>
</object>
</void>
</object>
</void>
<void method="add">
<object id="JScrollPane0" class="javax.swing.JScrollPane">
<void property="preferredSize">
<object class="java.awt.Dimension">
<int>500</int>
<int>300</int>
</object>
</void>
<void property="viewport">
<void method="add">
<object id="JEditorPane0" class="javax.swing.JEditorPane"/>
</void>
</void>
<void property="location">
<object class="java.awt.Point">
<int>10</int>
<int>40</int>
</object>
</void>
</object>
</void>
<void method="add">
<object id="JTextField0" class="javax.swing.JTextField">
<void property="text">
<string>file:///C:/</string>
</void>
<void method="addActionListener">
<object class="java.beans.EventHandler" method="create">
<class>java.awt.event.ActionListener</class>
<object idref="JEditorPane0"/>
<string>page</string>
<string>source.text</string>
</object>
</void>
<void property="location">
<object class="java.awt.Point">
<int>62</int>
<int>10</int>
</object>
</void>
</object>
</void>
<void property="layout">
<object class="javax.swing.SpringLayout">
<void method="putConstraint">
<string>East</string>
<object idref="JTextField0"/>
<int>0</int>
<string>East</string>
<object idref="JScrollPane0"/>
</void>
<void method="putConstraint">
<string>West</string>
<object idref="JTextField0"/>
<int>10</int>
<string>East</string>
<object idref="JLabel0"/>
</void>
<void method="putConstraint">
<string>South</string>
<object idref="JPanel0"/>
<int>10</int>
<string>South</string>
<object idref="JScrollPane0"/>
</void>
<void method="putConstraint">
<string>East</string>
<object idref="JPanel0"/>
<int>10</int>
<string>East</string>
<object idref="JScrollPane0"/>
</void>
<void method="putConstraint">
<string>North</string>
<object idref="JScrollPane0"/>
<int>40</int>
<string>North</string>
<object idref="JPanel0"/>
</void>
</object>
</void>
</void>
<void method="pack"/>
<void property="visible">
<boolean>true</boolean>
</void>
</object>
</java>

XMLEncoder生成的xml文檔的schema分析


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 甘孜| 仁寿县| 舞阳县| 正定县| 苏尼特右旗| 黄龙县| 芦山县| 昌宁县| 偃师市| 玉树县| 临高县| 元氏县| 济源市| 兴海县| 吉安市| 兴业县| 东宁县| 通山县| 苗栗县| 新密市| 兰州市| 栾城县| 克什克腾旗| 疏勒县| 广平县| 池州市| 涡阳县| 满洲里市| 宁波市| 鹤壁市| 洪泽县| 武川县| 沿河| 平利县| 勐海县| 邓州市| 手游| 安宁市| 淮南市| 九台市| 陕西省|