Package org.jibx.runtime

Examples of org.jibx.runtime.JiBXException


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


            String base = Character.toUpperCase(pname.charAt(0)) +
                pname.substring(1);
            String gname = "get" + base;
            ClassItem gmeth = cf.getMethod(gname, "()");
            if (gmeth == null) {
                throw new JiBXException("No method " + gname +
                    "() found for property " + base + " in class " +
                    cf.getName());
            } else {
                String tname = gmeth.getTypeName();
                String sname = "set" + base;
                String sig = "(" + gmeth.getSignature().substring(2) + ")V";
                ClassItem smeth = cf.getMethod(sname, sig);
                if (smeth == null) {
                    throw new JiBXException("No method " + sname + "(" + tname +
                        ") found for property " + base + " in class " +
                        cf.getName());
                } else {
                   
                    // find type of handling needed for field type
                    boolean simple = false;
                    boolean object = true;
                    boolean attribute = true;
                    if (ClassItem.isPrimitive(tname)) {
                        simple = true;
                        object = false;
                    } else if (s_objectPrimitiveSet.contains(tname)) {
                        simple = true;
                    } else if (tname.equals("byte[]")) {
                        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);
View Full Code Here

                while (i >= 0) {
                    buff.append(m_structureStack.peek(i--));
                    buff.append(" -> ");
                }
                buff.append(cname);
                throw new JiBXException(buff.toString());
            }
        }
        if (cname.startsWith("java.")) {
            nestingIndent(System.err);
            System.err.println("Warning: trying to create structure for " +
                cname);
        } else if (m_structureNames.contains(cname)) {
            nestingIndent(System.err);
            System.err.println("Warning: repeated usage of class " +
                cname + "; consider adding to mapping list");
        } else {
            m_structureNames.add(cname);
        }
        m_structureStack.push(cname);
        StructureElement element = new StructureElement();
        element.setFieldName(fname);
        element.setName(valueName(fname));
        defineStructure(cf, element);
        if (element.children().isEmpty()) {
            throw new JiBXException("No content found for class " + cname);
        }
        m_structureStack.pop();
        if (m_verbose) {
            nestingIndent(System.out);
            System.out.println("completed nested structure definition for " +
View Full Code Here

            try {
                m_schemaContext.setFromContext((MarshallingContext)ctx);
                ((IMarshallable)obj).marshal(m_schemaContext);
                m_schemaContext.getXmlWriter().flush();
            } catch (IOException e) {
                throw new JiBXException("Error writing schema", e);
            }
        }
View Full Code Here

            // modify the class files with JiBX hooks
            for (int i = 0; i < defs.length; i++) {
                try {
                    defs[i].generateCode(m_verbose1, m_verbose2);
                } catch (RuntimeException e) {
                    throw new JiBXException
                        ("\n*** Error during code generation for file '" +
                        files[i] + "' -\n this may be due to an error in " +
                        "your binding or classpath, or to an error in the " +
                        "JiBX code ***\n", e);
                }
            }
           
            // get the lists of class names modified, kept unchanged, and unused
            ClassFile[][] lists = MungedClass.fixDispositions();
           
            // add class used list to each binding factory and output files
            for (int i = 0; i < defs.length; i++) {
                defs[i].addClassList(lists[0], lists[1]);
            }
            MungedClass.writeChanges();
           
            // report modified file results to user
            ClassFile[] adds = lists[0];
            int addcount = adds.length;
            if (m_verbose1) {
                System.out.println("\nWrote " + addcount + " files");
            }
            if (m_verbose1 || m_load) {
               
                // generate class paths as URLs if needed for test loading
                URL[] urls = null;
                if (m_load) {
                    urls = new URL[paths.length];
                    for (int i = 0; i < urls.length; i++) {
                        urls[i] = new File(paths[i]).toURI().toURL();
                    }
                }
                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:");
                            for (int j = 0; j < methods.length; j++) {
                                java.lang.reflect.Method method = methods[j];
                                System.out.println("  " +
                                    method.getReturnType().getName() + " " +
                                    method.getName());
                            }
                        }
                    }
                }
            }
           
            // report summary information for files unchanged or deleted
            if (m_verbose1) {
                ClassFile[] keeps = lists[1];
                System.out.println("\nKept " + keeps.length + " files unchanged:");
                for (int i = 0; i < keeps.length; i++) {
                    System.out.println(" " + keeps[i].getName());
                }
                ClassFile[] dels = lists[2];
                System.out.println("\nDeleted " + dels.length + " files:");
                for (int i = 0; i < dels.length; i++) {
                    System.out.println(" " + dels[i].getName());
                }
            }
           
        } catch (IOException ex) {
            throw new JiBXException("IOException in compile", ex);
        } catch (ExceptionInInitializerError ex) {
            throw new JiBXException("Error during initialization;" +
                " is jibx-run.jar in load classpath?", ex.getException());
        } catch (Throwable ex) {
            throw new JiBXException("Error running binding compiler", ex);
        }
    }
