valueelement.java
来自「JiBX是一个为Java提供的XML数据绑定框架。它可以和现存的类一起运行」· Java 代码 · 共 798 行 · 第 1/2 页
JAVA
798 行
* * @return get value type (or <code>null</code> if none) */ public IClass getGetType() { return m_propertyAttrs.getGetType(); } /** * Set get method name. * * @param get get method name (or <code>null</code> if none) */ public void setGetName(String get) { m_propertyAttrs.setGetName(get); } /** * Get set method name. * * @return set method name (or <code>null</code> if none) */ public String getSetName() { return m_propertyAttrs.getSetName(); } /** * Get set method information. This call is only meaningful after * validation. * * @return set method information (or <code>null</code> if none) */ public IClassItem getSet() { return m_propertyAttrs.getSet(); } /** * Get type for value stored from stack. This call is only meaningful after * validation. * * @return set value type (or <code>null</code> if none) */ public IClass getSetType() { return m_propertyAttrs.getSetType(); } /** * Set set method name. * * @param set set method name (or <code>null</code> if none) */ public void setSetName(String set) { m_propertyAttrs.setSetName(set); } /** * Check if nillable object. * * @return nillable flag */ public boolean isNillable() { return m_isNillable; } /** * Set nillable flag. * * @param nillable flag */ public void setNillable(boolean nillable) { m_isNillable = nillable; } /** * Check if this value implicitly uses the containing object. This call * is only meaningful after prevalidation. * * @return <code>true</code> if using the containing object, * <code>false</code> if own value */ public boolean isImplicit() { return m_propertyAttrs.isImplicit(); } // // String attribute delegate methods /** * Get default value text. * * @return default value text */ public String getDefaultText() { return m_stringAttrs.getDefaultText(); } /** * Get default value. This call is only meaningful after validation. * * @return default value object */ public Object getDefault() { return m_stringAttrs.getDefault(); } /** * Set default value text. * * @param value default value text */ public void setDefaultText(String value) { m_stringAttrs.setDefaultText(value); } /** * Get base format name. * * @return referenced base format */ public String getFormatName() { return m_stringAttrs.getFormatName(); } /** * Set base format name. * * @param name referenced base format */ public void setFormatName(String name) { m_stringAttrs.setFormatName(name); } /** * Get format qualified name. * * @return format qualified name (<code>null</code> if none) */ public QName getFormatQName() { return m_stringAttrs.getFormatQName(); } /** * Set format qualified name. This method changes the label value to match * the qualified name. * * @return format qualified name (<code>null</code> if none) */ public void setFormatQName(QName qname) { m_stringAttrs.setFormatQName(qname); } /** * Get serializer name. * * @return fully qualified class and method name for serializer (or * <code>null</code> if none) */ public String getSerializerName() { return m_stringAttrs.getSerializerName(); } /** * Get serializer method information. This call is only meaningful after * validation. * * @return serializer information (or <code>null</code> if none) */ public IClassItem getSerializer() { return m_stringAttrs.getSerializer(); } /** * Set serializer method name. * * @param fully qualified class and method name for serializer */ public void setSerializerName(String name) { m_stringAttrs.setSerializerName(name); } /** * Get deserializer name. * * @return fully qualified class and method name for deserializer (or * <code>null</code> if none) */ public String getDeserializerName() { return m_stringAttrs.getDeserializerName(); } /** * Get deserializer method information. This call is only meaningful after * validation. * * @return deserializer information (or <code>null</code> if none) */ public IClassItem getDeserializer() { return m_stringAttrs.getDeserializer(); } /** * Set deserializer method name. * * @param fully qualified class and method name for deserializer */ public void setDeserializerName(String name) { m_stringAttrs.setDeserializerName(name); } // // IComponent implementation methods (also delegated name methods) /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#hasAttribute() */ public boolean hasAttribute() { return m_styleIndex == NestingAttributes.ATTRIBUTE_STYLE; } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#hasContent() */ public boolean hasContent() { return m_styleIndex != NestingAttributes.ATTRIBUTE_STYLE; } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#isOptional() */ public boolean isOptional() { return m_propertyAttrs.getUsage() == PropertyAttributes.OPTIONAL_USAGE; } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#hasName() */ public boolean hasName() { return m_nameAttrs.getName() != null; } /* (non-Javadoc) * @see org.jibx.binding.model.IComponent#getType() */ public IClass getType() { return m_propertyAttrs.getType(); } // // Validation methods /** * Make sure all attributes are defined. * * @param uctx unmarshalling context * @exception JiBXException on unmarshalling error */ private void preSet(IUnmarshallingContext uctx) throws JiBXException { validateAttributes(uctx, s_allowedAttributes); } /* (non-Javadoc) * @see org.jibx.binding.model.ElementBase#prevalidate(org.jibx.binding.model.ValidationContext) */ public void prevalidate(ValidationContext vctx) { // set the style value if (m_styleName != null) { m_styleIndex = s_styleEnum.getValue(m_styleName); if (m_styleIndex < 0) { vctx.addError("Value \"" + m_styleName + "\" is not a valid choice for style"); } } else { m_styleIndex = vctx.getParentElement().getDefaultStyle(); } // validate ID classification m_identIndex = s_identEnum.getValue(m_identName); if (m_identIndex < 0) { vctx.addError("Value \"" + m_identName + " is not a valid choice for ident"); } // validate basic attribute groups m_propertyAttrs.prevalidate(vctx); if (m_stringAttrs.getDefaultText() != null && !isOptional()) { vctx.addWarning("default attribute ignored for required value"); m_stringAttrs.setDefaultText(null); } m_nameAttrs.setIsAttribute (m_styleIndex == NestingAttributes.ATTRIBUTE_STYLE); m_nameAttrs.prevalidate(vctx); if (m_styleIndex == CDATA_STYLE || m_styleIndex == TEXT_STYLE) { if (m_nameAttrs.getName() != null) { vctx.addFatal("Values with \"text\" or \"cdata\" style " + "cannot have names"); } } else { if (m_nameAttrs.getName() == null) { vctx.addFatal ("Missing required name for element or attribute value"); } } // make sure value is not constant if (m_constantValue == null) { // make sure nillable only for element with object if (m_isNillable) { if (m_styleIndex != NestingAttributes.ELEMENT_STYLE) { vctx.addFatal("nillable can only be used with element style"); } } // process ID classification if (m_identIndex == DEF_IDENT/* || m_identIndex == AUTO_IDENT*/) { boolean valid = false; IClass gclas = m_propertyAttrs.getGetType(); if (gclas != null) { String gtype = gclas.getName(); if (gtype.equals("java.lang.String")) { vctx.getContextObject().setIdChild(this, vctx); valid = true; } } if (!valid) { vctx.addError("ID property must supply a " + "java.lang.String value"); }/* } else if (!m_propertyAttrs.hasProperty() && !(vctx.getContextObject() instanceof CollectionElement)) { vctx.addError("Need property definition", this); */ } // check string attributes only if valid to this point if (!vctx.isSkipped(this)) { // handle string attributes based on identity type if (m_identIndex == REF_IDENT) { if (m_propertyAttrs.isImplicit()) { vctx.addFatal ("No property value - ID reference can only " + "be used with a property of the appropriate type"); } if (m_stringAttrs.getDeserializerName() != null || m_stringAttrs.getSerializerName() != null || m_stringAttrs.getFormatName() != null || m_stringAttrs.getDefaultText() != null) { vctx.addWarning("String attributes serializer, " + "deserializer, format, and default are " + "prohibited with ID references"); } } else { m_stringAttrs.setType(m_propertyAttrs.getType()); m_stringAttrs.prevalidate(vctx); } super.prevalidate(vctx); } } else { // check prohibited attributes with constant value if (m_identIndex != NONE_IDENT) { vctx.addFatal("ident value must be \"none\" for constant"); } else if (m_propertyAttrs.hasProperty() || m_propertyAttrs.getDeclaredType() != null) { vctx.addFatal ("Property attributes cannot be used with constant"); } else if (m_stringAttrs.getDefaultText() != null || m_stringAttrs.getDeserializerName() != null || m_stringAttrs.getSerializerName() != null || m_stringAttrs.getFormatName() != null) { vctx.addFatal("String attributes cannot be used with constant"); } else if (m_isNillable) { vctx.addFatal("nillable cannot be used with constant"); } } } /* (non-Javadoc) * @see org.jibx.binding.model.ElementBase#validate(org.jibx.binding.model.ValidationContext) */ public void validate(ValidationContext vctx) { // validate basic attributes m_nameAttrs.validate(vctx); m_propertyAttrs.validate(vctx); if (!vctx.isSkipped(this)) { // check identity references for compatible objects if (m_identIndex == REF_IDENT) { String type = m_propertyAttrs.getType().getName(); if (!vctx.getBindingRoot().isIdClass(type)) { vctx.addError("No ID definitions for compatible type"); } } super.validate(vctx); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?