JDF Blog

Tools, techniques and advice for real-world JDF integrations

Archive for June 2011

Imagining a More Fluent JDF for .NET

leave a comment »

Imagine creating a trivial intent ticket with nothing more than a component output.  For example, something like this:

<?xml version="1.0" encoding="utf-8"?>
<JDF Type="Product" p1:type="Product" ID="MyId" JobID="MyJobId" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.CIP4.org/JDFSchema_1_1">
  <ResourcePool>
    <Component ID="component1" />
  </ResourcePool>
  <ResourceLinkPool>
    <ComponentLink Usage="Output" rRef="component1" />
  </ResourceLinkPool>
</JDF>

It’s not too hard to do but it isn’t exactly trivial either.  For example, here’s some code using XDocument:

public static class TestAuthoring {
	static readonly XNamespace JdfNamespace = "http://www.CIP4.org/JDFSchema_1_1";
	static readonly XNamespace XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance";

	public static XDocument GetTicket() {
		return new XDocument(
			new XElement(JdfNamespace.GetName("JDF"),
						 new XAttribute("Type", "Product"),
						 new XAttribute(XsiNamespace.GetName("type"), "Product"),
						 new XAttribute("ID", "MyId"),
						 new XAttribute("JobID", "MyJobId"),
						 new XElement(JdfNamespace.GetName("ResourcePool"),
									  new XElement(JdfNamespace.GetName("Component"),
												   new XAttribute("ID", "component1"))),
						 new XElement(JdfNamespace.GetName("ResourceLinkPool"),
									  new XElement(JdfNamespace.GetName("ComponentLink"),
												   new XAttribute("Usage", "Output"),
												   new XAttribute("rRef", "component1")))));
	}
}

I know it’s sort of painful to read even though I took the trouble to pull the name spaces up into variables.  I guess I could have gone further and made things a little better.  How about this?

public static class TestAuthoring {
	static readonly XNamespace XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance";

	public static XDocument GetTicket() {
		return new XDocument(
			new XElement(Element.Jdf,
						 new XAttribute("Type", "Product"),
						 new XAttribute(XsiNamespace.GetName("type"), "Product"),
						 new XAttribute("ID", "MyId"),
						 new XAttribute("JobID", "MyJobId"),
						 new XElement(Element.ResourcePool,
									  new XElement(Element.Component,
												   new XAttribute("ID", "component1"))),
						 new XElement(Element.ResourceLinkPool,
									  new XElement(Element.Component.Link(),
												   new XAttribute("Usage", "Output"),
												   new XAttribute("rRef", "component1")))));
	}
}

public static class Element {
	static readonly XNamespace JdfNamespace = "http://www.CIP4.org/JDFSchema_1_1";

	public static XName Jdf = JdfNamespace.GetName("JDF");
	public static XName ResourcePool = JdfNamespace.GetName("ResourcePool");
	public static XName ResourceLinkPool = JdfNamespace.GetName("ResourceLinkPool");
	public static XName Component = JdfNamespace.GetName("Component");

	public static XName Link(this XName resourceName) {
		return XName.Get(resourceName.LocalName + "Link", resourceName.NamespaceName);
	}
}

The static Element class helps a little but really not all that much.  It’s still a bit of a pain especially when you also have to know what the attributes are, spell them correctly, maintain the references properly an so on.  Wouldn’t it be nice to put all those worries aside and be able to write clean, simple code to produce the JDF?

public static XDocument GetTicket() {
	return Ticket.CreateIntent().WithOutput().Component().Ticket;
}

Well, you will be able to so in the very near future by taking advantage of the FluentJDF library Onpoint On Demand is planning to release as open source in the next few months.  It will include everything you need to build a JDF client that creates JDF, validates it, sends it to JDF consumers using JMF and parses synchronous responses.  All the basic JMF messages will be supported.  We also plan to include extended xpath query and traversal functionality that handles references automatically, knows about process and is just generally smart about JDF structure.  We have not selected a license yet.  However, we are planning to use a commercial-friendly license that will not force you to release source code for your product if you use and distribute FluentJDF.

I will blog more on FluentJDF as we get closer to release.

Written by Tom Cabanski

June 22, 2011 at 3:14 pm

Posted in FluentJDF