Hi Keith,

I spent some time to simplify my big and complex schema and to have still the problem with validation (see the attached file: grms_validate.xsd)
According to the schema <grmsjob> has to contain one <simplejob> , this has to contain one <executable> and executable can contain 0 or 1 <arguments> and/or <environment>.
<arguments> and <environment> if exist have to contain at least one <value> or <variable>.


When I try to marshal and unmarshal following XML-document using 0.9.5.4rc1:
<grmsjob>
   <simplejob>
       <executable>
           <environment>
           </environment>
       </executable>
   </simplejob>
</grmsjob>

the result is:

<?xml version="1.0" encoding="UTF-8"?>
<grmsjob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:type="grmsjob">
<simplejob>
<executable>
<environment/>
</executable>
</simplejob>
</grmsjob>


although the <environment> has no <variables>. All classes were generated by SourceGenerator coming from 0.9.5.4rc1.

When I try to do the same with following XML-document (which is also invalid - arguments has to values)
<grmsjob>
<simplejob>
<executable>
<arguments>
</arguments>
<environment>
</environment>
</executable>
</simplejob>
</grmsjob>


the results are better.
The following exception occurred while validating field: _simplejob of class: grms.types.jobdesc.Grmsjob
The following exception occured while validating field: _simplejob of class: grms.types.jobdesc.Grmsjob
The following exception occured while validating field: _executable of class: grms.types.jobdesc.Simplejob
The following exception occured while validating field: _environment of class: grms.types.jobdesc.Executable
ValidationException: A minimum of 1 _variableList object(s) (whose xml name is 'variable') are required for class: grms.types.jobdesc.Environment;
- location of error: XPATH: environment
at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:311)


When I replace castor jar 0.9.5.4rc1 with 0.9.5.3 both cases work fine:
ValidationException: A minimum of 1 _variableList object(s) (whose xml name is 'variable') are required.;
- location of error: XPATH: grmsjob/simplejob/executable/environment
at org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:277


I hope it helps you to find the problem.

All the best,
Tomek

Keith Visco wrote:


Hi Tomasz,

This was also reported over on the forums:

http://castor.exolab.org/phpBB2/viewtopic.php?t=263

Though I was unable to reproduce the problem myself.

The user on the forums reported the problem when using a mapping file. So I tried to reproduce that, as you can see from the forum message, but was unable to.

Since you're reporting the issue with Castor generated source code,
I also tried to reproduce it using the following schema:


<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";>

<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="foo" type="xsd:string" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>


</xsd:schema>

And the following xml instances:

valid-input.xml

<?xml version="1.0"?>
<root>
   <foo>Some foo data</foo>
</root>

invalid-input.xml

<?xml version="1.0"?>
<root>
   <!-- intentionally removed foo element -->
</root>

Castor definately complains when I try to unmarshal the invalid-input.xml

I also tried generating the sources with 0.9.5.3 and then unmarshalling with 0.9.5.4, but Castor still reports the error.

Since I do believe there is a problem somewhere, as you are not the only one who has experienced this, but I can't seem to reproduce it.

If you have a chance, perhaps you can modify the above schema to look more like the one you are using and see if it causes the problem or not. I'd like to be able to reproduce this so I can fix the problem.

Thanks,

--Keith




Tomasz Piontek wrote:


Hi,

I tried to use 0.9.5.4rc and it seems that it doesn't check constraints connected with required number of elements.
According to my XML-schema environment has to have at least ONE variable.


<environment>
   <variable name="PATH">/bin</variable>
</environment>

but in case

<environment>
</environment>

0.9.5.4 doesn't complain about the lack of variables.

with 0.9.5.3 the error message is:
ValidationException: A minimum of 1 _variableList object(s) (whose xml name is 'variable') are required for class: grms.types.jobdesc.Environment;
- location of error: XPATH: environment


