📄 typedesc.java
字号:
/** * Get the QName associated with this field, but only if it's * marked as an element. */ public QName getElementNameForField(String fieldName) { FieldDesc desc = (FieldDesc)fieldNameMap.get(fieldName); if (desc == null) { // check superclasses if they exist // and we are allowed to look if (canSearchParents) { if (parentDesc != null) { return parentDesc.getElementNameForField(fieldName); } } } else if (desc.isElement()) { return desc.getXmlName(); } return null; } /** * Get the QName associated with this field, but only if it's * marked as an attribute. */ public QName getAttributeNameForField(String fieldName) { FieldDesc desc = (FieldDesc)fieldNameMap.get(fieldName); if (desc == null) { // check superclasses if they exist // and we are allowed to look if (canSearchParents) { if (parentDesc != null) { return parentDesc.getAttributeNameForField(fieldName); } } } else if (!desc.isElement()) { QName ret = desc.getXmlName(); if (ret == null) { ret = new QName("", fieldName); } return ret; } return null; } /** * Get the field name associated with this QName, but only if it's * marked as an element. * * If the "ignoreNS" argument is true, just compare localNames. */ public String getFieldNameForElement(QName qname, boolean ignoreNS) { // have we already computed the answer to this question? if (fieldElementMap != null) { String cached = (String) fieldElementMap.get(qname); if (cached != null) return cached; } String result = null; String localPart = qname.getLocalPart(); // check fields in this class for (int i = 0; fields != null && i < fields.length; i++) { FieldDesc field = fields[i]; if (field.isElement()) { QName xmlName = field.getXmlName(); if (localPart.equals(xmlName.getLocalPart())) { if (ignoreNS || qname.getNamespaceURI(). equals(xmlName.getNamespaceURI())) { result = field.getFieldName(); break; } } } } // check superclasses if they exist // and we are allowed to look if (result == null && canSearchParents) { if (parentDesc != null) { result = parentDesc.getFieldNameForElement(qname, ignoreNS); } } // cache the answer away for quicker retrieval next time. if (result != null) { if (fieldElementMap == null) fieldElementMap = new HashMap(); fieldElementMap.put(qname, result); } return result; } /** * Get the field name associated with this QName, but only if it's * marked as an attribute. */ public String getFieldNameForAttribute(QName qname) { String possibleMatch = null; for (int i = 0; fields != null && i < fields.length; i++) { FieldDesc field = fields[i]; if (!field.isElement()) { // It's an attribute, so if we have a solid match, return // its name. if (qname.equals(field.getXmlName())) { return field.getFieldName(); } // Not a solid match, but it's still possible we might match // the default (i.e. QName("", fieldName)) if (qname.getNamespaceURI().equals("") && qname.getLocalPart().equals(field.getFieldName())) { possibleMatch = field.getFieldName(); } } } if (possibleMatch == null && canSearchParents) { // check superclasses if they exist // and we are allowed to look if (parentDesc != null) { possibleMatch = parentDesc.getFieldNameForAttribute(qname); } } return possibleMatch; } /** * Get a FieldDesc by field name. */ public FieldDesc getFieldByName(String name) { FieldDesc ret = (FieldDesc)fieldNameMap.get(name); if (ret == null && canSearchParents) { if (parentDesc != null) { ret = parentDesc.getFieldByName(name); } } return ret; } /** * Do we have any FieldDescs marked as attributes? */ public boolean hasAttributes() { if (_hasAttributes) return true; if (canSearchParents) { if (parentDesc != null) { return parentDesc.hasAttributes(); } } return false; } public QName getXmlType() { return xmlType; } public void setXmlType(QName xmlType) { this.xmlType = xmlType; } /** * Get/Cache the property descriptors * @return PropertyDescriptor */ public BeanPropertyDescriptor[] getPropertyDescriptors() { // Return the propertyDescriptors if already set. // If not set, use BeanUtils.getPd to get the property descriptions. // // Since javaClass is a generated class, there // may be a faster way to set the property descriptions than // using BeanUtils.getPd. But for now calling getPd is sufficient. if (propertyDescriptors == null) { makePropertyDescriptors(); } return propertyDescriptors; } private synchronized void makePropertyDescriptors() { if (propertyDescriptors != null) return; // javaClassRef is a WeakReference. So, our javaClass may have been GC'ed. // Protect against this case... Class javaClass = (Class)javaClassRef.get(); if (javaClass == null) { // could throw a RuntimeException, but instead log error and dummy up descriptors log.error(Messages.getMessage("classGCed")); propertyDescriptors = new BeanPropertyDescriptor[0]; anyDesc = null; lookedForAny = true; return; } propertyDescriptors = BeanUtils.getPd(javaClass, this); if (!lookedForAny) { anyDesc = BeanUtils.getAnyContentPD(javaClass); lookedForAny = true; } } public BeanPropertyDescriptor getAnyContentDescriptor() { if (!lookedForAny) { // javaClassRef is a WeakReference. So, our javaClass may have been GC'ed. // Protect against this case... Class javaClass = (Class)javaClassRef.get(); if (javaClass != null) { anyDesc = BeanUtils.getAnyContentPD(javaClass); } else { log.error(Messages.getMessage("classGCed")); anyDesc = null; } lookedForAny = true; } return anyDesc; } /** * Get/Cache the property descriptor map * @return Map with key=propertyName, value=descriptor */ public Map getPropertyDescriptorMap() { synchronized (this) { // Return map if already set. if (propertyMap != null) { return propertyMap; } // Make sure properties exist if (propertyDescriptors == null) { getPropertyDescriptors(); } // Build the map propertyMap = new HashMap(); for (int i = 0; i < propertyDescriptors.length; i++) { BeanPropertyDescriptor descriptor = propertyDescriptors[i]; propertyMap.put(descriptor.getName(), descriptor); } } return propertyMap; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -