Thanks Chad I'll take a look at it.
--Keith [EMAIL PROTECTED] wrote: > > Keith, > > Thanks for the quick response. > > Because I am behind a firewall I grabbed the daily snapshot from 04-30 so I > don't have the pserver connection to get the diff. I have attached the > SourceGenerator file that contains my changes along with the xsd file. > > When you drop this java file into your source and run the SourceGenerator > you should be able to see where I got stuck. At line 109 in > QuoteInquiry_TypeDescriptor.java you will find the validate code that I am > questioning. > > Thanks! > > Also, I am using this task to invoke the SourceGenerator: > <target name="quote-xsd2java" depends="quote-wsdl2java"> > <echo>org.exolab.castor.builder.SourceGenerator</echo> > <java classname="org.exolab.castor.builder.SourceGenerator" > fork="true" dir="${xml.home}"> > <classpath refid="axis-lib"/> > <arg value="-i"/> > <arg value="${xml.home}/StockQuote.xsd"/> > <arg value="-dest"/> > <arg value="${src.home}"/> > <arg value="-package"/> > <arg value="${package.name}"/> > <arg value="-nomarshall"/> > <arg value="-f"/> > </java> > </target> > > -----Original Message----- > From: Keith Visco [mailto:[EMAIL PROTECTED] > Sent: Monday, May 03, 2004 9:35 PM > To: [EMAIL PROTECTED] > Subject: Re: [castor-dev] changing SourceGenerator - classes for > simpleTypes? > > Hi Chad, > > Can you attach a diff file (using diff -u) so that I can better see the > changes that you made. Also if you have a small example which > demonstrates the problem, that would be great. > > Thanks, > > --Keith > > [EMAIL PROTECTED] wrote: > > > > Hi, > > > > I have been working with Castor with Axis for about 1 month. > > I am very satisfied with how Castor provides XML Schema validation. > > > > Please forgive the long message but it is important that I explain my > > situation so that it is clear what I am trying to do. > > > > At first I ran into the Descriptor not found for .. errors. > > When I read that global simpleTypes do not create classes I changed all > > of the project schemas to anonymously define all simpleTypes. > > > > After completing this everything was running and validating smoothly. > > My co-worker was not satisfied with this change because across multiple > > schemas we have many complexTypes that include a simpleType dollarsimple. > > This type is a simple int but it has a MinInclusive. Anytime this > > constraint > > changes we will need to change this in multiple XML schema files, plus we > > cannot ensure that this constraint is applied, or applied consistently > > across all schemas. Well, I convinced this co-worker that the luxury of > > declarative validation using Castor outweighed this drawback. > > > > Then along came Enterprise XML schemas. As we tried to import enterprise > > schemas into our project we found the practice of using global simpleTypes > > is a common practice for creating reusable constrained simpleTypes. > > > > We are required to import and use these enterprise schemas for certain > parts > > > > of the SOAP messages. We cannot modify these to work with Castor like we > > did for our original application schemas. So, my option using Castor is > > now only to use the validate method selectively rather than using the > > runtime validation for all objects. > > > > I love Castor but I would like to use validation for all objects created > > from all schemas, but I have not been able to determine how much extra > work > > it would be to change the SourceGenerator for the validation to work on > > these types. It looks like it is all almost there, but I am obviously > > missing something here. > > > > So, I dug into the Castor source and made some hacks: > > createClasses(ElementDecl elementDecl, SGStateInfo sInfo) > > private void processSimpleType(SimpleType simpleType, SGStateInfo sInfo) > > > > also added this method > > private void processSimpleType(SimpleType simpleType, SGStateInfo sInfo, > > String elementName) > > > > As you will see below, without disrupting the Enum generation I was able > > to create a "skeleton" class for all elements of derived simpleType. The > > class descriptor was also properly created. The class descriptor for the > > complexTypes that have member elements of derived simpleType actually add > > the > > constraints properly: > > //-- validation code for: _dollarsimple_element > > fieldValidator = new org.exolab.castor.xml.FieldValidator(); > > fieldValidator.setMinOccurs(1); > > { //-- local scope > > FloatValidator typeValidator = new FloatValidator(); > > typeValidator.setMinInclusive(5.0f); > > fieldValidator.setValidator(typeValidator); > > } > > desc.setValidator(fieldValidator); > > > > Now, Castor seems to have problem finding the descriptor: > > //-- _dollarsimple_element > > desc = new org.exolab.castor.xml.util.XMLFieldDescriptorImpl(float.class, > > "_dollarsimple_element", "dollarsimple_element", > > org.exolab.castor.xml.NodeType.Element); > > > > When I manually change the float.class to Dollarsimple_elementDescriptor > > Castor gives me errors with the text content of the field. At this point > > I am not sure if I need to get the generator to create a "real" type or if > > I can somehow get Castor to find the float.class field descriptor. I am > > willing to take suggestions and contribute my changes if anyone is > > interested. > > > > I just need Bruce or Keith or somebody with SourceGenerator experience to > > point me in the right direction. > > > > Thanks in advance, > > Chad > > > > private void createClasses(ElementDecl elementDecl, SGStateInfo > > sInfo) { > > > > if (sInfo.getStatusCode() == SGStateInfo.STOP_STATUS) return; > > > > if (elementDecl == null) return; > > //-- when mapping schema types, only interested in producing > classes > > //-- for elements with anonymous complex types > > //-- or elements with simple derived types --CI > > XMLType xmlType = elementDecl.getType(); > > boolean isDerivedByRestrictionType = > > ((xmlType.getDerivationMethod() != null) && > > (xmlType.getDerivationMethod().equals("restriction"))) ? true : false; > > > > String debugDescription = elementDecl.getName() + " xmlType: " > + > > xmlType.getName() + " "; > > > > if (mappingSchemaType2Java()) { > > if (elementDecl.isReference() || > > ((xmlType != null) && > > (xmlType.getName() != null) && > > (!isDerivedByRestrictionType) > > ) > > ) > > { > > return; > > } > > } > > > > //--create component > > ... > > //-- No type definition > > ... > > //-- ComplexType > > ... > > > > //-- SimpleType > > else if (xmlType.isSimpleType()) { > > SimpleType simpleType = (SimpleType)xmlType; > > System.out.println("create simpleType: " + > > debugDescription); > > processSimpleType((SimpleType)xmlType, sInfo, > > elementDecl.getName()); > > } > > //-- AnyType > > ... > > } //-- createClasses > > > > private void processSimpleType(SimpleType simpleType, SGStateInfo > > sInfo, String elementName) { > > > > String debugDescription = elementName + " xmlType: " + > > simpleType.getName() + " "; > > > > if (sInfo.getStatusCode() == SGStateInfo.STOP_STATUS) return; > > > > if (simpleType == null) > > return; > > > > if (simpleType.getSchema() != sInfo.getSchema()) > > return; > > > > boolean isDerivedByRestrictionType = > > ((simpleType.getDerivationMethod() != null) && > > (simpleType.getDerivationMethod().equals("restriction"))) ? true : false; > > > > if (simpleType.hasFacet(Facet.ENUMERATION)){ > > System.out.println("--create simpleType.ENUMERATION: > " > > + debugDescription); > > processSimpleType(simpleType, sInfo); > > } > > else if (isDerivedByRestrictionType){ > > System.out.println("--create > > simpleType.isDerivedByRestrictionType: " + debugDescription); > > simpleType.setName(elementName); > > processSimpleType(simpleType, sInfo); > > } > > > > } > > > > private void processSimpleType(SimpleType simpleType, SGStateInfo > sInfo) > > { > > > > if (sInfo.getStatusCode() == SGStateInfo.STOP_STATUS) return; > > > > if (simpleType == null) > > return; > > > > if (simpleType.getSchema() != sInfo.getSchema()) > > return; > > > > //-- Right now the only time we actually > > //-- generate source for a simpletype is > > //-- when it's an enumeration > > //if (! (simpleType instanceof BuiltInType) ) { > > // if (simpleType.hasFacet(Facet.ENUMERATION)) { > > > > ClassInfo classInfo = sInfo.resolve(simpleType); > > if (classInfo == null) { > > JClass jClass = > _sourceFactory.createSourceCode(simpleType, > > sInfo); > > processJClass(jClass, sInfo); > > } else { > > JClass jClass = classInfo.getJClass(); > > processJClass(jClass, sInfo); > > } > > //} > > } //-- processSimpleType > > > > ----------------------------------------------------------- > > If you wish to unsubscribe from this mailing, send mail to > > [EMAIL PROTECTED] with a subject of: > > unsubscribe castor-dev > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev > > ------------------------------------------------------------------------ > Name: StockQuote.xsd > StockQuote.xsd Type: MEW32 File (application/x-unknown-content-type-ft000003) > Encoding: quoted-printable > > Name: SourceGenerator.java > SourceGenerator.java Type: VisualCafe File > (application/x-unknown-content-type-VisualCafeFile.Document) > Encoding: quoted-printable > > Name: QuoteInquiry_TypeDescriptor.java > QuoteInquiry_TypeDescriptor.java Type: VisualCafe File > (application/x-unknown-content-type-VisualCafeFile.Document) > Encoding: quoted-printable > > ------------------------------------------------------------------------ > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev