Package org.jibx.runtime

Examples of org.jibx.runtime.JiBXException


        UnmarshallingContext ctx = (UnmarshallingContext)ictx;
        if (isPresent(ctx)) {
           
            // make sure there's a name for the document being parsed
            if (ctx.getDocumentName() == null) {
                throw new JiBXException("Unable to process include without " +
                    "base document name " + ctx.buildPositionString());
            } else {
               
                // check for conditionals on include
                boolean use = true;
                String name = ctx.attributeText(ATTR_NAMESPACE,
                    IFDEF_NAME, null);
                if (name != null) {
                    use = getValue(name, ctx) != null;
                }
                name = ctx.attributeText(ATTR_NAMESPACE, IFNDEF_NAME, null);
                if (use && name != null) {
                    use = getValue(name, ctx) == null;
                }
               
                // get the remaining attribute values and ditch element
                String path = ctx.attributeText(ATTR_NAMESPACE, PATH_NAME);
                String access =
                    ctx.attributeText(ATTR_NAMESPACE, ACCESSDIR_NAME);
                String label = ctx.attributeText(ATTR_NAMESPACE,
                    LABEL_NAME, null);
                ctx.parsePastElement(ELEMENT_NAMESPACE, INCLUDE_NAME);
               
                // check if this include is active
                if (use) {
                   
                    // find the file to be included
                    int index = ctx.getStackDepth() - 1;
                    Builder build = (Builder)ctx.getStackObject(index);
                    File config = Component.
                        applyFilePath(build.getSourceRoot(), path);
                    File root = config.getParentFile();
                   
                    // create new unmarshalling context for included file
                    UnmarshallingContext inctx = (UnmarshallingContext)
                        BindingDirectory.getFactory(Site.class).
                        createUnmarshallingContext();
                    try {
                        inctx.setDocument(new FileInputStream
                            (new File(root, path)), path, null);
                    } catch (FileNotFoundException e) {
                        throw new JiBXException("Include file " + path +
                            " not found " + ctx.buildPositionString());
                    }
                   
                    // unmarshal the included document
                    obj = inctx.unmarshalElement();
                    if (obj instanceof Site) {
                        return new Menu((Site)obj, root, access, label);
                    } else if (obj instanceof Menu) {
                        return new Menu((Menu)obj, root, access, label);
                    } else {
                        throw new JiBXException("Root element of file " + path +
                            " is not a valid type " +
                            ctx.buildPositionString());
                    }
                   
                } else {
View Full Code Here


     */
    public void linkMappings() throws JiBXException {
        if (m_baseType != null) {
            m_baseMapping = m_defContext.getClassMapping(m_baseType);
            if (m_baseMapping == null) {
                throw new JiBXException("Mapping for base class " + m_baseType +
                    " not defined");
            }
            m_baseMapping.addExtension(this);
        }
        m_defContext.linkMappings();
View Full Code Here

    public void marshal(Object obj, IMarshallingContext ictx)
        throws JiBXException {
       
        // make sure the parameters are as expected
        if (!(obj instanceof HashMap)) {
            throw new JiBXException("Invalid object type for marshaller");
        } else if (!(ictx instanceof MarshallingContext)) {
            throw new JiBXException("Invalid object type for marshaller");
        } else {
           
            // start by generating start tag for container
            MarshallingContext ctx = (MarshallingContext)ictx;
            HashMap map = (HashMap)obj;
            ctx.startTagAttributes(m_index, m_name).
                attribute(m_index, SIZE_ATTRIBUTE_NAME, map.size()).
                closeStartContent();
           
            // loop through all entries in hashmap
            Iterator iter = map.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry)iter.next();
                ctx.startTagAttributes(m_index, ENTRY_ELEMENT_NAME);
                if (entry.getKey() != null) {
                    ctx.attribute(m_index, KEY_ATTRIBUTE_NAME,
                        entry.getKey().toString());
                }
                ctx.closeStartContent();
                if (entry.getValue() instanceof IMarshallable) {
                    ((IMarshallable)entry.getValue()).marshal(ctx);
                    ctx.endTag(m_index, ENTRY_ELEMENT_NAME);
                } else {
                    throw new JiBXException("Mapped value is not marshallable");
                }
            }
           
            // finish with end tag for container element
            ctx.endTag(m_index, m_name);
View Full Code Here

                m_interfaceNames = m_curClass.getInterfaceNames();
                if (m_interfaceNames == null) {
                    m_interfaceNames = new String[0];
                }
            } catch (Exception ex) {
                throw new JiBXException("Error reading path " +
                    path + " for class " + name);
            }
        }
        initInterface();
    }
View Full Code Here

     * @throws JiBXException if field not found
     */
    public ClassItem getField(String name) throws JiBXException {
        Field field = getAccessibleField(name);
        if (field == null) {
            throw new JiBXException("Field " + name +
                " not found in class " + m_name);
        } else {
            ClassItem item = (ClassItem)m_itemMap.get(field);
            if (item == null) {
                item = new ClassItem(name, this, field);
View Full Code Here

        if (test == null) {
            m_testMethod = null;
        } else {
            m_testMethod = cf.getMethod(test, TEST_METHOD_SIGNATURES);
            if (m_testMethod == null) {
                throw new JiBXException("test-method " + test +
                    " not found in class " + cf.getName());
            }
        }
        if (get == null) {
            m_getMethod = null;
        } else {
            m_getMethod = cf.getMethod(get, GET_METHOD_SIGNATURES);
            if (m_getMethod == null) {
                throw new JiBXException("get-method " + get +
                    " not found in class " + cf.getName());
            } else {
                gtype = m_getMethod.getTypeName();
                if (dtype == null) {
                    dtype = gtype;
                }
            }
        }
        if (set == null) {
            m_setMethod = null;
        } else {
           
            // need to handle overloads, so generate possible signatures
            ArrayList sigs = new ArrayList();
            if (m_getMethod != null) {
                String psig = ClassUtils.getSignature(gtype);
                sigs.add("(" + psig +
                    "Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
                sigs.add("(" + psig + ")V");
            }
            if (type != null) {
                String psig = ClassUtils.getSignature(type);
                sigs.add("(" + psig +
                    "Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
                sigs.add("(" + psig + ")V");
            }
            if (m_fieldItem != null) {
                String psig = m_fieldItem.getSignature();
                sigs.add("(" + psig +
                    "Lorg/jibx/runtime/IUnmarshallingContext;" + ")V");
                sigs.add("(" + psig + ")V");
            }
            sigs.add
                ("(Ljava/lang/Object;Lorg/jibx/runtime/IUnmarshallingContext;)V");
            sigs.add("(Ljava/lang/Object;)V");
           
            // set method needs verification of argument and return type
            ClassItem setmeth = cf.getMethod(set,
                (String[])sigs.toArray(new String[0]));
            if (setmeth == null) {
               
                // nothing known about signature, try anything by name
                setmeth = cf.getMethod(set, "");
                if (setmeth != null) {
                    if (!setmeth.getTypeName().equals("void") ||
                        setmeth.getArgumentCount() > 2) {
                        setmeth = null;
                    } else if (setmeth.getArgumentCount() == 2) {
                        String xtype = setmeth.getArgumentType(1);
                        if (!"org.jibx.runtime.IUnmarshallingContext".equals(xtype)) {
                            setmeth = null;
                        }
                    }
                }
            }
           
            // check if method found
            m_setMethod = setmeth;
            if (m_setMethod == null) {
                throw new JiBXException("set-method " + set +
                    " not found in class " + cf.getName());
            } else {
                stype = m_setMethod.getArgumentType(0);
                if (dtype == null) {
                    dtype = stype;
                }
            }
        }
        if (flag == null) {
            m_flagMethod = null;
        } else {
            m_flagMethod = cf.getMethod(flag, FLAG_METHOD_SIGNATURES);
            if (m_flagMethod == null) {
                throw new JiBXException("flag-method " + flag +
                    " not found in class " + cf.getName());
            } else if (stype == null) {
                stype = "java.lang.String";
                if (dtype == null) {
                    dtype = stype;
                }
            }
        }
        if (gtype == null) {
            gtype = "java.lang.Object";
        }
        m_getValueType = gtype;
        m_setValueType = stype;

        // check that enough information is supplied
        BindingDefinition root = parent.getBindingRoot();
        if (!isthis && m_fieldItem == null) {
            if (root.isInput() && m_setMethod == null && m_flagMethod == null) {
                throw new JiBXException
                    ("Missing way to set value for input binding");
            }
            if (root.isOutput() && m_getMethod == null &&
                (m_flagMethod == null || m_testMethod == null)) {
                throw new JiBXException
                    ("Missing way to get value for output binding");
            }
        }
       
        // check that type information is consistent
        if (type == null) {
            m_typeName = dtype;
        } else {
            m_typeName = type;
            boolean valid = true;
            if (isthis) {
                valid = ClassItem.isAssignable(dtype, type);
            } else {
                if (root.isInput()) {
                    valid = ClassItem.isAssignable(type, m_setValueType) ||
                        ClassItem.isAssignable(m_setValueType, type);
                }
                if (valid && root.isOutput()) {
                    valid = ClassItem.isAssignable(type, m_getValueType) ||
                        ClassItem.isAssignable(m_getValueType, type);
                }
            }
            if (!valid) {
                throw new JiBXException
                    ("Incompatible types for property definition");
            }
        }
    }
View Full Code Here

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        try {
            m_document = dbf.newDocumentBuilder().newDocument();
        } catch (ParserConfigurationException e) {
            throw new JiBXException("Unable to create DOM document", e);
        }
    }
View Full Code Here

        } else {
            try {
                m_namespaceIndex = defc.getNamespaceIndex
                    (m_namespace, m_isAttribute);
            } catch (JiBXException ex) {
                throw new JiBXException("Undefined or unusable namespace \"" +
                    m_namespace + '"');
            }
        }
    }
View Full Code Here

                    !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

            String prefix = text.substring(0, split);
            text = text.substring(split+1);
           
            // make sure there aren't multiple colons
            if (text.indexOf(':') >= 0) {
                throw new JiBXException("Not a valid QName");
            } else {
               
                // look up the namespace URI associated with the prefix
                String uri =
                    ((UnmarshallingContext)ictx).getNamespaceUri(prefix);
                if (uri == null) {
                    throw new JiBXException("Undefined prefix " + prefix);
                } else {
                   
                    // create an instance of class to hold all components
                    return new QName(uri, prefix, text);
                   
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.