View Full Code Here

                    String name = prefix.length() > 0 ? "xmlns:" + prefix : "xmlns";
                    writer.addAttribute(0, name, writer.getNamespaceUri(indexes.get(i)));
                }
               
            } catch (IOException e) {
                throw new JiBXException("Error writing output document", e);
            }
        }
    }
View Full Code Here

                while (--index >= 0 && !uri.equals(writer.getNamespaceUri(index)));
                if (index >= 0) {
                    try {
                        writer.addAttribute(index, name, value);
                    } catch (IOException e) {
                        throw new JiBXException("Error writing attribute", e);
                    }
                } else {
                    throw new JiBXException("Namespace uri \"" + uri + "\" is not defined");
                }
            }
        }
    }
View Full Code Here

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

                String prename = names[index];
                String prens = namespaces[index];
                String defname = ctx.attributeText(URI_ATTRIBUTES, COMMON_NAME);
                String defns = ctx.attributeText(URI_ATTRIBUTES, COMMON_NAMESPACE, prens);
                if (!prename.equals(defname)) {
                    throw new JiBXException("Precompiled mapping for class " + type +
                        " uses element name '" + prename + "' which does not match element name '" +
                        defname + "' used in binding");
                } else if (!Utility.safeEquals(prens, defns)) {
                    throw new JiBXException("Precompiled mapping for class " + type +
                        " uses element namespace '" + prens + "' which does not match element namespace '" +
                        defns + "' used in binding");
                } else {
                    ndef = new NameDefinition(defname, defns, false);
                }
View Full Code Here

        String path = ctx.attributeText(URI_ATTRIBUTES, INCLUDE_PATH);
        URL url;
        try {
            url = ClasspathUrlExtender.buildURL(root, path);
        } catch (MalformedURLException e) {
            throw new JiBXException("Unable to handle include path " + path, e);
        }
        String fpath = url.toExternalForm();
        if (paths.add(fpath)) {
            try {
               
                // access the included binding as input stream
                UnmarshallingContext ictx = new UnmarshallingContext();
                ictx.setDocument(url.openStream(), null);
               
                // get basic name and package information from binding
                ictx.parseToStartTag(URI_ELEMENTS, BINDING_ELEMENT);
                String fname = org.jibx.binding.Utility.fileName(path);
                String name = ictx.attributeText(URI_ATTRIBUTES, BINDING_NAME,
                    org.jibx.binding.Utility.bindingFromFileName(fname));
                int major = ictx.attributeInt(URI_ATTRIBUTES,
                    BINDING_MAJORVER, 0);
                int minor = ictx.attributeInt(URI_ATTRIBUTES,
                    BINDING_MINORVER, 0);
                String tpack = ictx.attributeText(URI_ATTRIBUTES,
                    BINDING_PACKAGE, null);
                boolean direct = ctx.attributeBoolean(URI_ATTRIBUTES,
                    INCLUDE_PRECOMPILED, false);
                if (direct && tpack == null) {
                    throw new JiBXException("package attribute is required for precompiled binding");
                }
                if (direct) {
                   
                    // load and add binding factory for precompiled binding
                    factory = BindingDirectory.getFactory(name, tpack,
                        ClassFile.getClassLoader());
                    nsxlate = bdef.addPrecompiledBinding(factory, major, minor);
                }
                   
               
                // unmarshal namespaces (to apply to these mappings, only)
                ictx.parsePastStartTag(URI_ELEMENTS, BINDING_ELEMENT);
                ArrayList nss = new ArrayList(nslist);
                while (ictx.isAt(URI_ELEMENTS, NAMESPACE_ELEMENT)) {
                    nss.add(unmarshalNamespace(ictx));
                }
               
                // process any format definitions (for global context)
                precomp = precomp || direct;
                unmarshalFormats(ictx, precomp, bdef.getDefinitionContext());
               
                // check for nested includes
                while (ictx.isAt(URI_ELEMENTS, INCLUDE_ELEMENT)) {
                    unmarshalInclude(ictx, precomp, bdef, url, nss, paths,
                        factory, nsxlate);
                }
               
                // process all mappings defined in included binding
                if (precomp) {
                    unmarshalPrecompiledMappings(ictx, factory, bdef, nsxlate);
                } else {
                    unmarshalMappings(ictx, bdef, nss, false);
                }
               
            } catch (IOException e) {
                throw new JiBXException
                    ("Error accessing included binding with path " + path + " (" + fpath + ')', e);
            }
        }
       
        // finish by skipping past end of tag in main binding
View Full Code Here

TOP

Related Classes of org.jibx.runtime.JiBXException

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.