Hi Alex,
that is a hard question to answer, as the answer i snot a simpe yes
and/or no. But let me try .....
Regards
Werner
Alex Thieme wrote:
>
> I know that castor can generate Java classes (what I would consider
> POJOs); but, is there an option to generate a file or files from any
> arbitrary template and XSD? I'll provide examples in case my explanation
> is not clear.
>
> In the example below, there's an Adjustment.xsd, containing three
> attributes. The generator writes out a class header (package and import
> statements of my choosing), then writes a statement representing the
> "singleton" instance. Then, a "format" method is generated. Again,
> AdjustmentNativeFormatter (below) is the result of applying the
> Adjustment.xsd to a generator, say "FormatterGenerator" because this
> generator generates "Formatter" objects.
>
> What I can't find in castor is the piece of code that I could write,
> either in XML or more likely Java code, which has access to the metadata
> in the XSD (the root elements, nested elements, attributes, whether
> something is a simple type or complex type, XML Schema type, etc). From
> that, I would write code to iterate over the elements and attributes,
> write out statements that will be written to a file on disk.
It's not as easy as you think. Internally, Castor converts your XML
schemas and the types/elements defined therein into a set of in-memory
Java objects that represent your XML schema definitions.
It's those object instances that classes such as Source-/MemberFactory
will use to traverse these schema objects and build J* instances from;
eventually, the Castor XML code generator will serialize those J*
instances (such as JClass, JField, .....) to files on your file system.
In other words, most of what you need is in place; but on the other
hand, none of these classes expose any entry points fro you to use to
implement your own code fragments.
Does this answer your question ?
> As you can see, this is different from generating simply POJOs. I'd like
> to be able to generate any arbitrary code from XSD.
I do appreciate your needs here, but Castor's code generator will
generate POJOs only and the corresponding descriptor classes for XML
data binding and JDO persistence.
> And, dare I ask, if castor does not have this feature, can you recommend
> other open source projects that do have this feature?
>
> Thanks in advance,
>
> Alex
>
> Generated code:
> package com.athieme.KToW.formatters;
>
> import org.apache.log4j.Logger;
> import java.math.BigInteger;
> import java.util.Calendar;
> import com.athieme.AbstractFormatter;
> import com.athieme.interfaces.IAdjustment;
>
> public class AdjustmentFormatter extends
> AbstractFormatter<IAdjustment> {
>
> public static final AdjustmentFormatter singleton = new
> AdjustmentFormatter();
>
> public String format(final IAdjustment obj) {
> final StringBuffer sb = new StringBuffer();
> sb.append(obj.company());
> sb.append(obj.userId());
> sb.append(obj.dateStamp());
> sb.append(obj.timeStamp());
> return sb.toString();
> }
> }
>
> XSD:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:fd="http://athieme/FieldDef"
> xmlns:common="http://athieme/Common"
> targetNamespace="http://athieme/KToW"
> elementFormDefault="qualified">
>
> <xs:import namespace="http://athieme/FieldDef" schemaLocation="../
> FieldDef.xsd"/>
> <xs:import namespace="http://athieme/Common" schemaLocation="../
> Common.xsd"/>
>
> <xs:complexType name="Adjustment">
>
> <xs:attribute name="company"
> type="fd:fixedString10"
> fd:externalName="LDCO"
> fd:internalName="Company"/>
>
> <xs:attribute name="userId"
> type="fd:fixedString10"
> fd:externalName="PLUSER"
> fd:internalName="user_id"/>
>
> <xs:attribute name="dateStamp"
> type="fd:fixedInt8"
> fd:externalName="DateStamp"
> fd:internalName="DateStamp"
> fd:fieldDefType="int"/>
>
> </xs:complexType>
> </xs:schema>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email