Package org.jibx.binding.classes

Examples of org.jibx.binding.classes.ClassFile


                    simple = true;
                    attribute = false;
                } else if (tname.startsWith("java.")) {
                   
                    // check for standard library classes we can handle
                    ClassFile pcf = ClassCache.requireClassFile(tname);
                    ClassItem init = pcf.getInitializerMethod
                        ("(Ljava/lang/String;)");
                    if (init != null) {
                        simple = pcf.getMethod("toString",
                            "()Ljava/lang/String;") != null;
                        attribute = false;
                    }
                   
                }
               
                // check type of handling to use for value
                if (m_enumerationNames.get(tname) != null) {
                   
                    // define a value using deserializer method
                    String mname = (String)m_enumerationNames.get(tname);
                    int split = mname.lastIndexOf('.');
                    ClassFile dcf =
                        ClassCache.requireClassFile(mname.substring(0, split));
                    ClassItem dser =
                        dcf.getStaticMethod(mname.substring(split+1),
                        "(Ljava/lang/String;)");
                    if (dser == null || !tname.equals(dser.getTypeName())) {
                        throw new JiBXException("Deserializer method not " +
                            "found for enumeration class " + tname);
                    }
                    ValueElement value = new ValueElement();
                    value.setFieldName(fname);
                    value.setName(valueName(fname));
                    value.setUsageName("optional");
                    value.setStyleName("element");
                    value.setDeserializerName(mname);
                    contain.addChild(value);
                   
                } else if (m_mappedNames.get(tname) != null) {
                   
                    // use mapping definition for class
                    StructureElement structure = new StructureElement();
                    structure.setUsageName("optional");
                    structure.setFieldName(fname);
                    if (((String)m_mappedNames.get(tname)).length() == 0) {
                       
                        // add a name for reference to abstract mapping
                        structure.setName(elementName(tname));
                    }
                    contain.addChild(structure);
                    if (m_verbose) {
                        nestingIndent(System.out);
                        System.out.println("referenced existing binding for " +
                            tname);
                    }
                   
                } else if (simple) {
                   
                    // define a simple value
                    ValueElement value = new ValueElement();
                    value.setFieldName(fname);
                    value.setName(valueName(fname));
                    if (object) {
                        value.setUsageName("optional");
                    }
                    if (!attribute) {
                        value.setStyleName("element");
                    }
                    contain.addChild(value);
                   
                } else if (tname.endsWith("[]")) {
                   
                    // array, check if item type has a mapping
                    String bname = tname.substring(0, tname.length()-2);
                    if (m_mappedNames.get(bname) == null) {
                       
                        // no mapping, use collection with inline structure
                        // TODO: fill it in
                        throw new JiBXException("Base element type " + bname +
                            " must be mapped");
                       
                    } else {
                       
                        // mapping for type, use simple collection
                        CollectionElement collection = new CollectionElement();
                        collection.setUsageName("optional");
                        collection.setFieldName(fname);
                        contain.addChild(collection);
                    }
                   
                } else {
                   
                    // no defined handling, check for collection vs. structure
                    ClassFile pcf = ClassCache.requireClassFile(tname);
                    StructureElementBase element;
                    if (pcf.isImplements("Ljava/util/List;")) {
                       
                        // create a collection for list subclass
                        System.err.println("Warning: field " + fname +
                            " requires mapped implementation of item classes");
                        element = new CollectionElement();
                        element.setComment(" add details of collection items " +
                            "to complete binding definition ");
                        element.setFieldName(fname);
                       
                        // specify factory method if just typed as interface
                        if ("java.util.List".equals(tname)) {
                            element.setFactoryName
                                ("org.jibx.runtime.Utility.arrayListFactory");
                        }
                       
                    } else if (pcf.isInterface() ||
                        m_ignoreNames.contains(tname)) {
                       
                        // create mapping reference with warning for interface
                        nestingIndent(System.err);
                        System.err.println("Warning: reference to interface " +
View Full Code Here


                        simple = true;
                        attribute = false;
                    } else if (tname.startsWith("java.")) {
                       
                        // check for standard library classes we can handle
                        ClassFile pcf = ClassCache.requireClassFile(tname);
                        if (pcf.getInitializerMethod("()") != null) {
                            simple = pcf.getMethod("toString",
                                "()Ljava/lang/String;") != null;
                            attribute = false;
                        }
                       
                    }
                    if (simple) {
                       
                        // define a simple value
                        ValueElement value = new ValueElement();
                        value.setGetName(gname);
                        value.setSetName(sname);
                        value.setName(valueName(pname));
                        if (object) {
                            value.setUsageName("optional");
                        }
                        if (!attribute) {
                            value.setStyleName("element");
                        }
                        contain.addChild(value);
                       
                    } else if (m_enumerationNames.get(tname) != null) {
                       
                        // define a value using deserializer method
                        String mname = (String)m_enumerationNames.get(tname);
                        int split = mname.lastIndexOf('.');
                        ClassFile dcf = ClassCache.
                            requireClassFile(mname.substring(0, split));
                        ClassItem dser =
                            dcf.getStaticMethod(mname.substring(split+1),
                            "(Ljava/lang/String;)");
                        if (dser == null || !tname.equals(dser.getTypeName())) {
                            throw new JiBXException("Deserializer method not " +
                                "found for enumeration class " + tname);
                        }
                        ValueElement value = new ValueElement();
                        value.setGetName(gname);
                        value.setSetName(sname);
                        value.setName(valueName(pname));
                        value.setUsageName("optional");
                        value.setStyleName("element");
                        value.setDeserializerName(mname);
                        contain.addChild(value);
                       
                    } else if (m_mappedNames.get(tname) != null) {
                       
                        // use mapping definition for class
                        StructureElement structure = new StructureElement();
                        structure.setUsageName("optional");
                        structure.setGetName(gname);
                        structure.setSetName(sname);
                        if (((String)m_mappedNames.get(tname)).length() == 0) {
                           
                            // add a name for reference to abstract mapping
                            structure.setName(elementName(tname));
                        }
                        contain.addChild(structure);
                        if (m_verbose) {
                            nestingIndent(System.out);
                            System.out.println
                                ("referenced existing binding for " + tname);
                        }
                       
                    } else if (tname.endsWith("[]")) {
                       
                        // array, only supported for mapped base type
                        String bname = tname.substring(0, tname.length()-2);
                        if (m_mappedNames.get(bname) == null) {
                            throw new JiBXException("Base element type " +
                                bname + " must be mapped");
                        } else {
                            StructureElement structure = new StructureElement();
                            structure.setUsageName("optional");
                            structure.setGetName(gname);
                            structure.setSetName(sname);
                            structure.setMarshallerName
                                ("org.jibx.extras.TypedArrayMapper");
                            structure.setUnmarshallerName
                                ("org.jibx.extras.TypedArrayMapper");
                            contain.addChild(structure);
                        }
                       
                    } else {
                       
                        // no defined handling, check collection vs. structure
                        ClassFile pcf = ClassCache.requireClassFile(tname);
                        StructureElementBase element;
                        if (pcf.isImplements("Ljava/util/List;")) {
                           
                            // create a collection for list subclass
                            System.err.println("Warning: property " + pname +
                                " requires mapped implementation of item " +
                                "classes");
                            element = new CollectionElement();
                            element.setComment(" add details of collection " +
                                "items to complete binding definition ");
                            element.setGetName(gname);
                            element.setSetName(sname);
                           
                            // specify factory method if just typed as interface
                            if ("java.util.List".equals(tname)) {
                                element.setFactoryName("org.jibx.runtime." +
                                    "Utility.arrayListFactory");
                            }
                           
                        } else if (pcf.isInterface() ||
                            m_ignoreNames.contains(tname)) {
                           
                            // mapping reference with warning for interface
                            nestingIndent(System.err);
                            System.err.println("Warning: reference to " +
View Full Code Here

        } else {
            defineProperties(cf, (ArrayList)props, true, contain);
        }
       
        // check if superclass may have data for binding
        ClassFile sf = cf.getSuperFile();
        String sname = sf.getName();
        if (!"java.lang.Object".equals(sname) &&
            !m_ignoreNames.contains(sname)) {
            if (m_mappedNames.get(sname) != null) {
                StructureElement structure = new StructureElement();
                structure.setMapAsName(sname);
                structure.setName(elementName(sname));
                contain.addChild(structure);
            } else if (m_beanNames.get(sname) != null) {
                defineProperties(sf, (ArrayList)m_beanNames.get(sname),
                    false, contain);
            } else if (sf.getRawClass().getFields().length > 0) {
                nestingIndent(System.err);
                System.err.println("Warning: fields from base class " + sname +
                    " of class " + cf.getName() + " not handled by generated " +
                    "binding; use mapping or specify property list");
                contain.setComment(" missing information for base class " +
View Full Code Here

     * data classes not recorded if <code>null</code>)
     * @throws JiBXException on error in loading class information
     */
    public static void findClassesUsed(String cname, ArrayList mnames,
        HashSet dataset, HashSet exceptset) throws JiBXException {
        ClassFile cf = ClassCache.getClassFile(cname);
        if (cf != null) {
            for (int i = 0; i < mnames.size(); i++) {
                String mname = (String)mnames.get(i);
                ClassItem mitem = cf.getMethod(mname, "");
                if (mitem == null) {
                    System.err.println("Method " + mname +
                        " not found in class " + cname);
                } else {
                    if (dataset != null) {
View Full Code Here

        for (int i = 0; i < names.size(); i++) {
           
            // make sure class can potentially be handled automatically
            boolean drop = false;
            String name = (String)names.get(i);
            ClassFile cf = ClassCache.requireClassFile(name);
            if (cf.isImplements("Ljava/util/List;") ||
                cf.isImplements("Ljava/util/Map;")) {
                System.err.println("Warning: referenced class " + name +
                    " is a collection class that cannot be mapped " +
                    "automatically; dropped from mapped list in binding");
                drop = true;
            } else if (cf.isInterface()) {
                System.err.println("Warning: interface " + name +
                    " is being handled as abstract mapping");
                abstracts.add(name);
                drop = true;
            } else if (cf.isAbstract()) {
                System.err.println("Warning: mapping abstract class " + name +
                    "; make sure actual subclasses are mapped as extending " +
                    "this abstract mapping");
                abstracts.add(name);
                drop = true;
            }
            if (drop) {
                names.remove(i--);
            } else {
                m_mappedNames.put(name, elementName(name));
            }
        }
        for (Iterator iter = abstracts.iterator(); iter.hasNext();) {
            m_mappedNames.put((String)iter.next(), "");
        }
        for (Iterator iter = customs.keySet().iterator(); iter.hasNext();) {
            String name = (String)iter.next();
            m_mappedNames.put(name, elementName(name));
        }
       
        // create set for ignores
        m_ignoreNames.clear();
        m_ignoreNames.addAll(ignores);
       
        // create binding with optional namespace
        BindingElement binding = new BindingElement();
        binding.setStyleName("attribute");
        if (m_namespaceUri != null) {
            NamespaceElement namespace = new NamespaceElement();
            namespace.setComment(" namespace for all elements of binding ");
            namespace.setDefaultName("elements");
            namespace.setUri(m_namespaceUri);
            binding.addTopChild(namespace);
        }
       
        // add mapping for each specified class
        m_structureStack.clear();
        m_structureNames.clear();
        m_beanNames = beans;
        m_enumerationNames = enums;
        for (int i = 0; i < names.size(); i++) {
            String cname = (String)names.get(i);
            if (!abstracts.contains(cname)) {
                ClassFile cf = ClassCache.requireClassFile(cname);
                MappingElementBase mapping = createMapping(cf, false);
                mapping.setComment(" generated mapping for class " + cname);
                binding.addTopChild(mapping);
            }
        }
        for (Iterator iter = abstracts.iterator(); iter.hasNext();) {
            String cname = (String)iter.next();
            ClassFile cf = ClassCache.requireClassFile(cname);
            MappingElementBase mapping = createMapping(cf, true);
            mapping.setComment(" generate abstract mapping for class " + cname);
            binding.addTopChild(mapping);
        }
       
View Full Code Here

    /* (non-Javadoc)
     * @see org.jibx.binding.model.IClass#getSuperClass()
     */
    public IClass getSuperClass() {
        ClassFile scf = m_class.getSuperFile();
        if (scf == null) {
            return null;
        } else {
            return new ClassWrapper(m_locator, m_class.getSuperFile());
        }
View Full Code Here

    /* (non-Javadoc)
     * @see org.jibx.binding.model.IClass#isSuperclass(org.jibx.binding.model.IClass)
     */
    public boolean isSuperclass(String name) {
        ClassFile current = m_class;
        while (current != null) {
            if (current.getName().equals(name)) {
                return true;
            } else {
                current = current.getSuperFile();
            }
        }
        return false;
    }
View Full Code Here

                    }
                }
                for (int i = 0; i < addcount; i++) {
                   
                    // write class file to bytes
                    ClassFile file = adds[i];
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    file.writeFile(bos);
                    byte[] bytes = bos.toByteArray();
                    if(m_verbose1){
                        System.out.println("\n " + file.getName() +
                            " output file size is " + bytes.length + " bytes");
                    }
                   
                    // verify using BCEL verifier
                    if (m_verify) {
                        verifyBCEL(file);
                    }
                   
                    // load to JVM and list method information from class
                    if (m_load) {
                        DirectLoader cloader = new DirectLoader(urls);
                        Class clas = cloader.load(file.getName(), bytes);
                        if (m_verbose1) {
                            java.lang.reflect.Method[] methods =
                                clas.getDeclaredMethods();
                            System.out.println(" Found " + methods.length +
                                " methods:");
View Full Code Here

            }
           
            // build hashmap of modified classes
            count = lists[0].length;
            for (int i = 0; i < count; i++) {
                ClassFile clas = lists[0][i];
                m_classMap.put(clas.getName(), clas);
            }
           
            // finish by setting flag for binding done
            m_isBound = true;
        }
View Full Code Here

        // check if class has been modified by binding
        if (isBoundClass(name)) {
      try {
       
        // convert class information to byte array
                ClassFile clas = (ClassFile)m_classMap.get(name);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        clas.writeFile(bos);
                byte[] bytes = bos.toByteArray();
                return defineClass(name, bytes, 0, bytes.length);
       
      } catch (IOException e) {
        throw new ClassNotFoundException
View Full Code Here

TOP

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

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.