Example usage for javax.xml.bind.annotation XmlAccessOrder equals

List of usage examples for javax.xml.bind.annotation XmlAccessOrder equals

Introduction

In this page you can find the example usage for javax.xml.bind.annotation XmlAccessOrder equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:org.castor.jaxb.reflection.ClassDescriptorBuilder.java

/**
 * Builds a XMLClassDescriptor from the class information collected in
 * ClassInfo.//from   w  w  w  .ja  va  2s.  c  o  m
 * 
 * @param classInfo
 *            all information collected about a certain class
 * @param saveMapKeys
 * @HACK no idea what this is good for...
 * @return the XMLClassDescriptor representing the class
 */
public XMLClassDescriptor buildClassDescriptor(final ClassInfo classInfo, final boolean saveMapKeys) {
    if (classInfo == null) {
        IllegalArgumentException e = new IllegalArgumentException("Argument classInfo must not be null");
        throw e;
    }
    JAXBClassDescriptorImpl classDescriptor = new JAXBClassDescriptorImpl();
    JaxbClassNature jaxbClassNature = new JaxbClassNature(classInfo);

    classDescriptor.setJavaClass(jaxbClassNature.getType());
    classDescriptor.setXMLName(getXMLName(jaxbClassNature));
    classDescriptor.setNameSpacePrefix(getNamespacePrefix(jaxbClassNature));
    classDescriptor.setNameSpaceURI(getNamespaceURI(jaxbClassNature));

    List<JaxbFieldNature> fields = new ArrayList<JaxbFieldNature>();
    fields.addAll(jaxbClassNature.getFields());

    if (jaxbClassNature.getXmlTransient()) {
        classDescriptor.setTransientClass(true);
    }
    if (jaxbClassNature.getXmlAccessorOrder()) {
        XmlAccessOrder accessOrder = jaxbClassNature.getXmlAccessOrder();
        if (accessOrder.equals(XmlAccessOrder.ALPHABETICAL)) {
            Collections.sort(fields, new Comparator<JaxbFieldNature>() {

                public int compare(JaxbFieldNature fieldNature1, JaxbFieldNature fieldNature2) {
                    return getName(fieldNature1).compareTo(getName(fieldNature2));
                }

                private String getName(JaxbFieldNature fieldNature) {
                    String name = "";
                    if (StringUtils.isNotEmpty(fieldNature.getElementName())) {
                        name = fieldNature.getElementName();
                    }
                    if (StringUtils.isNotEmpty(fieldNature.getAttributeName())) {
                        name = fieldNature.getAttributeName();
                    }
                    return name;
                }
            });
        }
    }

    for (JaxbFieldNature jaxbFieldNature : fields) {
        LOG.info("Field info: " + jaxbFieldNature + " now used");
        XMLFieldDescriptor fieldDescriptor = buildFieldDescriptor(jaxbFieldNature,
                jaxbClassNature.getXmlAccessType(), saveMapKeys);
        classDescriptor.addFieldDescriptor(fieldDescriptor);
    }

    return classDescriptor;
}