The code was generated by SourceGenerator coming from 0.9.5.3 or 0.9.5 (i don't remember). The only thing I did was to replace castor jar 0.9.5.3 with 0.9.5.4rc

I found this searching for a cause of another error, but this I will describe in separated mail (I need more time for testing). The problem I got is not related to "rc" version.

All the best,
Tomek



----------------------------------------------------------- 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





--
***********************************************************
*   Tomasz Piontek               [EMAIL PROTECTED]    *
*   Research Programmer - GridLab Project                 *
*   Poznan Supercomputing and Networking Center           *
*   tel.(+48 61) 858-21-72       fax.(+48 61) 858-21-51   *
***********************************************************

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="grmsjob">
		<xs:annotation>
			<xs:documentation>Job Description for Gridlab Resource Management System</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:choice>
				<xs:element name="simplejob" type="simplejobType">
					<xs:annotation>
						<xs:documentation>Description of Simple Job</xs:documentation>
					</xs:annotation>
				</xs:element>
			</xs:choice>
		</xs:complexType>
	</xs:element>
	<xs:complexType name="simplejobType">
		<xs:annotation>
			<xs:documentation>Description of Simple Job</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="executable">
				<xs:annotation>
					<xs:documentation>Application description section</xs:documentation>
				</xs:annotation>
				<xs:complexType>
					<xs:sequence>
						<xs:element name="arguments" minOccurs="0">
							<xs:annotation>
								<xs:documentation>Arguments of execution</xs:documentation>
							</xs:annotation>
							<xs:complexType>
								<xs:choice maxOccurs="unbounded">
									<xs:element name="value" type="valueType"/>
								</xs:choice>
							</xs:complexType>
						</xs:element>
						<xs:element name="environment" minOccurs="0">
							<xs:annotation>
								<xs:documentation>Environment variables</xs:documentation>
							</xs:annotation>
							<xs:complexType>
								<xs:sequence>
									<xs:element name="variable" maxOccurs="unbounded">
										<xs:complexType>
											<xs:simpleContent>
												<xs:extension base="xs:string"/>
											</xs:simpleContent>
										</xs:complexType>
									</xs:element>
								</xs:sequence>
							</xs:complexType>
						</xs:element>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
	<xs:complexType name="valueType">
		<xs:annotation>
			<xs:documentation>Decribtion of value for arguments definition</xs:documentation>
		</xs:annotation>
		<xs:simpleContent>
			<xs:extension base="xs:string"/>
		</xs:simpleContent>
	</xs:complexType>
</xs:schema>
# THE CASTOR PROPERTIES FILE
# This file specifies values for Castor run-time 
# which may be configured by the user.
# $Id: castor.properties,v 1.10 2004/10/01 10:25:34 wguttmann Exp $


# This section defines Backward compatibility switches
#
# Hashtable/Map default mapping
#  - For backward compatibility with 0.9.5.2 and earlier
# 
#org.exolab.castor.xml.saveMapKeys=false


# Defines the default XML parser to be used by castor
# The parser must implement org.xml.sax.Parser
#
org.exolab.castor.parser=org.apache.xerces.parsers.SAXParser


# Defines the default XML serializer to be used by castor
# The serializer must implement org.apache.xml.serialize.Serializer
#
org.exolab.castor.serializer=org.apache.xml.serialize.XMLSerializer


# Defines the NodeType for use with Java primitive types (int, long,
# boolean, etc). This value is only used by the Introspector.
# valid values are either "attribute" or "element". By default
# all primitives are marshalled as attributes. Simply uncomment
# the following line to change the NodeType to element.
#
#org.exolab.castor.xml.introspector.primitive.nodetype=element


# Defines the Naming "style" or conventions to use when
# creating XML names from Java class or field names. 
# Valid values are as follows:
# -----------------------------------------------------------------
# lower (default)  |  All names are lowercase with hyphens
#                  |  separating words.
#                  |
#                  |  Example: personInfo = person-info
# -----------------------------------------------------------------
# mixed            |  All names are mixed case, with Uppercase
#                  |  character as the first letter of a new word.
#                  |
#                  |  Example: personInfo = personInfo
#                  |  Example: FooBar     = fooBar
# -----------------------------------------------------------------
# {Any ClassName}  |  Any Class which implements 
#                  |  org.exolab.castor.xml.XMLNaming
# -----------------------------------------------------------------
#
# By default all names are treated as the "lower" option.
# To preserve the Java mixed-case conventions simply
# uncomment the following line. 
#
#org.exolab.castor.xml.naming=mixed


###############################
# REGULAR EXPRESSION EVALUATORS
#
# Defines the Regular Expression Evaluator to be used by Castor
# The evaluator must implement org.exolab.castor.util.RegExpEvaluator
#
# Uncomment the following to basically supress evaluation of Regular expressions
#org.exolab.castor.regexp=org.exolab.castor.xml.util.AlwaysTrueRegExpEvaluator
#
# An implementation which uses the Jakarta RegExp library
#org.exolab.castor.regexp=org.exolab.castor.util.JakartaRegExpEvaluator
#
# An implementation which uses the Jakarta ORO library
org.exolab.castor.regexp=org.exolab.castor.util.JakartaOroEvaluator




# True if all documents should be indented on output by default
#
org.exolab.castor.indent=true


# True if xml documents should be validated by the SAX Parser
#
org.exolab.castor.parser.validation=false
org.exolab.castor.parser.namespaces=false

# True if all documents should be validated by the marshalling framework
#
org.exolab.castor.marshalling.validation=true



# Comma separated list of SAX 2 features that should be enabled
# for the default parser.
#
#org.exolab.castor.features=


# True if should produce verbose messages
#
org.exolab.castor.debug=false


# List of collection handlers for Java 1.1 and Java 1.2 run-times
#
org.exolab.castor.mapping.collections=\
  org.exolab.castor.mapping.loader.J1CollectionHandlers,\
  org.exolab.castor.mapping.loader.J2CollectionHandlers


# List of persistence factories for the supported database servers
#
org.exolab.castor.jdo.engines=\
  org.exolab.castor.jdo.drivers.OracleFactory,\
  org.exolab.castor.jdo.drivers.PostgreSQLFactory,\
  org.exolab.castor.jdo.drivers.SybaseFactory,\
  org.exolab.castor.jdo.drivers.SQLServerFactory,\
  org.exolab.castor.jdo.drivers.DB2Factory,\
  org.exolab.castor.jdo.drivers.InformixFactory,\
  org.exolab.castor.jdo.drivers.HsqlFactory,\
  org.exolab.castor.jdo.drivers.InstantDBFactory,\
  org.exolab.castor.jdo.drivers.InterbaseFactory,\
  org.exolab.castor.jdo.drivers.MySQLFactory,\
  org.exolab.castor.jdo.drivers.SapDbFactory,\
  org.exolab.castor.jdo.drivers.GenericFactory


# List of key generator factories 
#
org.exolab.castor.jdo.keyGeneratorFactories=\
  org.exolab.castor.jdo.drivers.MaxKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.HighLowKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.IdentityKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.SequenceKeyGeneratorFactory,\
  org.exolab.castor.jdo.drivers.UUIDKeyGeneratorFactory


# Collection handlers for the source code generator
#
org.exolab.castor.builder.type.j2=\
  org.exolab.castor.builder.FieldInfoFactoryJ2
org.exolab.castor.builder.type.j1=\
  org.exolab.castor.builder.FieldInfoFactory
org.exolab.castor.builder.type.odmg=\
  org.exolab.castor.builder.FieldInfoFactoryODMG30

# 
# TransactionManagerFactory implementations
# 
org.exolab.castor.jdo.spi.transactionManagerFactories=\
  org.exolab.castor.jdo.transactionmanager.spi.WebSphereTransactionManagerFactory,\
  org.exolab.castor.jdo.transactionmanager.spi.WebSphere5TransactionManagerFactory,\
  org.exolab.castor.jdo.transactionmanager.spi.WebSphere51TransactionManagerFactory,\
  org.exolab.castor.jdo.transactionmanager.spi.LocalTransactionManagerFactory,\
  org.exolab.castor.jdo.transactionmanager.spi.JNDIENCTransactionManagerFactory

#
# List of TxSynchronizeable implementations
#
#org.exolab.castor.persist.TxSynchronizable=

# 
# The buffer size in bytes for fetching LOBs (this is dependent upon
# the JDBC driver implementation) - value below is 5k 
# 
org.exolab.castor.jdo.lobBufferSize=5120

# 
# Cache implementations
# 
org.exolab.castor.jdo.cacheFactories=\
  org.exolab.castor.persist.cache.NoCacheFactory,\
  org.exolab.castor.persist.cache.TimeLimitedFactory,\
  org.exolab.castor.persist.cache.CountLimitedFactory,\
  org.exolab.castor.persist.cache.UnlimitedFactory
#
# Property file for SourceCodeGenerator
#
# $Id: castorbuilder.properties,v 1.8 2002/10/13 23:54:15 kvisco Exp $

# To enable bound properties uncomment the following line. Please
# note that currently *all* fields will be treated as bound properties
# when enabled. This will change in the future when we introduce
# fine grained control over each class and it's properties.
#
#org.exolab.castor.builder.boundproperties=true

# Java class mapping of <xsd:element>'s and <xsd:complexType>'s
#
org.exolab.castor.builder.javaclassmapping=element

# This property allows one to specify the super class of *all*
# generated classes
#
#org.exolab.castor.builder.superclass=com.xyz.BaseObject

# XML namespace mapping to Java packages
#
#org.exolab.castor.builder.nspackages=\
  http://www.xyz.com/schemas/project=com.xyz.schemas.project,\
  http://www.xyz.com/schemas/person=com.xyz.schemas.person

# Set to true if you want to generate the equals method
# for each generated class
# false by default
#
#org.exolab.castor.builder.equalsmethod=true

# Set to true if you want to use Object Wrappers instead
# of primitives (e.g Float instead of float).
# false by default.
#
#org.exolab.castor.builder.primitivetowrapper=false

# Set to true if you want the generated class descriptors to
# expose the element and attribute names they contain.
# false by default.
#
#org.exolab.castor.builder.classdescfieldnames=false

# Set to true if you want the generated source code to contain
# Extra methods for the collection fields, such as get/set using
# the collection type in addition to the type-safe array.
# Set this to true if you want your code to be more compatible
# with Castor JDO. This is false by default.
#
org.exolab.castor.builder.extraCollectionMethods=true
import grms.types.jobdesc.Grmsjob;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.StringWriter;
import java.util.Date;
import java.util.NoSuchElementException;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.exolab.castor.jdo.ClassNotPersistenceCapableException;
import org.exolab.castor.jdo.Database;
import org.exolab.castor.jdo.DatabaseNotFoundException;
import org.exolab.castor.jdo.DuplicateIdentityException;
import org.exolab.castor.jdo.JDO;
import org.exolab.castor.jdo.OQLQuery;
import org.exolab.castor.jdo.PersistenceException;
import org.exolab.castor.jdo.QueryException;
import org.exolab.castor.jdo.QueryResults;
import org.exolab.castor.jdo.TransactionAbortedException;
import org.exolab.castor.jdo.TransactionNotInProgressException;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;

/**
 * @author piontek
 *
 * TP_TO_DO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SchemaTest {
	
	private Grmsjob readGrmsJob(String file)
	{
		Grmsjob job = null;
		
		try {
			FileReader reader = new FileReader( file);
			job = new Grmsjob();

			job = (Grmsjob)Grmsjob.unmarshal( reader);
		} catch (MarshalException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (ValidationException e) {
			e.printStackTrace();
		}
		
		return job;
	}
	
	private void printGrmsJob( Grmsjob job)
	{
		StringWriter jobDescriptionWriter = new StringWriter();
	    
	    try {
			job.marshal(jobDescriptionWriter);
		} catch (MarshalException e) {
			e.printStackTrace();
		} catch (ValidationException e) {
			e.printStackTrace();
		}
	    
	    System.out.println( "**********************************************************************************");
	    System.out.println( jobDescriptionWriter.toString());
	    System.out.println( "**********************************************************************************");
	}
	
	private void testJob( Grmsjob job)
	{
	}
	
	private void test( String[] args)
	{
		String jobId;
		Grmsjob job = null;
		
		job = readGrmsJob( "./jobs/job.xml");
		
		printGrmsJob( job);
	}

	public static void main(String[] args)
	{
		SchemaTest schema = new SchemaTest();
		
		BasicConfigurator.configure();
		Logger.getRootLogger().setLevel( Level.ERROR);
		
		schema.test( args);
	}
}
----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to