⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bindingelement.java

📁 对xml很好的java处理引擎,编译中绑定xml
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * <code>false</code> if not     */    public void setInBinding(boolean in) {        m_isInput = in;        setDirection();    }    	/**     * Check if this binding component applies for unmarshalling XML.     *	 * @return <code>true</code> if binding supports input, <code>false</code>     * if not	 */	public boolean isInBinding() {		return m_isInput;	}        /**     * Add include path to set processed.     *     * @param path     * @return <code>true</code> if new path, <code>false</code> if duplicate     */    public boolean addIncludePath(String path) {        return m_includePaths.add(path);    }        /**     * Get included binding. If the binding was supplied directly it's just     * returned; otherwise, it's read from the URL. This method should only be     * called if {@link #addIncludePath(String)} returns <code>true</code>,     * so that each unique included binding is only processed once.     *     * @param url binding path     * @param root binding containing the include     * @param vctx validation context     * @return binding     * @throws IOException     * @throws JiBXException     */    public BindingElement getIncludeBinding(URL url, BindingElement root,        ValidationContext vctx) throws IOException, JiBXException {        String path = url.toExternalForm();        BindingElement bind = (BindingElement)m_includeBindings.get(path);        if (bind == null) {                        // get base name from path            path = path.replace('\\', '/');            int split = path.lastIndexOf('/');            String fname = path;            if (split >= 0) {                fname = fname.substring(split+1);            }                        // read stream to create object model            InputStream is = url.openStream();            bind = BindingElement.readBinding(is, fname, root, vctx);                    }                // set binding base, and context from root context        bind.setBaseUrl(url);        bind.setDefinitions(root.getDefinitions().getIncludeCopy());        m_includeBindings.put(path, bind);        return bind;    }        /**     * Add binding accessible to includes. This allows bindings to be supplied     * directly, without needing to be parsed from an input document.     *     * @param path URL string identifying the binding (virtual path)     * @param bind     */    public void addIncludeBinding(String path, BindingElement bind) {        m_includeBindings.put(path, bind);    }        /**     * Add a class defined with a ID value. This is used to track the classes     * with ID values for validating ID references in the binding. If the     * binding uses global IDs, the actual ID class is added to the table along     * with all interfaces implemented by the class and all superclasses, since     * instances of the ID class can be referenced in any of those forms. If the     * binding does not use global IDs, only the actual ID class is added, since     * references must be type-specific.     *      * @param clas information for class with ID value     */    public void addIdClass(IClass clas) {                // create the set if not already present        if (m_idClassSet == null) {            m_idClassSet = new HashSet();        }                // add the class if not already present        if (m_idClassSet.add(clas.getName())) {                        // new class, add all interfaces if not previously defined            String[] inames = clas.getInterfaces();            for (int i = 0; i < inames.length; i++) {                m_idClassSet.add(inames[i]);            }            while (clas != null && m_idClassSet.add(clas.getName())) {                clas = clas.getSuperClass();            }        }    }        /**     * Check if a class can be referenced by ID. This just checks if any classes     * compatible with the reference type are bound with ID values.     *     * @param name fully qualified name of class     * @return <code>true</code> if class is bound with an ID,     * <code>false</code> if not     */    public boolean isIdClass(String name) {        if (m_idClassSet == null) {            return false;        } else {            return m_idClassSet.contains(name);        }    }        /**     * Add top-level child element.     * TODO: should be ElementBase argument, but JiBX doesn't allow yet     *      * @param child element to be added as child of this element     */    public void addTopChild(Object child) {        m_children.add(child);    }        /**     * Get list of top-level child elements.     *      * @return list of child elements, or <code>null</code> if none     */    public ArrayList topChildren() {        return m_children;    }        /**     * Get iterator for top-level child elements.     *      * @return iterator for child elements     */    public Iterator topChildIterator() {        return m_children.iterator();    }        /**     * Add namespace declaration for output when marshalling.     *      * @param prefix      * @param uri      */    public void addNamespaceDecl(String prefix, String uri) {        if (m_namespaceDeclares == null) {            m_namespaceDeclares = new ArrayList();        }        m_namespaceDeclares.add(prefix);        m_namespaceDeclares.add(uri);    }        //    // Overrides of base class methods.    /* (non-Javadoc)     * @see org.jibx.binding.model.ElementBase#hasAttribute()     */    public boolean hasAttribute() {        throw new IllegalStateException            ("Internal error: method should never be called");    }    /* (non-Javadoc)     * @see org.jibx.binding.model.ElementBase#hasContent()     */    public boolean hasContent() {        throw new IllegalStateException            ("Internal error: method should never be called");    }    /* (non-Javadoc)     * @see org.jibx.binding.model.ElementBase#isOptional()     */    public boolean isOptional() {        throw new IllegalStateException            ("Internal error: method should never be called");    }        /**     * Get default style value for child components. This call is only     * meaningful after validation.     *      * @return default style value for child components     */    public int getDefaultStyle() {        int style = super.getDefaultStyle();        if (style < 0) {            style = NestingAttributes.s_styleEnum.getValue("element");        }        return style;    }        //    // Marshalling/unmarshalling methods        /**     * Marshalling hook method to add namespace declarations to &lt;binding>     * element.     *     * @param ictx     * @throws IOException     */    private void preGet(IMarshallingContext ictx) throws IOException {        if (m_namespaceDeclares != null) {                        // set up information for namespace indexes and prefixes            IXMLWriter writer = ictx.getXmlWriter();            String[] uris = new String[m_namespaceDeclares.size()/2];            int[] indexes = new int[uris.length];            String[] prefs = new String[uris.length];            int base = writer.getNamespaceCount();            for (int i = 0; i < uris.length; i++) {                indexes[i] = base + i;                prefs[i] = (String)m_namespaceDeclares.get(i*2);                uris[i] = (String)m_namespaceDeclares.get(i*2+1);            }                        // add the namespace declarations to current element            writer.pushExtensionNamespaces(uris);            writer.openNamespaces(indexes, prefs);            for (int i = 0; i < uris.length; i++) {                String prefix = prefs[i];                String name = prefix.length() > 0 ?                    "xmlns:" + prefix : "xmlns";                writer.addAttribute(0, name, uris[i]);            }                    }    }        //    // Validation methods        /**     * Make sure all attributes are defined.     *     * @param ictx unmarshalling context     * @exception JiBXException on unmarshalling error     */    private void preSet(IUnmarshallingContext ictx) throws JiBXException {                // validate the attributes defined for this element        validateAttributes(ictx, s_allowedAttributes);                // get the unmarshal wrapper        UnmarshalWrapper wrapper =            (UnmarshalWrapper)ictx.getStackObject(ictx.getStackDepth()-1);        if (wrapper.getContainingBinding() != null) {                        // check attributes not allowed on included binding            BindingElement root = wrapper.getContainingBinding();            ValidationContext vctx = wrapper.getValidation();            UnmarshallingContext uctx = (UnmarshallingContext)ictx;            for (int i = 0; i < uctx.getAttributeCount(); i++) {                                // check if nonamespace attribute is in the allowed set                String name = uctx.getAttributeName(i);                if (uctx.getAttributeNamespace(i).length() == 0) {                    if (s_allowedAttributes.indexOf(name) >= 0) {                        String value = uctx.getAttributeValue(i);                        if ("direction".equals(name)) {                            if (!root.m_direction.equals(value)) {                                vctx.addError("'direction' value on included binding must match the root binding",                                    this);                            }                        } else if ("track-source".equals(name)) {                            boolean flag = Utility.parseBoolean(value);                            if (root.m_isTrackSource != flag) {                                vctx.addError("'track-source' value on included binding must match the root binding",                                    this);                            }                        } else if ("value-style".equals(name)) {                            if (!root.getStyleName().equals(value)) {                                vctx.addError("'value-style' value on included binding must match the root binding",                                    this);                            }                        } else if ("force-classes".equals(name)) {                            boolean flag = Utility.parseBoolean(value);                            if (root.m_isForceClasses != flag) {                                vctx.addError("'force-classes' value on included binding must match the root binding",                                    this);                            }                        } else if ("add-constructors".equals(name)) {                            boolean flag = Utility.parseBoolean(value);                            if (root.m_isAddConstructors != flag) {                                vctx.addError("'add-constructors' value on included binding must match the root binding",                                    this);                            }                        } else if ("forwards".equals(name)) {                            boolean flag = Utility.parseBoolean(value);                            if (root.m_isForward != flag) {                                vctx.addError("'forwards' value on included binding must match the root binding",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -