dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28789
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14429: renamed PropertyScannerService => PropertyIntrospectorService
------------------------------------------------------------
revno: 14429
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-03-26 12:38:14 +0100
message:
renamed PropertyScannerService => PropertyIntrospectorService
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyScannerService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyScannerService.java
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java
modified:
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/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyIntrospectorService.java 2014-03-26 11:38:14 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.schema;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface PropertyIntrospectorService
+{
+ List<Property> getProperties( Class<?> klass );
+}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyScannerService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyScannerService.java 2014-03-26 11:32:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/PropertyScannerService.java 1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
-package org.hisp.dhis.schema;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface PropertyScannerService
-{
- List<Property> getProperties( Class<?> klass );
-}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyIntrospectorService.java 2014-03-26 11:38:14 +0000
@@ -0,0 +1,169 @@
+package org.hisp.dhis.schema;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.annotation.Description;
+import org.hisp.dhis.system.util.ReflectionUtils;
+import org.springframework.util.StringUtils;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Default PropertyIntrospectorService implementation that uses Reflection and Jackson annotations
+ * for reading in properties.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultPropertyIntrospectorService implements PropertyIntrospectorService
+{
+ @Override
+ public List<Property> getProperties( Class<?> klass )
+ {
+ return scanClass( klass );
+ }
+
+ // -------------------------------------------------------------------------
+ // Scanning Helpers
+ // -------------------------------------------------------------------------
+
+ private static Map<Class<?>, List<Property>> classMapCache = Maps.newHashMap();
+
+ private static List<Property> scanClass( Class<?> clazz )
+ {
+ if ( classMapCache.containsKey( clazz ) )
+ {
+ return classMapCache.get( clazz );
+ }
+
+ List<Property> properties = Lists.newArrayList();
+ List<Method> allMethods = ReflectionUtils.getAllMethods( clazz );
+
+ for ( Method method : allMethods )
+ {
+ if ( method.isAnnotationPresent( JsonProperty.class ) )
+ {
+ JsonProperty jsonProperty = method.getAnnotation( JsonProperty.class );
+ Property property = new Property( method );
+
+ String name = jsonProperty.value();
+
+ if ( StringUtils.isEmpty( name ) )
+ {
+ String[] getters = new String[]{
+ "is", "has", "get"
+ };
+
+ name = method.getName();
+
+ for ( String getter : getters )
+ {
+ if ( name.startsWith( getter ) )
+ {
+ name = name.substring( getter.length() );
+ }
+ }
+
+ name = StringUtils.uncapitalize( name );
+ }
+
+ if ( method.isAnnotationPresent( Description.class ) )
+ {
+ Description description = method.getAnnotation( Description.class );
+ property.setDescription( description.value() );
+ }
+
+ if ( method.isAnnotationPresent( JacksonXmlProperty.class ) )
+ {
+ JacksonXmlProperty jacksonXmlProperty = method.getAnnotation( JacksonXmlProperty.class );
+
+ if ( jacksonXmlProperty.localName().isEmpty() )
+ {
+ property.setXmlName( name );
+ }
+ else
+ {
+ property.setXmlName( jacksonXmlProperty.localName() );
+ }
+
+ property.setXmlNamespace( jacksonXmlProperty.namespace() );
+ property.setXmlAttribute( jacksonXmlProperty.isAttribute() );
+ }
+
+ if ( method.isAnnotationPresent( JacksonXmlElementWrapper.class ) )
+ {
+ JacksonXmlElementWrapper jacksonXmlElementWrapper = method.getAnnotation( JacksonXmlElementWrapper.class );
+ property.setXmlCollectionName( jacksonXmlElementWrapper.localName() );
+ }
+
+ property.setName( name );
+ properties.add( property );
+
+ Class<?> returnType = method.getReturnType();
+ property.setKlass( returnType );
+
+ if ( IdentifiableObject.class.isAssignableFrom( returnType ) )
+ {
+ property.setIdentifiableObject( true );
+ }
+ else if ( Collection.class.isAssignableFrom( returnType ) )
+ {
+ property.setCollection( true );
+
+ Type type = method.getGenericReturnType();
+
+ if ( ParameterizedType.class.isInstance( type ) )
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Class<?> klass = (Class<?>) parameterizedType.getActualTypeArguments()[0];
+
+ if ( IdentifiableObject.class.isAssignableFrom( klass ) )
+ {
+ property.setIdentifiableObject( true );
+ }
+ }
+ }
+ }
+ }
+
+ classMapCache.put( clazz, properties );
+
+ return properties;
+ }
+}
=== removed file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyScannerService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyScannerService.java 2014-03-26 11:32:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultPropertyScannerService.java 1970-01-01 00:00:00 +0000
@@ -1,169 +0,0 @@
-package org.hisp.dhis.schema;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.annotation.Description;
-import org.hisp.dhis.system.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Default PropertyScannerService implementation that uses Reflection and Jackson annotations
- * for reading in properties.
- *
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class DefaultPropertyScannerService implements PropertyScannerService
-{
- @Override
- public List<Property> getProperties( Class<?> klass )
- {
- return scanClass( klass );
- }
-
- // -------------------------------------------------------------------------
- // Scanning Helpers
- // -------------------------------------------------------------------------
-
- private static Map<Class<?>, List<Property>> classMapCache = Maps.newHashMap();
-
- private static List<Property> scanClass( Class<?> clazz )
- {
- if ( classMapCache.containsKey( clazz ) )
- {
- return classMapCache.get( clazz );
- }
-
- List<Property> properties = Lists.newArrayList();
- List<Method> allMethods = ReflectionUtils.getAllMethods( clazz );
-
- for ( Method method : allMethods )
- {
- if ( method.isAnnotationPresent( JsonProperty.class ) )
- {
- JsonProperty jsonProperty = method.getAnnotation( JsonProperty.class );
- Property property = new Property( method );
-
- String name = jsonProperty.value();
-
- if ( StringUtils.isEmpty( name ) )
- {
- String[] getters = new String[]{
- "is", "has", "get"
- };
-
- name = method.getName();
-
- for ( String getter : getters )
- {
- if ( name.startsWith( getter ) )
- {
- name = name.substring( getter.length() );
- }
- }
-
- name = StringUtils.uncapitalize( name );
- }
-
- if ( method.isAnnotationPresent( Description.class ) )
- {
- Description description = method.getAnnotation( Description.class );
- property.setDescription( description.value() );
- }
-
- if ( method.isAnnotationPresent( JacksonXmlProperty.class ) )
- {
- JacksonXmlProperty jacksonXmlProperty = method.getAnnotation( JacksonXmlProperty.class );
-
- if ( jacksonXmlProperty.localName().isEmpty() )
- {
- property.setXmlName( name );
- }
- else
- {
- property.setXmlName( jacksonXmlProperty.localName() );
- }
-
- property.setXmlNamespace( jacksonXmlProperty.namespace() );
- property.setXmlAttribute( jacksonXmlProperty.isAttribute() );
- }
-
- if ( method.isAnnotationPresent( JacksonXmlElementWrapper.class ) )
- {
- JacksonXmlElementWrapper jacksonXmlElementWrapper = method.getAnnotation( JacksonXmlElementWrapper.class );
- property.setXmlCollectionName( jacksonXmlElementWrapper.localName() );
- }
-
- property.setName( name );
- properties.add( property );
-
- Class<?> returnType = method.getReturnType();
- property.setKlass( returnType );
-
- if ( IdentifiableObject.class.isAssignableFrom( returnType ) )
- {
- property.setIdentifiableObject( true );
- }
- else if ( Collection.class.isAssignableFrom( returnType ) )
- {
- property.setCollection( true );
-
- Type type = method.getGenericReturnType();
-
- if ( ParameterizedType.class.isInstance( type ) )
- {
- ParameterizedType parameterizedType = (ParameterizedType) type;
- Class<?> klass = (Class<?>) parameterizedType.getActualTypeArguments()[0];
-
- if ( IdentifiableObject.class.isAssignableFrom( klass ) )
- {
- property.setIdentifiableObject( true );
- }
- }
- }
- }
- }
-
- classMapCache.put( clazz, properties );
-
- return properties;
- }
-}
=== 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-03-21 11:57:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java 2014-03-26 11:38:14 +0000
@@ -46,7 +46,7 @@
private Map<String, Schema> singularSchemaMap = Maps.newHashMap();
@Autowired
- private PropertyScannerService propertyScannerService;
+ private PropertyIntrospectorService propertyIntrospectorService;
@Autowired
private List<SchemaDescriptor> descriptors = Lists.newArrayList();
@@ -60,7 +60,7 @@
if ( schema.getProperties().isEmpty() )
{
- schema.setProperties( propertyScannerService.getProperties( schema.getKlass() ) );
+ schema.setProperties( propertyIntrospectorService.getProperties( schema.getKlass() ) );
}
classSchemaMap.put( schema.getKlass(), schema );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-03-24 13:22:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-03-26 11:38:14 +0000
@@ -9,7 +9,7 @@
<bean id="org.hisp.dhis.schema.SchemaService" class="org.hisp.dhis.schema.DefaultSchemaService" />
- <bean id="org.hisp.dhis.schema.PropertyScannerService" class="org.hisp.dhis.schema.DefaultPropertyScannerService" />
+ <bean id="org.hisp.dhis.schema.PropertyIntrospectorService" class="org.hisp.dhis.schema.DefaultPropertyIntrospectorService" />
<bean id="org.hisp.dhis.sharing.SharingService" class="org.hisp.dhis.sharing.DefaultSharingService" />