jochen      2005/07/30 14:05:16

  Modified:    src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg
                        GroupHandlerSG.java SimpleContentHandlerSG.java
                        HandlerSGImpl.java
               src/test/jaxb types.xsd
               src/jaxme/org/apache/ws/jaxme/generator/types StringSG.java
               src/jaxme/org/apache/ws/jaxme/junit JiraTest.java
  Log:
  An IllegalStateException was thrown, if a facet violation was detected in the
  Unmarshaller. This is now changed to a proper ValidationEvent.
  PR: JAXME-62
  
  Revision  Changes    Path
  1.9       +31 -9     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java
  
  Index: GroupHandlerSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/GroupHandlerSG.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- GroupHandlerSG.java       20 Jul 2005 20:48:29 -0000      1.8
  +++ GroupHandlerSG.java       30 Jul 2005 21:05:15 -0000      1.9
  @@ -27,7 +27,11 @@
   import org.apache.ws.jaxme.generator.sg.GroupSG;
   import org.apache.ws.jaxme.generator.sg.ObjectSG;
   import org.apache.ws.jaxme.generator.sg.ParticleSG;
  +import org.apache.ws.jaxme.generator.sg.PropertySG;
  +import org.apache.ws.jaxme.generator.sg.PropertySGChain;
   import org.apache.ws.jaxme.generator.sg.TypeSG;
  +import org.apache.ws.jaxme.generator.sg.impl.PropertySGChainImpl;
  +import org.apache.ws.jaxme.generator.sg.impl.PropertySGImpl;
   import org.apache.ws.jaxme.impl.JMSAXElementParser;
   import org.apache.ws.jaxme.impl.JMSAXGroupParser;
   import org.apache.ws.jaxme.impl.JMUnmarshallerHandlerImpl;
  @@ -321,20 +325,38 @@
                        TypedValue v = getParamResult();
                        if (childType.isComplex()) {
                                type = 
childType.getComplexTypeSG().getClassContext().getXMLInterfaceName();
  +                             if (isMixed) {
  +                                     pJm.addLine(pElement, 
".getContent().add(", v, ");");
  +                             } else {
  +                                     pParticle.getPropertySG().addValue(pJm, 
pElement, v, type);
  +                             }
                        } else {
  -                             v = createSimpleTypeConversion(pJm, childType, 
v, oSG.getName().toString());
  -                             type = null;
  +                             PropertySG pSG;
  +                             DirectAccessible element;
                                if (isMixed) {
                                        LocalJavaField f = 
pJm.newJavaField(GroupUtil.getContentClass(group, pParticle, 
ctSG.getClassContext().getXMLInterfaceName()));
                                        f.addLine("new ", 
GroupUtil.getContentClass(group, pParticle, 
ctSG.getClassContext().getXMLImplementationName()), "()");
  -                                     pJm.addLine(f, ".setValue(", v, ");");
  -                                     v = f;
  +                                     PropertySGChain chain = 
((PropertySGImpl) pParticle.getPropertySG()).getHeadOfChain();
  +                                     PropertySGChain head = new 
PropertySGChainImpl(chain){
  +                                             public String 
getXMLFieldName(PropertySG pController) throws SAXException {
  +                                                     return "_value";
  +                                             }
  +                                             public String 
getPropertyName(PropertySG pController) throws SAXException {
  +                                                     return "value";
  +                                             }
  +                                     };
  +                                     pSG = new PropertySGImpl(head);
  +                                     element = f;
  +                             } else {
  +                                     pSG = pParticle.getPropertySG();
  +                                     element = pElement;
  +                             }
  +                             createSimpleTypeConversion(pJm, childType, v,
  +                                                                             
   oSG.getName().toString(),
  +                                                                             
   pSG, element);
  +                             if (isMixed) {
  +                                     pJm.addLine(pElement, 
".getContent().add(", element, ");");
                                }
  -                     }
  -                     if (isMixed) {
  -                             pJm.addLine(pElement, ".getContent().add(", v, 
");");
  -                     } else {
  -                             pParticle.getPropertySG().addValue(pJm, 
pElement, v, type);
                        }
                        pJm.addLine("return;");
                        pJm.addEndIf();
  
  
  
  1.7       +4 -4      
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SimpleContentHandlerSG.java
  
  Index: SimpleContentHandlerSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/SimpleContentHandlerSG.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleContentHandlerSG.java       7 May 2005 19:42:26 -0000       1.6
  +++ SimpleContentHandlerSG.java       30 Jul 2005 21:05:15 -0000      1.7
  @@ -21,7 +21,6 @@
   import org.apache.ws.jaxme.js.JavaQName;
   import org.apache.ws.jaxme.js.JavaSource;
   import org.apache.ws.jaxme.js.LocalJavaField;
  -import org.apache.ws.jaxme.js.TypedValue;
   import org.xml.sax.SAXException;
   
   
  @@ -43,9 +42,10 @@
                LocalJavaField element = result.newJavaField(elementInterface);
                element.addLine("(", elementInterface, ") result");
                SimpleContentSG scSG = ctSG.getSimpleContentSG();
  -             TypedValue tv = createSimpleTypeConversion(result, 
scSG.getContentTypeSG(),
  -                                                                             
                   getParamResult(), scSG.getPropertySG().getPropertyName());
  -             scSG.getPropertySG().addValue(result, element, tv, null);
  +             createSimpleTypeConversion(result, scSG.getContentTypeSG(),
  +                                                                
getParamResult(),
  +                                                                
scSG.getPropertySG().getPropertyName(),
  +                                                                
scSG.getPropertySG(), element);
                return result;
        }
   }
  
  
  
  1.4       +9 -22     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/HandlerSGImpl.java
  
  Index: HandlerSGImpl.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/sg/impl/ccsg/HandlerSGImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HandlerSGImpl.java        28 Apr 2005 23:57:53 -0000      1.3
  +++ HandlerSGImpl.java        30 Jul 2005 21:05:15 -0000      1.4
  @@ -25,8 +25,8 @@
   import org.apache.ws.jaxme.ValidationEvents;
   import org.apache.ws.jaxme.generator.sg.AttributeSG;
   import org.apache.ws.jaxme.generator.sg.ComplexTypeSG;
  +import org.apache.ws.jaxme.generator.sg.PropertySG;
   import org.apache.ws.jaxme.generator.sg.TypeSG;
  -import org.apache.ws.jaxme.generator.types.BooleanSG;
   import org.apache.ws.jaxme.generator.types.StringSG;
   import org.apache.ws.jaxme.js.DirectAccessible;
   import org.apache.ws.jaxme.js.JavaMethod;
  @@ -138,8 +138,9 @@
                                
                                jm.addIf(firstInNamespace, 
JavaSource.getQuoted(attr.getName().getLocalName()), ".equals(", pLocalName, 
")");
                                firstInNamespace = false;
  -                             TypedValue v = createSimpleTypeConversion(jm, 
myAttributes[i].getTypeSG(), pValue, "@" + myAttributes[i].getName());
  -                             attr.getPropertySG().setValue(jm, result, v, 
null);
  +                             createSimpleTypeConversion(jm, 
myAttributes[i].getTypeSG(), pValue,
  +                                                                             
   "@" + myAttributes[i].getName(),
  +                                                                             
   attr.getPropertySG(), result);
                                jm.addLine("return;");
                        }
                        if (!firstInNamespace) {
  @@ -220,40 +221,26 @@
                return jm;
        }
   
  -     protected TypedValue createSimpleTypeConversion(JavaMethod pJm, TypeSG 
pType,
  -                                                                             
                        TypedValue pValue, String pName)
  +     protected void createSimpleTypeConversion(JavaMethod pJm, TypeSG pType,
  +                                                                             
          TypedValue pValue, String pName,
  +                                                                             
          PropertySG pPropertySG,
  +                                                                             
          DirectAccessible pElement)
                        throws SAXException {
  -             JavaQName runtimeType = 
pType.getSimpleTypeSG().getRuntimeType();
                boolean causingParseConversionEvent = 
pType.getSimpleTypeSG().isCausingParseConversionEvent();
  -             LocalJavaField f = null;
                if (causingParseConversionEvent) {
  -                     f = pJm.newJavaField(runtimeType);
                        pJm.addTry();
                }
                Object s = new Object[]{"(", StringSG.STRING_TYPE, ") ", 
pValue};
                TypedValue result = new 
TypedValueImpl(pType.getSimpleTypeSG().getCastFromString(pJm, s, 
"getHandler()"),
                                                                                
           pType.getSimpleTypeSG().getRuntimeType());
  +             pPropertySG.addValue(pJm, pElement, result, null);
                if (causingParseConversionEvent) {
  -                     pJm.addLine(f, " = ", result, ";");
  -                     result = f;
                        DirectAccessible e = pJm.addCatch(Exception.class);
                        pJm.addLine("getHandler().parseConversionEvent(",
                                                JavaSource.getQuoted("Failed to 
convert value of " + pName + ": "),
                                                " + ", pValue, ", ", e, ");");
  -                     Object o;
  -                     if (runtimeType.isPrimitive()) {
  -                             if (BooleanSG.BOOLEAN_TYPE.equals(runtimeType)) 
{
  -                                     o = "false";
  -                             } else {
  -                                     o = "0";
  -                             }
  -                     } else {
  -                             o = "null";
  -                     }
  -                     pJm.addLine(f, " = ", o, ";");
                        pJm.addEndTry();
                }
  -             return result;
        }
   
        public void generate() throws SAXException {
  
  
  
  1.14      +26 -0     ws-jaxme/src/test/jaxb/types.xsd
  
  Index: types.xsd
  ===================================================================
  RCS file: /home/cvs/ws-jaxme/src/test/jaxb/types.xsd,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- types.xsd 20 Jul 2005 20:48:30 -0000      1.13
  +++ types.xsd 30 Jul 2005 21:05:15 -0000      1.14
  @@ -299,4 +299,30 @@
           </xs:sequence>
         </xs:complexType>
       </xs:element>
  +
  +   <xs:element name="jira62">
  +     <xs:complexType>
  +       <xs:attribute name="a" use="optional">
  +         <xs:simpleType>
  +           <xs:restriction base="xs:string">
  +             <xs:maxLength value="4"/>
  +           </xs:restriction>
  +         </xs:simpleType>
  +       </xs:attribute>
  +       <xs:attribute name="b" use="optional">
  +         <xs:simpleType>
  +           <xs:restriction base="xs:string">
  +             <xs:minLength value="4"/>
  +           </xs:restriction>
  +         </xs:simpleType>
  +       </xs:attribute>
  +       <xs:attribute name="c" use="optional">
  +         <xs:simpleType>
  +           <xs:restriction base="xs:string">
  +             <xs:length value="4"/>
  +           </xs:restriction>
  +         </xs:simpleType>
  +       </xs:attribute>
  +     </xs:complexType>
  +   </xs:element>
   </xs:schema>
  
  
  
  1.5       +4 -4      
ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/types/StringSG.java
  
  Index: StringSG.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/generator/types/StringSG.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StringSG.java     28 Apr 2005 23:57:53 -0000      1.4
  +++ StringSG.java     30 Jul 2005 21:05:15 -0000      1.5
  @@ -141,21 +141,21 @@
                                pMethod.addIf(pValue, ".length()", " > ", 
maxLength);
                                
pMethod.addThrowNew(IllegalArgumentException.class,
                                                JavaSource.getQuoted("Length of 
" + maxLength + " characters exceeded: "),
  -                                             " + ", pValue);
  +                                                                             
         " + ", pValue);
                                pMethod.addEndIf();
                        }
                        if (minLength != null) {
                                pMethod.addIf(pValue, ".length()", " < ", 
minLength);
                                
pMethod.addThrowNew(IllegalArgumentException.class,
  -                                             JavaSource.getQuoted("Length of 
" + minLength + " characters exceeded: "),
  -                                             " + ", pValue);
  +                                             JavaSource.getQuoted("Minimum 
length of " + minLength + " characters not matched: "),
  +                                                                             
         " + ", pValue);
                                pMethod.addEndIf();
                        }
                        if (length != null) {
                                pMethod.addIf(pValue, ".length()", " != ", 
length);
                                
pMethod.addThrowNew(IllegalArgumentException.class,
                                                JavaSource.getQuoted("Length of 
" + length + " characters not matched: "),
  -                                             " + ", pValue);
  +                                                                             
         " + ", pValue);
                                pMethod.addEndIf();
                        }
                        if (pValue.isNullable()) {
  
  
  
  1.9       +48 -2     
ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java
  
  Index: JiraTest.java
  ===================================================================
  RCS file: 
/home/cvs/ws-jaxme/src/jaxme/org/apache/ws/jaxme/junit/JiraTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JiraTest.java     7 May 2005 20:37:35 -0000       1.8
  +++ JiraTest.java     30 Jul 2005 21:05:15 -0000      1.9
  @@ -4,6 +4,10 @@
   import java.io.StringWriter;
   
   import javax.xml.bind.JAXBContext;
  +import javax.xml.bind.JAXBException;
  +import javax.xml.bind.Unmarshaller;
  +import javax.xml.bind.ValidationEvent;
  +import javax.xml.bind.ValidationEventHandler;
   
   import magoffin.matt.ieat.domain.impl.IngredientImpl;
   import net.dspc.commons.activitymodel.TransmissionData;
  @@ -16,12 +20,11 @@
   import org.apache.ws.jaxme.generator.impl.GeneratorImpl;
   import org.apache.ws.jaxme.generator.sg.SchemaSG;
   import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaReader;
  -import org.apache.ws.jaxme.generator.sg.impl.JAXBSchemaSG;
   import org.apache.ws.jaxme.generator.util.JavaNamer;
  +import org.apache.ws.jaxme.test.misc.types.Jira62;
   import org.apache.ws.jaxme.test.misc.types.Row;
   import org.apache.ws.jaxme.test.misc.types.impl.RowImpl;
   import org.apache.ws.jaxme.test.misc.xsimport.a.Outer;
  -import org.apache.ws.jaxme.xs.xml.XsQName;
   import org.xml.sax.InputSource;
   
   
  @@ -150,4 +153,47 @@
                assertEquals("Element1", JavaNamer.convert("element1", schema));
                assertEquals("Element_1", JavaNamer.convert("element_1", 
schema));
        }
  +
  +     /** Test for <a 
href="http://issues.apache.org/jira/browse/JAXME-62";>JAXME-62</a>.
  +      */
  +     public void testJAXME62() throws Exception {
  +             for (int i = 0;  i < 6;  i++) {
  +                     runFacetTest(i, "a", i < 5);
  +             }
  +             for (int i = 0;  i < 6;  i++) {
  +                     runFacetTest(i, "b", i > 3);
  +             }
  +             for (int i = 0;  i < 6;  i++) {
  +                     runFacetTest(i, "c", i == 4);
  +             }
  +     }
  +
  +     private static class EventDetector implements ValidationEventHandler {
  +             private boolean gotEvent = false;
  +             public boolean handleEvent(ValidationEvent pEvent) {
  +                     gotEvent = true;
  +                     return true;
  +             }
  +             boolean isSuccess() { return !gotEvent; }
  +     };
  +
  +     private void runFacetTest(int i, String pAttrName, boolean pSuccess) 
throws JAXBException {
  +             JAXBContext ctx = super.getJAXBContext(Jira62.class);
  +             String xml =
  +                     "<ex:jira62"
  +                     + "  
xmlns:ex='http://ws.apache.org/jaxme/test/misc/types'"
  +                     + "  " + pAttrName + "='";
  +             for (int j = 0;  j < i;  j++) {
  +                     xml += (char) ('0' + j);
  +             }
  +             xml += "'/>";
  +             System.out.println("Parsing " + xml);
  +             InputSource isource = new InputSource(new StringReader(xml));
  +             isource.setSystemId("testJAXME62-a-" + i + ".xsd");
  +             EventDetector ed = new EventDetector();
  +             Unmarshaller u = ctx.createUnmarshaller();
  +             u.setEventHandler(ed);
  +             u.unmarshal(isource);
  +             assertEquals(pSuccess, ed.isSuccess());
  +     }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to