Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jamesagnew/hapi-fhir
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Oct 13, 2015
2 parents 15b7da1 + a2bf374 commit b97f7d4
Show file tree
Hide file tree
Showing 21 changed files with 735 additions and 244 deletions.
220 changes: 113 additions & 107 deletions hapi-fhir-android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-android</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -74,7 +80,11 @@
</dependency>

<!-- Android does not come with the Servlet API bundled, and MethodUtil
requires it -->
requires it.
We provide a dummy implementation of servlet api to reduce size
and prevent from rewriting the BaseMethodBinding and friends.
-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down Expand Up @@ -120,138 +130,134 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<artifactSet>
<includes combine.children="append">
<include>ca.uhn.hapi.fhir:hapi-fhir-base</include>
<include>org.glassfish:javax.json</include>
<include>org.codehaus.woodstox:woodstox-core-asl</include>
<include>javax.xml.stream:stax-api</include>
<include>org.codehaus.woodstox:stax2-api</include>
<include>org.glassfish:javax.json</include>
<include>net.sourceforge.cobertura:cobertura</include>
<!--
<include>org.apache.commons:*</include>
<include>org.apache.httpcomponents:*</include>
<include>commons-codec:commons-codec</include>
-->
<include>javax.servlet:javax.servlet-api</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>javax.xml.stream</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.xml.stream</shadedPattern>
</relocation>
<relocation>
<pattern>javax.json</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.json</shadedPattern>
</relocation>
</relocations>
<filters combine.children="append">
<!-- Make CoverageIgnore annotation available for android. -->
<filter>
<artifact>net.sourceforge.cobertura:cobertura</artifact>
<includes>
<include>net/sourceforge/cobertura/CoverageIgnore*</include>
</includes>
</filter>
<!-- Exclude server side stuff, except exceptions which are used clientside -->
<filter>
<artifact>ca.uhn.hapi.fhir:hapi-fhir-base</artifact>
<excludes>
<!-- Exclude test stuff which depends on httpservlet -->
<exclude>ca/uhn/fhir/util/ITestingUiClientFactory</exclude>
<!-- Exclude server side stuff. This could be made nicer if code was divided into shared, server and client -->
<!--exclude>ca/uhn/fhir/rest/server/Add*</exclude>
<exclude>ca/uhn/fhir/rest/server/Apache*</exclude>
<exclude>ca/uhn/fhir/rest/server/Bundle*</exclude>
<exclude>ca/uhn/fhir/rest/server/ETag*</exclude>
<exclude>ca/uhn/fhir/rest/server/Fifo*</exclude>
<exclude>ca/uhn/fhir/rest/server/Hard*</exclude>
<exclude>ca/uhn/fhir/rest/server/IBundle*</exclude>
<exclude>ca/uhn/fhir/rest/server/IDynamic*</exclude>
<exclude>ca/uhn/fhir/rest/server/Incoming*</exclude>
<exclude>ca/uhn/fhir/rest/server/IPaging*</exclude>
<exclude>ca/uhn/fhir/rest/server/IServerAdd*</exclude>
<exclude>ca/uhn/fhir/rest/server/Resource*</exclude>
<exclude>ca/uhn/fhir/rest/server/Rest*</exclude>
<exclude>ca/uhn/fhir/rest/server/Search*</exclude>
<exclude>ca/uhn/fhir/rest/server/Simple*</exclude>
<exclude>ca/uhn/fhir/rest/server/audit/**</exclude>
<exclude>ca/uhn/fhir/rest/server/interceptor/**</exclude-->
<!-- Exclude Phloc validator to make android libs small -->
<exclude>ca/uhn/fhir/validation/schematron/SchematronBaseValidator*</exclude>
<!-- Exclude Thymeleaf to make android libs small -->
<exclude>ca/uhn/fhir/narrative/*Thymeleaf*</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<!-- shaded jar -->
<execution>
<id>normal</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<artifactSet>
<includes>
<include>ca.uhn.hapi.fhir:hapi-fhir-base</include>
<include>org.glassfish:javax.json</include>
<include>org.codehaus.woodstox:woodstox-core-asl</include>
<include>javax.xml.stream:stax-api</include>
<include>org.codehaus.woodstox:stax2-api</include>
<include>org.glassfish:javax.json</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>javax.xml.stream</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.xml.stream</shadedPattern>
</relocation>
<relocation>
<pattern>javax.json</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.json</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>ca.uhn.hapi.fhir:hapi-fhir-base</artifact>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
<id>shaded</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
<!-- dstu jar -->
<execution>
<id>dstu</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>dstu</shadedClassifierName>
<artifactSet>
<includes>
<!--
<include>commons-codec:commons-codec</include>
-->
<include>ca.uhn.hapi.fhir:hapi-fhir-base</include>
<include>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu</include>
<include>org.glassfish:javax.json</include>
<include>org.codehaus.woodstox:woodstox-core-asl</include>
<include>javax.xml.stream:stax-api</include>
<!-- <include>javax.servlet:javax.servlet-api</include>-->
<include>org.codehaus.woodstox:stax2-api</include>
<!-- <include>org.slf4j:slf4j*</include> -->
<!--
<include>org.apache.commons:*</include>
<include>org.apache.httpcomponents:*</include>
-->
<include>org.glassfish:javax.json</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>javax.xml.stream</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.xml.stream</shadedPattern>
</relocation>
<relocation>
<pattern>javax.json</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.json</shadedPattern>
</relocation>
</relocations>
<filters>
<!-- Exclude server side stuff, except exceptions which are used clientside -->
<!--filters>
<filter>
<artifact>ca.uhn.hapi.fhir:hapi-fhir-base</artifact>
<artifact>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu</artifact>
<excludes>
<exclude>**/*.java</exclude>
<exclude>ca/uhn/fhir/rest/server/**</exclude>
</excludes>
</filter>
</filters>
</filters-->
</configuration>
</execution>
<!-- dstu2 jar -->
<execution>
<id>dstu2</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>dstu2</shadedClassifierName>
<artifactSet>
<includes>
<!--
<include>commons-codec:commons-codec</include>
-->
<include>ca.uhn.hapi.fhir:hapi-fhir-base</include>
<include>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu2</include>
<include>org.glassfish:javax.json</include>
<include>org.codehaus.woodstox:woodstox-core-asl</include>
<include>javax.xml.stream:stax-api</include>
<!-- <include>javax.servlet:javax.servlet-api</include>-->
<include>org.codehaus.woodstox:stax2-api</include>
<!--
<include>org.apache.commons:*</include>
<include>org.apache.httpcomponents:*</include>
-->
<include>org.glassfish:javax.json</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>javax.xml.stream</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.xml.stream</shadedPattern>
</relocation>
<relocation>
<pattern>javax.json</pattern>
<shadedPattern>ca.uhn.fhir.repackage.javax.json</shadedPattern>
</relocation>
</relocations>
<!-- Exclude server side stuff, except exceptions which are used clientside -->
<!--filters>
<filter>
<artifact>ca.uhn.hapi.fhir:hapi-fhir-structures-dstu2</artifact>
<excludes>
<exclude>ca/uhn/fhir/rest/server/**</exclude>
</excludes>
</filter>
</filters-->
</configuration>
</execution>
</executions>
Expand Down
14 changes: 14 additions & 0 deletions hapi-fhir-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
Expand Down
58 changes: 23 additions & 35 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BeanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,37 @@
* #L%
*/

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

