DSL Toolkit: How can I get correct elements written in this scenario? - dsl

Info: C# , VS2010 Beta 2 , DSL ToolKit Beta 2
I am trying to create the following generated XML in my DSL Diagram when used
<Method>
...
<FilterDescriptors>
<FilterDescriptor Type="Comparison" Name="EmployeeKey" />
</FilterDescriptors>
...
</Method>
This is how the Method and Filter Descriptor Domain Classes look
I believe I have set the multiplicity correct:
Method should only have 1 Filter Descriptor
A Filter Descriptor can have many Filter Descriptors i.e
<FilterDescriptors>
<FilterDescriptor Type="Comparison" Name="EmployeeKey" />
<FilterDescriptor Type="Wildcard" Name="EmployeeName" />
</FilterDescriptors>
The issue is that the output XML is like this:
<FilterDescriptors>
<FilterDescriptor>
<FilterDescriptors>
<FilterDescriptor Type="Comparison" Name="EmployeeKey" />
</FilterDescriptors>
</FilterDescriptor>
</FilterDescriptors>
We have this same pattern is several locations in our DSL Diagram and was hoping there is a something simple to resolve this rather than overriding the ReadElements and WriteElements of each domain class

Have you posted this in the DSL Tools forum at http://social.msdn.microsoft.com/Forums/en-US/dslvsarchx/threads? I don't see a thread there for it.

Related

write own Spring PayloadTransformer and load it

I'm currently working with citrus-framework to test an application.
One of my interfaces uses Protobuf and I would like to implement a protobuf-to-json-transformer which is compatible with spring-integration to use it similarly like the following but with my transformer instead of the object-to-string-transformer:
<int:channel id="configRawReplies" />
<int:object-to-string-transformer id="configtransformer" input-channel="configRawReplies" output-channel="configResponse" />
<int:channel id="configResponse">
<int:queue />
</int:channel>
for now I have a prototyp exactly like object-to-string-transformer and I'm loading it with:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString">
<property name="input-channel" value="none"/>
<property name="output-channel" value="none"/>
</bean>
but it fails.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Proto2Json' defined in URL [file:/Users/nobody/DevOops/test/citrus-scala/target/test-classes/citrus-context.xml]:
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'input-channel' of bean class [com.pme.citrus.transformer.ProtoToJSONString]:
Bean property 'input-channel' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Does somebody have an idea or an hint where to look on the web?
BR
That's correct. You really need to follow a design in the ObjectToStringTransformer to implement your own AbstractPayloadTransformer. And that one has to be as a plain <bean> definition in your application context.
Only the problem that you don't understand why we really have all those custom tags to utilize input-channel and output-channel attributes as well. The point is that this
<int:object-to-string-transformer>, for example, provides for the application context several beans, including the mentioned ObjectToStringTransformer instance, a MessageTransformingHandler and, finally, ConsumerEndpointFactoryBean to connect a MessageHandler with an inputChannel.
So, what you are missing here is a generic <int:transformer> definition for your custom AbstractPayloadTransformer implementation:
<bean id="Proto2Json" class="com.nobody.citrus.transformer.ProtoToJSONString"/>
<int:tranformer ref="Proto2Json" input-channel="configRawReplies" output-channel="configResponse"/>
Please, read more Reference Manual to avoid similar discussions in the future:
https://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips
https://docs.spring.io/spring-integration/reference/html/messaging-transformation-chapter.html

Wrong alias pattern when importing taxonomy terms

