This invention relates generally to computer systems and, more particularly, relates to a method and system to declaratively create hierarchies of objects and object types.
Markup languages are generally easy to create and understand. The Extensible Markup Language, commonly known as XML, is one of the most prevalent markup languages in use today. XML is a format designed to bring structured information to the Web. It is a Web-based language for electronic data interchange. XML is an open technology standard of the World Wide Web Consortium (W3C), which is the standards group responsible for maintaining and advancing the hypertext markup language (HTML) and other Web-related standards.
XML is a sub-set of the Standard Generalized Markup Language (SGML) that maintains the important architectural aspects of contextual separation while removing nonessential features. The XML document format embeds the content within tags that express its structure. XML also provides the ability to express rules for the grammar of a document. These two features allow automatic separation of data and metadata, and allow generic tools to validate an XML document against its grammar.
XML has been designed for system integration. XML provides a structural representation of data that has proved broadly implementable and easy to deploy. A piece of information marked by the presence of tags is called an element. Matching start and end tags are used to mark up information. Elements can be further described by attaching name value pairs called attributes. An XML element can declare its associated data to be any desired data element. For example, the element can be a retail price, a book title, etc. Presently, XML has been applied to grammar-based representations of applications data (e.g., business documents, EDI messages, etc.), user-interfaces of applications, XHTML, and other grammars having a fixed set of tags.
These grammar-based representations are limited in that they do not have the ability to easily extend the fixed set of tags to create new types of XML elements. Additionally, as the computer industry steadily moves towards object-oriented programming, XML does not adequately represent objects of executable components. These objects are re-usable by other software programs and new objects can be easily extended from existing objects. As a result, programmers often create hierarchies of objects programmatically in a programming language instead of declaratively. The hierarchy of objects has to be created in the programming language every time it is used.
A system to provide programmers with the ability to create hierarchies of objects and types declaratively in conjunction with programmatic logic has eluded those skilled in the art.
The invention is directed to a mechanism for defining hierarchies of objects declaratively in a markup language. These objects include objects such as common language runtime types of the Microsoft .NET framework. Traditional methods of implementing items such as user interfaces require that the item be created synchronously. For very large items, the time to load the item can be time constrictive. The invention provides users the ability to either synchronously or asynchronously create objects in a hierarchy (i.e., a tree).
The markup language is XML-based. The object is written in the markup language based on a mapping. The mapping includes a URL attribute for defining a location for a definition file having assemblies and namespaces where object classes are specified. The tag name in the markup language is mapped to a class name. Attributes of a tag are mapped to properties and events of a class associated with the tag. Attributes that do not map directly to a class are defined with a definition tag. The definition tag is also used to add programming code to a page.
The invention further includes a method to parse the markup language to create a hierarchy of objects. The definition file is used to determine where-the object class is located for the mechanism of the invention to search for classes in which a tag is mapped. Once a class is determined, the attribute name is searched in the property section and event section of the class. An instance of an object of the class is created. Attributes may be specified using compound properties.
The invention provides the capability for items such as user interfaces, vector graphic drawings, and documents to be created synchronously or asynchronously using the markup language. The documents include fixed-format documents and adaptive-flow documents. The fixed-format documents are documents that explicitly define in a device independent manner the number of pages and the placement of objects on each page. Adaptive-flow documents are documents that can be automatically repaginated, repositioning objects on each page, whenever the page size is changed.
Additional features and advantages of the invention will be made apparent from the following detailed description of illustrative embodiments which proceeds with reference to the accompanying figures.
While the appended claims set forth the features of the present invention with particularity, the invention, together with its objects and advantages, may be best understood from the following detailed description taken in conjunction with the accompanying drawings of which:
The invention provides a mechanism that allows a user to specify a hierarchy of objects and the programmatic logic behind the hierarchy of objects with an XML based markup language. This provides the ability for an object model to be described in XML. One result is that the extensible classes such as classes in the Common Language Runtime (CLR) of the .NET Framework by Microsoft Corporation can be accessed in XML. The number of classes in CLR is continuously growing, which means that the XML representation of object models is dynamically growing. As described herein, the mechanism provides a direct mapping of XML tags to CLR objects and the ability to represent related code in the markup. The mechanism can be used to create fixed-format documents, adaptive-flow documents, vector graphic drawings, application user-interfaces and controls, and the like in XML markups and any combination of the foregoing.
Turning to the drawings, wherein like reference numerals refer to like elements, the invention is illustrated as being implemented in a suitable computing environment. Although not required, the invention will be described in the general context of computer-executable instructions, such as program modules, being executed by a personal computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. Moreover, those skilled in the art will appreciate that the invention may be practiced with other computer system configurations, including hand-held devices, multi-processor systems, microprocessor based or programmable consumer electronics, network PCs, minicomputers, mainframe computers, and the like. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote memory storage devices.
The invention is operational with numerous other general purpose or special purpose computing system environments or configurations. Examples of well known computing systems, environments, and/or configurations that may be suitable for use with the invention include, but are not limited to, personal computers, server computers, hand-held or laptop devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like.
The invention may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
With reference to
Computer 110 typically includes a variety of computer readable media. Computer readable media can be any available media that can be accessed by computer 110 and includes both volatile and nonvolatile media, removable and non-removable media. By way of example, and not limitation, computer readable media may comprise computer storage media and communication media. Computer storage media includes both volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by computer 110. Communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media. The term “modulated-data signal” means a signal that has one or more of its characteristics set or changed in such a manner as to encode information in the signal. By way of example, and not limitation, communication media includes wired media such as a wired network or direct-wired connection, and wireless media such as acoustic, RF, infrared and other wireless media. Combinations of the any of the above should also be included within the scope of computer readable media.
The system memory 130 includes computer storage media in the form of volatile and/or nonvolatile memory such as read only memory (ROM) 131 and random access memory (RAM) 132. A basic input/output system 133 (BIOS), containing the basic routines that help to transfer information between elements within computer 110, such as during start-up, is typically stored in ROM 131. RAM 132 typically contains data and/or program modules that are immediately accessible to and/or presently being operated on by processing unit 120. By way of example, and not limitation,
The computer 110 may also include other removable/non-removable, volatile/nonvolatile computer storage media. By way of example only,
The drives and their associated computer storage media discussed above and illustrated in
The computer 110 may operate in a networked environment using logical connections to one or more remote computers, such as a remote computer 180. The remote computer 180 may be another personal computer, a server, a router, a network PC, a peer device or other common network node, and typically includes many or all of the elements described above relative to the personal computer 110, although only a memory storage device 181 has been illustrated in
When used in a LAN networking environment, the personal computer 110 is connected to the LAN 171 through a network interface or adapter 170. When used in a WAN networking environment, the computer 110 typically includes a modem 172 or other means for establishing communications over the WAN 173, such as the Internet. The modem 172, which may be internal or external, may be connected to the system bus 121 via the user input interface 160, or other appropriate mechanism. In a networked environment, program modules depicted relative to the personal computer 10, or portions thereof, may be stored in the remote memory storage device. By way of example, and not limitation,
In the description that follows, the invention will be described with reference to acts and symbolic representations of operations that are performed by one or more computers, unless indicated otherwise. As such, it will be understood that such acts and operations, which are at times referred to as being computer-executed, include the manipulation by the processing unit of the computer of electrical signals representing data in a structured form. This manipulation transforms the data or maintains it at locations in the memory system of the computer, which reconfigures or otherwise alters the operation of the computer in a manner well understood by those skilled in the art. The data structures where data is maintained are physical locations of the memory that have particular properties defined by the format of the data. However, while the invention is being described in the foregoing context, it is not meant to be limiting as those of skill in the art will appreciate that various of the acts and operation described hereinafter may also be implemented in hardware.
As previously indicated, extensible classes in the CLR of the .NET Framework can be accessed in XML with the invention. Although not required, a brief overview of the .NET framework may be instructive for a better understanding of the benefits provided by the invention. Turning now to
The user interface 206 and web services and applications 208 provides for general input/output including file access, XML support, and services. They expose web technology and services from HTTP to HTML, provide user interface elements for building web pages and/or traditional Windows based user interfaces, and exposes ASP.NET and many other services.
The CLR 202 is responsible for managing memory, starting up and stopping threads and processes, and enforcing security policies. It provides a common type system that provides a programming language-independent concept of data types, which enables numerous programming languages to share data and code in the .NET framework. The CLR 202 also has a just-in-time compiler that translates the MSIL (Microsoft intermediate language) code and optimizes it for a specific machine to execute natively on the system processor of the machine.
The framework class library includes classes. A class defines the operations an object can perform (methods, events, or properties) and defines a value that holds the state of the object (fields). Although a class generally includes both definition and implementation, it can have one or more members that have no implementation. The common type system defines how types are declared, used, and managed in the runtime. The .NET framework types use a dot syntax naming scheme that connotes a hierarchy. This technique groups related types into namespaces so they can be searched and referenced more easily. The first part of the full name, up to the rightmost dot, is the namespace name. The last part of the name is the type name. For example, System.Collections.ArrayList represents the ArrayList type, which belongs to the System.Collections namespace. The types in System.Collections can be used to manipulate collections of objects. When classes are organized this way, it is easy to understand the purpose a namespace serves and what class functionality it will contain. For example, System.Web.Services conveys that the classes will provide a service for some kind of Web functionality. Likewise, it is easy to conclude that System.Windows.Shapes provides a service for shapes. In addition to logically grouping classes in easily decipherable, unified classes, namespaces are extensible in that a user can derive her own namespace from an existing one. For example, System.Web.UI.ACMECorp could be derived from System.Web.UI and provide custom UI elements. The framework namespaces provide the “system,” or base functionality, and services needed to build and run solutions.
In the description that follows, the invention will be described using a xaml nomenclature to distinguish the features of the invention from XML. Turning now to
Xaml files are xml files with a .xaml extension and a mediatype of application/xaml+xml. Xaml files have one root tag that typically specifies a namespace using the xmlns attribute. No specific root tag is required, thereby allowing users to have different CLR associated tags as the root. The namespace may be specified in other types of tags.
A default set of namespaces is used. In one embodiment, five namespaces are used. These namespaces are System.Windows (having classes for elements), System.Windows.Controls (having classes for control elements such as buttons, panels, text panels, etc.), System.Windows.Documents (having classes for document-centric text rendering elements), System.Windows.Shapes (having classes for Windows Vector Graphics elements), and System.Windows.Controls.Atoms (having classes for building block elements such as scroll viewers) and they are specified in the xmlns declaration. Other namespaces may be used and the default set can be application configurable.
As previously indicated, tags in a xaml file generally map to CLR objects. Tags can be elements, compound properties, definitions, or resources. Elements are CLR objects that are generally instantiated during runtime and form a hierarchy of objects. These elements remain in the hierarchy. Some elements are instantiated only when needed. Elements are capitalized in a way that is consistent with the .NET framework. In one embodiment there are five primary sets of elements. These are Panels, Controls, DocumentElements, Shapes, and Decorators. Panels are used to define how the elements on a page are arranged. Examples of Panels include TextPanel, DockPanel, Canvas, FlowPanel, and Table. Controls provide interactive experience. Examples of Controls include Button, RadioButton, and ListBox. DocumentElements are used to render and format flowing text. These elements can be placed inside any element which can contain other elements. Examples of DocumentElements are Paragraph, Section, Bold, and Italic. Shapes are elements of Vector Graphics. Examples of Shapes include Ellipse, Line, and Path. Decorators are like Panel elements, except they can only have one child. Examples of Decorators include Border and Glow.
Compound property tags are used to set a property in a parent tag and are discussed in greater detail below. During runtime, a compound property tag will not be in the hierarchy tree as an element. Definition tags are used to add code into a page and define resources. The definition tags are identified in a xaml page or inside a component of a xaml page as <def:xyz> where xyz is the item being defined. For example, <def:Code> is used to add code into a page and <def:Resources> defines one or more reusable resources. Tags that appear inside a <def:Resources> tag can map to any Element or any arbitrary CLR object. The resource tag provides the ability to reuse a tree of objects merely be specifying the tree as a resource. Definition tags may also be defined within another tag as an xmlns attribute.
As previously indicated, attributes map to properties and events associated with classes. Some attributes aren't associated with real CLR classes, so the definition tag is also used to distinguish these attributes from attributes that map to properties or events. The following table lists these attributes.
Now that the basic namespace to xmlns attribute, class name to tag name, and property and events to attribute mappings and defined attributes have been described, the steps the invention takes in parsing xaml files will be described. The parser of the invention, which will be called the xaml parser from here on determines from the root tag which CLR assemblies and namespaces should be searched to find a tag. An exemplary root tag is of the form
The xaml parser looks for a namespace definition file in the URL directory specified by the xmlns attribute. For example, in the exemplary root tag above, the xaml parser will search for the definition file at http://microsoft.com/xaml/2004/xmlns.definition.
In scenarios where the namespace definition is not at the xmlns location, the <?Mapping?> tag is used in one embodiment. For custom components that have been built into an assembly, a tag is of the form
The namespace definition file provides the name of the assemblies and their install path and a list of CLR namespaces. An exemplary definition file is below:
When the xaml parser encounters a new xmlns definition file, the definition file is fetched and stored locally.
When the parser encounters a tag, the parser determines which CLR class the tag refers to using the xmlns of the tag and the xmlns definition file for that xmlns. For example, if the tag is <Text xmlns=“. . . ”>, the parser searches for a class called text within the namespace(s) provided in the definition file. The parser searches in the order that the assemblies and namespaces are specified in the definition file. When it finds a match, the parser instantiates an object of the class.
An attribute in a xaml tag is used in one of two ways. It can either be setting a property or hooking up an event handler. For example, the xaml parser interprets the tag below
<Button Text=“OK”Background=“Red”Click=“RunHandler”ID=“b1”>
as a class called Button having text, background, and click properties and/or events. The parser searches for the text, background, and click names in the properties section of the Button class. If a name is not in the properties section, the parser looks for the name in the event section.
In the above example, the parser determines that Text and Background are properties and Click is an event. The text string “OK” is set. For properties and events that are more complex than setting text strings, a CLR type converter is used to create an object that converts to and from the string. For example, the property Background is determined to be a CLR type of type Paint. The CLR type converter for the type Paint is used to convert the string “Red” to an object of type Paint. The string is set as the value of the Button's background color. Similarly, the Click event is wired up to the RunHandler method and the ID property is set to b1.
Properties can be set as a simple attribute, a compound property with a string value, or a compound property with an object as the value. A simple attribute is of the form <Button Background=“Blue”/>. In this case “Blue” is interpreted by calling the type converter that knows how to convert a string to an object of type Paint (the type of the Background property). It should then be set as the value of the Button's Background property. If the attribute value starts with *, the attribute is not specifying a literal value, but instead is setting the value equal to a newly instantiated object or an existing object.
A compound property with a string value is of the form
The tag with a period in it indicates that the tag is a reference to a property. When the parser sees a tag beginning with the tag name of the parent tag followed by a period (e.g., “Button.” in a “Button.Background” tag), it searches for a property specified by the name after that period (e.g. “Background” in a “Button.Background” tag). In this case “Blue” should be interpreted by calling the type converter that knows how to convert a string to an object of type Paint (the type of the Background property). It should then be set as the value of the Button's Background property.
Properties from another class can also be declared in a tag. For example, a tag of
<TextBox Button.Background=“Blue”>
indicates that the attribute Button.Background is mapped to a different class than the TextBox class. The parser sees the period and searches for a property specified by the name after that period (e.g. “Background” in a “Button.Background”) in the class specified by the name before the period (e.g., “Button”).
A compound property with an object as the value is of the form
In this case, the CLR HorizontalGradient object is created and then set as the value of the Button's Background property.
The compound property syntax can be used to provide more than just objects for the value. For example, an Animation or a Bind to some data can be accomplished:
In these cases, the tags are used to give the Animation or Bind the ability to set up the appropriate systems to provide the feature. For example, after creating the Animation object, the xaml parser queries the object to see if it implemented an interface called IApplyValue. If it did, the xaml parser calls
ColorAnimationObject.ApplyValue(elementReference, BackgroundPropertyID). The ColorAnimationObject would then wire up the animation. If the object doesn't support the interface, the xaml parser sets the Background property of the Button to the ColorAnimationObject.
As previously indicated, if the attribute value starts with *, the attribute is setting the value equal to a newly instantiated object or an existing object. The xaml parser looks for the name after the * and looks for a CLR type of the name after the *. For example, with a <Button Background=“*HorizontalGradient(Start=Red End=Blue)”> tag, the parser determines the name before the parenthesis (i.e., HorizontalGradient) and does a search for that CLR type in the current namespace established by the preceding xmlns settings. The parser treats the items after the parenthesis as attributes and values (e.g., start is an attribute and red is a value for the attribute). Other examples of using the “*” escape character are below. In all of these cases, the value will be set once. It is not setting up an expression or binding to maintain a relationship between this property and some object. Forward referencing is allowed. During tree creation, if the object referenced doesn't exist yet, the setting of that property is delayed until it does or until the tree is completely created.
Programming languages can be associated with a .xaml page in two places. These places are in the .xaml file and in an associated code-behind file. The code-behind files are generally named the same as the .xaml file with the addition of the programming language's typical extension appended to the end. For example, .xaml.cs is used for C#, .xaml.vb is used for VB, and .xamljs is used for Jscript. A namespace of xmlns:def=“Definition” is added to the root element in order to use the tags needed to add code to a page. The user chooses the programming language associated with a xaml page by adding a def:Language attribute to the root element of the page. For example, the following tag shows how the definition and language attribute are added to the root element: <DockPanel xmlns=“http://microsoft.com/xaml/2005” xmlns:def=“Definition”xmlns:Language=“C#”>.
In order to add code within a xaml file that contains “>”, “<”, and/or “&” characters, CDATA sections as defined in XML are required in the <def:Code> section. An example of this is below (note that, in this example, the CDATA bracketing is not required, since the contained code does not use “<”, “>”, or “&” characters):
In order to specify code in a code-beside file, a source attribute is used. The source attribute provides a URI to the code behind for the xaml file. The URI can be relative or absolute. An example of specifying the URI and a simple code-beside file is below.
The simple code-beside file is below:
The xaml parser also supports a feature called ILiteralContent. For objects that implement ILiteralContent, the xaml parser treats the tag for the object as a string and does not parse the tag. For example, if Public class FooObject implements ILiteralContent, then whenever the xaml parser encounters the tag <FooObject> “I am a string” </FooObject>, the parser creates an instance of FooObject and passes the data within the <FooObject> tag (e.g., “I am a string”) to the newly created FooObject.
In summary, the following rules are used when parsing the root tag or tags that are directly contained by an element/object. Turning to
It can be seen from the foregoing that the invention provides a mechanism that allows object models to be represented in an XML based file using markup tags. This ability to represent object models as markup tags can be used to create vector graphic drawings, fixed-format documents, adaptive-flow documents, and application UI. These Vector graphic drawings, fixed-format documents, adaptive-flow documents, and application UI can be created asynchronously or synchronously. This provides the benefit that these items can be built from markup to create a tree of objects.
Fixed-format documents are documents that explicitly define in a predetermined device-independent manner the number and size of document pages and the placement of objects on each page. This provides a user with the ability to create and share a document in a format that will render the same pages regardless of the implementation system used to view the document. In one embodiment, one of the root tags for fixed-format documents is <FixedPanel> and pages are specified using <Fixed Page> tags. Within a fixed page, several types of elements can be used. These elements include text, vector graphics, and images. External resources such as fonts and shared images are specified. The tag used for text provides the user with exact control over individual character glyphs and placement for the character glyphs. Additional tags provide the user with control over how text, vector graphics, and images are combined on a page. The .xaml parser recognizes the tag for fixed-format documents. As with any other type of .xaml file, the parser determines the CLR namespaces and classes associated with the tags and calls the type converters for the tags within the xaml file and renders a fixed-format document.
An adaptive-flow document does not have a predetermined page size. The set of text, images, DocumentElements, and other objects in an adaptive-flow document can flow or be repositioned on the page in order to adapt to varying page widths. For example, a page rendered in a window on the display screen may be a different width on different display screens, depending on the computing system used or on user preferences. A printed page will have different width depending on the paper size. Lines of text, for instance, will have shorter length if the page width is narrower, causing the text to flow or reposition additional words onto lines further down the page in a cascading sequence from text line to text line. Attributes are used to specify a user's preferences to how the adaptive-flow document appears.
The xaml parser passes these attributes to the CLR type converter for objects to create the document. The objects can create unpaginated or paginated presentations. An unpaginated presentation has a single bottomless page viewed on the display screen with the aid of a control such as a vertical scrollbar. A paginated presentation breaks the document content up into segments based on the page height and shows each page separately, viewed on the display screen with the aid of controls such as next and previous buttons. Further attributes determine the width and number of columns on a page, the sizes for all text elements, text line spacing, sizes and positions for all images or figures, and the widths of margins and gutters. A user also may specify via the attributes whether the objects that create the document should automatically adjust columns, text size and line spacing, image size and placement, margins and gutters, and other page or text parameters, for optimum readability for the page size. The xaml parser parses the tags for adaptive-flow documents, determines the CLR namespaces and classes associated with the tags and calls the type converters for the objects specified within the xaml file for rendering an adaptive-flow document.
In view of the many possible embodiments to which the principles of this invention may be applied, it should be recognized that the embodiment described herein with respect to the drawing figures is meant to be illustrative only and should not be taken as limiting the scope of invention. For example, those of skill in the art will recognize that the elements of the illustrated embodiment shown in software may be implemented in hardware and vice versa or that the illustrated embodiment can be modified in arrangement and detail without departing from the spirit of the invention. Therefore, the invention as described herein contemplates all such embodiments as may come within the scope of the following claims and equivalents thereof.
Number | Name | Date | Kind |
---|---|---|---|
5459837 | Caccavale | Oct 1995 | A |
6085243 | Fletcher et al. | Jul 2000 | A |
6327620 | Tams et al. | Dec 2001 | B1 |
6366934 | Cheng et al. | Apr 2002 | B1 |
6493756 | O'Brien et al. | Dec 2002 | B1 |
6516322 | Meredith | Feb 2003 | B1 |
6615261 | Smørgrav | Sep 2003 | B1 |
6636845 | Chau et al. | Oct 2003 | B2 |
20020010700 | Wotring et al. | Jan 2002 | A1 |
20030140308 | Murthy et al. | Jul 2003 | A1 |
20050246370 | Rubendall | Nov 2005 | A1 |
Number | Date | Country | |
---|---|---|---|
20040230900 A1 | Nov 2004 | US |