import ca.uhn.fhir.util.reflection.IBeanUtils;

public class BeanUtils {

public static Method findAccessor(Class<?> theClassToIntrospect, Class<?> theTargetReturnType, String thePropertyName) throws NoSuchFieldException {
BeanInfo info;
try {
info = Introspector.getBeanInfo(theClassToIntrospect);
} catch (IntrospectionException e) {
throw new NoSuchFieldException(e.getMessage());
}
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
if (thePropertyName.equals(pd.getName())) {
if (theTargetReturnType.isAssignableFrom(pd.getPropertyType())) {
return pd.getReadMethod();
}else {
throw new NoSuchFieldException(theClassToIntrospect + " has an accessor for field " + thePropertyName + " but it does not return type " + theTargetReturnType);
private static IBeanUtils beanUtils;

private static IBeanUtils getBeanUtils() {
if (beanUtils == null) {
try {
beanUtils = (IBeanUtils) Class.forName("ca.uhn.fhir.util.reflection.JavaBeansBeanUtil").newInstance();
} catch (ReflectiveOperationException e) {
try {
beanUtils = (IBeanUtils) Class.forName("ca.uhn.fhir.util.reflection.JavaReflectBeanUtil")
.newInstance();
} catch (ReflectiveOperationException e1) {
throw new RuntimeException("Could not resolve BeanUtil implementation");
}
}
}
throw new NoSuchFieldException(theClassToIntrospect + " has no accessor for field " + thePropertyName);
return beanUtils;
}

public static Method findMutator(Class<?> theClassToIntrospect, Class<?> theTargetReturnType, String thePropertyName) throws NoSuchFieldException {
BeanInfo info;
try {
info = Introspector.getBeanInfo(theClassToIntrospect);
} catch (IntrospectionException e) {
throw new NoSuchFieldException(e.getMessage());
}
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
if (thePropertyName.equals(pd.getName())) {
if (theTargetReturnType.isAssignableFrom(pd.getPropertyType())) {
return pd.getWriteMethod();
}else {
throw new NoSuchFieldException(theClassToIntrospect + " has an mutator for field " + thePropertyName + " but it does not return type " + theTargetReturnType);
}
}
}
throw new NoSuchFieldException(theClassToIntrospect + " has no mutator for field " + thePropertyName);
public static Method findAccessor(Class<?> theClassToIntrospect, Class<?> theTargetReturnType, String thePropertyName)
throws NoSuchFieldException {
return getBeanUtils().findAccessor(theClassToIntrospect, theTargetReturnType, thePropertyName);
}

public static Method findMutator(Class<?> theClassToIntrospect, Class<?> theTargetReturnType, String thePropertyName)
throws NoSuchFieldException {
return getBeanUtils().findMutator(theClassToIntrospect, theTargetReturnType, thePropertyName);
}
}
14 changes: 14 additions & 0 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ObjectUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.uhn.fhir.util;

import org.apache.commons.lang3.StringUtils;

/*
* #%L
* HAPI FHIR - Core Library
Expand Down Expand Up @@ -32,4 +34,16 @@ public static boolean equals(Object object1, Object object2) {
return object1.equals(object2);
}

public static <T> T requireNonNull(T obj, String message) {
if (obj == null)
throw new NullPointerException(message);
return obj;
}

public static void requireNotEmpty(String str, String message) {
if (StringUtils.isBlank(str)) {
throw new IllegalArgumentException(message);
}
}

}

0 comments on commit b97f7d4

Please sign in to comment.