I'm trying to leverage Import/Export module to import taxonomies and taxonomy terms like so
<Orchard>
<Data>
<Taxonomy Id="/Identifier=Product-Categories" Status="Published">
<AutoroutePart Alias="eshop/categories" UseCustomPattern="false" />
<IdentityPart Identifier="Product-Categories" />
<TitlePart Title="Product Categories" />
<TaxonomyPart TermTypeName="ProductCategoriesTerm" />
</Taxonomy>
<ProductCategoriesTerm Id="/Identifier=Category-1" Status="Published">
<AutoroutePart UseCustomPattern="false" />
<IdentityPart Identifier="Category-1" />
<TitlePart Title="Test category" />
<TermPart Count="0" Selectable="true" Weight="1" TaxonomyId="/Identifier=Product-Categories" Path="" />
</ProductCategoriesTerm>
</Data>
</Orchard>
ProductCategoriesTerm when created through dashboard has default pattern
{Content.Container.Path}/{Content.Slug} ### my-taxonomy/my-term/sub-term
but importing terms makes them to use just {Content.Slug} ... How do I instruct AutoroutePart to use the default pattern? Tried UseCustomPattern="false" or exclude AutoroutePart with no effect it's just test-category instead of eshop/categories/test-category and won't regenerate even if if I set AutouroutePart to automatically regenerate when editing content and disable custom patterns and it won't revert to default pattern even if I try to publish it through dashboard.
Also it's mandatory to include "Count" for the TermPart when importing, does it affect anything? Sounds like something that should be dynamic and relevant only with export.
When importing taxonomy terms (and I guess any other part that has a container) it's necessary to specify Container for the common part. Without it Container for the part is null and therefore can't resolve {Content.Container.Path} in the alias pattern.
<CommonPart Container="/Identifier=Product-Categories" />
Or if it's nested term then Container is the parent term.

How to call different XSL resources using the same XSLT Transformer

I have to call 2 different XSL depending on some basis set in the input XML .
I don't want to write 2 separate transformer for this task. The current Code has been written like this
<int:router input-channel="inputchannel"
default-output-channel="outputChannel" expression="headers.get('someValue')">
<int:mapping value="x" channel="xChannel" />
<int:mapping value="y" channel="yChannel" />
</int:router>
<int-xml:xslt-transformer inputChannel="xChannel" output-channel= "output"
xsl-resource="xRelated.xsl" />
<int-xml:xslt-transformer inputChannel="yChannel" output-channel="output"
xsl-resource="yRelated.xsl" />
However , this seems to be a dirty solution as this is just a sample . I will be having 14 different type of XSLs. Does anyone have an idea,how can I re factor this.
The Spring Integration XsltPayloadTransformer relies on TransformerFactory abstraction which preduces Templates based on Source from underlying XSTL.
So, looks like there is no choice to have just only one component who can handle several XSLT at once.
It would be great, if know other XSLT engine which can provide desired solution, but it hasn't to be based on standard TransformerFactory.

XSD having metadata at each field level

