Package org.jibx.binding.classes

Examples of org.jibx.binding.classes.BoundClass


     */
    private static void buildEnumValueMethods(boolean exists, String type,
        String evmeth) throws JiBXException {
       
        // set up for adding serialize/deserialize methods to enum class
        BoundClass bndclas = BoundClass.getInstance(type, null);
        ClassFile ecf = bndclas.getClassFile();
        String typesig = ecf.getSignature();
        String evfull = type + '.' + evmeth;
        String sersig = "(" + typesig + ")Ljava/lang/String;";
        String dsersig = "(Ljava/lang/String;)" + typesig;
       
        // check verify vs. add
        if (exists) {
           
            // just verify existing methods
            if (ecf.getMethod(CUSTOM_ENUM_SERIALIZER_NAME,
                new String[] { sersig }) == null) {
                throw new JiBXException("Expected serializer method " +
                    CUSTOM_ENUM_SERIALIZER_NAME + " not found in enum class " +
                    type);
            }
            if (ecf.getMethod(CUSTOM_ENUM_DESERIALIZER_NAME,
                new String[] { dsersig }) == null) {
                throw new JiBXException("Expected deserializer method " +
                    CUSTOM_ENUM_DESERIALIZER_NAME +
                    " not found in enum class " + type);
            }
           
        } else {
           
            // build the serializer method (just delegates to value method)
            ClassFile cf = bndclas.getMungedFile();
            ExceptionMethodBuilder smeth = new ExceptionMethodBuilder
                (CUSTOM_ENUM_SERIALIZER_NAME, sersig, cf,
                Constants.ACC_PUBLIC | Constants.ACC_STATIC);
            smeth.appendLoadLocal(0);
            BranchWrapper nonnull = smeth.appendIFNONNULL(smeth);
            smeth.appendACONST_NULL();
            smeth.appendReturn("java.lang.String");
            smeth.targetNext(nonnull);
            smeth.appendLoadLocal(0);
            smeth.appendCallVirtual(evfull, "()Ljava/lang/String;");
            smeth.appendReturn("java.lang.String");
            bndclas.getUniqueNamed(smeth);
           
            // create the deserializer method
            ExceptionMethodBuilder dmeth = new ExceptionMethodBuilder
                (CUSTOM_ENUM_DESERIALIZER_NAME, dsersig, cf,
                Constants.ACC_PUBLIC | Constants.ACC_STATIC);
            dmeth.addException(MethodBuilder.FRAMEWORK_EXCEPTION_CLASS);
           
            // start by handling the null string case
            dmeth.appendLoadLocal(0);
            nonnull = dmeth.appendIFNONNULL(dmeth);
            dmeth.appendACONST_NULL();
            dmeth.appendReturn(type);
            dmeth.targetNext(nonnull);
           
            // set up locals for array of values and decrementing index
            dmeth.appendCallStatic(type + ".values", "()[" + typesig);
            dmeth.appendDUP();
            int arraylocal = dmeth.addLocal("values",
                ClassItem.typeFromName(type + "[]"));
            dmeth.appendARRAYLENGTH();
            int arrayindex = dmeth.addLocal("index",
                ClassItem.typeFromName("int"));
           
            // start comparison loop with check for off bottom of array
            BranchTarget start = dmeth.appendTargetNOP();
            dmeth.appendIncrementLocal(-1, arrayindex);
            dmeth.appendLoadLocal(arrayindex);
            BranchWrapper loadnext = dmeth.appendIFGE(dmeth);
           
            // throw an exception for value not found
            dmeth.appendCreateNew("java.lang.StringBuffer");
            dmeth.appendDUP();
            dmeth.appendLoadConstant("No match found for value '");
            dmeth.appendCallInit("java.lang.StringBuffer",
                "(Ljava/lang/String;)V");
            dmeth.appendLoadLocal(0);
            dmeth.appendCallVirtual("java.lang.StringBuffer.append",
                "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
            dmeth.appendLoadConstant("' in enum class " + type);
            dmeth.appendCallVirtual("java.lang.StringBuffer.append",
                "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
            dmeth.appendCallVirtual("java.lang.StringBuffer.toString",
                "()Ljava/lang/String;");
            dmeth.appendCreateNew(MethodBuilder.FRAMEWORK_EXCEPTION_CLASS);
            dmeth.appendDUP_X1();
            dmeth.appendSWAP();
            dmeth.appendCallInit(MethodBuilder.FRAMEWORK_EXCEPTION_CLASS,
                MethodBuilder.EXCEPTION_CONSTRUCTOR_SIGNATURE1);
            dmeth.appendThrow();
           
            // load and compare the value
            dmeth.targetNext(loadnext);
            dmeth.appendLoadLocal(0);
            dmeth.appendLoadLocal(arraylocal);
            dmeth.appendLoadLocal(arrayindex);
            dmeth.appendALOAD(type);
            dmeth.appendCallVirtual(evfull, "()Ljava/lang/String;");
            dmeth.appendCallVirtual("java.lang.Object.equals",
                "(Ljava/lang/Object;)Z");
            BranchWrapper tonext = dmeth.appendIFEQ(dmeth);
            tonext.setTarget(start, dmeth);
           
            // return the matching instance
            dmeth.appendLoadLocal(arraylocal);
            dmeth.appendLoadLocal(arrayindex);
            dmeth.appendALOAD(type);
            dmeth.appendReturn(type);
           
            // add completed method to class
            bndclas.getUniqueNamed(dmeth);
        }
    }
View Full Code Here


        ArrayList maps = m_activeContext.getMappings();
        if (maps != null) {
            for (int i = 0; i < maps.size(); i++) {
                IMapping map = (IMapping)maps.get(i);
                if (map instanceof MappingBase) {
                    BoundClass bound = ((MappingBase)map).getBoundClass();
                    if (bound.getClassFile().isModifiable()) {
                        bound.addFactory(m_factoryName);
                    }
                }
            }
        }
    }
View Full Code Here

     * @throws JiBXException if error in generating code
     */
  protected void addIMarshallableMethod() throws JiBXException {
     
      // set up for constructing actual marshal method
        BoundClass clas = getBoundClass();
      ClassFile cf = clas.getMungedFile();
      ContextMethodBuilder mb = new ContextMethodBuilder
          (MARSHALLABLE_METHODNAME, MARSHALLABLE_SIGNATURE, cf,
          Constants.ACC_PUBLIC, 0, clas.getClassFile().getName(),
          1, MARSHALLER_INTERFACE);
     
      // create call to marshalling context method with class name
      mb.loadContext();
      mb.appendLoadConstant(cf.getName());
      mb.appendCallInterface(GETMARSHALLER_METHOD, GETMARSHALLER_SIGNATURE);
     
      // call the returned marshaller with this object and the marshalling
      //  context as parameters
      mb.loadObject();
      mb.loadContext();
      mb.appendCallInterface(MARSHALLERMARSHAL_METHOD,
          MARSHALLERMARSHAL_SIGNATURE);
      mb.appendReturn();
     
      // add method to class
      clas.getUniqueNamed(mb);
     
      // generate and add get mapping name method
      ExceptionMethodBuilder xb = new ExceptionMethodBuilder
            (GETNAME_METHODNAME, GETNAME_SIGNATURE, cf, Constants.ACC_PUBLIC);
      xb.appendLoadConstant(cf.getName());
      xb.appendReturn("java.lang.String");
      clas.getUniqueNamed(xb);
     
      // add the interface to class
      clas.getClassFile().addInterface(IMARSHALLABLE_INTERFACE);
  }
View Full Code Here

     * @throws JiBXException if error in generating code
     */
  protected void addIUnmarshallableMethod() throws JiBXException {
     
      // set up for constructing new method
        BoundClass clas = getBoundClass();
      ClassFile cf = clas.getMungedFile();
      ContextMethodBuilder mb = new ContextMethodBuilder
          (UNMARSHALLABLE_METHODNAME, UNMARSHALLABLE_SIGNATURE, cf,
          Constants.ACC_PUBLIC, 0, clas.getClassFile().getName(),
          1, UNMARSHALLER_INTERFACE);
     
      // create call to unmarshalling context method with class name
      mb.loadContext();
        mb.appendLoadConstant(cf.getName());
      mb.appendCallInterface(GETUNMARSHALLER_METHOD,
          GETUNMARSHALLER_SIGNATURE);
     
      // call the returned unmarshaller with this object and the unmarshalling
      //  context as parameters
      mb.loadObject();
      mb.loadContext();
      mb.appendCallInterface(UNMARSHALLERUNMARSHAL_METHOD,
          UNMARSHALLERUNMARSHAL_SIGNATURE);
      mb.appendReturn();
     
      // add the method to class
      clas.getUniqueNamed(mb);
       
        // generate and add get mapping name method
        ExceptionMethodBuilder xb = new ExceptionMethodBuilder
            (GETNAME_METHODNAME, GETNAME_SIGNATURE, cf, Constants.ACC_PUBLIC);
        xb.appendLoadConstant(cf.getName());
        xb.appendReturn("java.lang.String");
        clas.getUniqueNamed(xb);
       
        // add the interface to class
      clas.getClassFile().addInterface(IUNMARSHALLABLE_INTERFACE);
  }
View Full Code Here

        String fact, String pres, String posts, String pget, String ctype)
        throws JiBXException {
       
        // initialize the basics
        m_container = contain;
        BoundClass ctxc = (objc == null) ? null : objc.getBoundClass();
        m_class = BoundClass.getInstance(type, ctxc);
        ClassFile cf = m_class.getClassFile();
        if (ctype == null) {
            m_createClass = cf;
        } else {
View Full Code Here

TOP

Related Classes of org.jibx.binding.classes.BoundClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.