Package org.jibx.binding.model

Examples of org.jibx.binding.model.BindingElement


        // 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);
        }
       
        // finish with custom mapping definitions
        for (Iterator iter = customs.keySet().iterator(); iter.hasNext();) {
            String cname = (String)iter.next();
            String mname = (String)customs.get(cname);
            MappingElementBase mapping = new MappingElement();
            mapping.setComment(" specified mapping for class " + cname);
            mapping.setClassName(cname);
            mapping.setName((String)m_mappedNames.get(cname));
            mapping.setMarshallerName(mname);
            mapping.setUnmarshallerName(mname);
            binding.addTopChild(mapping);
        }
       
        // list classes handled if verbose
        if (m_verbose) {
            for (int i = 0; i < names.size(); i++) {
View Full Code Here


                ClassFile.setPaths(parray);
               
                // generate the binding
                BindingGenerator generate =
                    new BindingGenerator(verbose, mixed, uri);
                BindingElement binding = generate.generate(names, abstracts,
                    customs, beans, enums, ignores);
               
                // marshal binding out to file
                IBindingFactory bfact =
                    BindingDirectory.getFactory("normal", BindingElement.class);
View Full Code Here

        types.add("DefaultPackageClass");
        gen.generate(null, types);
        gen.finish("binding");
        BindingHolder hold = gen.getBinding(null);
        assertNotNull("no-namespace binding", hold);
        BindingElement binding = hold.getBinding();
        ArrayList childs = binding.topChildren();
        assertEquals("child count", 2, childs.size());
        Object child = childs.get(0);
        assertTrue("child type", child instanceof MappingElement);
        MappingElementBase mapping = (MappingElementBase)child;
        assertEquals("mapped class", mapping.getClassName(), "DefaultPackageClass");
View Full Code Here

        types.add("org.jibx.binding.generator.DataClass1");
        gen.generate(null, types);
        gen.finish("binding");
        BindingHolder hold = gen.getBinding("http://jibx.org/binding/generator");
        assertNotNull("default namespace binding", hold);
        BindingElement binding = hold.getBinding();
        ArrayList childs = binding.topChildren();
        assertEquals("child count", 3, childs.size());
        Object child = childs.get(1);
        assertTrue("child type", child instanceof MappingElement);
        MappingElementBase mapping = (MappingElementBase)child;
        assertEquals("mapped class", mapping.getClassName(), "org.jibx.binding.generator.DataClass1");
View Full Code Here

        types.add("org.jibx.binding.generator.DataClass2");
        gen.generate(null, types);
        gen.finish("binding");
        BindingHolder hold = gen.getBinding("http://jibx.org/binding/generator");
        assertNotNull("default namespace binding", hold);
        BindingElement binding = hold.getBinding();
        ArrayList childs = binding.topChildren();
        assertEquals("child count", 5, childs.size());
        Object child = childs.get(1);
        assertTrue("child type", child instanceof MappingElement);
        MappingElementBase mapping = (MappingElementBase)child;
        assertTrue("expected abstract mapping first", mapping.isAbstract());
View Full Code Here

        types.add("org.jibx.binding.generator.DataClass2");
        gen.generate(null, types);
        gen.finish("binding");
        BindingHolder hold = gen.getBinding("http://www.jibx.org/test");
        assertNotNull("specified namespace binding", hold);
        BindingElement binding = hold.getBinding();
        ArrayList childs = binding.topChildren();
        assertEquals("child count", 5, childs.size());
        Object child = childs.get(1);
        assertTrue("child type", child instanceof MappingElement);
        MappingElementBase mapping = (MappingElementBase)child;
        assertTrue("expected abstract mapping first", mapping.isAbstract());
View Full Code Here

        }
       
        // construct object model for binding
        org.jibx.binding.model.ValidationContext vctx =
            new org.jibx.binding.model.ValidationContext(new DummyClassLocator());
        BindingElement binding = BindingElement.readBinding(url.openStream(), name, null, true,
            vctx);
        binding.setBaseUrl(url);
        vctx.setBindingRoot(binding);
       
        // validate the binding definition
        binding.runValidation(vctx);
       
        // list validation errors
        ArrayList probs = vctx.getProblems();
        if (probs.size() > 0) {
            for (int i = 0; i < probs.size(); i++) {
View Full Code Here

     */
    public static BindingElement validateBinding(String name, URL url,
        InputStream is) {
        try {
            ValidationContext vctx = BindingElement.newValidationContext();
            BindingElement root =
                BindingElement.validateBinding(name, url, is, vctx);
            if (vctx.getErrorCount() == 0 && vctx.getFatalCount() == 0) {
                return root;
            }
        } catch (JiBXException ex) {
View Full Code Here

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

                    }
                   
                } 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

TOP

Related Classes of org.jibx.binding.model.BindingElement

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.