i have XML structure as below (just part of large XML)
<Person>
<firstName>
<lastName>
<Partner>
<firstName>
...
</Person>
i need to keep additional metadata with each field for example to indicate if its updatable or not
i c two approaches
1) add the metadata at each FIELD level. i feel this overly complicates the XSD as each element is now an OBJECT
<Person>
<firstName updatable="true" ... />
...
</Person>
2) separate out the metadata as below
BUt how do i link the metadata to the data? via a uniquie name? can someone consuming the XML easily link it?
Is there a better way? Thanks!
<data>
<Person>one
<firstName>
<lastName>
<Partner>
<firstName>
...
</Person>
<Person>two
<firstName>
<lastName>
<Partner>
<firstName>
...
</Person>
</data>
<metadata>
<field name="firstName" updateble="false"/>
....
</metadata>
i think this is similar to
Add metadata to an XSD definition
but it does not have any answer
My (maybe rhetoric) question would be why would someone want to see this metadata with each XML if it is static in relationship to the model?
I'll show you a UBL XSD snippet (XML namespaces elided as irrelevant):
<xsd:element ref="cbc:UBLVersionID" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
<ccts:Component>
<ccts:ComponentType>BBIE</ccts:ComponentType>
<ccts:DictionaryEntryName>Application Response. UBL Version Identifier. Identifier</ccts:DictionaryEntryName>
<ccts:Definition>The earliest version of the UBL 2 schema for this document type that defines all of the elements that might be encountered in the current instance.</ccts:Definition>
<ccts:Cardinality>0..1</ccts:Cardinality>
<ccts:ObjectClass>Application Response</ccts:ObjectClass>
<ccts:PropertyTerm>UBL Version Identifier</ccts:PropertyTerm>
<ccts:RepresentationTerm>Identifier</ccts:RepresentationTerm>
<ccts:DataType>Identifier. Type</ccts:DataType>
<ccts:Examples>2.0.5</ccts:Examples>
</ccts:Component>
</xsd:documentation>
</xsd:annotation>
</xsd:element>
You could see here that there's a lot of structured data which could easily pass as something related to your question. Fundamentally though, this is a mechanism that uses the XSD annotations mechanism, to achieve things in relationship to the XSD. Another one is that used by JAXB custom binding mechanism:
<xsd:simpleType name="ZipCodeType">
<xsd:annotation>
<xsd:appinfo>
<jxb:javaType name="int" parseMethod="javax.xml.bind.DatatypeConverter.parseInt" printMethod="javax.xml.bind.DatatypeConverter.printInt"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="10000"/>
<xsd:maxInclusive value="99999"/>
</xsd:restriction>
</xsd:simpleType>
While this is different than the UBL example, (documentation vs. appinfo), both are using the XSD annotation mechanism.
JAXB's custom bindings also supports a model where the custom bindings are separate from the XSD (in their own separate XML file). The correlation between the custom binding file (the metadata in your case) and the XSD (the XML in your case) is done through XPath matches.
This brings about another clarification: what is the processing model you have in mind? Dynamic (i.e. the metamodel is static, but can be applied to arbitrary XSDs)? Platform? Below is a solution that could work for what you need, in a dynamic fashion, if it happens to match your platform.
.NET:
Build an XSD the way I've referred to above (i.e. annotations of some sort).
At runtime, validate your XML against this XSD. Each node will then have the SchemaInfo property filled in. Using classes in System.Xml.Schema you could easily process the SchemaElement or SchemaAttribute in your SchemaInfo property as an XmlSchemaAnnotated class, which is what both are.
The above is basically PSVI applied to your XML. The same exists for Java (on this Xerces page search for How do I retrieve PSVI from the DOM?)...
I could picture solutions for XSLT as well, or not involving XSD at all... the above though should be sufficient to get you started.

Mule ESB JAXB XML To Object Transformer Better Way?

Mule 3.3 can automatically unmarshall an XML string to an object using JAXB given that:
1. you first register your jaxb annotated classes with spring.
2. there is a component that requires such type as input
So I have managed to do the transformation, but I had to create a "DumbTransformer" that does nothing. It has a method that returns the same object it receives. I need it in order to trigger the XML to Object conversion so that I can further process the message.
Flow Example:
<spring:beans>
<spring:bean id="dumbTransformer" class="foo.bar.DumbTransformer"/>
</spring:beans>
<flow name="main" doc:name="main">
<vm:inbound-endpoint path="in" doc:name="VM" />
<component doc:name="Java">
<spring-object bean="dumbTransformer"/>
</component>
<splitter expression="#[payload.items]" doc:name="Split Items"/>
<logger message="#[payload]" level="INFO" doc:name="Log Item"/>
<vm:outbound-endpoint path="out" doc:name="VM" />
</flow>
DumbTransformer.java
package foo.bar;
#ContainsTransformerMethods
public class InvoiceUnmarshaller extends AbstractTransformer {
#Transformer
public MyJaxbAnnotatedClass foo(#Payload MyJaxbAnnotatedClass i) {
return i;
}
}
Is there a way to acomplish this without having to create such DumbTransformers?
Thanks.
As you guessed it, the JAXB deserialization doesn't occur because there is no component to satisfy:
there is a component that requires such type as input
So what if you had an auto-transformer to do just that:
<auto-transformer returnClass="foo.bar.MyJaxbAnnotatedClass" />
The Mule XML Module provides OOTB a JAXB Transformer. I would rather leverage mule capabilities whenever possible rather than writing custom code

Resources