private namespace support

Sep 29, 2011 at 3:54 PM

Private attributes are well supported.

But I couldn't find a way to add a private resource within the fluent paradigm.  The builder classes tend to have internal constructors, so there is no way to supply a private namespace.   The simplest hack is to make the ResourceNodeBuilder constructor public, and call it directly (non-fluently).   Is there a better approach?

 I also failed to add a private JDF process fluently.   The types are passed as strings, and I think they need XNames instead to allow for namespaces.

FWIW, here's my private namespace exploration code.

public void PrivateNamespaceTest()
{
	XNamespace myNS = "http://www.MyCompany.com/MySchema 1 1";
	var myNSAlias = "MyCompany";

	var intentNode = Ticket.CreateIntent();
	//	<JDF Type="Product" xsi:type="Product" ID="R_959d9" Status="Waiting" JobID="J_771ee" Version="1.4" 
	//		xmlns="http://www.CIP4.org/JDFSchema_1_1">
	//		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	//	</JDF>

	var ticket = intentNode.Ticket;

	// add a private namespace
	intentNode.RootJdfNode.Element.SetAttributeValue(XNamespace.Xmlns.GetName(myNSAlias), myNS);
	//		xmlns:MyCompany="http://www.MyCompany.com/MySchema 1 1" 

	// Add a BindingIntent resource
	var bindingIntentResource = intentNode
		.WithInput().BindingIntent().With().Id("myId");
	//	<JDF Type="Product" xsi:type="Product" ...>
	//	  <ResourcePool>
	//		<BindingIntent ID="myId" Class="Intent" />
	//	  </ResourcePool>
	//	  <ResourceLinkPool>
	//		<BindingIntentLink rRef="myId" Usage="Input" />
	//	  </ResourceLinkPool>
	//	</JDF>

	// set private attribute
	bindingIntentResource
		.Attribute(myNS + "MyAttribute", "123");
	// <BindingIntent ID="myId" Class="Intent" MyCompany:MyAttribute="123" />

	// retrieve private attribute value
	var mySpecialValue = bindingIntentResource.Element.GetAttributeValueOrNull(myNS + "MyAttribute");

	// create a private resource (requires the ResourceNodeBuilder constructor be public instead of internal)
	var privateResource = new FluentJdf.LinqToJdf.Builder.Jdf.ResourceNodeBuilder(intentNode, myNS + "MyPrivateResource", ResourceUsage.Input, "r123");
	//    <MyCompany:MyPrivateResource ID="r123" />

	// find a private resource
	var privateResource2 = ticket.GetIntent().WithInput(myNS + "MyPrivateResource").Elements.FirstOrDefault();

	// create a private process
	// Currently not supported (that I can see)
}

 

 

Coordinator
Sep 29, 2011 at 7:28 PM
Edited Sep 29, 2011 at 7:29 PM

There is some support for foreign namespaces, but it is not complete yet.  The attribute functions is already there.  It is possible to add foreign namespace resources like so:

intentNode.WithInput().ResourceWithName(myNS + "foo");

You can arbitrary add foreign namespace elements using code like the following:

intentNode.WithInput().ResourceWithName(myNS + "myResource").AddNode(myNS + "nodeName");

We plan to add support for foreign namespace processes.  We would probably add signatures for AddProcess() and CreateProcess() that take an array of XNames in addition to the ones that takes an array of strings.  Any thoughts?

Sep 30, 2011 at 12:38 AM

Thanks, I'm still wrapping my mind around the fluent paradigm.  (I think a "railroad track" diagram (like I used to have in my Pascal book) would help make the transitions more obvious, say, from an intent node to a resource.  Right now I'm just wandering through the fog...)

I think passing an array of XNames would work for creating private processes.

Oct 4, 2011 at 2:52 PM

An updated code snippet incorporating what I learned above.

public void PrivateNamespaceTest()
{
	XNamespace myNS = "http://www.MyCompany.com/MySchema 1 1";
	var myNSAlias = "MyCompany";

	var intentNode = Ticket.CreateIntent();
	//	<JDF Type="Product" xsi:type="Product" ID="R_959d9" Status="Waiting" JobID="J_771ee" Version="1.4" 
	//		xmlns="http://www.CIP4.org/JDFSchema_1_1">
	//		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	//	</JDF>

	var ticket = intentNode.Ticket;

	// add a private namespace
	intentNode.RootJdfNode.Element.SetAttributeValue(XNamespace.Xmlns.GetName(myNSAlias), myNS);
	//		xmlns:MyCompany="http://www.MyCompany.com/MySchema 1 1" 

	// Add a BindingIntent resource
	var bindingIntentResource = intentNode
		.WithInput().BindingIntent().With().Id("myId");
	//	<JDF Type="Product" xsi:type="Product" ...>
	//	  <ResourcePool>
	//		<BindingIntent ID="myId" Class="Intent" />
	//	  </ResourcePool>
	//	  <ResourceLinkPool>
	//		<BindingIntentLink rRef="myId" Usage="Input" />
	//	  </ResourceLinkPool>
	//	</JDF>

	// set private attribute
	bindingIntentResource
		.Attribute(myNS + "MyAttribute", "123");
	// <BindingIntent ID="myId" Class="Intent" MyCompany:MyAttribute="123" />

	// retrieve private attribute value
	var mySpecialValue = bindingIntentResource.Element.GetAttributeValueOrNull(myNS + "MyAttribute");

	// create a private resource
	var privateResource = intentNode.WithInput().ResourceWithName(myNS + "MyPrivateResource");
	// <MyCompany:MyPrivateResource />

	// find a private resource
	var privateResource2 = ticket.GetIntent().WithInput(myNS + "MyPrivateResource").Elements.FirstOrDefault();

	// create private node
	var privateNode = privateResource.AddNode(myNS + "myNode");
	// <MyCompany:myNode />

	// create a private process (Currently not supported)
}