Examples of ClassFile


Examples of org.jibx.binding.classes.ClassFile

    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);
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

        String type = (prop == null || constant != null) ?
            "java.lang.String" : prop.getTypeName();
        String evmeth = ctx.attributeText(URI_ATTRIBUTES,
            COMMON_ENUMVALUEMETHOD, null);
        boolean basicenum = false;
        ClassFile target = ClassCache.requireClassFile(type);
        if (evmeth != null) {
           
            // handle enum using generated serialize and deserialize methods
            ser = type + '.' + CUSTOM_ENUM_SERIALIZER_NAME;
            dser = type + '.' + CUSTOM_ENUM_DESERIALIZER_NAME;
            buildEnumValueMethods(false, type, evmeth);
           
        } else {
           
            // check for a Java 5 enumeration
            ClassFile sclas = target;
            while ((sclas = sclas.getSuperFile()) != null) {
                if (sclas.getName().equals("java.lang.Enum")) {
                    basicenum = true;
                    break;
                }
            }
        }
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

    private static DirectObject unmarshalDirectObj(UnmarshallingContext ctx,
        String type, IContainer parent, DefinitionContext defc, String mapname,
        NameDefinition name) throws JiBXException {
       
        // define and validate marshaller
        ClassFile mcf = null;
        if (parent.getBindingRoot().isOutput()) {
            String clas = ctx.attributeText(URI_ATTRIBUTES, COMMON_MARSHALLER);
            mcf = ClassCache.requireClassFile(clas);
            if (!mcf.isImplements(MARSHALLER_INTERFACETYPE)) {
                ctx.throwStartTagException("Marshaller class " + clas +
                    " does not implement required interface " +
                    MARSHALLER_INTERFACE);
            }
        }
       
        // define and validate unmarshaller
        ClassFile ucf = null;
        if (parent.getBindingRoot().isInput()) {
            String clas = ctx.attributeText(URI_ATTRIBUTES,
                COMMON_UNMARSHALLER);
            ucf = ClassCache.requireClassFile(clas);
            if (!ucf.isImplements(UNMARSHALLER_INTERFACETYPE)) {
                ctx.throwStartTagException("Unmarshaller class " + clas +
                    " does not implement required interface " +
                    UNMARSHALLER_INTERFACE);
            }
        }
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

                }
               
            } else {
               
                // must be an object type, find best match
                ClassFile cf = ClassCache.requireClassFile(type);
                base = defc.getConversion(cf);
               
            }
           
            // unmarshal with defaults provided by existing format
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

                                " and " + COLLECTION_STOREMETHOD +
                                " attributes cannot be used together");
                        }
                       
                        // set defaults based on collection type
                        ClassFile cf = ClassCache.requireClassFile
                            (prop.getTypeName());
                        if (cf.isSuperclass("java.util.Vector")||
                            cf.isSuperclass("java.util.ArrayList")) {
                            if (stname == null && aname == null) {
                                aname = "add";
                            }
                            if (iname == null && lname == null) {
                                lname = "get";
                                szname = "size";
                            }
                        } else if (cf.isImplements("Ljava/util/Collection;")) {
                            if (stname == null && aname == null) {
                                aname = "add";
                            }
                            if (iname == null && lname == null) {
                                iname = "iterator";
                            }
                        } else if (cf.isArray()) {
                            String ptype = prop.getTypeName();
                            itype = ptype.substring(0, ptype.length()-2);
                        }
                       
                        // check binding direction(s)
                        BindingDefinition bdef = contain.getBindingRoot();
                        boolean isdoub =
                            "long".equals(itype) || "double".equals(itype);
                        if (bdef.isInput()) {
                           
                            // define strategy for adding items to collection
                            if (aname != null) {
                                ClassItem meth = cf.getBestMethod(aname,
                                    null, new String[] { itype });
                                if (meth == null) {
                                    ctx.throwStartTagException
                                        ("Add method " + aname +
                                        " not found in collection type " +
                                        cf.getName());
                                }
                                boolean hasval =
                                    !"void".equals(meth.getTypeName());
                                store = new NestedCollection.AddStore(meth,
                                    isdoub, hasval);
                            } else if (stname != null) {
                                ClassItem meth = cf.getBestMethod(stname,
                                    null, new String[] { "int", itype });
                                if (meth == null) {
                                    ctx.throwStartTagException
                                        ("Indexed store method " + stname +
                                        " not found in collection type " +
                                        cf.getName());
                                }
                                boolean hasval =
                                    !"void".equals(meth.getTypeName());
                                store = new NestedCollection.IndexedStore(meth,
                                    isdoub, hasval);
                            } else if (cf.isArray()) {
                                store = new NestedCollection.ArrayStore(itype,
                                    isdoub);
                            } else {
                                ctx.throwStartTagException
                                    ("Unknown collection " +
                                    "type with no add or store method defined");
                            }
                           
                        }
                        if (bdef.isOutput()) {
                           
                            // define strategy for loading items from collection
                            if (lname != null) {
                                ClassItem smeth = cf.getMethod(szname, "()I");
                                if (smeth == null) {
                                    ctx.throwStartTagException
                                        ("Size method " + szname +
                                        " not found in collection type " +
                                        cf.getName());
                                }
                                ClassItem lmeth = cf.getBestMethod(lname,
                                    itype, new String[] { "int" });
                                if (lmeth == null) {
                                    ctx.throwStartTagException
                                        ("Load method " + lname +
                                        " not found in collection type " +
                                        cf.getName());
                                }
                                load = new NestedCollection.
                                    IndexedLoad(smeth, isdoub, lmeth);
                            } else if (iname != null) {
                                String mname = "hasNext";
                                String nname = "next";
                                ClassItem meth = cf.getMethod(iname,
                                    "()Ljava/util/Iterator;");
                                if (meth == null) {
                                    mname = "hasMoreElements";
                                    nname = "nextElement";
                                    meth = cf.getMethod(iname,
                                        "()Ljava/util/Enumeration;");
                                    if (meth == null) {
                                        ctx.throwStartTagException
                                            ("Iterator method " + iname +
                                            " not found in collection type " +
                                            cf.getName());
                                    }
                                }
                                load = new NestedCollection.
                                    IteratorLoad(meth, isdoub,
                                    "java.util.Iterator." + mname,
                                    "java.util.Iterator." + nname);
                            } else if (cf.isArray()) {
                                load = new NestedCollection.ArrayLoad(itype,
                                    isdoub);
                            } else {
                                ctx.throwStartTagException
                                    ("Unknown collection " +
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

     * @param name fully-qualified class name (using '$' as inner class marker)
     * @return class information, or <code>null</code> if not found
     */
    public IClass getClassInfo(String name) {
        try {
            ClassFile clas = ClassCache.getClassFile(name);
            if (clas == null) {
                return null;
            } else {
                return new ClassSourceWrapper(this, clas);
            }
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

        // read stream into memory buffer
        byte[] data = getStreamData(istrm);
       
        // validate using binding object model
        boolean valid = true;
        ClassFile cf = null;
        String tpack = null;
        String bname = null;
        if (test) {
            BindingElement root = validateBinding(fname, url,
                new ByteArrayInputStream(data));
            if (root == null) {
                valid = false;
            } else {
               
                // find package of first mapping to use for added classes
                cf = findMappedClass(root);
                tpack = root.getTargetPackage();
                if (tpack == null && cf != null) {
                    tpack = cf.getPackage();
                }
                bname = root.getName();
               
            }
        }
        if (valid) {
            try {
               
                // construct the binding definition code generator
                UnmarshallingContext uctx = new UnmarshallingContext();
                uctx.setDocument(new ByteArrayInputStream(data), fname, null);
                if (cf != null) {
                   
                    // set target root and package for created classes
                    if (bname == null) {
                        bname = sname;
                    }
                    BoundClass.setModify(cf.getRoot(), tpack, bname);
                   
                }
                BindingDefinition bdef =
                    BindingBuilder.unmarshalBindingDefinition(uctx, sname, url);
               
                // set package and class if not validated
                if (!test) {
                   
                    // a kludge, but needed to support skipping validation
                    ArrayList maps = bdef.getDefinitionContext().getMappings();
                    if (maps != null) {
                       
                        // set up package information from mapped class
                        for (int i = 0; i < maps.size(); i++) {
                            Object child = maps.get(i);
                            if (child instanceof MappingBase) {
                               
                                // end scan if a real mapping is found
                                MappingBase mapbase = (MappingBase)child;
                                cf = mapbase.getBoundClass().getMungedFile();
                                if (mapbase.getBoundClass().isDirectAccess()) {
                                    break;
                                }
                               
                            }
                        }
                    }
                }
               
                // set up binding root based on first mapping
                File root = null;
                if (tpack == null) {
                    tpack = bdef.getDefaultPackage();
                }
                if (cf == null) {
                    root = ClassCache.getModifiablePath();
                    if (root == null) {
                        throw new IllegalStateException("Need modifiable directory on classpath for storing generated factory class file");
                    }
                    if (tpack == null) {
                        tpack = "";
                    }
                } else {
                    root = cf.getRoot();
                    if (tpack == null) {
                        tpack = cf.getPackage();
                    }
                }
                bdef.setFactoryLocation(tpack, root);
                return bdef;
               
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

                Object child = childs.get(i);
                if (child instanceof MappingElement) {
                   
                    // end scan if a real mapping is found
                    MappingElementBase map = (MappingElementBase)child;
                    ClassFile cf = map.getHandledClass().getClassFile();
                    if (!cf.isInterface() && cf.isModifiable()) {
                        return cf;
                    }
                   
                } else if (child instanceof IncludeElement) {
                   
                    // recurse on included binding
                    BindingElement bind = ((IncludeElement)child).getBinding();
                    if (bind != null) {
                        ClassFile cf = findMappedClass(bind);
                        if (cf != null) {
                            return cf;
                        }
                    }
                }
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

            m_extensions = new ArrayList();
        }
        if (!m_extensions.contains(mdef)) {
            m_extensions.add(mdef);
        }
        ClassFile cf = mdef.getBoundClass().getClassFile();
        if (!cf.isSuperclass(m_referenceType) &&
            !cf.isImplements(m_referenceType)) {
            m_referenceType = "java.lang.Object";
        }
    }
View Full Code Here

Examples of org.jibx.binding.classes.ClassFile

        String name = init;
        int loop = 0;
        while (ClassCache.hasClassFile(name)) {
            name = init + ++loop;
        }
        ClassFile base = ClassCache.requireClassFile("java.lang.Object");
        String[] intfs = def.isInput() ?
            (def.isOutput() ? BOTH_INTERFACES : UNMARSHALLER_INTERFACES) :
            MARSHALLER_INTERFACES;
        ClassFile cf = new ClassFile(name, m_class.getMungedFile().getRoot(),
            base, Constants.ACC_PUBLIC, intfs);
        cf.addDefaultConstructor();
       
        // add marshaller/unmarshaller implementation methods
        boolean hasattr = m_component.hasAttribute();
        boolean hascont = m_component.hasContent();
        boolean hasname = !m_isAbstract && m_name != null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.