啥是对象字面量量?定义我看得懂,但是没记忆想不通。大神,给个例子不?

&&&&&C安全编码标准:开发安全、可靠、稳固系统的98条规则(原书第2版...
邀请好友参加吧
版 次:1页 数:392字 数:277印刷时间:日开 本:16开纸 张:胶版纸印 次:1包 装:平装是否套装:否国际标准书号ISBN:0所属分类:&&&
下载免费当当读书APP
品味海量优质电子书,尊享优雅的阅读体验,只差手机下载一个当当读书APP
本商品暂无详情。
当当价:为商品的销售价,具体的成交价可能因会员使用优惠券、积分等发生变化,最终以订单结算页价格为准。
划线价:划线价格可能是图书封底定价、商品吊牌价、品牌专柜价或由品牌供应商提供的正品零售价(如厂商指导价、建议零售价等)或该商品曾经展示过的销售价等,由于地区、时间的差异化和市场行情波动,商品吊牌价、品牌专柜价等可能会与您购物时展示的不一致,该价格仅供您参考。
折扣:折扣指在划线价(图书定价、商品吊牌价、品牌专柜价、厂商指导价等)某一价格基础上计算出的优惠比例或优惠金额。如有疑问,您可在购买前联系客服咨询。
异常问题:如您发现活动商品销售价或促销信息有异常,请立即联系我们补正,以便您能顺利购物。
当当购物客户端手机端1元秒
当当读书客户端万本电子书免费读The following notations are used in this article: BP: best practice
G: general guideline
PS: proposed TIP: implementation tip
AR: arguably RESTful -- may not be RESTful in the strict sense Reprising RESTLet's briefly reiterate the REST web services architecture. REST web services architecture conforms to the W3C's , and leverages the architectural principles of the Web, building its strength on the proven infrastructure of the Web. It utilizes the semantics of HTTP whenever possible and most of the
also apply.The REST web services architecture is related to the . This limits the interface to HTTP with the four well-defined verbs: GET, POST, PUT, and DELETE. REST web services also tend to use XML as the main messaging format. [G] Implementing REST correctly requires a resource-oriented view of the world instead of the object-oriented views many developers are familiar with.ResourceOne of the most important concepts of web architecture is a "resource." A resource is an abstract thing identified by a . A REST service is a resource. A service provider is an implementation of a service. URI Opacity [BP]The creator of a URI decides the encoding of the URI, and users should not derive metadata from the URI itself. URI opacity only applies to the path of a URI. The query string and fragment have special meaning that can be understood by users. There must be a shared vocabulary between a service and its consumers.Query String Extensibility [BP, AR]A service provider should ignore any query parameters it does not understand during processing. If it needs to consume other services, it should pass all ignored parameters along. This practice allows new functionality to be added without breaking existing services. [TIP]
provides a good framework for defining simple types, which can be used for validating query parameters.Deliver Correct Resource Representation [G]A resource may have more than one representation. There are four frequently used ways of delivering the correct resource representation to consumers:Server-driven negotiation. The service provider determines the right representation from prior knowledge of its clients or uses the information provided in HTTP headers like Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent. The drawback of this approach is that the server may not have the best knowledge about what a client really wants.
Client-driven negotiation. A client initiates a request to a server. The server returns a list of available of representations. The client then selects the representation it wants and sends a second request to the server. The drawback is that a client needs to send two requests.
Proxy-driven negotiation. A client initiates a request to a server through a proxy. The proxy passes the request to the server and obtains a list of representations. The proxy selects one representation according to preferences set by the client and returns the representation back to the client.
URI-specified representation. A client specifies the representation it wants in the URI query string. Server-Driven Negotiation [BP]When delivering a representation to its client, a server MUST check the following HTTP headers: Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent to ensure the representation it sends satisfies the user agent's capability.
When consuming a service, a client should set the value of the following HTTP headers: Accept, Accept-Charset, Accept-Encoding, Accept-Language, and User-Agent. It should be specific about the type of representation it wants and avoid "*/*", unless the intention is to retrieve a list of all possible representations.
A server may determine the type of representation to send from the profile information of the client. URI-Specified Representation [PS, AR]A client can specify the representation using the following query string:mimeType={mime-type}A REST server should support this query.Different Views of a Resource [PS, AR]A resource may have different views, even if there is only one representation available. For example, a resource has an XML representation but different clients may only see different portion of the same XML. Another common example is that a client might want to obtain metadata of the current representation.To obtain a different view, a client can set a "view" parameter in the URI query string. For example:
GET /abc?view=metawhere the value of the "view" parameter determines the actual view. Although the value of "view" is application specific in most cases, this guideline reserves the following words:"meta," for obtaining the metadata view of the resource or representation.
"status," for obtaining the status of a request/transaction resource. ServiceA service represents a specialized business function. A service is safe if it does not incur any obligations from its invoking client, even if this service may cause a change of state on the server side. A service is obligated if the client is held responsible for the change of states on server side.Safe ServiceA safe service should be invoked by the GET method of HTTP. Parameters needed to invoke the service can be embedded in the query string of a URI. The main purpose of a safe service is to obtain a representation of a resource.Service Provider Responsibility [BP]If there is more than one representation available for a resource, the service should negotiate with the client as discussed above. When returning a representation, a service provider should set the HTTP headers that relate to caching policies for better performance.A safe service is by its nature idempotent. A service provider should not break this constraint. Clients should expect to receive consistent representations. Obligated Services [BP]Obligated services should be implemented using POST. A request to an obligated service should be described by some kind of XML instance, which should be constrained by a schema. The schema should be written in W3C XML Schema or Relax NG. An obligated service should be made idempotent so that if a client is unsure about the state of its request, it can send it again. This allows low-cost error recovery. An obligated service usually has the simple semantic of "process this" and has two potential impacts: either the creation of new resources or the creation of a new representation of a resource.Asynchronous ServicesOne often hears the criticism that HTTP is synchronous, while many services need to be asynchronous. It is actually quite easy to implement an asynchronous REST service. An asynchronous service needs to perform the following:Return a receipt immediately upon receiving a request.
Validate the request.
If the request if valid, the service must act on the request as soon as possible. It must report an error if the service cannot process the request after a period of time defined in the service contract. Request ReceiptAn example receipt is shown below:&receipt xmlns="http://www.xml.org/2004/rest/receipt" requestUri = "/xya343343" received = "T12:34:33+10:00"&
&transaction uri="/xyz2343" status = "/xyz2343?view=status"/&&/receipt& A receipt is a confirmation that the server has received a request from a client and promises to act on the request as soon as possible. The receipt element should include a received attribute, the value of which is the time the server received the request in WXS dateTime type format. The requestUri attribute is optional. A service may optionally create a request resource identified by the requestUri. The request resource has a representation, which is equivalent to the request content the server receives. A client may use this URI to inspect the actual request content as received by the server. Both client and server may use this URI for future reference. However, this is application-specific. A request may initiate more than one transaction. Each transaction element must have a URI attribute which identifies this transaction. A server should also create a transaction resource identified by the URI value. The transaction element must have a status attribute whose value is a URI pointing to a status resource. The status resource must have an XML representation, which indicates the status of the transaction. TransactionA transaction represents an atomic unit of work done by a server. The goal of a transaction is to complete the work successfully or return to the original state if an error occurs. For example, a transaction in a purchase order service should either place the order successfully or not place the order at all, in which case the client incurs no obligation. Status URI [BP, AR]The status resource can be seen as a different view of its associated transaction resource. The status URI should only differ in the query string with an additional status parameter. For example: Transaction URI: /xyz2343 Transaction Status URI: /xyz2343?view=status Transaction Lifecycle [G]A transaction request submitted to a service will experience the following lifecycle as defined in :Start -- the transaction is created. This is triggered by the arrival of a request.
Received -- the transaction has been received. This status is reached when a request is persisted and the server is committed to fulfill the request.
Processing -- the transaction is being processed, that is, the server has committed resources to process the request.
Processed -- processing is successfully finished. This status is reached when all processing has completed without any errors.
Failed -- processing is terminated due to errors. The error is usually caused by invalid submission. A client may rectify its submission and resubmit. If the error is caused by system faults, logging messages should be included. An error can also be caused by internal server malfunction.
Final -- the request and its associated resources may be removed from the server. An implementation may choose not to remove those resources. This state is triggered when all results are persisted correctly. Note that it is implementation-dependent as to what operations must be performed on the request itself in order to transition it from one status to another. The state diagram of a request (taken from ) is shown below: As an example of the status XML, when a request is just received: &status state="received" timestamp="T12:34:33+10:00" /& The XML contains a state attribute, which indicates the current state of the request. Other possible values of the state attribute are processing, processed, and failed. When a request is processed, the status XML is (non-normative):&status state="processed" timestamp="T12:34:33+10:00" &
&result uri="/rest/1123/xyz" /&&/status& This time, a result element is included and it points to a URL where the client can GET request results. In case a request fails, the status XML is (non-normative):
state="failed" timestamp="T12:34:33+10:00" &
&error code="3" &
&message&A bad request. &/message&
&exception&line 3234&/exception&
&/status&A client application can display the message enclosed within the message tag. It should ignore all other information. If a client believes that the error was not caused by its fault, this XML may serve as a proof. All other information is for internal debugging purposes. Request Result [BP]A request result view should be regarded as a special view of a transaction. One may create a request resource and transaction resources whenever a request is received. The result should use XML markup that is as closely related to the original request markup as possible. Receiving and Sending XML [BP]When receiving and sending XML, one should follow the principle of "strict out and loose in." When sending XML, one must ensure it is validated against the relevant schema. When receiving an XML document, one should only validate the XML against the smallest set of schema that is really needed. Any software agent must not change XML it does not understand. An Implementation ArchitectureThe architecture represented above has a pipe-and-filter style, a classical and robust architectural style used as early as in 1944 by the famous physicist, Richard Feynman, to build the first atomic bomb in his computing team. A request is processed by a chain of filters and each filter is responsible for a well-defined unit of work. Those filters are further classified as two distinct groups: front-end and back-end. Front-end filters are responsible to handle common Web service tasks and they must be light weight. Before or at the end of front-end filters, a response is returned to the invoking client. All front-end filters must be lightweight and must not cause serious resource drain on the host. A common filter is a bouncer filter, which checks the eligibility of the request using some simple techniques: IP filtering. Only requests from eligible IPs are allowed.
URL mapping. Only certain URL patterns are allowed.
Time-based filtering. A client can only send a certain number of requests per second.
Cookie-based filtering. A client must have a cookie to be able to access this service.
Duplication-detection filter. This filter checks the content of a request and determines whether it has received it before. A simple technique is based on the hash value of the received message. However, a more sophisticated technique involves normalizing the contents using an application-specific algorithm. A connector, whose purpose is to decouple the time dependency between front-end filters and back-end filters, connects front-end filters and back-end filters. If back-end processing is lightweight, the connector serves mainly as a delegator, which delegates requests to its corresponding back-end processors. If back-end processing is heavy, the connector is normally implemented as a queue. Back-end filters are usually more application specific or heavy. They should not respond directly to requests but create or update resources. This architecture is known to have many good properties, as observed by Feynman, whose team improved its productivity many times over. Most notably, the filters can be considered as a standard form of computing and new filters can be added or extended from existing ones easily. This architecture has good user-perceived performance because responses are returned as soon as possible once a request becomes fully processed by lightweight filters. This architecture also has good security and stability because security breakage and errors can only propagate a limited number of filters. However, it is important to note that one must not put a heavyweight filter in the front-end or the system may become vulnerable to denial-of-service attacks.
I am seeing a lot of new web services are implemented using a REST style architecture these days rather than a SOAP one. Lets step back a second and explain what REST is.
What is a REST Web Service
The acronym REST stands for Representational State Transfer, this basically means that each unique URL is a representation of some object. You can get the contents of that object using an HTTP GET, to delete it, you then might use a POST, PUT, or DELETE to modify the object (in practice most of the services use a POST for this).
Who's using REST?
All of Yahoo's web services use REST, including Flickr, del.icio.us API uses it, pubsub, bloglines, technorati, and both eBay, and Amazon have web services for both REST and SOAP.
Who's using SOAP?
Google seams to be consistent in implementing their web services to use SOAP, with the exception of Blogger, which uses XML-RPC. You will find SOAP web services in lots of enterprise software as well.
REST vs SOAP
As you may have noticed the companies I mentioned that are using REST api's haven't been around for very long, and their apis came out this year mostly. So REST is definitely the trendy way to create a web service, if creating web services could ever be trendy (lets face it you use soap to wash, and you rest when your tired). The main advantages of REST web services are:
Lightweight - not a lot of extra xml markup
Human Readable Results
Easy to build - no toolkits required
SOAP also has some advantages:
Easy to consume - sometimes
Rigid - type checking, adheres to a contract
Development tools
For consuming web services, its sometimes a toss up between which is easier. For instance Google's AdWords web service is really hard to consume (in CF anyways), it uses SOAP headers, and a number of other things that make it kind of difficult. On the converse, Amazon's REST web service can sometimes be tricky to parse because it can be highly nested, and the result schema can vary quite a bit based on what you search for.
Which ever architecture you choose make sure its easy for developers to access it, and well documented.原文:
Building Web Services the REST Way
Roger L. Costello
I will first provide a brief introduction to REST and then describe how to build Web services in the REST style.
What is REST?
REST is a term coined by Roy Fielding in his Ph.D. dissertation [1] to describe an architecture style of networked systems. REST is an acronym standing for Representational State Transfer.
Why is it called Representational State Transfer?
The Web is comprised of resources. A resource is any item of interest. For example, the Boeing Aircraft Corp may define a 747 resource. Clients may access that resource with this URL:
/aircraft/747
A representation of the resource is returned (e.g., Boeing747.html). The representation places the client application in a state. The result of the client traversing a hyperlink in Boeing747.html is another resource is accessed. The new representation places the client application into yet another state. Thus, the client application changes (transfers) state with each resource representation --& Representational State Transfer!
Here is Roy Fielding's explanation of the meaning of Representational State Transfer:
"Representational State Transfer is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use."
Motivation for REST
The motivation for REST was to capture the characteristics of the Web which made the Web successful. Subsequently these characteristics are being used to guide the evolution of the Web.
REST - An Architectural Style, Not a Standard
REST is not a standard. You will not see the W3C putting out a REST specification. You will not see IBM or Microsoft or Sun selling a REST developer's toolkit. Why? Because REST is just an architectural style. You can't bottle up that style. You can only understand it, and design your Web services in that style. (Analogous to the client-server architectural style. There is no client-server standard.)
While REST is not a standard, it does use standards:
XML/HTML/GIF/JPEG/etc (Resource Representations)
text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)
The Classic REST System
The Web is a REST system! Many of those Web services that you have been using these many years - book-ordering services, search services, online dictionary services, etc - are REST-based Web services. Alas, you have been using REST, building REST services and you didn't even know it.
REST is concerned with the "big picture" of the Web. It does not deal with implementation details (e.g., using Java servlets or CGI to implement a Web service). So let's look at an example of creating a Web service from the REST "big picture" perspective.
Parts Depot Web Services
Parts Depot, Inc (fictitious company) has deployed some web services to enable its customers to:
get a list of parts
get detailed information about a particular part
submit a Purchase Order (PO)
Let's consider how each of these services are implemented in a RESTful fashion.
Get Parts List
The web service makes available a URL to a parts list resource. For example, a client would use this URL to get the parts list:
http://www./parts
Note that "how" the web service generates the parts list is completely transparent to the client. All the client knows is that if he/she submits the above URL then a document containing the list of parts is returned. Since the implementation is transparent to clients, Parts Depot is free to modify the underlying implementation of this resource without impacting clients. This is loose coupling.
Here's the document that the client receives:
&?xml version="1.0"?&
&p:Parts xmlns:p="http://www."
xmlns:xlink="http://www.w3.org/1999/xlink"&
&Part id="00345" xlink:href="http://www./parts/00345"/&
&Part id="00346" xlink:href="http://www./parts/00346"/&
&Part id="00347" xlink:href="http://www./parts/00347"/&
&Part id="00348" xlink:href="http://www./parts/00348"/&
&/p:Parts&
[Assume that through content negotiation the service determined that the client wants the representation as XML (for machine-to-machine processing).] Note that the parts list has links to get detailed info about each part. This is a key feature of REST. The client transfers from one state to the next by examining and choosing from among the alternative URLs in the response document.
Get Detailed Part Data
The web service makes available a URL to each part resource. Example, here's how a client requests part 00345:
http://www./parts/00345
Here's the document that the client receives:
&?xml version="1.0"?&
&p:Part xmlns:p="http://www."
xmlns:xlink="http://www.w3.org/1999/xlink"&
&Part-ID&00345&/Part-ID&
&Name&Widget-A&/Name&
&Description&This part is used within the frap assembly&/Description&
&Specification xlink:href="http://www./parts/00345/specification"/&
&UnitCost currency="USD"&0.10&/UnitCost&
&Quantity&10&/Quantity&
Again observe how this data is linked to still more data - the specification for this part may be found by traversing the hyperlink. Each response document allows the client to drill down to get more detailed information.
The web service makes available a URL to submit a PO. The client creates a PO instance document which conforms to the PO schema that Parts Depot has designed (and publicized in a WSDL document). The client submits PO.xml as the payload of an HTTP POST.
The PO service responds to the HTTP POST with a URL to the submitted PO. Thus, the client can retrieve the PO any time thereafter (to update/edit it). The PO has become a piece of information which is shared between the client and the server. The shared information (PO) is given an address (URL) by the server and is exposed as a Web service.
Logical URLs versus Physical URLs
A resource is a conceptual entity. A representation is a concrete manifestation of the resource. This URL:
http://www./parts/00345
is a logical URL, not a physical URL. Thus, there doesn't need to be, for example, a static HTML page for each part. In fact, if there were a million parts then a million static HTML pages would not be a very attractive design.
[Implementation detail: Parts Depot could implement the service that gets detailed data about a particular part by employing a Java Servlet which parses the string after the host name, uses the part number to query the parts database, formulate the query results as XML, and then return the XML as the payload of the HTTP response.]
As a matter of style URLs should not reveal the implementation technique used. You need to be free to change your implementation without impacting clients or having misleading URLs.
REST Web Services Characteristics
Here are the characteristics of REST:
Client-Server: a pull-based interaction style: consuming components pull representations.
Stateless: each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
Cache: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.
Uniform interface: all resources are accessed with a generic interface (e.g., HTTP GET, POST, PUT, DELETE).
Named resources - the system is comprised of resources which are named using a URL.
Interconnected resource representations - the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another.
Layered components - intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.
Principles of REST Web Service Design
1. The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services. Above we saw some examples of resources: parts list, detailed part data, purchase order.
2. Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:
http://www./parts/getPart?id=00345
Note the verb, getPart. Instead, use a noun:
http://www./parts/00345
3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.
4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.
5. No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information.
6. Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details.
7. Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron). For those services that require a POST or PUT to it, also provide a schema to specify the format of the response.
8. Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.
This article described REST as an architectural style. In fact, it's the architectural style of the Web. REST describes what makes the Web work well. Adhering to the REST principles will make your services work well in the context of the Web.
In a future article I will write about the evolution of the Web using the REST principles.
Acknowledgement
Thanks to Robert Leftwich and Philip Eskelin for their very helpful comments in creating this document.
References
市长热线:12345
反扒热线:
交通伤急救热线:
中毒援助热线:
抗癌互助热线:
查号台:114
移动电话话费查询台:1861
铁路查询售票信息:2586
市燃气集团公司24小时热线电话:
北京市煤气公司急修:
北京市供电局报修中心:
公证咨询专线:98148
节水服务热线:
特快专递服务台:185
报时:12117
气象综合信息服务台:211
首都公众信息网:263
秘书台:269
青春热线:
人工信息服务台:160
道路交通事故咨询热线:
法律服务专线:1600148
老年痴呆症咨询热线:
市政热线:
医疗急救台:120
道路交通报警台:122
紧急避孕热线:
移动电话服务台:222
铁路车票定票热线:
北京市热力公司急修:
天然气急修:
施工扰民投诉电话:
中国政法大学环境法研究和服务中心热线电话:
水上搜救专用电话:12395
天气预报台:12121
语音信箱:166
妇女热线:
北京公共交通李素丽服务热线:96166小公共汽车营运服务监督电话:
火车票新订票热线:016688
复婚热线:
违规用水举报电话:
中华骨髓库信息热线:
市地税局举报电话:12366 免费宠物热线: 公共卫生投诉电话: 拆迁举报电话: 市公安局监督养犬举报电话: 道路质量监督电话: 劳保咨询热线:12333 土地矿产法律免费热线: 单亲孩子援助热线: 热水器抢修服务热线:1600110 市重大动物疫病指挥部办公室:
危改热线:weigai@ 北京新闻广播“新闻热线”: 民工维权热线电话:12333 西站24小时举报电话: 燃气报修热线:96777 自来水集团报修中心: 电梯安全问题投诉电话:12365 加油卡更换咨询电话: 食品安全监察处:315 黑车、黑导游举报电话:96310 北京通信公司北京客户服务中心:10060 北京通信公司话费传真号码: 北京市电信公司客户服务热线:96388 金银建出租汽车调度中心:96103 汽车援救电话: 驾驶员违章积分短信查询热线: 城八区闯红灯咨询电话: 北京西站问讯处: 北京南站问讯处: 北京北站问讯处: 铁路信息查询台:962585 火车票订票热线:962586 客票中心订票热线: 北京火车站订票热线:
使用TreeViewer贡献视图(根据《Eclipse入门到精通》中的例子进行的改编)作者:李红霞 本文章允许转载,但请要求注明文章作者及出处一 创建插件项目创建一个插件项目example.my.treeview,这个例子将向eclipse贡献一个视图,这个视图采用树(Treeviewer)来实现。下图是本例的文件清单&抱歉,图片传不上来&+ example.my.treeview+ src
+ example.my.treeview
- TreeviewPlugin.java
+ exampe.my.treeview.data
- CityEntity.java
- CountryEntity.java
- DataFactory.java
- PeopleEnrity.java
+ example.my.treeview.internal
- ITreeEntry.java
- TreeViewerContentProvider.java
- TreeViewerLabelProvider.java
- TreeViewPart.java
+ JRE System Library
+ Plug-in dependencies
+ META-INF
- MENIFEST.MF
- build.properties
- plugin.xml二 准备数据模型首先我们准备数据模型,这些数据模型都保存在example.my.treeview.data这个包中我们定义一个接口ItreeEntry,这个接口将定义树中每个节点共同特征(名称和子节点),代码如下package example.my.treeview.import java.util.Lpublic interface ITreeEntry {
public String getName();
public void setName(String name);
//设置得到子节点的集合
public void setChildren(List children);
public List getChildren();}这里涉及的实体一共有3个,以下是他们的代码package example.my.treeview.import java.util.Limport example.my.treeview.internal.ITreeEpublic class CityEntity implements ITreeEntry{
private L//唯一识别码
private S//城市名
private L//城市中的人
public CityEntity(){}
public CityEntity(String name){this.name=}
public Long getId() {}
public void setId(Long id) {this.id =}
public String getName() {}
public void setName(String name) {this.name =}
public List getChildren() {}
public void setChildren(List peoples) {
this.peoples =
}}package example.my.treeview.import java.util.Limport example.my.treeview.internal.ITreeEpublic class CountryEntity implements ITreeEntry{
//唯一识别码,在数据库里常为自动递增的ID列
private S//国家名//此国家所包含的城市的集合,集合元素为City对象
//两个构造函数
public CountryEntity(){}
public CountryEntity(String name){this.name =}
//相应的get和set方法
public List getChildren() {}
public void setChildren(List cities) {this.cities =}
public Long getId() {}
public void setId(Long id) {this.id =}
public String getName() {}
public void setName(String name) {this.name =}}package example.my.treeview.import java.util.Limport example.my.treeview.internal.ITreeEpublic class PeopleEntity implements ITreeEntry{
public PeopleEntity(){}
public PeopleEntity(String name){this.name=}
public List getChildren(){}
public void setChildren(List children){}
public String getName() {}
public void setName(String name) {this.name =}}三 创建树中的数据结构代码如下package example.my.treeview.import java.util.ArrayLpublic class DataFactory {
public static Object createTreeData(){
//生成人的数据对象
PeopleEntity p1 = new PeopleEntity("李红霞");
PeopleEntity p2 = new PeopleEntity("金利军");
PeopleEntity p3 = new PeopleEntity("何涛");
//生成城市的数据对象
CityEntity city1=new CityEntity("湖北");
CityEntity city2=new CityEntity("北京");
CityEntity city3=new CityEntity("湖南");
//生成国家的数据对象
CountryEntity c1 = new CountryEntity("美国");
CountryEntity c2 = new CountryEntity("中国");
//将数据对象连接起来
//人和城市的关系
ArrayList list = new ArrayList();
list.add(p1);
city1.setChildren(list);
ArrayList list = new ArrayList();
list.add(p2);
city2.setChildren(list);
ArrayList list = new ArrayList();
list.add(p3);
city3.setChildren(list);
//城市和国家的关系
ArrayList list = new ArrayList();
list.add(city1);
c1.setChildren(list);
ArrayList list = new ArrayList();
list.add(city2);
list.add(city3);
c2.setChildren(list);
//将国家置于一个对象之下,//这个对象可以是List也可以是数组
ArrayList list = new ArrayList();
list.add(c1);
list.add(c2);
}}四 标签器和内容器TreeViewer和TableViewer一样,是用内容器和标签器来控制记录对象的显示,并且使用内容器和标签器的语句也是一样的。下面是标签器的代码package example.my.treeview.import org.eclipse.jface.viewers.ILabelPimport org.eclipse.jface.viewers.ILabelProviderLimport org.eclipse.swt.graphics.I/*** @author hopeshared* 标签提供器,控制纪录在树中显示的文字和图像等*/public class TreeViewerLabelProvider implements ILabelProvider{
//纪录显示 的文字,不能返回null
public String getText(Object element){
ITreeEntry entry = (ITreeEntry)
return entry.getName();
//纪录显示的图像
public Image getImage(Object element){
//以下方法暂不用,空实现
public void addListener(ILabelProviderListener listener){}
public void dispose(){}
public boolean isLabelProperty(Object e, String p){}
public void removeListener(ILabelProviderListener listen){}}下面是内容器的代码package example.my.treeview.import java.util.Limport org.eclipse.jface.viewers.ITreeContentPimport org.eclipse.jface.viewers.V/*** @author hopeshared* 内容器,由它决定哪些对象应该输出在TreeViewer里显示*/public class TreeViewerContentProvider implements ITreeContentProvider{
//由这种方法决定树的哪一级显示哪些对象
public Object[] getElements(Object inputElement)
if(inputElement instanceof List){
List list = (List)inputE
return list.toArray();
return new Object[0];//生成一个空的数组
//判断某节点是否有子节点,如果有子节点,//这时节点前都有一个“+”号图标
public boolean hasChildren(Object element){
ITreeEntry entry = (ITreeEntry)
List list = entry.getChildren();
if(list==null||list.isEmpty()){
//由这个方法来决定父节点应该显示哪些子节点
public Object[] getChildren(Object parentElement){
ITreeEntry entry = (ITreeEntry)parentE
List list = entry.getChildren();
if(list==null || list.isEmpty()){return new Object[0];
}else{return list.toArray();}
//以下方法空实现
public Object getParent(Object element){}
public void dispose(){}
public void inputChanged(Viewer v, Object oldInput, Object newInput){}}五 修改清单文件下面给出的是plugin.xml文件代码&?xml version="1.0" encoding="UTF-8"?&&?eclipse version="3.0"?&&plugin&
&extension point="org.eclipse.ui.views"&
class="example.my.treeview.internal.TreeViewPart"id="example.my.treeview.treeview"name="my first tree view plugin"/&
&/extension&&/plugin&六 插件的实现在清单文件中已经指出了这个视图的实现类是example.my.treeview.internal.TreeViewPart,下面给出这个文件的代码package example.my.treeview.import org.eclipse.jface.viewers.TreeVimport org.eclipse.swt.SWT;import org.eclipse.swt.layout.FillLimport org.eclipse.import org.eclipse.ui.part.ViewPimport example.my.treeview.data.DataFpublic class TreeViewPart extends ViewPart{
public void createPartControl(Composite parent){
Composite topComp = new Composite(parent, SWT.NONE);
topComp.setLayout(new FillLayout());
TreeViewer tv = new TreeViewer(topComp, SWT.BORDER);
tv.setContentProvider(new TreeViewerContentProvider());
tv.setLabelProvider(new TreeViewerLabelProvider());
Object inputObj = DataFactory.createTreeData();
tv.setInput(inputObj);
public void setFocus(){}}七 运行结果&抱歉,图片上传失败&八 给节点增加动作增加一个ActionGroup类package example.my.treeview.import org.eclipse.jface.action.Aimport org.eclipse.jface.action.IMenuMimport org.eclipse.jface.action.MenuMimport org.eclipse.jface.dialogs.MessageDimport org.eclipse.jface.viewers.IStructuredSimport org.eclipse.jface.viewers.TreeVimport org.eclipse.swt.widgets.Mimport org.eclipse.swt.widgets.Timport org.eclipse.ui.actions.ActionG/*** @author hopeshared* 生成菜单Menu,并将两个Action传入*/public class MyActionGroup extends ActionGroup{
private TreeV
public MyActionGroup(TreeViewer treeViewer){
this.tv = treeV
//生成菜单Menu,并将两个Action传入
public void fillContextMenu(IMenuManager mgr){
//加入两个Action对象到菜单管理器
MenuManager menuManager = (MenuManager)
menuManager.add(new OpenAction());
menuManager.add(new RefreshAction());
//生成Menu并挂在树Tree上
Tree tree = tv.getTree();
Menu menu = menuManager.createContextMenu(tree);
tree.setMenu(menu);
//打开Action类
private class OpenAction extends Action{
public OpenAction(){
setText("打开");
//继承自Action的方法,动作代码写在此方法中
public void run(){
IStructuredSelection selection = (IStructuredSelection)tv.getSelection();
ITreeEntry obj = (ITreeEntry)(selection.getFirstElement());
if(obj != null){
MessageDialog.openInformation(null, null, obj.getName());
//刷新的Action类
private class RefreshAction extends Action{
public RefreshAction(){
setText("刷新");
//继承自Action的方法,动作代码写在此方法中
public void run(){
tv.refresh();
}}接着,修改TreeViewPart.java,代码如下……Object inputObj = DataFactory.createTreeData();
//-------------加入动作开始
MyActionGroup actionGroup = new MyActionGroup(tv);
actionGroup.fillContextMenu(new MenuManager());
//-------------加入动作结束
tv.setInput(inputObj);……结果如下图所示&抱歉,图片上传不成功&九 自定义扩展点我们想将这个视图的显示内容与视图框架分开,这样,我们需要修改视图显示内容的时候只要重新贡献一次显示内容就可以了。9.1 添加shema文件这个sheme文件是采用可视化编辑器进行编辑,然后pde自动生成的,代码如下&?xml version='1.0' encoding='UTF-8'?&&!-- Schema file written by PDE --&&schema targetNamespace="example.my.treeview"&&annotation&
&meta.schema plugin="example.my.treeview" id="datafactory" name="Data Factory"/&
&/appInfo&
&documentation&
[Enter description of this extension point.]
&/documentation&
&/annotation&&element name="extension"&
&complexType&
&sequence&&element ref="factory"/&&/sequence&
&attribute name="point" type="string" use="required"&
&annotation&&documentation&&/documentation&&/annotation&&/attribute&
&attribute name="id" type="string"&
&annotation&&documentation&&/documentation&&/annotation&&/attribute&
&attribute name="name" type="string"&
&annotation&&documentation&&/documentation&
&appInfo&&meta.attribute translatable="true"/&&/appInfo&&/annotation&
&/attribute&
&/complexType&
&/element&
&element name="factory"&
&complexType&
&attribute name="id" type="string"&
&annotation&&documentation&&/documentation&&/annotation&&/attribute&
&attribute name="name" type="string"&
&annotation&&documentation&&/documentation&&/annotation&&/attribute&
&attribute name="class" type="string" use="required"&
&annotation&&documentation&&/documentation&&/annotation&&/attribute&
&/complexType&
&/element&
&annotation&
&appInfo&&meta.section type="since"/&&/appInfo&&documentation&[Enter the first release in which this extension point appears.]&/documentation&
&/annotation&
&annotation&
&appInfo&&meta.section type="examples"/&&/appInfo&
&documentation&[Enter extension point usage example here.]&/documentation&
&/annotation&
&annotation&
&appInfo&&meta.section type="apiInfo"/&&/appInfo&
&documentation&[Enter API information here.]&/documentation&&/annotation&
&annotation&
&appInfo&&meta.section type="implementation"/&&/appInfo&&documentation&[Enter information about supplied implementation of this extension point.]
&/documentation&&/annotation&
&annotation&
&appInfo&&meta.section type="copyright"/&&/appInfo&
&documentation&&/documentation&&/annotation&&/schema&9.2 创建接口文件ItreeEntry.java之前就已经创建好了,不需要修改。现在添加另一个接口文件,代码如下:package example.my.treeview.public interface IDataFactory {
public Object createTreeData();}于是我们修改DataFactory.java,使它实现这个接口。9.3 修改清单文件我们来修改清单文件,加入扩展点声明,并扩展它,代码如下……&extension-point id="datafactory" name="Data Factory" schema="schema/datafactory.exsd"/&&extension point="example.my.treeview.datafactory"&&factoryclass="example.my.treeview.data.DataFactory"/&&/extension&……9.4 修改TreeviewPlugin.java增加一个方法Object loadDataFactory(),代码如下……public static Object loadDataFactory(){
IPluginRegistry r=Platform. getPluginRegistry();
String pluginID="example.my.treeview";
String extensionPointID="datafactory";
IExtensionPoint p=r.getExtensionPoint( pluginID, extensionPointID);
IConfigurationElement[] c=p.getConfigurationElements();
if( c != null) {
for( int i= 0; i &c. i++) {
IDataFactory data =
try { data=( IDataFactory)c
.createExecutableExtension("class");
if( data != null){ return data.createTreeData(); }
} catch( CoreException x) { }}}
return new Object();
}……9.5 修改TreeViewPart.java将Object inputObj = DataFactory.createTreeData();替换为Object inputObj = TreeviewPlugin.loadDataFactory();9.6 其他辅助文件其实TreeViewerLabelProvider.java和TreeViewerContentProvider.java可以看成是对DataFactory这个扩展点的辅助文件9.7运行跟之前的实现没有区别,但是我们向eclipse贡献了一个扩展点十 参考资料《Eclipse入门到精通》
《自己动手编写Eclipse扩展点》EclipseCon2005_Tutorial1.pdf 《Contributing to Eclipse: Understanding and WritingPlug- ins》
经过一个多小时的努力。。。(嘿嘿,以前没有仔细研究Property什么的,今天弄了一下)终于出现了property并且可以修改属性页中的值代码哦,补充一下,由于模型(就是treeviewer中的初始数据)是写死的,改的property其实是修改了内存中的对象的值。假如用emf做模型持久化,就会保存修改。但是目前是不能保存修改的。关于本文的讨论还是很多的,也有很多有用的信息。见本文第一次发表是在社区之中,本来也没觉得有转到blog的必要,但是后来发觉自己的记忆力越来越差,曾经作过的都忘记的差不多了,为了避免丢失,还是存在这里备份比较好。
总是写不好ppt,为什么呢?先把ppt的写法总结放在这里,这样就不容易忘记了。1. 选择合适的模板,通常选择根内容相关,简单清新的模板就可以了。当然,也要看ppt是用来做什么的。2. 标题简单明了,突出核心内容。3. 第一页一般为Outline或者Agenda。我经常犯的错误是第一页命名为Outline,但是Outline其实跟Introduction是一个抽象级别的。4. 每页的Items都要在一个抽象级别。5. 每个子Item都要从同一个角度来划分6. 通常在Introduction中介绍Challeges。如果Challeges不太多Solutions也不复杂,那么可以将两者合并作为一个Topic。如果Challeges太多在Introduction中讲不清楚,那么可以在Introduction之后列一个Challeges的Topic。7. Introduction中应列出问题,现状,目前的挑战以及High Level的解决办法。8. ppt的一般结构是:本项目的意义,难度,如何解决,演示。9. Introduction之后应该紧接着介绍项目中“创造”的概念。10. Solution应该是紧接在Challeges后面的一个Topic,它仍然是抽象的描述解决方法。更具体的涉及到技术细节的应归结为Approach或者Technics紧跟在Solution之后作为补充。11. 实现本系统用到了其他的成熟技术。那么应该首先说明遇到了什么问题(why),如何来解决(how),有多少种解决方法(what),为什么选择你使用的这种(why)。我想可能要补充上如何来用它吧。12. 具体的技术细节应该是在Scenarios之前。13. Scenarios应该用少量的文字配合大量的图片来表达,不应该出现技术14. 项目的关键特性要结合Demo体现出来15. ppt中的结构图应该采用立体感强的图片来表示。ppt中出现的图片都应该有很强的表现力(千言万语尽在图中)。16. 作为ppt还有一点跟paper不一样,那就是,不再需要Reference。而Conclusion&Future work则应该提炼成精简的Sumerize。最后,ppt的灵魂就是逻辑,逻辑,还是逻辑。一定要有逻辑。经常作总结,是增强逻辑性,条理性的最有效途径。sigh,谁让我一向不用逻辑思考问题呢,555
作者:Brian McBride发表时间:日原文链接:译者:翻译时间:日
是最近宣布的一个格式,顺从于 W3C 的 RDF (资源定义框架),用来分发(distributing) 站点摘要 (site summary) 和企业联合 (syndication) 元数据。一个站点摘要文档的例子可以在规范中找到。Jena 是一套实验性的用来处理 RDF 的 Java API。这篇笔记描述了一个应用程序使用 Jena 来将一个站点摘要文档翻译成 HTML。整个程序的源代码作为 RenderToHTML 可以在 Jena 发布的例子包里得到。
这篇文章和例子代码基于 RSS 规范候选发布版本1 (Release Candidate 1 version)。
这个应用程序以创建一个 RDF 模型开始,实际上在内存中是一个 RDF statement 的集合。然后解析站点摘要文档,使用一个 RDF 解析器,并加载 statement 到新创建的模型中。
Model model = new ModelMem();
model.read("");
在写出一个样板 HTML 头后,程序列出和处理在输入流中的每个 channel。在 RDF 术语中,channel 是具有一个 rdf:type 属性的 rss:channel 的资源。我们使用 Jena API 来列出具有一个有这个值的 rdf:type 属性的所有的资源。在下面的代码中,假设输出是一个接收 HTML 输出的 PrintWriter。
ResIterator channels =
model.listSubjectsWithProperty(RDF.type, RSS.channel);
while (channels.hasNext()) {
renderChannel(channels.next(), out);
为了呈现 (render) 一个 channel,程序首先写出它的 title,description 和相关的 image 和 textinput 字段 (如果有的话)。getProperty 方法用来得到 channel 的 title,link 和 description 属性,随后这些可以被呈现为 HTML。
void renderChannel(Resource channel, PrintStream out)
throws RDFException {
String url =
String title =
String desc =
url = channel.getProperty(RSS.link).getString();
title = channel.getProperty(RSS.title).getString();
desc = channel.getProperty(RSS.description).getString();
一个 channel 可以有一个相关联的 image 和 textinput,测试是否存在这些属性和是否需要调用合适的方法来呈现它们是很简单的。
if (channel.hasProperty(RSS.image)) {
renderImage(channel.getProperty(RSS.image) .getResource(), out);
if (channel.hasProperty(RSS.textinput)) {
renderImage(channel.getProperty(RSS.textinput) .getResource(), out);
为了处理一个 image,同样的调用被用来确定 image 的属性。
String url =
String title =
// does the image have a link?
if (image.hasProperty(RSS.link)) {
url = image.getProperty(RSS.link).getString();
// does the image have a title?
if (image.hasProperty(RSS.title)) {
title = image.getProperty(RSS.title).getString();
} image.getProperty(SSF.title).getString();
然后这个 image 可以被呈现成为 output stream。textinput 以 相似的方法处理。
channel 有一个 items 属性,它的值为一个 RDF sequence。因此使用 getProperty 方法得到这个 sequence 就很简单的了。然后迭代每一个元素以呈现它。
if (channel.hasProperty(RSS.items)) {
Seq items = channel.getProperty(RSS.items).getSeq();
for (int i=1; i&= items.size(); i++) {
renderItem(items.getResource(i), out);
以相同的模式呈现每一个 items。首先得到需要呈现的 items 的属性,然后写出 HTML。
void renderItem(Resource item, PrintWriter out) {
String url = item.getProperty(RSS.link).getString();
String title = item.getProperty(RSS.title).getString();
String desc = item.getProperty(RSS.description) .getString();
使用 Jena 来处理 RSS 1.0 流是简单和直接的。
Brian McBride
HP实验室,日
jUDDI,发音(Judy),是服务于WebServices 的UDDI的java实现开源包。
1 安装1.1 下载下载地址:http://ws.apache.org/juddi/releases.html 目前的jUDDI的最新版本是0.9rc3(Release Candidate #3 for Version 0.9),不过在这个版本中有一些的bug。 juddi0.9版本发布应该是不会久,可以参考下面这段话,是Viens Stephen(juddi主要开发者之一)在mail list中说的:we've closed 40+ issues since January 1, 2005. We'll be releasing a 0.9rc4 as soon as Axis 1.2 final is released and then releasing a 0.9 final a few weeks after that. (March 22, 2005)
1.2 数据库安装UDDI需要有一个地方来存储注册的数据,因此首先要选择一个关系数据库安装。JUDDI可以使用任何支持ANSI standard SQL关系数据库( 例如MySQL, DB2, Sybase, JdataStore等)。本实例使用MySQL。 数据库安装完成后,在MySQL数据库中运行juddi-0.9rc3\\sql\\mysql\\create_database.sql, juddi-0.9rc3\\sql\\mysql\\insert_publishers.sql。数据库准备完成。
1.3 安装juddi及配置首先将juddi-0.9rc3\\webapp下的juddi文件夹复制到Tomcat下的webapps中,并将 mysql-connector-java-3.1.7\\mysql-connector-java-3.1.7-bin.jar复制到Tomcat 5.0\\webapps\\juddi\\WEB-INF\\lib下。 下面就是连接数据库的配置,在Tomcat/conf/server.xml的Host element中加入: &Context path="/juddi" docBase="juddi" debug="5" reloadable="true" crossContext="true"&
&Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_juddiDB_log"
suffix=".txt" timestamp="true"/&
&Resource name="jdbc/juddiDB" auth="Container" type="javax.sql.DataSource"/&
&ResourceParams name="jdbc/juddiDB"&
&parameter&
&name&factory&/name&
&value&mons.dbcp.BasicDataSourceFactory&/value&
&/parameter&
&!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit. --&
&parameter&&name&maxActive&/name&&value&100&/value&&/parameter&
&!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit. --&
&parameter&&name&maxIdle&/name&&value&30&/value&&/parameter&
&parameter&&name&maxWait&/name&&value&10000&/value&&/parameter&
&!-- MySQL dB username and password for dB connections 帐号密码根据数据库安装配置修改 --&
&parameter&&name&username&/name&&value&root&/value&&/parameter&
&parameter&&name&password&/name&&value&****&/value&&/parameter&
&!-- Class name for mysql JDBC driver --&
&parameter&
&name&driverClassName&/name&
&value&com.mysql.jdbc.Driver&/value&
&/parameter&
&!-- The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection.
mysqld by default closes idle connections after 8 hours.
数据库url连接配置
&parameter&
&name&url&/name&
&value&jdbc:mysql://:3306/juddi?autoReconnect=true&/value&
&/parameter&
&parameter&
&name&validationQuery&/name&
&value&select count(*) from PUBLISHER&/value&
&/parameter&
&/ResourceParams&&/Context&1.4 本地安装检查访问http://127.0.0.1:8080/juddi/happyjuddi.jsp页面,此页面检查了jUDDI所必须的包和配置的正确性,并测试数据库连接是否成功。 如果没有红色文字,即本地安装成功,即可进行webservices的发布发现等服务。
2 测试实例以上安装成功的是UDDI的服务器端,而进行发布、查找服务的客户端的应用则要用jUDDI、UDDI4J等包来进行开发。我们可以直接使用jUDDI自 带的测试代码来进行客户端使用的学习。
2.1 使用uddi4j测试使用uddi4j作为客户端进行测试。 代码位置:juddi-0.9rc3\\src\\uddi4j\\org\\apache\\juddi\\uddi4j 新建立好一个工程并引入此代码,然后对代码进行必要的修改,主要是包名和配置。引入必要的包,比如:junit.jar、 uddi4j.jar、juddi.jar、soap.jar等(因为欧的代码库中有很多种代码,对应很多包,不知道其他哪些是必须的了:)。 接着是数据库的初始化,需要插入一个可以添加其他Publisher的Publisher,sql 语句: INSERT INTO PUBLISHER (PUBLISHER_ID,PUBLISHER_NAME,ENABLIED,ADMIN) VALUES ('juddi','juddi user','true','true'); 调试代码后,运行TestAll测试,您可能会发现测试FAILURE很多,这些当中有些是测试代码的错误,也有可能是juddi-0.9rc3的缺陷( juddi-0.9rc3不是正式发布版)。 以下列举一些本测试案例测试失败的可能出现的修改方法:
2.1.1 加载配置文件时访问不到samples.prop我的解决办法是将建立一个新配置文件位置,在工程目录下的:conf\\samples.prop。 在Configurator.load()方法中代码可以这样修改:
Properties config = new Properties();
config.load(new java.io.FileInputStream("./conf/samples.prop"));
catch (Exception e) {
System.out.println("Error loading samples property file\\n" + e);
}解决方法很多,您可以自己思索。
2.1.2 TransportClassName配置错误如果错误提示中有这样的报告,即可能是此错误: org.xml.sax.SAXParseException: Element or attribute do not match QName production: QName::=(NCName':')?NCName. 在当前测试实例代码中的默认配置(samples.prop)中,TransportClassName定义成org.uddi4j.transport.ApacheSOAPTransport, 而我们使用的包是axis.jar,因此需要修改成相应的类,代码修改如下: # -----------------------------------------------------------------------# Transport classname. Typically defined on commandline as# -Dorg.uddi4j.TransportClassName=xxx.# -----------------------------------------------------------------------#TransportClassName=org.uddi4j.transport.ApacheSOAPTransport TransportClassName=org.uddi4j.transport.ApacheAxisTransport# TransportClassName=org.uddi4j.transport.HPSOAPTransport2.1.3 TestFindBusiness案例不通过TestFindBusiness中有大小写匹配测试,但是在juddi-0.9rc3中的大小写匹配(caseSensitiveMatch)有bug,因此可以将大小写匹配的测 试案例注释掉。
2.1.4 PublisherManager的代码错误在测试Test_save_tModel的时候_testAuthTokenExpired()中,我们测试过期验证时,在错误匹配的时候,会出现测试失败,如果捕捉这个 匹配的结果,你会发现,出错的类型是E_authTokenRequired而不是期待的E_authTokenExpired。 这是因为在我们所获得的AuthToken是空的,在根源就是在PublisherManager. getExpiredAuthToken(String, String)方法中,代码: RegistryProxy proxy = new RegistryProxy();proxy的实例的配置是空的。因此,我们修改这个方法变成:
* changed by xio
* @param publisher String
* @param password String
* @param testprops Properties:增加的参数,传入基本配置
* @return String
*/public static String getExpiredAuthToken(String publisher, String password,
Properties testprops) {
Properties props = new Properties();
props.setProperty(RegistryProxy.ADMIN_ENDPOINT_PROPERTY_NAME,
testprops.getProperty("adminURL"));
props.setProperty(RegistryProxy.INQUIRY_ENDPOINT_PROPERTY_NAME,
testprops.getProperty("inquiryURL"));
props.setProperty(RegistryProxy.PUBLISH_ENDPOINT_PROPERTY_NAME,
testprops.getProperty("publishURL"));
RegistryProxy proxy = new RegistryProxy(props);
AuthToken token =
AuthInfo authInfo =
String ret =
token = proxy.getAuthToken(publisher, password);
authInfo = token.getAuthInfo();
ret = authInfo.getValue();
System.out.println("getExpiredAuthToken:" + authInfo);
proxy.discardAuthToken(authInfo);
catch (Exception ex) {
ex.printStackTrace();
}2.2 使用jUDDI测试在juddi-0.9rc3版本中自带的代码中没有客户端的使用实例,虽然附带了整个项目代码的测试代码,但是估计没什么人喜欢从这里抽取学 习客户端使用的学习。 当然,学习的实例还是有的,在cvs当前的工程代码中,有个samples的文件夹,这部分代码便是一个十分齐全的实例(有几个类没完成, 但不影响:)。 Cvs服务器数据:http://ws.apache.org/juddi/cvs.html Wincvs的使用请网上下载阅读。 其他:在进行代码学习的同时,建议阅读webservices相关资料文档。强烈建议阅读:理解 UDDI 注册中心的 WSDL 系列 (http://www-/developerWorks/cn/webservices/ws-uwsdl/part1/) 参考资料:原作者:xio&#来 源:原文地址:
在过去的数年中,许多开发人员都使用了各种版本的J2EE,使服务器端软件编程的情形得到了很大的改观,现在,他们将再次挑战SOAP,在服务器端软件编程方面取得更大的进展。 SOAP服务的支持者认为: ·企业级应用服务器是服务(或事务)的集合。 ·可以使用的服务应当很方便地列出来供用户浏览、搜索和访问。 ·象现在的基于组件的开发模式那样,将应用服务器设计为服务的集合将鼓励开发人员采用更好的设计模式。 ·这些事务能够被重新定位、负载平衡、替代等。 而对SOAP持怀疑态度的人认为,SOAP是推广CORBA和COM的又一次尝试。他们指出,要简单地访问一个对象,需要完成太多的准备性工作,而且,UDDI带来的好处也被夸大了。 那么,到底哪一种观点更合理呢?对于一些思想开放的人士而言,在决定是否采用SOAP服务前,他们一定希望了解其中的一些核心技术。 解密UDDI 我们首先来看看UDDI代表什么?UDDI是Universal Description, Discovery and Integration(统一描述、发现和集成)的缩写。UDDI的意图是作为一个注册簿,就象黄页是一个地区企业的注册簿一样。象在黄页中那样,在UDDI注册簿中,企业将在不同的目录下注册它们自己或其服务。通过浏览一个UDDI注册簿,开发人员能够查找一种服务或一个公司,并发现如何调用该服务。 除了黄页外,UDDI还使用了白页和绿页。白页是企业实体列表,绿页是调用一项服务所必需的文档。 UDDI的定义非常全面,足以适应不同种类的服务。一个UDDI服务定义可能代表一个传真服务或电话服务。作为一种注册簿,UDDI一般使用数据库一类的软件来实现,在该数据库中,存在一个允许发布或查询服务的有关信息。 UDDI数据模型 UDDI数据模型包括下面的主要元素: ·businessEntity:表示一个实际的企业。 ·businessService:表示一个企业提供的服务。 ·bindingTemplate:如何调用服务的说明。 ·tModel&: Good luck understanding this! (Just kidding, I will explain this later.) 为了加深对UDDI数据模型的理解,我们来看看这些数据元素的UML表示法。图1是这四种主要元素之间的关系图: 从上面的图中我们可以知道,一个businessEntity(一家公司)有一个能够告诉我们更多有关公司信息的描述性URL和联系人清单,此外,businessEntity还有一个商业服务清单。每种服务可能有多种调用方法,每种调用都由一个绑定模板描述。绑定模板详细地描述了如何访问一个服务,它受益于一系列描述用户如何访问这一服务的文档。绑定模板和其必要的文档之间的联系是通过所谓的tModel完成的。在上面的图中,这种联系被简单地描述为一个绑定模板有许多tModels。在进一步地解释tModels与绑定模板的关系前,我们必须先弄清楚tModels是什么。 TModel是什么? 我们可以把tModel想象成数据库库中的一个独立的表,其中包含下面的字段:名字、描述、URL、唯一的关健字。实际上,tModel就是包括有名字和描述,那么使用数据库表表示它是否是一种浪费呢?我们下面就会讨论这一问题: 下面是一个假想的tModel数据库表中的二个实体: 键 名字 描述 URL 1 Java-class 表示一个具备完全资格的java类的名字 / 2 Jndi-home 表示一个JNDI名字 / 在将tModel比作数据库表方面,有几点值得注意。首先,tModel是一个独立的表,意味着它可以不依赖其他软件而存在;其次,tModel是查找表,提供了键与键的表示之间的转换关系。从这一点来看,tModel象词典那样,是一个引用表。在一些数据库中,这样的表也被称作是码集。 因此,如果在上面的tModel中存在下面的记录: com.mycompany.HelloWorld, 1 com.mycompany.HelloWorldHome, 2 就意味着字符串com.mycompany.HelloWorld是一个有完整资格的Java类;而字符串com.mycompany.HelloWorldHome是一个JNDI名。 因此在一定程度上,tModels中唯一的键与“名字空间”这个概念差不多。为了进一步地说明这个问题,我们来看一下下面的数字: 904-555-1212 904-555-1213 1--x 你能够分清这些数字的意义吗?我们需要在一个环境或名字空间中来确认,904-555-1212是电话号码,904-555-1213是传真号,1--x是一个ISBN号。 因此在tModel数据库表中,我们将需要定义三个实体:一个是电话号码;一个是传真号码,一个是ISBN号码。 下面我们以mycompany公司公布了一条号码为1-800-my-helpline的电话支持热线,并在UDDI中注册。那么,我们的数据模型为: company name: mycompany Service name: helpline tModel: key=11 (representing telephoneline), name=telephone, description=telephone stuff, url: some at&t url binding: accesspoint: 1-800-my-helpline tModelInstanceInfo: 11 有了对tModel的基本理解后,我们就可以利用UML图表来研究绑定模板与tModels之间的关系了。我在上面曾经说过,这将使我们对绑定模板如何完成UDDI的“如何调用一项服务”的要求有一个直观的理解。 在图2中,我们讨论了一个绑定模板与tModels之间的关系。从图表中我们可以看出,一个绑定模板可以指向一个由一个tModel确定的技术规格,技术规格有二部分组成: ·规格的类型。(例如电子邮件、传真、WSDL、SOAP等。) ·确定输入和输出的文档(在SOAP服务中,这些文档可以是XML输入/输出消息格式。) 既然我们已经对tModels有了一定程度的详细了解,就该再讨论UDDI中更复杂的东西了,也就是身份包和类别包。 理解标识符包和类别包 如果说从概念上理解tModels是理解UDDI需要跨越的第一道障碍,那么理解标识符包和类别包则是需要跨越的第二道障碍。下面的例子可以帮助我们理解这二个概念。 例如,您的公司在美国开展业务需要有一个税号,如果还在另外的国家(例如墨西哥)开展业务,就需要有一个墨西哥的税号。为了能够在UDDI注册簿中获取您的公司的这些信息,在UDDI中应当包括下面的内容: 公司名字:mycompany 标识符: 美国税号:111111 墨西哥税号:2223344 其他国家税号: 333333 ...其他的xml内容 &identifierBag& &keyedReference tModelKey="US-tax-code" keyName="taxnumber" keyValue="1111111"& &keyedReference tModelKey="Mexico-tax-code" keyName="taxnumber" keyValue="2223344"& &keyedReference tModelKey="other-stuff" keyName="taxnumber" keyValue="333333"& &/identifiedBag& ... 其他的xml内容 现在明白tModels如何被用作名字空间了吧。为了进一步地深化对标识符包的理解,我们在下面的图中再次解释了标识符和类别包的概念: 从上面的图中我们能够看出,标识符包是一个在特定环境中的键/值对集合,这个环境从本质上说就是能够唯一地解析名字/值对儿的名字空间,它是由tModel确定的。类别包也是如此,二者之间唯一的区别就是类别包中由tModel确定的名字空间是一个预先确定好的类别。 类别包 我想将公司归类于饭店,其地理位置位于杰克逊维尔。 公司名字:mycompany 适用类: 企业类型:饭店 所在城市:杰克逊维尔 &categoryBag& &keyedReference tModelKey="BusinessTypeClassification" keyName="restaurant" keyValue=".."& &keyedReference tModelKey="CityClassification" keyName="JAX" keyValue=".."& &/categoryBag& 现在,我们已经搞清楚了tModels是如何用在标识符和类别包中的。从本质上说,tModels就是名字空间。 tModels也能被分类吗? 我们已经明白了企业实体是如何利用使用了类别包的。另外,UDDI也允许tModels本身被分类。 我们用分层次的文件系统进行说明。目录是用来对文件进行分类的,但目录还可以在父目录下再被分类。象硬盘上的目录那样,tModels也可以被分层次地进行组织。 下面我们来讨论名字为getUniversalTime()的服务,该服务将返回当前全球任一地方的时间。二家存在竞争关系的公司可能会提供这一服务的不同实现。商业服务只限于在公司内部使用,公司之外的用户是不可使用的: company1:getTime() company1:getCurrentTime() 这二者的作用相同,为了表明它们实现的是同一个被称作getUniversalTime()的服务,我们可以定义如下所示的tModel: tModel name:: Get Universal Time category: uddi-org:types, wsdl [意味着这是一个由WSDL文档定义的服务] 上面的定义表明getUniversalTime()是一个WSDL服务,可以由任何公司实现。 既然已经阐明了tModels和包之间的关系,我们下面可以看看一个tModel的UML表示: 从上面的图表中,我们可以看出tModel基本上就是一个名字和描述,另外,它也可以包含一个URL,以提供更进一步的详细资料。它可以由一个标识符包确定和由一个类别包进行分类。 我们已经知道,一个tModel所属于的类别是由UDDI━━WSDL、SOAP等预先定义好的,下面是一个uddi-org:types名字空间中预先定义类别的清单: tModel identifier (唯一标识符) namespace categorization specification xmlSpec soapSpec wsdlSpec protocol transport signatureComponent 如何开始在UDDI中创建一个服务? 在开始定义服务的tModel时,要求我们为服务指定一个名字和上面所列出的服务类型中的一个。当然了,如果不喜欢上面的分类可以自己创建类别。 我们可以针对上面定义的tModel开发一个商业服务。在商业服务定义中,我们需要指定一个指向定义了服务的输入/输出的WSDL文档的URL。 在UDDI中为什么需要tModels? 在UDDI中使用tModels的目的如下: ·对商业实体进行标识和分类 ·对商业服务进行标识和分类 ·对tModels进行标识和分类 ·将商业服务绑定到它们抽象的tModel定义上 UDDI名词的快速参考 在看有关UDDI的资料时,如果看到很深奥的术语是一件很烦人的事儿,下面我们就把一些经常用到的与UDDI有关的概念搜集起来,通过比较帮助我们对UDDI概念的理解: 接口和实现 服务绑定是一个容器,接口依赖于其实现;绑定元素详细说明了tModelInstaceInfo和instanceDetail, 我们将再通过一个例子加深对这一问题的例子。对于“获得统一时间”服务而言,细节将提供定义了输入、输出的实际的WSDL文档,绑定的访问点将提供实现服务的物理机器和端口。了解了这些,我们可以得出如下的结论: ·为一种服务定义的tModel是允许多家公司提供该服务的多个实现的界面。 ·服务绑定是具体的实现。 名字空间 Java、C++和XML中都有名字空间的概念,尽管其叫法可能不同,但它们都提供了使名字有意义的环境。在UDDI中,tModel象征着“名字”。当把这个名字作为目录使用时,你的本意是,“我属于这个名字”。从这个意义上说,tModel表示的是名字空间。 技术指纹 当一种服务被注册为tModel时,我们可以注册用来与该服务通讯的协议(例如WSDL、SOAP等)。因此根据所使用的协议不同,tModel有WSDL指纹或SOAP指纹。因此tModel被认为是技术性指纹,每种指纹与一种特定的协议有关。如果说一种tModel可以代表一个“技术性指纹”,我们也可以说tModel能够表示一种“协议”。 分类 分类与类别、名字空间类似,它提供了一种环境,只有在这种环境下,一些数字和名字才有意义。例如, 白页 UDDI注册簿中的企业实体列表和根据名字搜索企业的能力。 黄页 黄页将企业实体按企业类别或其他适用的类别分类。 绿页(技术规格) 绿页有助于我们理解服务的定义和访问服务的要求,serviceBindings和tModels也有助于这一目标的实现。 JAXR JAXR是在服务注册中使用的一种Java XML API。我们以前曾经讨论过,UDDI中的所有元素都用XML文档进行描述。从某种意义上说,嘦我们能够发送包含有服务描述的XML消息,UDDI注册簿就能够对它进行注册或更新。下面我们讨论在没有工具的情况下如何完成这一任务: 1、编写必要的服务描述XML文档。 2、理解SOAP头部,以便能够将XML文件作为一个SOAP附件发送给UDDI注册簿。 3、使用SOAP客户端Java API完成第二步中的任务。 4、通过编程的方式处理SOAP消息。 5、根据UDDI服务的描述,构造消息完成该UDDI服务的任务。 6、对每个消息,完成第2、3步中的操作。 如果使用JAXR,我们可以更好地完成这一任务。因为JAXR允许我们在发送XML消息时无需考虑SOAP头部,而且是一种严格的面向消息的协议。使用JAXR,上面的任务将简化为: 1、编写必要的服务描述XML文档。 2、使用JAXM API发送和接收XML消息,JAXR隐藏了SOAP信息。 3、根据UDDI服务构建消息完成该UDDI服务。(例如,向UDDI注册簿注册UDDI服务包含有4次信息交换过程。)这意味着我们仍然需要与XML内容打交道。 使用这种方式,我们只需处理高层次的Java API即可,这些Java API能够产生必需的消息并通过JAXR传输它们。需要指出的一点是,JAXR也用来完成该任务。 下面列出了JAXR的一些目标: ·支持业界标准的XML注册功能 ·支持成员机构和企业的注册 ·支持任意注册内容的存储和提交 ·支持XML、非XML注册内容的管理 ·支持注册内容间用户定义的结合 ·支持用户定义的注册内容的多级分类 ·支持基于定义的分类计划的注册内容查询 ·支持基于复杂查询的注册内容查询 ·支持基于关健词的注册内容查询 ·支持Web服务的共享 ·支持合作伙伴间商业过程的共享 ·支持合作伙伴间计划的共享 ·支持合作伙伴间商业文档的共享 ·支持合作伙伴间贸易伙伴协议的谈判 ·支持计划汇编 ·支持异类分布注册 ·支持参与各方发布/订阅XML消息 JAXR将不仅仅支持UDDI,还会支持其他的类似注册服务标准(例如ebXML)。 原文地址:
利用w3c的dom:
DocumentBuilderFactory factory
DocumentBuilderFactory.newInstance();
factory.newDocumentBuilder();
Document doc
builder.parse(
ByteArrayInputStream(str.getBytes()));
(ParserConfigurationException e)
TODO Auto-generated catch block
e.printStackTrace();
(SAXException e)
TODO Auto-generated catch block
e.printStackTrace();
(IOException e)
TODO Auto-generated catch block
e.printStackTrace();
利用dom4jSAXReader saxReader = new SAXReader();
document = saxReader.read(new ByteArrayInputStream(str.getBytes()));
Element incomingForm = document.getRootElement();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();

我要回帖

更多关于 java 字面量 的文章

 

随机推荐