Update of /cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types
In directory sc8-pr-cvs1:/tmp/cvs-serv14248/src/net/sf/jaxme/generator/javasg/types

Modified Files:
        DurationTypeSG.java 
Added Files:
        Base64BinaryTypeSG.java HexBinaryTypeSG.java 
Log Message:
Added xs:hexBinary, xs:base64Binary, xs:positiveInteger and
xs:NMTOKEN. JUnit tests are partially missing or not working.
(Jochen Wiedmann)
Added example schema PurchaseOrder (Marty Kube).


--- NEW FILE: Base64BinaryTypeSG.java ---
package net.sf.jaxme.generator.javasg.types;

import java.io.IOException;

import net.sf.jaxme.ValidationEvents;
import net.sf.jaxme.generator.SchemaException;
import net.sf.jaxme.generator.javasg.ComplexTypeSG;
import net.sf.jaxme.generator.types.SchemaSimpleType;
import net.sf.jaxme.javasource.JavaMethod;
import net.sf.jaxme.javasource.JavaQName;
import net.sf.jaxme.javasource.JavaSource;
import net.sf.jaxme.util.Base64Binary;


/**
 * @author <a href="mailto:[EMAIL PROTECTED]";>Jochen Wiedmann</a>
 */
public class Base64BinaryTypeSG extends AtomicTypeSG {
  public Object getCloneFor(SchemaSimpleType pType, JavaMethod pMethod,
                             Object pValue, Object pFactory)
      throws SchemaException {
    return new Object[]{Base64Binary.class, ".getClone(", pValue, ")"};
  }

  public boolean hasCastFromStringWithParam(SchemaSimpleType pType) {
    return false;
  }

  public Object getCastFromString(SchemaSimpleType pType, JavaMethod pMethod,
                                   Object pValue,
                                   ComplexTypeSG.UnmarshallerSGData pUnmarshallerData)
      throws SchemaException {
    JavaQName qName = pType.getRuntimeType();
    String e = pMethod.getLocalVariableName();
    String var = pMethod.getLocalVariableName();
    pMethod.addLine(qName, " ", var, ";");
    pMethod.addLine("try {");
    pMethod.indent();
    pMethod.addLine(var, " = ", Base64Binary.class, ".decode(", pValue, ");");
    pMethod.unindent();
    pMethod.addLine("} catch (", IOException.class, " ", e, ") {");
    pMethod.indent();
    Object msg = new Object[]{JavaSource.getQuoted("Illegal hex value: "),
                              " + ", pValue};
    Object errorCode = new Object[]{ValidationEvents.class, ".EVENT_ILLEGAL_VALUE"};
    pMethod.addLine(pUnmarshallerData.getException(msg, errorCode, e));
    pMethod.addLine(var, " = null;");
    pMethod.unindent();
    pMethod.addLine("}");
    return var;
  }

  public Object getCastToString(SchemaSimpleType pType, JavaMethod pMethod,
                                 Object pValue,
                                 ComplexTypeSG.UnmarshallerSGData pUnmarshallerData)
      throws SchemaException {
    return new Object[]{Base64Binary.class, ".encode(", pValue, ")"};
  }
}

--- NEW FILE: HexBinaryTypeSG.java ---
package net.sf.jaxme.generator.javasg.types;

import net.sf.jaxme.ValidationEvents;
import net.sf.jaxme.generator.SchemaException;
import net.sf.jaxme.generator.javasg.ComplexTypeSG;
import net.sf.jaxme.generator.types.SchemaSimpleType;
import net.sf.jaxme.javasource.JavaMethod;
import net.sf.jaxme.javasource.JavaQName;
import net.sf.jaxme.javasource.JavaSource;
import net.sf.jaxme.util.HexBinary;


/**
 * @author <a href="mailto:[EMAIL PROTECTED]";>Jochen Wiedmann</a>
 */
public class HexBinaryTypeSG extends AtomicTypeSG {
  public Object getCloneFor(SchemaSimpleType pType, JavaMethod pMethod,
                             Object pValue, Object pFactory)
      throws SchemaException {
    return new Object[]{HexBinary.class, ".getClone(", pValue, ")"};
  }

  public boolean hasCastFromStringWithParam(SchemaSimpleType pType) {
    return false;
  }

  public Object getCastFromString(SchemaSimpleType pType, JavaMethod pMethod,
                                   Object pValue,
                                   ComplexTypeSG.UnmarshallerSGData pUnmarshallerData)
      throws SchemaException {
    JavaQName qName = pType.getRuntimeType();
    String e = pMethod.getLocalVariableName();
    String var = pMethod.getLocalVariableName();
    pMethod.addLine(qName, " ", var, ";");
    pMethod.addLine("try {");
    pMethod.indent();
    pMethod.addLine(var, " = ", HexBinary.class, ".decode(", pValue, ");");
    pMethod.unindent();
    pMethod.addLine("} catch (", IllegalArgumentException.class, " ", e, ") {");
    pMethod.indent();
    Object msg = new Object[]{JavaSource.getQuoted("Illegal hex value: "),
                              " + ", pValue};
    Object errorCode = new Object[]{ValidationEvents.class, ".EVENT_ILLEGAL_VALUE"};
    pMethod.addLine(pUnmarshallerData.getException(msg, errorCode, e));
    pMethod.addLine(var, " = null;");
    pMethod.unindent();
    pMethod.addLine("}");
    return var;
  }

  public Object getCastToString(SchemaSimpleType pType, JavaMethod pMethod,
                                 Object pValue,
                                 ComplexTypeSG.UnmarshallerSGData pUnmarshallerData)
      throws SchemaException {
    return new Object[]{HexBinary.class, ".encode(", pValue, ")"};
  }
}

Index: DurationTypeSG.java
===================================================================
RCS file: 
/cvsroot/jaxme/JaxMe2/src/net/sf/jaxme/generator/javasg/types/DurationTypeSG.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- DurationTypeSG.java 9 Feb 2003 17:51:56 -0000       1.1
+++ DurationTypeSG.java 10 Feb 2003 21:07:46 -0000      1.2
@@ -40,7 +40,7 @@
     pMethod.unindent();
     pMethod.addLine("} catch (", ParseException.class, " ", e, ") {");
     pMethod.indent();
-    Object msg = new Object[]{JavaSource.getQuoted("Illegal dateTime value: "),
+    Object msg = new Object[]{JavaSource.getQuoted("Illegal duration value: "),
                               " + ", pValue};
     Object errorCode = new Object[]{ValidationEvents.class, ".EVENT_ILLEGAL_VALUE"};
     pMethod.addLine(pUnmarshallerData.getException(msg, errorCode, e));




-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Jaxme-jaxb-dev mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxme-jaxb-dev

Reply via email to