Thursday, January 13, 2011

Variables and Schemas in Portlet Factory

Anyone who has played with portlet factory will quickly learn that it depends heavily on xml defined by a schema. Putting some thought into this I realized that a schema is really a way to define a type and a WPF variable is an instance of that type. For example there is a close correlation between a java type definition such as:

public class Contact{
   public String name;
   public String phone;
}
...
public class Data{
   public List<Contact> dsixe;
}

and an xml representation of the same information as

<dsixe>
    <contact>
        <name/>
        <phone/>
    </contact>
</dsixe>

with a schema that looks like this

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dsixe="http://dsixe.com/contact" targetNamespace="http://dsixe.com/contact">
   <xsd:element name="dsixe">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element ref="dsixe:contact" minOccurs="1" maxOccurs="unbounded" />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
   <xsd:element name="contact">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element ref="dsixe:name" minOccurs="1" maxOccurs="1" />
            <xsd:element ref="dsixe:phone" minOccurs="1" maxOccurs="1" />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
   <xsd:element name="name" type="xsd:string" />
   <xsd:element name="phone" type="xsd:string" />
</xsd:schema>

Combining the variable builder with the schema builder

Portlet factory provides separate builders to define a schema and a variable, but sometimes it would be nice to combine both into one when I need a quick and dirty variable and I don't want to create a standalone schema file. If I know what my xml structure looks like then I want WPF to just figure out what the schema is based on some sample data in one motion.
To that end I created a custom builder that combines elements from the variable builder with those of a schema builder:


The builder creates a schema in the model with a suffix _xsd and a variable with a suffix _var:

The builder can be downloaded and installed as a WPF package under Optional Libraries feature set.
Please note that generic comments containing links with the intent of self promotion will be flagged as spam and deleted.

0 comments:

Post a Comment

Are you about to post a generic comment that has nothing to do with this post? Something like "Hey thanks for this very valuable information, BTW here's my website". If so, it will be marked as spam and deleted within 24 hours.

Note: Only a member of this blog may post a comment.