Wednesday, August 19, 2009

Exploring xsd.core

I mentioned in the previous blog that the getProperty() method under the class XSDSchemaAdapter in org.eclipse.wst.xsd.core, XSDImpl.java calculates the name space of an attribute. However, as i looked more into the code, I found that the getProperty() method does not do more than retrieving the value from a created attribute. So, to find out how the name space of an attribute is calculated, I would need to look into the code where an attribute is created.

First, I go back to org.eclipse.wst.xml.core, DOMContentBuilderImpl.java and find out the method creating an element, which is visitCMElementDeclaration(). In visitCMElementDeclaration(), the following line of code is trying to creat the attributes of an element.

CMNamedNodeMap nodeMap = ed.getAttributes();

When ed is passed to visitCMElementDeclaration(), it is claimed to be an instance of CMElementDeclaration, but it is actually of data type XSDElementDeclarationAdapter derived from ElementDeclarationBaseImpl. XSDElementDeclarationAdapter and ElementDeclarationBaseImpl are both defined in org.eclipse.wst.xsd.core, XSDImpl.java.getAttributes() is one of the methods defined in ElementDeclarationBaseImpl. The following lines of code in getAttributes() are creating the attributes of an element.

XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) xsdTypeDefinition;
for (Iterator i = ctd.getAttributeUses().iterator(); i.hasNext();) {    XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) i.next();
    XSDAttributeUseAdapter adapter =          (XSDAttributeUseAdapter)getAdapter(xsdAttributeUse);
    if (adapter != null && adapter.getNodeName() != null) {
       map.getHashtable().put(adapter.getNodeName(), adapter);
    }
}

The most important variable in the these lines is ctd, which is corresponding to the definition of an element. XSDComplexTypeDefinition is defined in org.eclipse.xsd_2.5.0.v200905041408.jar in the plug-in dependencies folder. At this point, the "lang" attribute still gets the correct name space url, which is http://www.w3c.org/XML/1998/namespace. However, once the CMNode, representing the "lang" attribute, is converted to CMDocument later in DOMNamespaceHelper.java, the namespace url, for some unknown reason, has been changed to http://java.sun.com/xml/ns/javaee, which I think is the cause of Bug 245698

38 comments:

  1. 您的部落格文章真棒!!有空我一定會常來逛!!........................................

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. Nice to meet you~!!!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    ReplyDelete
  5. 當一個人內心能容納兩樣相互衝突的東西,這個人便開始變得有價值了。...............................................................

    ReplyDelete
  6. 思想與理論,貴呼先於行動,但行動較思想或理論更高貴..................................................

    ReplyDelete
  7. 一棵樹除非在春天開了花,否則難望在秋天結果。 ..................................................

    ReplyDelete
  8. 噴泉的高度,不會超過它的源頭。一個人的事業也是如此,它的成就絕不會超過自己的信念。.................................................................

    ReplyDelete
  9. 喜歡看大家的文章,每篇都是一個故事,都是一種心情~~祝大家開心愉快............................................................

    ReplyDelete
  10. 世間事沒有一樣沒有困難,只要有信心去做,至少可以做出一些成績。..................................................

    ReplyDelete
  11. 好久沒有這樣輕鬆享受閱讀的樂趣了~~留個言邀您分享我的快樂~~..................................................................

    ReplyDelete
  12. 愛情是一種發明,需要不斷改良。只是,這種發明和其他發明不一樣,它沒有專利權,隨時會被人搶走。.................................................................

    ReplyDelete
  13. 愛,拆開來是心和受兩個字。用心去接受對方的一切,用心去愛對方的所有。......................................................................

    ReplyDelete