=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-06-03 07:51:25 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java 2014-06-03 08:19:42 +0000 @@ -51,7 +51,7 @@ /** * Direct link to getter for this property. */ - private final Method getterMethod; + private Method getterMethod; /** * Name for this property, if this class is a collection, it is the name of the items -inside- the collection @@ -102,6 +102,10 @@ */ private boolean nameableObject; + public Property() + { + } + public Property( Method getterMethod ) { this.getterMethod = getterMethod; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java 2014-06-03 07:51:25 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java 2014-06-03 08:19:42 +0000 @@ -83,18 +83,18 @@ private String namespaceURI; /** + * This will normally be set to equal singular, but in certain cases it might be useful to have another name + * for when this class is used as an item inside a collection. + */ + private String name; + + /** * This will normally be set to equal plural, and is normally used as a wrapper for a collection of * instances of this klass type. */ private String collectionName; /** - * This will normally be set to equal singular, but in certain cases it might be useful to have another name - * for when this class is used as an item inside a collection. - */ - private String collectionItemName; - - /** * Is sharing supported for instances of this class. */ private boolean shareable; @@ -213,14 +213,14 @@ @JsonProperty @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) - public String getCollectionItemName() + public String getName() { - return collectionItemName == null ? singular : collectionItemName; + return name == null ? singular : name; } - public void setCollectionItemName( String collectionItemName ) + public void setName( String name ) { - this.collectionItemName = collectionItemName; + this.name = name; } @JsonProperty @@ -338,9 +338,16 @@ ", nameableObject=" + nameableObject + ", singular='" + singular + '\'' + ", plural='" + plural + '\'' + + ", namespaceURI='" + namespaceURI + '\'' + + ", name='" + name + '\'' + + ", collectionName='" + collectionName + '\'' + ", shareable=" + shareable + + ", apiEndpoint='" + apiEndpoint + '\'' + + ", metadata=" + metadata + ", authorities=" + authorities + ", propertyMap=" + propertyMap + + ", order=" + order + + ", authorityMap=" + authorityMap + '}'; } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-06-03 07:51:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-06-03 08:19:42 +0000 @@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.hisp.dhis.common.IdentifiableObject; @@ -80,6 +81,27 @@ } Map propertyMap = Maps.newHashMap(); + + // TODO this is quite nasty, should find a better way of exposing properties at class-level + if ( clazz.isAnnotationPresent( JacksonXmlRootElement.class ) ) + { + Property property = new Property(); + + JacksonXmlRootElement jacksonXmlRootElement = clazz.getAnnotation( JacksonXmlRootElement.class ); + + if ( !StringUtils.isEmpty( jacksonXmlRootElement.localName() ) ) + { + property.setName( jacksonXmlRootElement.localName() ); + } + + if ( !StringUtils.isEmpty( jacksonXmlRootElement.namespace() ) ) + { + property.setNamespaceURI( jacksonXmlRootElement.namespace() ); + } + + propertyMap.put( "__self__", property ); + } + List allMethods = ReflectionUtils.getAllMethods( clazz ); for ( Method method : allMethods ) @@ -120,7 +142,7 @@ { JacksonXmlProperty jacksonXmlProperty = method.getAnnotation( JacksonXmlProperty.class ); - if ( jacksonXmlProperty.localName().isEmpty() ) + if ( StringUtils.isEmpty( jacksonXmlProperty.localName() ) ) { property.setName( name ); } @@ -140,7 +162,12 @@ if ( method.isAnnotationPresent( JacksonXmlElementWrapper.class ) ) { JacksonXmlElementWrapper jacksonXmlElementWrapper = method.getAnnotation( JacksonXmlElementWrapper.class ); - property.setCollectionName( jacksonXmlElementWrapper.localName() ); + + // TODO what if element-wrapper have different namespace? + if ( !StringUtils.isEmpty( jacksonXmlElementWrapper.localName() ) ) + { + property.setCollectionName( jacksonXmlElementWrapper.localName() ); + } } property.setName( name ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java 2014-06-02 22:47:30 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java 2014-06-03 08:19:42 +0000 @@ -69,6 +69,13 @@ classSchemaMap.put( schema.getKlass(), schema ); singularSchemaMap.put( schema.getSingular(), schema ); + + if ( schema.getPropertyMap().containsKey( "__self__" ) ) + { + Property property = schema.getPropertyMap().get( "__self__" ); + schema.setName( property.getName() ); + schema.setNamespaceURI( property.getNamespaceURI() ); + } } }