Codebase list libhibernate-commons-annotations-java / 2d2ef97b-047d-4bbb-aec4-8b18859c3aa9/upstream
Import upstream version 5.1.2 Debian Janitor 2 years ago
92 changed file(s) with 2113 addition(s) and 1338 deletion(s). Raw diff Collapse all Expand all
0 # Typically *NIX text editors, by default, append '~' to files on saving to make backups
1 *~
2
3 # Gradle work directory
4 .gradle
5
6 # Build output directies
7 /target
8 */target
9 /build
10 */build
11
12 # IntelliJ specific files/directories
13 out
14 .idea
15 *.ipr
16 *.iws
17 *.iml
18 atlassian-ide-plugin.xml
19
20 # Eclipse specific files/directories
21 .classpath
22 .project
23 .settings
24 .metadata
25 bin
26
27 # NetBeans specific files/directories
28 .nbattrs
29
30 # Miscellaneous
31 *.log
32 .clover
0 buildscript {
1 repositories {
2 mavenCentral()
3 }
4 dependencies {
5 classpath 'org.hibernate.build.gradle:gradle-maven-publish-auth:2.0.1'
6 classpath 'org.hibernate.build.gradle:version-injection-plugin:1.0.0'
7 classpath 'org.hibernate.build.gradle:gradle-animalSniffer-plugin:1.0.1.Final'
8 }
9 }
10
11 repositories {
12 mavenCentral()
13 }
14
15 apply plugin: 'java'
16 apply plugin: 'osgi'
17
18 apply plugin: 'version-injection'
19
20 apply plugin: 'maven-publish'
21 apply plugin: 'maven-publish-auth'
22
23 apply plugin: 'idea'
24 apply plugin: 'eclipse'
25
26 group = 'org.hibernate.common'
27 version = '5.1.2.Final'
28
29 buildDir = "target"
30
31 ext.javaLanguageLevel = '1.8'
32 targetCompatibility = project.javaLanguageLevel
33 sourceCompatibility = project.javaLanguageLevel
34
35 configurations {
36 jbossLoggingTool {
37 description = 'Configuration for defining dependencies needed to run the JBoss Logging AnnotationProcessor tool'
38 }
39 }
40
41 dependencies {
42 compile 'org.jboss.logging:jboss-logging:3.3.2.Final'
43
44 jbossLoggingTool 'org.jboss.logging:jboss-logging-annotations:2.1.0.Final'
45 jbossLoggingTool 'org.jboss.logging:jboss-logging-processor:2.1.0.Final'
46
47 testCompile( 'junit:junit:3.8.1' )
48 }
49
50 // create a special 'compile' task that performs all the tasks normally associated with compiling a project
51 // via task dependencies
52 task compile
53 compile.dependsOn compileJava, processResources, compileTestJava, processTestResources
54
55
56 project.getConvention().findPlugin( JavaPluginConvention.class ).sourceSets.each { sourceSet ->
57 JavaCompile javaCompileTask = project.tasks.findByName( sourceSet.compileJavaTaskName ) as JavaCompile
58
59 File aptDir = project.file( "${project.buildDir}/generated-src/apt/${sourceSet.name}" )
60 sourceSet.allJava.srcDir( aptDir )
61 sourceSet.compileClasspath += configurations.jbossLoggingTool
62
63 javaCompileTask.options.compilerArgs += [
64 "-nowarn",
65 "-encoding", "UTF-8",
66 "-s", "${aptDir.absolutePath}"
67 ]
68
69 javaCompileTask.doFirst {
70 aptDir.mkdirs()
71 }
72 }
73
74
75 // Project version injection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76 versionInjection {
77 into( 'org.hibernate.annotations.common.Version', 'getVersionString' )
78 }
79
80 jar {
81 manifest = osgiManifest { manifest ->
82 mainAttributes(
83 'Main-Class': 'org.hibernate.annotations.common.Version'
84 )
85 // See https://discuss.gradle.org/t/balancing-deprecation-of-sourcesetoutput-classesdir-and-other-parts-of-gradle-that-only-accept-a-dir-file/25283
86 classesDir = sourceSets.main.output.classesDir
87 classpath = configurations.runtime
88
89 instruction 'Bundle-Vendor', 'Hibernate.org'
90
91 // Java 9 module name
92 instruction 'Automatic-Module-Name', 'org.hibernate.commons.annotations'
93
94 OsgiManifestPackagingInfo.buildInfo( project ).applyTo( manifest )
95
96 instruction 'Implementation-Url', 'http://hibernate.org'
97 instruction 'Implementation-Version', version
98 instruction 'Implementation-Vendor', 'Hibernate.org'
99 instruction 'Implementation-Vendor-Id', 'org.hibernate'
100 }
101 }
102
103 // publishing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
105 task sourceJar(type: Jar) {
106 from sourceSets.main.allJava
107 }
108
109 publishing {
110 publications {
111 mavenJava(MavenPublication) {
112 from components.java
113
114 artifact sourceJar {
115 classifier 'sources'
116 }
117
118 pom {
119 name = 'Hibernate Commons Annotations'
120 description = 'Common reflection code used in support of annotation processing'
121 url = 'http://hibernate.org'
122
123 organization {
124 name = 'Hibernate.org'
125 url = 'http://hibernate.org'
126 }
127
128 licenses {
129 license {
130 name = 'GNU Library General Public License v2.1 or later'
131 url = 'http://www.opensource.org/licenses/LGPL-2.1'
132 comments = 'See discussion at http://hibernate.org/community/license/ for more details.'
133 distribution = 'repo'
134 }
135 }
136
137 scm {
138 url = 'http://github.com/hibernate/hibernate-commons-annotations'
139 connection = 'scm:git:http://github.com/hibernate/hibernate-commons-annotations.git'
140 developerConnection = 'scm:git:git@github.com:hibernate/hibernate-commons-annotations.git'
141 }
142
143 issueManagement {
144 system = 'jira'
145 url = 'https://hibernate.atlassian.net/browse/HCANN'
146 }
147
148 developers {
149 developer {
150 id = 'hibernate-team'
151 name = 'The Hibernate Development Team'
152 organization = 'Hibernate.org'
153 organizationUrl = 'http://hibernate.org'
154 }
155 }
156 }
157 }
158 }
159
160 repositories {
161 maven {
162 if ( version.endsWith( 'SNAPSHOT' ) ) {
163 name 'jboss-snapshots-repository'
164 url 'https://repository.jboss.org/nexus/content/repositories/snapshots'
165 }
166 else {
167 name 'jboss-releases-repository'
168 url 'https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/'
169 }
170 }
171 }
172 }
173
174 wrapper {
175 distributionType = Wrapper.DistributionType.ALL
176 }
177
178
179 // OSGi manifest helpers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
180
181 class OsgiManifestPackagingInfo {
182 private String[] exportPackageInstructions;
183 private String[] privatePackageInstructions;
184
185 String[] getExportPackageInstructions() {
186 return exportPackageInstructions
187 }
188
189 String[] getPrivatePackageInstructions() {
190 return privatePackageInstructions
191 }
192
193 public static OsgiManifestPackagingInfo buildInfo(Project project) {
194 final String exportPackageVersion = project.version.replaceAll( "-SNAPSHOT", "" )
195 .replaceAll( ".Final-redhat-", "DO_NOT_REPLACE" )
196 .replaceAll( ".Final", "" )
197 .replaceAll( "DO_NOT_REPLACE", ".Final-redhat-" );
198
199 final Set<String> exportPackageInstructionSet = new HashSet<String>()
200 final Set<String> privatePackageInstructionSet = new HashSet<String>()
201
202 final SourceDirectorySet sourceDirectorySet = project.sourceSets.main.java;
203 sourceDirectorySet.each { javaSrcFile ->
204 final String packageName = determinePackageName( sourceDirectorySet, javaSrcFile );
205 if ( packageName.endsWith( ".internal" )
206 || packageName.contains( ".internal." ) ) {
207 privatePackageInstructionSet.add( packageName );
208 }
209 else {
210 exportPackageInstructionSet.add( packageName + ";version=\"" + exportPackageVersion + "\"" );
211 }
212 }
213
214 return new OsgiManifestPackagingInfo(
215 exportPackageInstructionSet.toArray( new String[ exportPackageInstructionSet.size() ] ),
216 privatePackageInstructionSet.toArray( new String[ privatePackageInstructionSet.size() ] )
217 );
218 }
219
220 private static String determinePackageName(SourceDirectorySet sourceDirectorySet, File javaFile) {
221 final javaFileAbsolutePath = javaFile.absolutePath;
222 for ( File sourceDirectory : sourceDirectorySet.srcDirs ) {
223 final String sourceDirectoryAbsolutePath = sourceDirectory.absolutePath;
224 if ( javaFileAbsolutePath.startsWith( sourceDirectoryAbsolutePath ) ) {
225 final String javaFileRelativePath = javaFileAbsolutePath.substring(
226 sourceDirectoryAbsolutePath.length() + 1,
227 javaFileAbsolutePath.lastIndexOf( File.separator )
228 );
229 return javaFileRelativePath.replace( File.separator, "." );
230 }
231 }
232 throw new RuntimeException( "ugh" );
233 }
234
235 private OsgiManifestPackagingInfo(String[] exportPackageInstructions, String[] privatePackageInstructions) {
236 this.exportPackageInstructions = exportPackageInstructions
237 this.privatePackageInstructions = privatePackageInstructions
238 }
239
240 def applyTo(def manifest) {
241 if ( exportPackageInstructions.length > 0 ) {
242 manifest.instruction 'Export-Package', exportPackageInstructions
243 }
244 if ( privatePackageInstructions.length > 0 ) {
245 manifest.instruction 'Private-Package', privatePackageInstructions
246 }
247 }
248 }
00 Hibernate Annotations Changelog
11 ===============================
2
3 4.0.1.Final (29-11-2011)
4 ------------------------
5
6 ** Task
7 * [HCANN-43] - Move to JBoss Logging 3.1.0.CR2
8
9
10 4.0.0.Final (10-11-2011)
11 ------------------------
12
13 * [HCANN-41] - Upgrade JBoss Logging and align version numbers
14 * [HCANN-42] - Make sure project build with JDK 7
15
16
17 4.0.0.CR2 (31-08-2011)
18 ----------------------
19
20 * [HCANN-40] - Make JBoss logging annotation processor an optional dependency to avoid JDK bug uncovering in Core
21
22
23 4.0.0.CR1 (31-08-2011)
24 ----------------------
25
26 ** Bug
27 * [HCANN-37] - Upgrade pom.xml info on SCM (move to Git)
28
29 ** Improvement
30 * [HCANN-36] - Add lgpl.txt file to the repository
31 * [HCANN-39] - Move to new Maven groupId
32
33 ** New Feature
34 * [HCANN-38] - change to use jboss logging from slf4j
35
36 ** Task
37 * [HCANN-20] - Update pom to use the new distributationManagement information
38
239
340 3.2.0.GA (9-03-2010)
441 --------------------
643 ** New Feature
744 * [HCANN-5] - Decouple the reflection work from the metadata overriding facility
845
46
947 3.1.0.GA (20-08-2008)
1048 ----------------------
49
1150
1251 3.1.0.CR2 (23-07-2008)
1352 ----------------------
2463 * [HCANN-2] - Add POM
2564 * [HCANN-3] - Make build independent of Hibernate Core structure
2665
66
2767 3.0.0.GA (19-03-2007)
2868 ---------------------
2969
0 distributionBase=GRADLE_USER_HOME
1 distributionPath=wrapper/dists
2 distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
3 zipStoreBase=GRADLE_USER_HOME
4 zipStorePath=wrapper/dists
0 #!/usr/bin/env sh
1
2 ##############################################################################
3 ##
4 ## Gradle start up script for UN*X
5 ##
6 ##############################################################################
7
8 # Attempt to set APP_HOME
9 # Resolve links: $0 may be a link
10 PRG="$0"
11 # Need this for relative symlinks.
12 while [ -h "$PRG" ] ; do
13 ls=`ls -ld "$PRG"`
14 link=`expr "$ls" : '.*-> \(.*\)$'`
15 if expr "$link" : '/.*' > /dev/null; then
16 PRG="$link"
17 else
18 PRG=`dirname "$PRG"`"/$link"
19 fi
20 done
21 SAVED="`pwd`"
22 cd "`dirname \"$PRG\"`/" >/dev/null
23 APP_HOME="`pwd -P`"
24 cd "$SAVED" >/dev/null
25
26 APP_NAME="Gradle"
27 APP_BASE_NAME=`basename "$0"`
28
29 # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
30 DEFAULT_JVM_OPTS=""
31
32 # Use the maximum available, or set MAX_FD != -1 to use that value.
33 MAX_FD="maximum"
34
35 warn () {
36 echo "$*"
37 }
38
39 die () {
40 echo
41 echo "$*"
42 echo
43 exit 1
44 }
45
46 # OS specific support (must be 'true' or 'false').
47 cygwin=false
48 msys=false
49 darwin=false
50 nonstop=false
51 case "`uname`" in
52 CYGWIN* )
53 cygwin=true
54 ;;
55 Darwin* )
56 darwin=true
57 ;;
58 MINGW* )
59 msys=true
60 ;;
61 NONSTOP* )
62 nonstop=true
63 ;;
64 esac
65
66 CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
67
68 # Determine the Java command to use to start the JVM.
69 if [ -n "$JAVA_HOME" ] ; then
70 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
71 # IBM's JDK on AIX uses strange locations for the executables
72 JAVACMD="$JAVA_HOME/jre/sh/java"
73 else
74 JAVACMD="$JAVA_HOME/bin/java"
75 fi
76 if [ ! -x "$JAVACMD" ] ; then
77 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
78
79 Please set the JAVA_HOME variable in your environment to match the
80 location of your Java installation."
81 fi
82 else
83 JAVACMD="java"
84 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
85
86 Please set the JAVA_HOME variable in your environment to match the
87 location of your Java installation."
88 fi
89
90 # Increase the maximum file descriptors if we can.
91 if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
92 MAX_FD_LIMIT=`ulimit -H -n`
93 if [ $? -eq 0 ] ; then
94 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
95 MAX_FD="$MAX_FD_LIMIT"
96 fi
97 ulimit -n $MAX_FD
98 if [ $? -ne 0 ] ; then
99 warn "Could not set maximum file descriptor limit: $MAX_FD"
100 fi
101 else
102 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
103 fi
104 fi
105
106 # For Darwin, add options to specify how the application appears in the dock
107 if $darwin; then
108 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
109 fi
110
111 # For Cygwin, switch paths to Windows format before running java
112 if $cygwin ; then
113 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
114 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
115 JAVACMD=`cygpath --unix "$JAVACMD"`
116
117 # We build the pattern for arguments to be converted via cygpath
118 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
119 SEP=""
120 for dir in $ROOTDIRSRAW ; do
121 ROOTDIRS="$ROOTDIRS$SEP$dir"
122 SEP="|"
123 done
124 OURCYGPATTERN="(^($ROOTDIRS))"
125 # Add a user-defined pattern to the cygpath arguments
126 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
127 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
128 fi
129 # Now convert the arguments - kludge to limit ourselves to /bin/sh
130 i=0
131 for arg in "$@" ; do
132 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
133 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
134
135 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
136 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
137 else
138 eval `echo args$i`="\"$arg\""
139 fi
140 i=$((i+1))
141 done
142 case $i in
143 (0) set -- ;;
144 (1) set -- "$args0" ;;
145 (2) set -- "$args0" "$args1" ;;
146 (3) set -- "$args0" "$args1" "$args2" ;;
147 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
148 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
149 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
150 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
151 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
152 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
153 esac
154 fi
155
156 # Escape application args
157 save () {
158 for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
159 echo " "
160 }
161 APP_ARGS=$(save "$@")
162
163 # Collect all arguments for the java command, following the shell quoting and substitution rules
164 eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
165
166 # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
167 if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
168 cd "$(dirname "$0")"
169 fi
170
171 exec "$JAVACMD" "$@"
0 @if "%DEBUG%" == "" @echo off
1 @rem ##########################################################################
2 @rem
3 @rem Gradle startup script for Windows
4 @rem
5 @rem ##########################################################################
6
7 @rem Set local scope for the variables with windows NT shell
8 if "%OS%"=="Windows_NT" setlocal
9
10 set DIRNAME=%~dp0
11 if "%DIRNAME%" == "" set DIRNAME=.
12 set APP_BASE_NAME=%~n0
13 set APP_HOME=%DIRNAME%
14
15 @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
16 set DEFAULT_JVM_OPTS=
17
18 @rem Find java.exe
19 if defined JAVA_HOME goto findJavaFromJavaHome
20
21 set JAVA_EXE=java.exe
22 %JAVA_EXE% -version >NUL 2>&1
23 if "%ERRORLEVEL%" == "0" goto init
24
25 echo.
26 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
27 echo.
28 echo Please set the JAVA_HOME variable in your environment to match the
29 echo location of your Java installation.
30
31 goto fail
32
33 :findJavaFromJavaHome
34 set JAVA_HOME=%JAVA_HOME:"=%
35 set JAVA_EXE=%JAVA_HOME%/bin/java.exe
36
37 if exist "%JAVA_EXE%" goto init
38
39 echo.
40 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
41 echo.
42 echo Please set the JAVA_HOME variable in your environment to match the
43 echo location of your Java installation.
44
45 goto fail
46
47 :init
48 @rem Get command-line arguments, handling Windows variants
49
50 if not "%OS%" == "Windows_NT" goto win9xME_args
51
52 :win9xME_args
53 @rem Slurp the command line arguments.
54 set CMD_LINE_ARGS=
55 set _SKIP=2
56
57 :win9xME_args_slurp
58 if "x%~1" == "x" goto execute
59
60 set CMD_LINE_ARGS=%*
61
62 :execute
63 @rem Setup the command line
64
65 set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
66
67 @rem Execute Gradle
68 "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
69
70 :end
71 @rem End local scope for the variables with windows NT shell
72 if "%ERRORLEVEL%"=="0" goto mainEnd
73
74 :fail
75 rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
76 rem the _cmd.exe /c_ return code!
77 if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
78 exit /b 1
79
80 :mainEnd
81 if "%OS%"=="Windows_NT" endlocal
82
83 :omega
0 GNU LESSER GENERAL PUBLIC LICENSE
1 Version 2.1, February 1999
2
3 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
4 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5 Everyone is permitted to copy and distribute verbatim copies
6 of this license document, but changing it is not allowed.
7
8 [This is the first released version of the Lesser GPL. It also counts
9 as the successor of the GNU Library Public License, version 2, hence
10 the version number 2.1.]
11
12 Preamble
13
14 The licenses for most software are designed to take away your
15 freedom to share and change it. By contrast, the GNU General Public
16 Licenses are intended to guarantee your freedom to share and change
17 free software--to make sure the software is free for all its users.
18
19 This license, the Lesser General Public License, applies to some
20 specially designated software packages--typically libraries--of the
21 Free Software Foundation and other authors who decide to use it. You
22 can use it too, but we suggest you first think carefully about whether
23 this license or the ordinary General Public License is the better
24 strategy to use in any particular case, based on the explanations below.
25
26 When we speak of free software, we are referring to freedom of use,
27 not price. Our General Public Licenses are designed to make sure that
28 you have the freedom to distribute copies of free software (and charge
29 for this service if you wish); that you receive source code or can get
30 it if you want it; that you can change the software and use pieces of
31 it in new free programs; and that you are informed that you can do
32 these things.
33
34 To protect your rights, we need to make restrictions that forbid
35 distributors to deny you these rights or to ask you to surrender these
36 rights. These restrictions translate to certain responsibilities for
37 you if you distribute copies of the library or if you modify it.
38
39 For example, if you distribute copies of the library, whether gratis
40 or for a fee, you must give the recipients all the rights that we gave
41 you. You must make sure that they, too, receive or can get the source
42 code. If you link other code with the library, you must provide
43 complete object files to the recipients, so that they can relink them
44 with the library after making changes to the library and recompiling
45 it. And you must show them these terms so they know their rights.
46
47 We protect your rights with a two-step method: (1) we copyright the
48 library, and (2) we offer you this license, which gives you legal
49 permission to copy, distribute and/or modify the library.
50
51 To protect each distributor, we want to make it very clear that
52 there is no warranty for the free library. Also, if the library is
53 modified by someone else and passed on, the recipients should know
54 that what they have is not the original version, so that the original
55 author's reputation will not be affected by problems that might be
56 introduced by others.
57
58 Finally, software patents pose a constant threat to the existence of
59 any free program. We wish to make sure that a company cannot
60 effectively restrict the users of a free program by obtaining a
61 restrictive license from a patent holder. Therefore, we insist that
62 any patent license obtained for a version of the library must be
63 consistent with the full freedom of use specified in this license.
64
65 Most GNU software, including some libraries, is covered by the
66 ordinary GNU General Public License. This license, the GNU Lesser
67 General Public License, applies to certain designated libraries, and
68 is quite different from the ordinary General Public License. We use
69 this license for certain libraries in order to permit linking those
70 libraries into non-free programs.
71
72 When a program is linked with a library, whether statically or using
73 a shared library, the combination of the two is legally speaking a
74 combined work, a derivative of the original library. The ordinary
75 General Public License therefore permits such linking only if the
76 entire combination fits its criteria of freedom. The Lesser General
77 Public License permits more lax criteria for linking other code with
78 the library.
79
80 We call this license the "Lesser" General Public License because it
81 does Less to protect the user's freedom than the ordinary General
82 Public License. It also provides other free software developers Less
83 of an advantage over competing non-free programs. These disadvantages
84 are the reason we use the ordinary General Public License for many
85 libraries. However, the Lesser license provides advantages in certain
86 special circumstances.
87
88 For example, on rare occasions, there may be a special need to
89 encourage the widest possible use of a certain library, so that it becomes
90 a de-facto standard. To achieve this, non-free programs must be
91 allowed to use the library. A more frequent case is that a free
92 library does the same job as widely used non-free libraries. In this
93 case, there is little to gain by limiting the free library to free
94 software only, so we use the Lesser General Public License.
95
96 In other cases, permission to use a particular library in non-free
97 programs enables a greater number of people to use a large body of
98 free software. For example, permission to use the GNU C Library in
99 non-free programs enables many more people to use the whole GNU
100 operating system, as well as its variant, the GNU/Linux operating
101 system.
102
103 Although the Lesser General Public License is Less protective of the
104 users' freedom, it does ensure that the user of a program that is
105 linked with the Library has the freedom and the wherewithal to run
106 that program using a modified version of the Library.
107
108 The precise terms and conditions for copying, distribution and
109 modification follow. Pay close attention to the difference between a
110 "work based on the library" and a "work that uses the library". The
111 former contains code derived from the library, whereas the latter must
112 be combined with the library in order to run.
113
114 GNU LESSER GENERAL PUBLIC LICENSE
115 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
116
117 0. This License Agreement applies to any software library or other
118 program which contains a notice placed by the copyright holder or
119 other authorized party saying it may be distributed under the terms of
120 this Lesser General Public License (also called "this License").
121 Each licensee is addressed as "you".
122
123 A "library" means a collection of software functions and/or data
124 prepared so as to be conveniently linked with application programs
125 (which use some of those functions and data) to form executables.
126
127 The "Library", below, refers to any such software library or work
128 which has been distributed under these terms. A "work based on the
129 Library" means either the Library or any derivative work under
130 copyright law: that is to say, a work containing the Library or a
131 portion of it, either verbatim or with modifications and/or translated
132 straightforwardly into another language. (Hereinafter, translation is
133 included without limitation in the term "modification".)
134
135 "Source code" for a work means the preferred form of the work for
136 making modifications to it. For a library, complete source code means
137 all the source code for all modules it contains, plus any associated
138 interface definition files, plus the scripts used to control compilation
139 and installation of the library.
140
141 Activities other than copying, distribution and modification are not
142 covered by this License; they are outside its scope. The act of
143 running a program using the Library is not restricted, and output from
144 such a program is covered only if its contents constitute a work based
145 on the Library (independent of the use of the Library in a tool for
146 writing it). Whether that is true depends on what the Library does
147 and what the program that uses the Library does.
148
149 1. You may copy and distribute verbatim copies of the Library's
150 complete source code as you receive it, in any medium, provided that
151 you conspicuously and appropriately publish on each copy an
152 appropriate copyright notice and disclaimer of warranty; keep intact
153 all the notices that refer to this License and to the absence of any
154 warranty; and distribute a copy of this License along with the
155 Library.
156
157 You may charge a fee for the physical act of transferring a copy,
158 and you may at your option offer warranty protection in exchange for a
159 fee.
160
161 2. You may modify your copy or copies of the Library or any portion
162 of it, thus forming a work based on the Library, and copy and
163 distribute such modifications or work under the terms of Section 1
164 above, provided that you also meet all of these conditions:
165
166 a) The modified work must itself be a software library.
167
168 b) You must cause the files modified to carry prominent notices
169 stating that you changed the files and the date of any change.
170
171 c) You must cause the whole of the work to be licensed at no
172 charge to all third parties under the terms of this License.
173
174 d) If a facility in the modified Library refers to a function or a
175 table of data to be supplied by an application program that uses
176 the facility, other than as an argument passed when the facility
177 is invoked, then you must make a good faith effort to ensure that,
178 in the event an application does not supply such function or
179 table, the facility still operates, and performs whatever part of
180 its purpose remains meaningful.
181
182 (For example, a function in a library to compute square roots has
183 a purpose that is entirely well-defined independent of the
184 application. Therefore, Subsection 2d requires that any
185 application-supplied function or table used by this function must
186 be optional: if the application does not supply it, the square
187 root function must still compute square roots.)
188
189 These requirements apply to the modified work as a whole. If
190 identifiable sections of that work are not derived from the Library,
191 and can be reasonably considered independent and separate works in
192 themselves, then this License, and its terms, do not apply to those
193 sections when you distribute them as separate works. But when you
194 distribute the same sections as part of a whole which is a work based
195 on the Library, the distribution of the whole must be on the terms of
196 this License, whose permissions for other licensees extend to the
197 entire whole, and thus to each and every part regardless of who wrote
198 it.
199
200 Thus, it is not the intent of this section to claim rights or contest
201 your rights to work written entirely by you; rather, the intent is to
202 exercise the right to control the distribution of derivative or
203 collective works based on the Library.
204
205 In addition, mere aggregation of another work not based on the Library
206 with the Library (or with a work based on the Library) on a volume of
207 a storage or distribution medium does not bring the other work under
208 the scope of this License.
209
210 3. You may opt to apply the terms of the ordinary GNU General Public
211 License instead of this License to a given copy of the Library. To do
212 this, you must alter all the notices that refer to this License, so
213 that they refer to the ordinary GNU General Public License, version 2,
214 instead of to this License. (If a newer version than version 2 of the
215 ordinary GNU General Public License has appeared, then you can specify
216 that version instead if you wish.) Do not make any other change in
217 these notices.
218
219 Once this change is made in a given copy, it is irreversible for
220 that copy, so the ordinary GNU General Public License applies to all
221 subsequent copies and derivative works made from that copy.
222
223 This option is useful when you wish to copy part of the code of
224 the Library into a program that is not a library.
225
226 4. You may copy and distribute the Library (or a portion or
227 derivative of it, under Section 2) in object code or executable form
228 under the terms of Sections 1 and 2 above provided that you accompany
229 it with the complete corresponding machine-readable source code, which
230 must be distributed under the terms of Sections 1 and 2 above on a
231 medium customarily used for software interchange.
232
233 If distribution of object code is made by offering access to copy
234 from a designated place, then offering equivalent access to copy the
235 source code from the same place satisfies the requirement to
236 distribute the source code, even though third parties are not
237 compelled to copy the source along with the object code.
238
239 5. A program that contains no derivative of any portion of the
240 Library, but is designed to work with the Library by being compiled or
241 linked with it, is called a "work that uses the Library". Such a
242 work, in isolation, is not a derivative work of the Library, and
243 therefore falls outside the scope of this License.
244
245 However, linking a "work that uses the Library" with the Library
246 creates an executable that is a derivative of the Library (because it
247 contains portions of the Library), rather than a "work that uses the
248 library". The executable is therefore covered by this License.
249 Section 6 states terms for distribution of such executables.
250
251 When a "work that uses the Library" uses material from a header file
252 that is part of the Library, the object code for the work may be a
253 derivative work of the Library even though the source code is not.
254 Whether this is true is especially significant if the work can be
255 linked without the Library, or if the work is itself a library. The
256 threshold for this to be true is not precisely defined by law.
257
258 If such an object file uses only numerical parameters, data
259 structure layouts and accessors, and small macros and small inline
260 functions (ten lines or less in length), then the use of the object
261 file is unrestricted, regardless of whether it is legally a derivative
262 work. (Executables containing this object code plus portions of the
263 Library will still fall under Section 6.)
264
265 Otherwise, if the work is a derivative of the Library, you may
266 distribute the object code for the work under the terms of Section 6.
267 Any executables containing that work also fall under Section 6,
268 whether or not they are linked directly with the Library itself.
269
270 6. As an exception to the Sections above, you may also combine or
271 link a "work that uses the Library" with the Library to produce a
272 work containing portions of the Library, and distribute that work
273 under terms of your choice, provided that the terms permit
274 modification of the work for the customer's own use and reverse
275 engineering for debugging such modifications.
276
277 You must give prominent notice with each copy of the work that the
278 Library is used in it and that the Library and its use are covered by
279 this License. You must supply a copy of this License. If the work
280 during execution displays copyright notices, you must include the
281 copyright notice for the Library among them, as well as a reference
282 directing the user to the copy of this License. Also, you must do one
283 of these things:
284
285 a) Accompany the work with the complete corresponding
286 machine-readable source code for the Library including whatever
287 changes were used in the work (which must be distributed under
288 Sections 1 and 2 above); and, if the work is an executable linked
289 with the Library, with the complete machine-readable "work that
290 uses the Library", as object code and/or source code, so that the
291 user can modify the Library and then relink to produce a modified
292 executable containing the modified Library. (It is understood
293 that the user who changes the contents of definitions files in the
294 Library will not necessarily be able to recompile the application
295 to use the modified definitions.)
296
297 b) Use a suitable shared library mechanism for linking with the
298 Library. A suitable mechanism is one that (1) uses at run time a
299 copy of the library already present on the user's computer system,
300 rather than copying library functions into the executable, and (2)
301 will operate properly with a modified version of the library, if
302 the user installs one, as long as the modified version is
303 interface-compatible with the version that the work was made with.
304
305 c) Accompany the work with a written offer, valid for at
306 least three years, to give the same user the materials
307 specified in Subsection 6a, above, for a charge no more
308 than the cost of performing this distribution.
309
310 d) If distribution of the work is made by offering access to copy
311 from a designated place, offer equivalent access to copy the above
312 specified materials from the same place.
313
314 e) Verify that the user has already received a copy of these
315 materials or that you have already sent this user a copy.
316
317 For an executable, the required form of the "work that uses the
318 Library" must include any data and utility programs needed for
319 reproducing the executable from it. However, as a special exception,
320 the materials to be distributed need not include anything that is
321 normally distributed (in either source or binary form) with the major
322 components (compiler, kernel, and so on) of the operating system on
323 which the executable runs, unless that component itself accompanies
324 the executable.
325
326 It may happen that this requirement contradicts the license
327 restrictions of other proprietary libraries that do not normally
328 accompany the operating system. Such a contradiction means you cannot
329 use both them and the Library together in an executable that you
330 distribute.
331
332 7. You may place library facilities that are a work based on the
333 Library side-by-side in a single library together with other library
334 facilities not covered by this License, and distribute such a combined
335 library, provided that the separate distribution of the work based on
336 the Library and of the other library facilities is otherwise
337 permitted, and provided that you do these two things:
338
339 a) Accompany the combined library with a copy of the same work
340 based on the Library, uncombined with any other library
341 facilities. This must be distributed under the terms of the
342 Sections above.
343
344 b) Give prominent notice with the combined library of the fact
345 that part of it is a work based on the Library, and explaining
346 where to find the accompanying uncombined form of the same work.
347
348 8. You may not copy, modify, sublicense, link with, or distribute
349 the Library except as expressly provided under this License. Any
350 attempt otherwise to copy, modify, sublicense, link with, or
351 distribute the Library is void, and will automatically terminate your
352 rights under this License. However, parties who have received copies,
353 or rights, from you under this License will not have their licenses
354 terminated so long as such parties remain in full compliance.
355
356 9. You are not required to accept this License, since you have not
357 signed it. However, nothing else grants you permission to modify or
358 distribute the Library or its derivative works. These actions are
359 prohibited by law if you do not accept this License. Therefore, by
360 modifying or distributing the Library (or any work based on the
361 Library), you indicate your acceptance of this License to do so, and
362 all its terms and conditions for copying, distributing or modifying
363 the Library or works based on it.
364
365 10. Each time you redistribute the Library (or any work based on the
366 Library), the recipient automatically receives a license from the
367 original licensor to copy, distribute, link with or modify the Library
368 subject to these terms and conditions. You may not impose any further
369 restrictions on the recipients' exercise of the rights granted herein.
370 You are not responsible for enforcing compliance by third parties with
371 this License.
372
373 11. If, as a consequence of a court judgment or allegation of patent
374 infringement or for any other reason (not limited to patent issues),
375 conditions are imposed on you (whether by court order, agreement or
376 otherwise) that contradict the conditions of this License, they do not
377 excuse you from the conditions of this License. If you cannot
378 distribute so as to satisfy simultaneously your obligations under this
379 License and any other pertinent obligations, then as a consequence you
380 may not distribute the Library at all. For example, if a patent
381 license would not permit royalty-free redistribution of the Library by
382 all those who receive copies directly or indirectly through you, then
383 the only way you could satisfy both it and this License would be to
384 refrain entirely from distribution of the Library.
385
386 If any portion of this section is held invalid or unenforceable under any
387 particular circumstance, the balance of the section is intended to apply,
388 and the section as a whole is intended to apply in other circumstances.
389
390 It is not the purpose of this section to induce you to infringe any
391 patents or other property right claims or to contest validity of any
392 such claims; this section has the sole purpose of protecting the
393 integrity of the free software distribution system which is
394 implemented by public license practices. Many people have made
395 generous contributions to the wide range of software distributed
396 through that system in reliance on consistent application of that
397 system; it is up to the author/donor to decide if he or she is willing
398 to distribute software through any other system and a licensee cannot
399 impose that choice.
400
401 This section is intended to make thoroughly clear what is believed to
402 be a consequence of the rest of this License.
403
404 12. If the distribution and/or use of the Library is restricted in
405 certain countries either by patents or by copyrighted interfaces, the
406 original copyright holder who places the Library under this License may add
407 an explicit geographical distribution limitation excluding those countries,
408 so that distribution is permitted only in or among countries not thus
409 excluded. In such case, this License incorporates the limitation as if
410 written in the body of this License.
411
412 13. The Free Software Foundation may publish revised and/or new
413 versions of the Lesser General Public License from time to time.
414 Such new versions will be similar in spirit to the present version,
415 but may differ in detail to address new problems or concerns.
416
417 Each version is given a distinguishing version number. If the Library
418 specifies a version number of this License which applies to it and
419 "any later version", you have the option of following the terms and
420 conditions either of that version or of any later version published by
421 the Free Software Foundation. If the Library does not specify a
422 license version number, you may choose any version ever published by
423 the Free Software Foundation.
424
425 14. If you wish to incorporate parts of the Library into other free
426 programs whose distribution conditions are incompatible with these,
427 write to the author to ask for permission. For software which is
428 copyrighted by the Free Software Foundation, write to the Free
429 Software Foundation; we sometimes make exceptions for this. Our
430 decision will be guided by the two goals of preserving the free status
431 of all derivatives of our free software and of promoting the sharing
432 and reuse of software generally.
433
434 NO WARRANTY
435
436 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
437 WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
438 EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
439 OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
440 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
441 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
442 PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
443 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
444 THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
445
446 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
447 WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
448 AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
449 FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
450 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
451 LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
452 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
453 FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
454 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
455 DAMAGES.
456
457 END OF TERMS AND CONDITIONS
458
459 How to Apply These Terms to Your New Libraries
460
461 If you develop a new library, and you want it to be of the greatest
462 possible use to the public, we recommend making it free software that
463 everyone can redistribute and change. You can do so by permitting
464 redistribution under these terms (or, alternatively, under the terms of the
465 ordinary General Public License).
466
467 To apply these terms, attach the following notices to the library. It is
468 safest to attach them to the start of each source file to most effectively
469 convey the exclusion of warranty; and each file should have at least the
470 "copyright" line and a pointer to where the full notice is found.
471
472 <one line to give the library's name and a brief idea of what it does.>
473 Copyright (C) <year> <name of author>
474
475 This library is free software; you can redistribute it and/or
476 modify it under the terms of the GNU Lesser General Public
477 License as published by the Free Software Foundation; either
478 version 2.1 of the License, or (at your option) any later version.
479
480 This library is distributed in the hope that it will be useful,
481 but WITHOUT ANY WARRANTY; without even the implied warranty of
482 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
483 Lesser General Public License for more details.
484
485 You should have received a copy of the GNU Lesser General Public
486 License along with this library; if not, write to the Free Software
487 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
488
489 Also add information on how to contact you by electronic and paper mail.
490
491 You should also get your employer (if you work as a programmer) or your
492 school, if any, to sign a "copyright disclaimer" for the library, if
493 necessary. Here is a sample; alter the names:
494
495 Yoyodyne, Inc., hereby disclaims all copyright interest in the
496 library `Frob' (a library for tweaking knobs) written by James Random Hacker.
497
498 <signature of Ty Coon>, 1 April 1990
499 Ty Coon, President of Vice
500
501 That's all there is to it!
+0
-163
pom.xml less more
0 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1
2 <modelVersion>4.0.0</modelVersion>
3
4 <groupId>org.hibernate</groupId>
5 <artifactId>hibernate-commons-annotations</artifactId>
6 <packaging>jar</packaging>
7 <version>3.2.0.Final</version>
8
9 <name>Hibernate Commons Annotations</name>
10 <description>Common reflection code used in support of annotation processing</description>
11 <url>http://hibernate.org</url>
12 <inceptionYear>2005</inceptionYear>
13
14 <organization>
15 <name>Hibernate.org</name>
16 <url>http://hibernate.org</url>
17 </organization>
18
19 <licenses>
20 <license>
21 <name>GNU LESSER GENERAL PUBLIC LICENSE</name>
22 <url>http://www.gnu.org/licenses/lgpl.txt</url>
23 </license>
24 </licenses>
25
26 <developers>
27 <developer>
28 <id>epbernard</id>
29 <name>Emmanuel Bernard</name>
30 <email>emmanuel@hibernate.org</email>
31 <organization>JBoss, a division of Red Hat</organization>
32 <url>http://in.relation.to/Bloggers/Emmanuel</url>
33 </developer>
34 </developers>
35
36 <mailingLists>
37 <mailingList>
38 <name>Hibernate Announcements</name>
39 <post>hibernate-announce@lists.jboss.org</post>
40 <subscribe>https://lists.jboss.org/mailman/listinfo/hibernate-announce</subscribe>
41 <unsubscribe>https://lists.jboss.org/mailman/listinfo/hibernate-announce</unsubscribe>
42 <archive>http://lists.jboss.org/pipermail/hibernate-dev/</archive>
43 </mailingList>
44 <mailingList>
45 <name>Hibernate Commit Notificatons</name>
46 <post>hibernate-commits@lists.jboss.org</post>
47 <subscribe>https://lists.jboss.org/mailman/listinfo/hibernate-commits</subscribe>
48 <unsubscribe>https://lists.jboss.org/mailman/listinfo/hibernate-commits</unsubscribe>
49 <archive>http://lists.jboss.org/pipermail/hibernate-commits/</archive>
50 </mailingList>
51 <mailingList>
52 <name>Hibernate Developers</name>
53 <post>hibernate-dev@lists.jboss.org</post>
54 <subscribe>https://lists.jboss.org/mailman/listinfo/hibernate-dev</subscribe>
55 <unsubscribe>https://lists.jboss.org/mailman/listinfo/hibernate-dev</unsubscribe>
56 <archive>http://lists.jboss.org/pipermail/hibernate-dev/</archive>
57 <otherArchives>
58 <otherArchive>http://www.mail-archive.com/hibernate-dev%40lists.jboss.org/index.html</otherArchive>
59 </otherArchives>
60 </mailingList>
61 <mailingList>
62 <name>Hibernate Issue Notifications</name>
63 <post>hibernate-issues@lists.jboss.org</post>
64 <subscribe>https://lists.jboss.org/mailman/listinfo/hibernate-issues</subscribe>
65 <unsubscribe>https://lists.jboss.org/mailman/listinfo/hibernate-issues</unsubscribe>
66 <archive>http://lists.jboss.org/pipermail/hibernate-issues/</archive>
67 </mailingList>
68 </mailingLists>
69
70 <issueManagement>
71 <system>jira</system>
72 <url>http://opensource.atlassian.com/projects/hibernate/browse/HCANN</url>
73 </issueManagement>
74
75 <scm>
76 <connection>scm:svn:https://svn.jboss.org/repos/hibernate/commons-annotations/tags/3.2.0.Final</connection>
77 <developerConnection>scm:svn:https://svn.jboss.org/repos/hibernate/commons-annotations/tags/3.2.0.Final</developerConnection>
78 <url>https://svn.jboss.org/repos/hibernate/commons-annotations/tags/3.2.0.Final</url>
79 </scm>
80
81 <dependencies>
82 <dependency>
83 <groupId>org.slf4j</groupId>
84 <artifactId>slf4j-api</artifactId>
85 </dependency>
86 <!-- test-scoped dependencies for common testing dependencies -->
87 <dependency>
88 <groupId>junit</groupId>
89 <artifactId>junit</artifactId>
90 <version>3.8.1</version>
91 <scope>test</scope>
92 </dependency>
93 <dependency>
94 <groupId>org.slf4j</groupId>
95 <artifactId>jcl-over-slf4j</artifactId>
96 <version>${slf4jVersion}</version>
97 <scope>test</scope>
98 </dependency>
99 <dependency>
100 <groupId>org.slf4j</groupId>
101 <artifactId>slf4j-log4j12</artifactId>
102 <version>${slf4jVersion}</version>
103 <scope>test</scope>
104 </dependency>
105 <dependency>
106 <groupId>commons-logging</groupId>
107 <artifactId>commons-logging</artifactId>
108 <version>99.0-does-not-exist</version>
109 <scope>test</scope>
110 </dependency>
111 <dependency>
112 <groupId>commons-logging</groupId>
113 <artifactId>commons-logging-api</artifactId>
114 <version>99.0-does-not-exist</version>
115 <scope>test</scope>
116 </dependency>
117 <!-- / test-scoped dependencies for common testing dependencies -->
118 </dependencies>
119
120 <dependencyManagement>
121 <dependencies>
122 <dependency>
123 <groupId>org.slf4j</groupId>
124 <artifactId>slf4j-api</artifactId>
125 <version>${slf4jVersion}</version>
126 </dependency>
127 </dependencies>
128 </dependencyManagement>
129
130 <distributionManagement>
131 <repository>
132 <!-- Copy the dist to the local checkout of the JBoss maven2 repo ${maven.repository.root} -->
133 <!-- It is anticipated that ${maven.repository.root} be set in user's settings.xml -->
134 <!-- todo : replace this with direct svn access once the svnkit providers are available -->
135 <id>repository.jboss.org</id>
136 <url>file://${maven.repository.root}</url>
137 </repository>
138 <snapshotRepository>
139 <id>snapshots.jboss.org</id>
140 <name>JBoss Snapshot Repository</name>
141 <url>dav:https://snapshots.jboss.org/maven2</url>
142 </snapshotRepository>
143 </distributionManagement>
144
145 <properties>
146 <slf4jVersion>1.5.8</slf4jVersion>
147 </properties>
148
149 <build>
150 <plugins>
151 <plugin>
152 <groupId>org.apache.maven.plugins</groupId>
153 <artifactId>maven-compiler-plugin</artifactId>
154 <configuration>
155 <source>1.5</source>
156 <target>1.5</target>
157 </configuration>
158 </plugin>
159 </plugins>
160 </build>
161
162 </project>
00 Hibernate Commons Annotations
11 ==================================================
2 Version: @version@, @releasedate@
32
43 Description
54 -----------
65
7 Hibernate Commons Annotations is a utility project used by annotations based
8 Hibernate sub-projects.
6 Hibernate Commons Annotations is a utility project used by several Hibernate projects;
7 as a user of Hibernate libraries you probably are not going to use this directly.
8
99 It's first scope is to support Java Generics type discovery.
1010 It's second scope is to support Java Annotations overriding through XML files
11 (mainly but not conceptually limited to)
11 (mainly but not conceptually limited to).
1212
13 Requirements
14 ------------
15 Since version 5.1 this project requires Java 8.
1316
1417 Instructions
1518 ------------
2225
2326 Latest Documentation:
2427
25 This project has no documentation per se, because of it's internal use focus.
28 This project has no documentation per se, because of its internal use focus.
2629 Please ask questions to the technical support forum.
2730
2831 Bug Reports:
2932
30 Hibernate JIRA (preferred)
31 hibernate-devel@lists.sourceforge.net
33 Hibernate JIRA (preferred): https://hibernate.atlassian.net
3234
33 Free Technical Support:
35 Or contact us via chat, mailing list, etc as described on:
3436
35 http://forum.hibernate.org (http://forum.hibernate.org/viewforum.php?f=9)
37 http://hibernate.org/community/
38
39 Free, volunteers based technical support:
40
41 https://discourse.hibernate.org
3642
3743
3844 Notes
4147 If you want to contribute, go to http://www.hibernate.org/
4248
4349 This software and its documentation are distributed under the terms of the
44 FSF Lesser Gnu Public License (see lgpl.txt).
50 GNU Lesser General Public License v2.1 or later (see lgpl.txt).
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6 if ( !JavaVersion.current().java8Compatible ) {
7 throw new GradleException( "Gradle must be run with Java 8" )
8 }
9
10 enableFeaturePreview('STABLE_PUBLISHING')
11
12 rootProject.name = 'hibernate-commons-annotations'
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common;
247
25 import org.slf4j.LoggerFactory;
26 import org.slf4j.Logger;
8 import org.hibernate.annotations.common.util.impl.Log;
9 import org.hibernate.annotations.common.util.impl.LoggerFactory;
2710
2811
2912 /**
3013 * Indicates failure of an assertion: a possible bug in Hibernate.
31 * <p/>
32 * TODO : Copy from Hibernate Core, do some mutualization here?
3314 *
3415 * @author Gavin King
3516 * @auhor Emmanuel Bernard
17 * @deprecated This is an old class which will be removed; this project no longer uses it. No specific alternative is recommended.
3618 */
19 @Deprecated
3720 public class AssertionFailure extends RuntimeException {
3821
39 private static final Logger log = LoggerFactory.getLogger(AssertionFailure.class);
40
41 private static final String MESSAGE = "an assertion failure occured (this may indicate a bug in Hibernate)";
22 private static final Log log = LoggerFactory.make( AssertionFailure.class.getName() );
4223
4324 public AssertionFailure(String s) {
4425 super(s);
45 log.error(MESSAGE, this);
26 log.assertionFailure( this );
4627 }
4728
4829 public AssertionFailure(String s, Throwable t) {
4930 super(s, t);
50 log.error(MESSAGE, t);
31 log.assertionFailure( this );
5132 }
52
5333 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
277
288 /**
299 * @author Emmanuel Bernard
3010 */
3111 public class Version {
32 public static final String VERSION = "3.2.0.Final";
33 private static Logger log = LoggerFactory.getLogger( Version.class );
34
35 static {
36 log.info( "Hibernate Commons Annotations {}", VERSION );
12 public static String getVersionString() {
13 return "[WORKING]";
3714 }
3815
3916 public static void touch() {
4017 }
18
19 public static void main(String[] args) {
20 System.out.println( "Hibernate Commons Annotations {" + getVersionString() + "}" );
21 }
4122 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.annotationfactory;
247
3720 * @author Paolo Perrotta
3821 * @author Davide Marchignoli
3922 */
40 public class AnnotationDescriptor {
23 public final class AnnotationDescriptor {
4124
4225 private final Class<? extends Annotation> type;
43
44 private final Map<String, Object> elements = new HashMap<String, Object>();
26 private Map<String, Object> elements;
4527
4628 public AnnotationDescriptor(Class<? extends Annotation> annotationType) {
4729 type = annotationType;
4830 }
4931
5032 public void setValue(String elementName, Object value) {
33 if ( elements == null ) {
34 elements = new HashMap<>( 4 ); //likely to be small
35 }
5136 elements.put( elementName, value );
5237 }
5338
5439 public Object valueOf(String elementName) {
55 return elements.get( elementName );
40 return elements == null ? null : elements.get( elementName );
5641 }
5742
5843 public boolean containsElement(String elementName) {
59 return elements.containsKey( elementName );
44 return elements == null ? false : elements.containsKey( elementName );
6045 }
6146
6247 public int numberOfElements() {
63 return elements.size();
48 return elements == null ? 0 : elements.size();
6449 }
6550
6651 public Class<? extends Annotation> type() {
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.annotationfactory;
247
3518 * @author Davide Marchignoli
3619 * @see AnnotationProxy
3720 */
38 public class AnnotationFactory {
21 public final class AnnotationFactory {
3922
40 @SuppressWarnings("unchecked")
23 /**
24 * Creates an Annotation proxy for the given annotation descriptor.
25 * <p/>
26 * NOTE: the proxy here is generated using the ClassLoader of the Annotation type's Class. E.g.,
27 * if asked to create an Annotation proxy for javax.persistence.Entity we would use the ClassLoader
28 * of the javax.persistence.Entity Class for generating the proxy.
29 *
30 * @param descriptor The annotation descriptor
31 *
32 * @return The annotation proxy
33 */
4134 public static <T extends Annotation> T create(AnnotationDescriptor descriptor) {
42 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
43 //TODO round 34ms to generate the proxy, hug! is Javassist Faster?
44 //TODO prebuild the javax.persistence and org.hibernate.annotations classes?
45 Class<T> proxyClass = (Class<T>) Proxy.getProxyClass( classLoader, descriptor.type() );
46 InvocationHandler handler = new AnnotationProxy( descriptor );
47 try {
48 return getProxyInstance( proxyClass, handler );
49 }
50 catch (RuntimeException e) {
51 throw e;
52 }
53 catch (Exception e) {
54 throw new RuntimeException( e );
55 }
35 return create( descriptor, descriptor.type().getClassLoader() );
5636 }
5737
58 private static <T extends Annotation> T getProxyInstance(Class<T> proxyClass, InvocationHandler handler) throws
59 SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException,
60 IllegalAccessException, InvocationTargetException {
61 Constructor<T> constructor = proxyClass.getConstructor( new Class[]{InvocationHandler.class} );
62 return constructor.newInstance( new Object[]{handler} );
38 /**
39 * Legacy form of {@link #create(AnnotationDescriptor) using the current Thread#getContextClassLoader
40 * for proxy generation
41 *
42 * @param descriptor The annotation descriptor
43 *
44 * @return The annotation proxy
45 */
46 public static <T extends Annotation> T createUsingTccl(AnnotationDescriptor descriptor) {
47 return create( descriptor, Thread.currentThread().getContextClassLoader() );
48 }
49
50 /**
51 * Overloaded form of Annotation proxy creation that accepts an explicit ClassLoader.
52 *
53 * @param descriptor The annotation descriptor
54 * @param classLoader The ClassLoader to be used in defining the proxy
55 *
56 * @return The annotation proxy
57 */
58 @SuppressWarnings("unchecked")
59 public static <T extends Annotation> T create(AnnotationDescriptor descriptor, ClassLoader classLoader) {
60 return (T) Proxy.newProxyInstance(
61 classLoader,
62 new Class[] {descriptor.type()},
63 new AnnotationProxy( descriptor )
64 );
6365 }
6466 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.annotationfactory;
247
258 import java.lang.annotation.Annotation;
269 import java.lang.reflect.InvocationHandler;
2710 import java.lang.reflect.Method;
11 import java.util.Collections;
2812 import java.util.Comparator;
2913 import java.util.HashMap;
3014 import java.util.Map;
5539 * @author Davide Marchignoli
5640 * @see java.lang.annotation.Annotation
5741 */
58 public class AnnotationProxy implements Annotation, InvocationHandler {
42 public final class AnnotationProxy implements Annotation, InvocationHandler {
5943
6044 private final Class<? extends Annotation> annotationType;
6145 //FIXME it's probably better to use String as a key rather than Method
6549
6650 public AnnotationProxy(AnnotationDescriptor descriptor) {
6751 this.annotationType = descriptor.type();
68 values = getAnnotationValues( descriptor );
52 this.values = getAnnotationValues( annotationType, descriptor );
6953 }
7054
71 private Map<Method, Object> getAnnotationValues(AnnotationDescriptor descriptor) {
55 private static Map<Method, Object> getAnnotationValues(
56 Class<? extends Annotation> annotationType,
57 AnnotationDescriptor descriptor) {
7258 Map<Method, Object> result = new HashMap<Method, Object>();
7359 int processedValuesFromDescriptor = 0;
7460 for ( Method m : annotationType.getDeclaredMethods() ) {
8672 if ( processedValuesFromDescriptor != descriptor.numberOfElements() ) {
8773 throw new RuntimeException( "Trying to instanciate " + annotationType + " with unknown elements" );
8874 }
89 return result;
75 return toSmallMap( result );
76 }
77
78 static <K, V> Map<K, V> toSmallMap(Map<K, V> map) {
79 switch ( map.size() ) {
80 case 0:
81 return Collections.emptyMap();
82 case 1:
83 Map.Entry<K, V> entry = map.entrySet().iterator().next();
84 return Collections.singletonMap( entry.getKey(), entry.getValue() );
85 default:
86 return map;
87 }
9088 }
9189
9290 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
126124 }
127125 }
128126 );
129 //List<Method> result = new LinkedList<Method>();
130127 result.addAll( values.keySet() );
131128 return result;
132129 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6 package org.hibernate.annotations.common.reflection;
7
8 /**
9 * Delegate for interacting with {@link ClassLoader} methods.
10 *
11 * @author Steve Ebersole
12 * @deprecated This will be removed with no replacement: it will no longer be needed.
13 */
14 @Deprecated
15 public interface ClassLoaderDelegate {
16 /**
17 * Locate a class by name.
18 *
19 * @param className The name of the class to locate
20 * @param <T> The returned class type.
21 *
22 * @return The class reference
23 */
24 public <T> Class<T> classForName(String className) throws ClassLoadingException;
25
26 }
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6 package org.hibernate.annotations.common.reflection;
7
8 /**
9 * @author Steve Ebersole
10 * @deprecated This will be removed with no replacement: it will no longer be needed.
11 */
12 @Deprecated
13 public class ClassLoadingException extends RuntimeException {
14 public ClassLoadingException(String message) {
15 super( message );
16 }
17
18 public ClassLoadingException(String message, Throwable cause) {
19 super( message, cause );
20 }
21 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.reflection;
17
28 import java.util.Map;
612 * Provides metadata
713 *
814 * @author Emmanuel Bernard
15 * @author Sanne Grinovero
916 */
1017 public interface MetadataProvider {
1118
1522 Map<Object, Object> getDefaults();
1623
1724 /**
18 * provide metadata for a gien annotated element
25 * provide metadata for a given annotated element
1926 */
2027 AnnotationReader getAnnotationReader(AnnotatedElement annotatedElement);
28
29 /**
30 * Reset any internal caches.
31 * This will free up memory in some implementations, at the cost of
32 * possibly being a bit slower if its services are needed again.
33 * Other configuration aspects are not affected.
34 */
35 default void reset() {
36 //By default a no-op
37 }
38
2139 }
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.reflection;
17
28 /**
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
3114 *
3215 * @author Paolo Perrotta
3316 * @author Davide Marchignoli
17 * @author Sanne Grinovero
3418 */
3519 public interface ReflectionManager {
20 /**
21 * Allows injection of a ClassLoaderDelegate into the ReflectionManager
22 *
23 * @param delegate The ClassLoaderDelegate to use
24 * @deprecated This will be removed with no replacement: it will no longer be needed.
25 */
26 @Deprecated
27 public void injectClassLoaderDelegate(ClassLoaderDelegate delegate);
28
29 /**
30 * Access to the ClassLoaderDelegate currently associated with this ReflectionManager
31 *
32 * @return The current ClassLoaderDelegate
33 * @deprecated This will be removed with no replacement: it will no longer be needed.
34 */
35 @Deprecated
36 public ClassLoaderDelegate getClassLoaderDelegate();
3637
3738 public <T> XClass toXClass(Class<T> clazz);
3839
4041
4142 public Method toMethod(XMethod method);
4243
44 /**
45 * Deprecated; do not use.
46 *
47 * @deprecated Instead use:<ul>
48 * <li>
49 * {@link #toXClass(Class)} after resolving the Class yourself
50 * </li>
51 * <li>
52 * {@link #classForName(String)} after having injected the proper ClassLoaderDelegate to use via
53 * {@link #injectClassLoaderDelegate}
54 * </li>
55 * </ul>
56 *
57 * @param name
58 * @param caller
59 * @param <T>
60 * @return
61 * @throws ClassNotFoundException
62 * @deprecated This will be removed with no replacement: it will no longer be needed.
63 */
64 @Deprecated
4365 public <T> XClass classForName(String name, Class<T> caller) throws ClassNotFoundException;
4466
67 /**
68 * Given the name of a Class, retrieve the XClass representation.
69 * <p/>
70 * Uses ClassLoaderDelegate (via {@link #getClassLoaderDelegate()}) to resolve the Class reference
71 *
72 * @param name The name of the Class to load (as an XClass)
73 *
74 * @return The XClass instance
75 *
76 * @throws ClassLoadingException Indicates a problem resolving the Class; see {@link ClassLoaderDelegate#classForName}
77 * @deprecated This will be removed with no replacement: it will no longer be needed.
78 */
79 @Deprecated
80 public XClass classForName(String name) throws ClassLoadingException;
81
82 /**
83 * @deprecated This will be removed with no replacement: it will no longer be needed.
84 * @param packageName
85 * @return
86 * @throws ClassNotFoundException
87 */
88 @Deprecated
4589 public XPackage packageForName(String packageName) throws ClassNotFoundException;
90
91 public XPackage toXPackage(Package pkg);
4692
4793 public <T> boolean equals(XClass class1, Class<T> class2);
4894
4995 public AnnotationReader buildAnnotationReader(AnnotatedElement annotatedElement);
5096
5197 public Map getDefaults();
98
99 /**
100 * This resets any internal caches.
101 * This will free up memory in some implementations, at the cost of
102 * possibly being a bit slower if its services are needed again.
103 * <p>
104 * Ideally the ReflectionManager should be discarded after use,
105 * but sometimes that's not posible.
106 * This method is intended to be used when there is reasonable
107 * expectation for te ReflectionManager to no longer be needed,
108 * while having the option to still use it in case the assumption
109 * doesn't hold true.
110 * </p>
111 * <p>
112 * Careful: after invoking this method, returned X* instances will
113 * no longer honour any identity equality contract with X* instances
114 * which have been returned before resetting the cache.
115 * </p>
116 * This operation does not affect the configuration.
117 */
118 default void reset() {
119 //By default a no-op
120 }
121
52122 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
2811 * @author Emmanuel Bernard
2912 */
3013 public abstract interface XMember extends XAnnotatedElement {
14
15 /**
16 * Retrieve the XClass reference for the class which declares this member.
17 *
18 * @return The XClass representing the declaring class of the underlying member
19 */
20 public XClass getDeclaringClass();
3121
3222 String getName();
3323
7363
7464 public Object invoke(Object target, Object... parameters);
7565
66 /**
67 * Invoke the method with no parameters.
68 * Same as {@link #invoke(Object, Object...)}.
69 * @param target
70 * @return
71 */
72 public Object invoke(Object target);
73
7674 boolean isTypeResolved();
7775 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection;
247
3518 * @author Emmanuel Bernard
3619 */
3720 public interface XProperty extends XMember {
38
39 /**
40 * Unqualify the getter name
41 */
42 String getName();
4321 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
3316 * @author Paolo Perrotta
3417 * @author Davide Marchignoli
3518 */
36 class JavaAnnotationReader implements AnnotationReader {
19 final class JavaAnnotationReader implements AnnotationReader {
3720
3821 protected final AnnotatedElement element;
3922
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.reflection.java;
17
28 import java.util.Map;
915 /**
1016 * @author Emmanuel Bernard
1117 */
12 public class JavaMetadataProvider implements MetadataProvider {
18 public final class JavaMetadataProvider implements MetadataProvider {
1319
1420 public Map<Object, Object> getDefaults() {
1521 return Collections.emptyMap();
1824 public AnnotationReader getAnnotationReader(AnnotatedElement annotatedElement) {
1925 return new JavaAnnotationReader(annotatedElement);
2026 }
27
28 @Override
29 public void reset() {
30 //no-op
31 }
32
2133 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
2912 import java.lang.reflect.Type;
3013 import java.util.HashMap;
3114 import java.util.Map;
15 import java.util.concurrent.atomic.AtomicBoolean;
3216
3317 import org.hibernate.annotations.common.reflection.AnnotationReader;
18 import org.hibernate.annotations.common.reflection.ClassLoaderDelegate;
19 import org.hibernate.annotations.common.reflection.ClassLoadingException;
3420 import org.hibernate.annotations.common.reflection.ReflectionManager;
3521 import org.hibernate.annotations.common.reflection.XClass;
3622 import org.hibernate.annotations.common.reflection.XMethod;
4531 import org.hibernate.annotations.common.reflection.java.generics.TypeUtils;
4632 import org.hibernate.annotations.common.Version;
4733 import org.hibernate.annotations.common.util.ReflectHelper;
34 import org.hibernate.annotations.common.util.StandardClassLoaderDelegateImpl;
35 import org.hibernate.annotations.common.util.impl.LoggerFactory;
4836
4937 /**
5038 * The factory for all the objects in this package.
5240 * @author Paolo Perrotta
5341 * @author Davide Marchignoli
5442 * @author Emmanuel Bernard
43 * @author Sanne Grinovero
5544 */
56 public class JavaReflectionManager implements ReflectionManager, MetadataProviderInjector {
45 public final class JavaReflectionManager implements ReflectionManager, MetadataProviderInjector {
46
47 private static final boolean METADATA_CACHE_DIAGNOSTICS = Boolean.getBoolean( "org.hibernate.annotations.common.METADATA_CACHE_DIAGNOSTICS" );
5748
5849 private MetadataProvider metadataProvider;
50 private ClassLoaderDelegate classLoaderDelegate = StandardClassLoaderDelegateImpl.INSTANCE;
51
52 private final AtomicBoolean empty = new AtomicBoolean(true);
53
54 static {
55 LoggerFactory.make( Version.class.getName() ).version( Version.getVersionString() );
56 }
5957
6058 public MetadataProvider getMetadataProvider() {
6159 if (metadataProvider == null) {
6866 this.metadataProvider = metadataProvider;
6967 }
7068
71 static {
72 Version.touch();
73 }
74
75 private static class TypeKey extends Pair<Type, TypeEnvironment> {
76 TypeKey(Type t, TypeEnvironment context) {
77 super( t, context );
78 }
79 }
80
81 private static class MemberKey extends Pair<Member, TypeEnvironment> {
82 MemberKey(Member member, TypeEnvironment context) {
83 super( member, context );
84 }
85 }
86
87 private final Map<TypeKey, JavaXClass> xClasses = new HashMap<TypeKey, JavaXClass>();
88
89 private final Map<Package, JavaXPackage> packagesToXPackages = new HashMap<Package, JavaXPackage>();
90
91 private final Map<MemberKey, JavaXProperty> xProperties = new HashMap<MemberKey, JavaXProperty>();
92
93 private final Map<MemberKey, JavaXMethod> xMethods = new HashMap<MemberKey, JavaXMethod>();
94
95 private final TypeEnvironmentFactory typeEnvs = new TypeEnvironmentFactory();
69 @Override
70 public void injectClassLoaderDelegate(ClassLoaderDelegate delegate) {
71 if ( delegate == null ) {
72 this.classLoaderDelegate = StandardClassLoaderDelegateImpl.INSTANCE;
73 }
74 else {
75 this.classLoaderDelegate = delegate;
76 }
77 }
78
79 @Override
80 public ClassLoaderDelegate getClassLoaderDelegate() {
81 return classLoaderDelegate;
82 }
83
84 private final TypeEnvironmentMap<Class,JavaXClass> xClasses = new TypeEnvironmentMap<>( this::javaXClassConstruction );
85
86 private JavaXClass javaXClassConstruction(
87 Class classType,
88 TypeEnvironment typeEnvironment) {
89 used();
90 return new JavaXClass( classType, typeEnvironment, this );
91 }
92
93 private Map<Package, JavaXPackage> packagesToXPackages;
94
95 private final TypeEnvironmentMap<Member, JavaXProperty> xProperties = new TypeEnvironmentMap<>( this::javaXPropertyConstruction );
96
97 private JavaXProperty javaXPropertyConstruction(Member member, TypeEnvironment typeEnvironment) {
98 used();
99 return JavaXProperty.create( member, typeEnvironment, this );
100 }
101
102 private final TypeEnvironmentMap<Member, JavaXMethod> xMethods = new TypeEnvironmentMap<>( this::javaJavaXMethodConstruction );
103
104 private JavaXMethod javaJavaXMethodConstruction(Member member, TypeEnvironment typeEnvironment) {
105 used();
106 return JavaXMethod.create( member, typeEnvironment, this );
107 }
96108
97109 public XClass toXClass(Class clazz) {
98110 return toXClass( clazz, IdentityTypeEnvironment.INSTANCE );
112124 return (Method) ( (JavaXAnnotatedElement) xMethod ).toAnnotatedElement();
113125 }
114126
127 @Override
128 @Deprecated
129 @SuppressWarnings("deprecation")
115130 public XClass classForName(String name, Class caller) throws ClassNotFoundException {
116131 return toXClass( ReflectHelper.classForName( name, caller ) );
117132 }
118133
119 public XPackage packageForName(String packageName) throws ClassNotFoundException {
120 return getXAnnotatedElement( ReflectHelper.classForName( packageName + ".package-info" ).getPackage() );
134 @Override
135 public XClass classForName(String name) throws ClassLoadingException {
136 return toXClass( getClassLoaderDelegate().classForName( name ) );
137 }
138
139 @Override
140 public XPackage packageForName(String packageName) {
141 return getXAnnotatedElement( getClassLoaderDelegate().classForName( packageName + ".package-info" ).getPackage() );
121142 }
122143
123144 XClass toXClass(Type t, final TypeEnvironment context) {
124145 return new TypeSwitch<XClass>() {
125146 @Override
126147 public XClass caseClass(Class classType) {
127 TypeKey key = new TypeKey( classType, context );
128 JavaXClass result = xClasses.get( key );
129 if ( result == null ) {
130 result = new JavaXClass( classType, context, JavaReflectionManager.this );
131 xClasses.put( key, result );
132 }
133 return result;
148 return xClasses.getOrCompute( context, classType );
134149 }
135150
136151 @Override
137152 public XClass caseParameterizedType(ParameterizedType parameterizedType) {
138153 return toXClass( parameterizedType.getRawType(),
139 typeEnvs.getEnvironment( parameterizedType, context )
154 TypeEnvironmentFactory.getEnvironment( parameterizedType, context )
140155 );
141156 }
142157 }.doSwitch( context.bind( t ) );
143158 }
144159
160 @Deprecated
145161 XPackage getXAnnotatedElement(Package pkg) {
146 JavaXPackage xPackage = packagesToXPackages.get( pkg );
162 return toXPackage( pkg );
163 }
164
165 @Override
166 public XPackage toXPackage(Package pkg) {
167 final Map<Package, JavaXPackage> packagesToXPackagesMap = getPackagesToXPackagesMap();
168 JavaXPackage xPackage = packagesToXPackagesMap.get( pkg );
147169 if ( xPackage == null ) {
148170 xPackage = new JavaXPackage( pkg, this );
149 packagesToXPackages.put( pkg, xPackage );
171 used();
172 packagesToXPackagesMap.put( pkg, xPackage );
150173 }
151174 return xPackage;
152175 }
153176
177 private Map<Package, JavaXPackage> getPackagesToXPackagesMap() {
178 if ( this.packagesToXPackages == null ) {
179 this.packagesToXPackages = new HashMap<>( 8, 0.5f );
180 }
181 return this.packagesToXPackages;
182 }
183
154184 XProperty getXProperty(Member member, TypeEnvironment context) {
155 MemberKey key = new MemberKey( member, context );
156 //FIXME get is as expensive as create most time spent in hashCode and equals
157 JavaXProperty xProperty = xProperties.get( key );
158 if ( xProperty == null ) {
159 xProperty = JavaXProperty.create( member, context, this );
160 xProperties.put( key, xProperty );
161 }
162 return xProperty;
185 return xProperties.getOrCompute( context, member );
163186 }
164187
165188 XMethod getXMethod(Member member, TypeEnvironment context) {
166 MemberKey key = new MemberKey( member, context );
167 //FIXME get is as expensive as create most time spent in hashCode and equals
168 JavaXMethod xMethod = xMethods.get( key );
169 if ( xMethod == null ) {
170 xMethod = JavaXMethod.create( member, context, this );
171 xMethods.put( key, xMethod );
172 }
173 return xMethod;
189 return xMethods.getOrCompute( context, member );
174190 }
175191
176192 TypeEnvironment getTypeEnvironment(final Type t) {
177193 return new TypeSwitch<TypeEnvironment>() {
178194 @Override
179195 public TypeEnvironment caseClass(Class classType) {
180 return typeEnvs.getEnvironment( classType );
196 return TypeEnvironmentFactory.getEnvironment( classType );
181197 }
182198
183199 @Override
184200 public TypeEnvironment caseParameterizedType(ParameterizedType parameterizedType) {
185 return typeEnvs.getEnvironment( parameterizedType );
201 return TypeEnvironmentFactory.getEnvironment( parameterizedType );
186202 }
187203
188204 @Override
214230 }
215231
216232 public TypeEnvironment toApproximatingEnvironment(TypeEnvironment context) {
217 return typeEnvs.toApproximatingEnvironment( context );
233 return TypeEnvironmentFactory.toApproximatingEnvironment( context );
218234 }
219235
220236 public AnnotationReader buildAnnotationReader(AnnotatedElement annotatedElement) {
225241 return getMetadataProvider().getDefaults();
226242 }
227243
244 @Override
245 public void reset() {
246 boolean wasEmpty = empty.getAndSet( true );
247 if ( !wasEmpty ) {
248 this.xClasses.clear();
249 this.packagesToXPackages = null;
250 this.xProperties.clear();
251 this.xMethods.clear();
252 if ( METADATA_CACHE_DIAGNOSTICS ) {
253 new RuntimeException( "Diagnostics message : Caches now empty" ).printStackTrace();
254 }
255 }
256 if ( metadataProvider != null ) {
257 this.metadataProvider.reset();
258 }
259 }
260
261 private void used() {
262 boolean wasEmpty = empty.getAndSet( false );
263 if ( wasEmpty && METADATA_CACHE_DIAGNOSTICS ) {
264 new RuntimeException( "Diagnostics message : Caches now being used" ).printStackTrace();
265 }
266 }
267
228268 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
3518 * @author Emmanuel Bernard
3619 * @author Paolo Perrotta
3720 */
38 class JavaXArrayType extends JavaXType {
21 final class JavaXArrayType extends JavaXType {
3922
4023 public JavaXArrayType(Type type, TypeEnvironment context, JavaReflectionManager factory) {
4124 super( type, context, factory );
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
258 import java.lang.reflect.Field;
269 import java.lang.reflect.Method;
2710 import java.lang.reflect.Modifier;
28 import java.util.LinkedList;
11 import java.util.ArrayList;
2912 import java.util.List;
3013
3114 import org.hibernate.annotations.common.reflection.Filter;
4023 * @author Paolo Perrotta
4124 * @author Davide Marchignoli
4225 */
43 class JavaXClass extends JavaXAnnotatedElement implements XClass {
26 final class JavaXClass extends JavaXAnnotatedElement implements XClass {
4427
4528 private final TypeEnvironment context;
4629 private final Class clazz;
9780 }
9881
9982 private List<XProperty> getDeclaredFieldProperties(Filter filter) {
100 List<XProperty> result = new LinkedList<XProperty>();
101 for ( Field f : toClass().getDeclaredFields() ) {
83 Field[] declaredFields = toClass().getDeclaredFields();
84 ArrayList<XProperty> result = new ArrayList<>();
85 for ( Field f : declaredFields ) {
10286 if ( ReflectionUtil.isProperty( f, getTypeEnvironment().bind( f.getGenericType() ), filter ) ) {
10387 result.add( getFactory().getXProperty( f, getTypeEnvironment() ) );
10488 }
10589 }
90 result.trimToSize();
10691 return result;
10792 }
10893
10994 private List<XProperty> getDeclaredMethodProperties(Filter filter) {
110 List<XProperty> result = new LinkedList<XProperty>();
111 for ( Method m : toClass().getDeclaredMethods() ) {
95 ArrayList<XProperty> result = new ArrayList<XProperty>();
96 Method[] declaredMethods = toClass().getDeclaredMethods();
97 for ( Method m : declaredMethods ) {
11298 if ( ReflectionUtil.isProperty( m, getTypeEnvironment().bind( m.getGenericReturnType() ), filter ) ) {
11399 result.add( getFactory().getXProperty( m, getTypeEnvironment() ) );
114100 }
115101 }
102 result.trimToSize();
116103 return result;
117104 }
118105
131118 }
132119
133120 public List<XMethod> getDeclaredMethods() {
134 List<XMethod> result = new LinkedList<XMethod>();
135 for ( Method m : toClass().getDeclaredMethods() ) {
121 Method[] declaredMethods = toClass().getDeclaredMethods();
122 List<XMethod> result = new ArrayList<>( declaredMethods.length );
123 for ( Method m : declaredMethods ) {
136124 result.add( getFactory().getXMethod( m, getTypeEnvironment() ) );
137125 }
138126 return result;
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236
24 // $Id: JavaXCollectionType.java 15416 2008-10-28 18:43:14Z steve.ebersole@jboss.com $
7 // $Id$
258 package org.hibernate.annotations.common.reflection.java;
269
2710 import java.lang.reflect.ParameterizedType;
4023 * @author Paolo Perrotta
4124 */
4225 @SuppressWarnings("unchecked")
43 class JavaXCollectionType extends JavaXType {
26 final class JavaXCollectionType extends JavaXType {
4427
4528 public JavaXCollectionType(Type type, TypeEnvironment context, JavaReflectionManager factory) {
4629 super( type, context, factory );
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236
24 //$Id: JavaXMember.java 15416 2008-10-28 18:43:14Z steve.ebersole@jboss.com $
7 //$Id$
258 package org.hibernate.annotations.common.reflection.java;
269
2710 import java.lang.reflect.AccessibleObject;
6750
6851 public abstract String getName();
6952
70 protected Type getJavaType() {
53 public Type getJavaType() {
7154 return env.bind( type );
7255 }
7356
7558 return env;
7659 }
7760
78 protected Member getMember() {
61 public Member getMember() {
7962 return (Member) toAnnotatedElement();
63 }
64
65 @Override
66 public XClass getDeclaringClass() {
67 return getFactory().toXClass( getMember().getDeclaringClass() );
8068 }
8169
8270 public Class<? extends Collection> getCollectionClass() {
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236
24 //$Id: JavaXMethod.java 15416 2008-10-28 18:43:14Z steve.ebersole@jboss.com $
7 //$Id$
258 package org.hibernate.annotations.common.reflection.java;
269
2710 import java.lang.reflect.Member;
3417 /**
3518 * @author Emmanuel Bernard
3619 */
37 public class JavaXMethod extends JavaXMember implements XMethod {
20 final public class JavaXMethod extends JavaXMember implements XMethod {
21
22 private static final Object[] EMPTY_ARRAY = new Object[0];
3823
3924 static JavaXMethod create(Member member, TypeEnvironment context, JavaReflectionManager factory) {
4025 final Type propType = typeOf( member, context );
4732 assert member instanceof Method;
4833 }
4934
35 @Override
5036 public String getName() {
5137 return getMember().getName();
5238 }
5339
40 @Override
41 public Object invoke(Object target) {
42 return invoke( target, EMPTY_ARRAY );
43 }
44
45 @Override
5446 public Object invoke(Object target, Object... parameters) {
5547 try {
5648 return ( (Method) getMember() ).invoke( target, parameters );
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
2811 * @author Paolo Perrotta
2912 * @author Davide Marchignoli
3013 */
31 class JavaXPackage extends JavaXAnnotatedElement implements XPackage {
14 final class JavaXPackage extends JavaXAnnotatedElement implements XPackage {
3215
3316 public JavaXPackage(Package pkg, JavaReflectionManager factory) {
3417 super( pkg, factory );
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
25 import java.beans.Introspector;
268 import java.lang.reflect.Field;
279 import java.lang.reflect.Member;
2810 import java.lang.reflect.Method;
3517 * @author Paolo Perrotta
3618 * @author Davide Marchignoli
3719 */
38 class JavaXProperty extends JavaXMember implements XProperty {
20 final class JavaXProperty extends JavaXMember implements XProperty {
21
22 private static final Object[] EMPTY_ARRAY = new Object[0];
3923
4024 static JavaXProperty create(Member member, final TypeEnvironment context, final JavaReflectionManager factory) {
4125 final Type propType = typeOf( member, context );
5236 String fullName = getMember().getName();
5337 if ( getMember() instanceof Method ) {
5438 if ( fullName.startsWith( "get" ) ) {
55 return Introspector.decapitalize( fullName.substring( "get".length() ) );
39 return decapitalize( fullName.substring( "get".length() ) );
5640 }
5741 if ( fullName.startsWith( "is" ) ) {
58 return Introspector.decapitalize( fullName.substring( "is".length() ) );
42 return decapitalize( fullName.substring( "is".length() ) );
5943 }
6044 throw new RuntimeException( "Method " + fullName + " is not a property getter" );
6145 }
6448 }
6549 }
6650
67 public Object invoke(Object target, Object... parameters) {
68 if ( parameters.length != 0 ) {
69 throw new IllegalArgumentException( "An XProperty cannot have invoke parameters" );
51 // See conventions expressed by https://docs.oracle.com/javase/7/docs/api/java/beans/Introspector.html#decapitalize(java.lang.String)
52 private static String decapitalize(String name) {
53 if (name != null && name.length() != 0) {
54 if (name.length() > 1 && Character.isUpperCase(name.charAt(1))) {
55 return name;
56 } else {
57 char[] chars = name.toCharArray();
58 chars[0] = Character.toLowerCase(chars[0]);
59 return new String(chars);
60 }
61 } else {
62 return name;
7063 }
64 }
65
66 @Override
67 public Object invoke(Object target) {
68 //Implementation note: only #invoke(Object target, Object... parameters)
69 //existed until HCANN 5.0.0.Final, but it turned out to be a performance issue as that would cause
70 //each invocation to allocate an empty array to pass as vararg.
7171 try {
7272 if ( getMember() instanceof Method ) {
73 return ( (Method) getMember() ).invoke( target );
73 return ( (Method) getMember() ).invoke( target, EMPTY_ARRAY );
7474 }
7575 else {
76 return ( (Field) getMember() ).get( target );
76 Field field = (Field) getMember();
77 // This is needed because until JDK 9 the Reflection API
78 // does not use the same caching as used for auto-boxing.
79 // See https://bugs.openjdk.java.net/browse/JDK-5043030 for details.
80 // The code below can be removed when we move to JDK 9.
81 // double and float are intentionally not handled here because
82 // the JLS § 5.1.7 does not define caching for boxed values of
83 // this types.
84 Class<?> type = field.getType();
85 if ( type.isPrimitive() ) {
86 if ( type == Boolean.TYPE ) {
87 return Boolean.valueOf( field.getBoolean( target ) );
88 } else if ( type == Byte.TYPE ) {
89 return Byte.valueOf( field.getByte( target ) );
90 } else if ( type == Character.TYPE ) {
91 return Character.valueOf( field.getChar( target ) );
92 } else if ( type == Integer.TYPE ) {
93 return Integer.valueOf( field.getInt( target ) );
94 } else if ( type == Long.TYPE ) {
95 return Long.valueOf( field.getLong( target ) );
96 } else if ( type == Short.TYPE ) {
97 return Short.valueOf( field.getShort( target ) );
98 }
99 }
100 return field.get( target );
77101 }
78102 }
79103 catch (NullPointerException e) {
88112 }
89113
90114 @Override
115 public Object invoke(Object target, Object... parameters) {
116 if ( parameters.length != 0 ) {
117 throw new IllegalArgumentException( "An XProperty cannot have invoke parameters" );
118 }
119 return invoke( target );
120 }
121
122 @Override
91123 public String toString() {
92124 return getName();
93125 }
94 }
126 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java;
247
3215 * @author Emmanuel Bernard
3316 * @author Paolo Perrotta
3417 */
35 class JavaXSimpleType extends JavaXType {
18 final class JavaXSimpleType extends JavaXType {
3619
3720 public JavaXSimpleType(Type type, TypeEnvironment context, JavaReflectionManager factory) {
3821 super( type, context, factory );
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236
247 //$Id: PropertyTypeExtractor.java 9316 2006-02-22 20:47:31Z epbernard $
+0
-81
src/main/java/org/hibernate/annotations/common/reflection/java/Pair.java less more
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
22 */
23 package org.hibernate.annotations.common.reflection.java;
24
25 /**
26 * A pair of objects that can be used as a key in a Map.
27 *
28 * @author Paolo Perrotta
29 * @author Davide Marchignoli
30 */
31 abstract class Pair<T, U> {
32
33 private final T o1;
34
35 private final U o2;
36 private final int hashCode;
37
38 Pair(T o1, U o2) {
39 this.o1 = o1;
40 this.o2 = o2;
41 this.hashCode = doHashCode();
42 }
43
44 @Override
45 public boolean equals(Object obj) {
46 if ( ! (obj instanceof Pair) ) {
47 return false;
48 }
49 Pair other = (Pair) obj;
50 return !differentHashCode( other ) && safeEquals( o1, other.o1 ) && safeEquals( o2, other.o2 );
51 }
52
53 private boolean differentHashCode(Pair other) {
54 return hashCode != other.hashCode;
55 }
56
57 @Override
58 public int hashCode() {
59 //cached because the inheritance can be big
60 return hashCode;
61 }
62
63 private int doHashCode() {
64 return safeHashCode( o1 ) ^ safeHashCode( o2 );
65 }
66
67 private int safeHashCode(Object o) {
68 if ( o == null ) {
69 return 0;
70 }
71 return o.hashCode();
72 }
73
74 private boolean safeEquals(Object obj1, Object obj2) {
75 if ( obj1 == null ) {
76 return obj2 == null;
77 }
78 return obj1.equals( obj2 );
79 }
80 }
0 package org.hibernate.annotations.common.reflection.java;
1
2 import java.util.HashMap;
3 import java.util.Objects;
4
5 import org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment;
6
7 /**
8 * We need a two-level sparse tree for best efficiency in this case;
9 * the first split uses TypeEnvironment as a key, under which we store
10 * an additional Map to further organize by K.
11 * This used to be implemented as a HashMap with a composite key {TypeEnvironment,K},
12 * but this wasn't memory efficient as all composite keys take too much space:
13 * the nested structure has some overhead as well, but has been shown to cost less
14 * overall.
15 * In addition, we strife to not need to compute hashkeys multiple times while
16 * not needing to allocate stateful lambdas; for this reason the tree nodes
17 * need to store some additional references.
18 *
19 * @param <K>
20 * @param <V>
21 * @author Sanne Grinovero
22 */
23 final class TypeEnvironmentMap<K,V> {
24
25 //First level is optimised for fast access; it's expected to be small so a low load factor
26 //should be fine in terms of memory costs.
27 private HashMap<TypeEnvironment, ContextScope> rootMap;
28 private final XTypeConstruction<K,V> constructionMethod;
29
30 TypeEnvironmentMap(final XTypeConstruction<K, V> constructionMethod) {
31 Objects.requireNonNull( constructionMethod );
32 this.constructionMethod = constructionMethod;
33 }
34
35 private <K, V> HashMap<TypeEnvironment, ContextScope> getOrInitRootMap() {
36 if ( this.rootMap == null ) {
37 this.rootMap = new HashMap<>( 8, 0.5f );
38 }
39 return this.rootMap;
40 }
41
42 V getOrCompute(final TypeEnvironment context, final K subKey) {
43 final ContextScope contextualMap = getOrInitRootMap().computeIfAbsent( context, ContextScope::new );
44 return contextualMap.getOrCompute( subKey );
45 }
46
47 void clear() {
48 final HashMap<TypeEnvironment, ContextScope> m = this.rootMap;
49 if ( m != null ) {
50 // Remove the reference to the rootMap, as very large arrays within HashMap
51 // are not resized when clearing.
52 this.rootMap = null;
53 m.clear();
54 }
55 }
56
57 private final class ContextScope extends HashMap<K,V> {
58
59 private final TypeEnvironment context;
60
61 private ContextScope(TypeEnvironment context) {
62 //In the second level of the tree we expect many entries, but we can't have it consume too much memory:
63 super( 64, 0.85f );
64 this.context = context;
65 }
66
67 private V getOrCompute(K subKey) {
68 return computeIfAbsent( subKey, this::buildObject );
69 }
70
71 private V buildObject(K subKey) {
72 return constructionMethod.createInstance( subKey, context );
73 }
74 }
75 }
0 package org.hibernate.annotations.common.reflection.java;
1
2 import org.hibernate.annotations.common.reflection.java.generics.TypeEnvironment;
3
4 @FunctionalInterface
5 interface XTypeConstruction<K,V> {
6
7 V createInstance(K typeKey, TypeEnvironment context);
8
9 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
5942 * @author Paolo Perrotta
6043 * @return a type where the generic arguments have been replaced by raw classes.
6144 */
62 class ApproximatingTypeEnvironment implements TypeEnvironment {
45 final class ApproximatingTypeEnvironment implements TypeEnvironment {
6346
6447 public Type bind(final Type type) {
6548 Type result = fineApproximation( type );
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
3013 * @author Davide Marchignoli
3114 * @author Paolo Perrotta
3215 */
33 public class CompoundTypeEnvironment implements TypeEnvironment {
16 public final class CompoundTypeEnvironment implements TypeEnvironment {
3417
3518 private final TypeEnvironment f;
36
3719 private final TypeEnvironment g;
38
3920 private final int hashCode;
4021
4122 public static TypeEnvironment create(TypeEnvironment f, TypeEnvironment g) {
4930 private CompoundTypeEnvironment(TypeEnvironment f, TypeEnvironment g) {
5031 this.f = f;
5132 this.g = g;
52 hashCode = doHashCode();
33 this.hashCode = doHashCode( f, g );
5334 }
5435
5536 public Type bind(Type type) {
6647
6748 if ( !f.equals( that.f ) ) return false;
6849 return g.equals( that.g );
69
7050 }
7151
7252 private boolean differentHashCode(CompoundTypeEnvironment that) {
7353 return hashCode != that.hashCode;
7454 }
7555
76 private int doHashCode() {
56 private static int doHashCode(
57 TypeEnvironment f,
58 TypeEnvironment g) {
7759 int result;
7860 result = f.hashCode();
7961 result = 29 * result + g.hashCode();
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
3013 * @author Davide Marchignoli
3114 * @author Paolo Perrotta
3215 */
33 public class IdentityTypeEnvironment implements TypeEnvironment {
16 public final class IdentityTypeEnvironment implements TypeEnvironment {
3417
3518 public static final TypeEnvironment INSTANCE = new IdentityTypeEnvironment();
3619
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
3518 * @author Davide Marchignoli
3619 * @author Paolo Perrotta
3720 */
38 class SimpleTypeEnvironment extends HashMap<Type, Type> implements TypeEnvironment {
21 final class SimpleTypeEnvironment extends HashMap<Type, Type> implements TypeEnvironment {
3922
4023 private static final long serialVersionUID = 1L;
4124
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
3417 * @author Davide Marchignoli
3518 * @author Paolo Perrotta
3619 */
37 public class TypeEnvironmentFactory {
20 public final class TypeEnvironmentFactory {
21
22 private TypeEnvironmentFactory() {
23 //no need to construct
24 }
3825
3926 /**
4027 * @return Returns a type environment suitable for resolving types occurring
4128 * in subclasses of the context class.
4229 */
43 public TypeEnvironment getEnvironment(Class context) {
30 public static TypeEnvironment getEnvironment(Class context) {
4431 if ( context == null ) {
4532 return IdentityTypeEnvironment.INSTANCE;
4633 }
4734 return createEnvironment( context );
4835 }
4936
50 public TypeEnvironment getEnvironment(Type context) {
37 public static TypeEnvironment getEnvironment(Type context) {
5138 if ( context == null ) {
5239 return IdentityTypeEnvironment.INSTANCE;
5340 }
5441 return createEnvironment( context );
5542 }
5643
57 public TypeEnvironment getEnvironment(Type t, TypeEnvironment context) {
58 return CompoundTypeEnvironment.create( getEnvironment(t), context );
44 public static TypeEnvironment getEnvironment(Type t, TypeEnvironment context) {
45 return CompoundTypeEnvironment.create( getEnvironment( t ), context );
5946 }
6047
61 public TypeEnvironment toApproximatingEnvironment(TypeEnvironment context) {
48 public static TypeEnvironment toApproximatingEnvironment(TypeEnvironment context) {
6249 return CompoundTypeEnvironment.create( new ApproximatingTypeEnvironment(), context );
6350 }
6451
65 private TypeEnvironment createEnvironment(Type context) {
52 private static TypeEnvironment createEnvironment(Type context) {
6653 return new TypeSwitch<TypeEnvironment>() {
6754 @Override
6855 public TypeEnvironment caseClass(Class classType) {
8471 }.doSwitch( context );
8572 }
8673
87 private TypeEnvironment createSuperTypeEnvironment(Class clazz) {
74 private static TypeEnvironment createSuperTypeEnvironment(Class clazz) {
8875 Class superclass = clazz.getSuperclass();
8976 if ( superclass == null ) {
9077 return IdentityTypeEnvironment.INSTANCE;
9178 }
9279
93 Type[] formalArgs = superclass.getTypeParameters();
9480 Type genericSuperclass = clazz.getGenericSuperclass();
9581
9682 if ( genericSuperclass instanceof Class ) {
9884 }
9985
10086 if ( genericSuperclass instanceof ParameterizedType ) {
87 Type[] formalArgs = superclass.getTypeParameters();
10188 Type[] actualArgs = ( (ParameterizedType) genericSuperclass ).getActualTypeArguments();
10289 return new SimpleTypeEnvironment( formalArgs, actualArgs );
10390 }
10592 throw new AssertionError( "Should be unreachable" );
10693 }
10794
108 private TypeEnvironment createEnvironment(ParameterizedType t) {
95 private static TypeEnvironment createEnvironment(ParameterizedType t) {
10996 Type[] tactuals = t.getActualTypeArguments();
11097 Type rawType = t.getRawType();
11198 if ( rawType instanceof Class ) {
114101 }
115102 return IdentityTypeEnvironment.INSTANCE;
116103 }
104
117105 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.reflection.java.generics;
247
8164 public static Class<? extends Collection> getCollectionClass(Type type) {
8265 return new TypeSwitch<Class<? extends Collection>>() {
8366 @Override
67 @SuppressWarnings("unchecked")
8468 public Class<? extends Collection> caseClass(Class clazz) {
8569 return isCollectionClass( clazz ) ? (Class<? extends Collection>) clazz : null;
8670 }
10791 }
10892
10993 private static boolean isCollectionClass(Class<?> clazz) {
110 return clazz == Collection.class
111 || clazz == java.util.List.class
112 || clazz == java.util.Set.class
113 || clazz == java.util.Map.class
114 || clazz == java.util.SortedSet.class // extension to the specs
115 || clazz == java.util.SortedMap.class; // extension to the specs
94 return Collection.class.isAssignableFrom( clazz)
95 || java.util.Map.class.isAssignableFrom( clazz);
11696 }
11797
11898 public static boolean isSimple(Type type) {
148128 return true;
149129 }
150130
131 @SuppressWarnings("EqualsBetweenInconvertibleTypes")
151132 public static boolean isVoid(Type type) {
152133 return void.class.equals( type );
153134 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.util;
247
25 import java.lang.reflect.Member;
26 import java.lang.reflect.Method;
27 import java.lang.reflect.Modifier;
28
29 import org.hibernate.annotations.common.AssertionFailure;
30
318 /**
32 * Complete duplication of {@link org.hibernate.util.ReflectHelper}.
33 *
349 * @author Emmanuel Bernard
10 * @deprecated This will be removed with no replacement: it will no longer be needed.
3511 */
12 @Deprecated
3613 public final class ReflectHelper {
37
38 public static final Class[] NO_PARAM_SIGNATURE = new Class[0];
39 public static final Object[] NO_PARAMS = new Object[0];
40
41 public static final Class[] SINGLE_OBJECT_PARAM_SIGNATURE = new Class[] { Object.class };
42
43 private static final Method OBJECT_EQUALS;
44 private static final Method OBJECT_HASHCODE;
45
46 static {
47 Method eq;
48 Method hash;
49 try {
50 eq = extractEqualsMethod( Object.class );
51 hash = extractHashCodeMethod( Object.class );
52 }
53 catch ( Exception e ) {
54 throw new AssertionFailure( "Could not find Object.equals() or Object.hashCode()", e );
55 }
56 OBJECT_EQUALS = eq;
57 OBJECT_HASHCODE = hash;
58 }
5914
6015 /**
6116 * Disallow instantiation of ReflectHelper.
6217 */
6318 private ReflectHelper() {
64 }
65
66 /**
67 * Encapsulation of getting hold of a class's {@link Object#equals equals} method.
68 *
69 * @param clazz The class from which to extract the equals method.
70 * @return The equals method reference
71 * @throws NoSuchMethodException Should indicate an attempt to extract equals method from interface.
72 */
73 public static Method extractEqualsMethod(Class clazz) throws NoSuchMethodException {
74 return clazz.getMethod( "equals", SINGLE_OBJECT_PARAM_SIGNATURE );
75 }
76
77 /**
78 * Encapsulation of getting hold of a class's {@link Object#hashCode hashCode} method.
79 *
80 * @param clazz The class from which to extract the hashCode method.
81 * @return The hashCode method reference
82 * @throws NoSuchMethodException Should indicate an attempt to extract hashCode method from interface.
83 */
84 public static Method extractHashCodeMethod(Class clazz) throws NoSuchMethodException {
85 return clazz.getMethod( "hashCode", NO_PARAM_SIGNATURE );
86 }
87
88 /**
89 * Determine if the given class defines an {@link Object#equals} override.
90 *
91 * @param clazz The class to check
92 * @return True if clazz defines an equals override.
93 */
94 public static boolean overridesEquals(Class clazz) {
95 Method equals;
96 try {
97 equals = extractEqualsMethod( clazz );
98 }
99 catch ( NoSuchMethodException nsme ) {
100 return false; //its an interface so we can't really tell anything...
101 }
102 return !OBJECT_EQUALS.equals( equals );
103 }
104
105 /**
106 * Determine if the given class defines a {@link Object#hashCode} override.
107 *
108 * @param clazz The class to check
109 * @return True if clazz defines an hashCode override.
110 */
111 public static boolean overridesHashCode(Class clazz) {
112 Method hashCode;
113 try {
114 hashCode = extractHashCodeMethod( clazz );
115 }
116 catch ( NoSuchMethodException nsme ) {
117 return false; //its an interface so we can't really tell anything...
118 }
119 return !OBJECT_HASHCODE.equals( hashCode );
12019 }
12120
12221 /**
12928 * @param caller The class from which this call originated (in order to access that class's loader).
13029 * @return The class reference.
13130 * @throws ClassNotFoundException From {@link Class#forName(String, boolean, ClassLoader)}.
31 *
32 * @deprecated Deprecated in favor of {@link org.hibernate.annotations.common.reflection.ClassLoaderDelegate}
13233 */
34 @Deprecated
13335 public static Class classForName(String name, Class caller) throws ClassNotFoundException {
13436 try {
13537 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
14143 }
14244 return Class.forName( name, true, caller.getClassLoader() );
14345 }
144
145 /**
146 * Perform resolution of a class name.
147 * <p/>
148 * Same as {@link #classForName(String, Class)} except that here we delegate to
149 * {@link Class#forName(String)} if the context classloader lookup is unsuccessful.
150 *
151 * @param name The class name
152 * @return The class reference.
153 * @throws ClassNotFoundException From {@link Class#forName(String)}.
154 */
155 public static Class classForName(String name) throws ClassNotFoundException {
156 try {
157 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
158 if ( contextClassLoader != null ) {
159 return contextClassLoader.loadClass(name);
160 }
161 }
162 catch ( Throwable ignore ) {
163 }
164 return Class.forName( name );
165 }
166
167 /**
168 * Is this member publicly accessible.
169 *
170 * @param clazz The class which defines the member
171 * @param member The memeber.
172 * @return True if the member is publicly accessible, false otherwise.
173 */
174 public static boolean isPublic(Class clazz, Member member) {
175 return Modifier.isPublic( member.getModifiers() ) && Modifier.isPublic( clazz.getModifiers() );
176 }
177
178 /**
179 * Resolve a constant to its actual value.
180 *
181 * @param name The name
182 * @return The value
183 */
184 public static Object getConstantValue(String name) {
185 Class clazz;
186 try {
187 clazz = classForName( StringHelper.qualifier( name ) );
188 }
189 catch ( Throwable t ) {
190 return null;
191 }
192 try {
193 return clazz.getField( StringHelper.unqualify( name ) ).get( null );
194 }
195 catch ( Throwable t ) {
196 return null;
197 }
198 }
199
200 /**
201 * Determine if the given class is declared abstract.
202 *
203 * @param clazz The class to check.
204 * @return True if the class is abstract, false otherwise.
205 */
206 public static boolean isAbstractClass(Class clazz) {
207 int modifier = clazz.getModifiers();
208 return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier);
209 }
210
211 /**
212 * Determine is the given class is declared final.
213 *
214 * @param clazz The class to check.
215 * @return True if the class is final, flase otherwise.
216 */
217 public static boolean isFinalClass(Class clazz) {
218 return Modifier.isFinal( clazz.getModifiers() );
219 }
220
221 public static Method getMethod(Class clazz, Method method) {
222 try {
223 return clazz.getMethod( method.getName(), method.getParameterTypes() );
224 }
225 catch (Exception e) {
226 return null;
227 }
228 }
229
23046 }
23147
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6 package org.hibernate.annotations.common.util;
7
8 import org.jboss.logging.Logger;
9
10 import org.hibernate.annotations.common.reflection.ClassLoaderDelegate;
11 import org.hibernate.annotations.common.reflection.ClassLoadingException;
12 import org.hibernate.annotations.common.util.impl.LoggerFactory;
13
14 /**
15 * @author Steve Ebersole
16 * @deprecated This will be removed with no replacement: it will no longer be needed.
17 */
18 @Deprecated
19 public class StandardClassLoaderDelegateImpl implements ClassLoaderDelegate {
20 /**
21 * Singleton access
22 */
23 public static final StandardClassLoaderDelegateImpl INSTANCE = new StandardClassLoaderDelegateImpl();
24
25 private static final Logger log = LoggerFactory.logger( StandardClassLoaderDelegateImpl.class );
26
27 @Override
28 @SuppressWarnings("unchecked")
29 public <T> Class<T> classForName(String className) throws ClassLoadingException {
30 try {
31 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
32 if ( contextClassLoader != null ) {
33 return (Class<T>) Class.forName( className, true, contextClassLoader );
34 }
35 }
36 catch ( Throwable ignore ) {
37 log.debugf( "Unable to locate Class [%s] using TCCL, falling back to HCANN ClassLoader", className );
38 }
39
40 try {
41 return (Class<T>) Class.forName( className, true, getClass().getClassLoader() );
42 }
43 catch (ClassNotFoundException e) {
44 throw new ClassLoadingException( "Unable to load Class [" + className + "]", e );
45 }
46 }
47 }
00 /*
11 * Hibernate, Relational Persistence for Idiomatic Java
22 *
3 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
4 * indicated by the @author tags or express copyright attribution
5 * statements applied by the authors. All third-party contributions are
6 * distributed under license by Red Hat Middleware LLC.
7 *
8 * This copyrighted material is made available to anyone wishing to use, modify,
9 * copy, or redistribute it subject to the terms and conditions of the GNU
10 * Lesser General Public License, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this distribution; if not, write to:
19 * Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02110-1301 USA
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
225 */
236 package org.hibernate.annotations.common.util;
247
2811
2912
3013 /**
31 * Complete duplication of {@link org.hibernate.util.StringHelper}.
14 * This project no longer uses this class.
15 * @deprecated This will be removed.
3216 *
3317 * @author Emmanuel Bernard
3418 */
19 @Deprecated
3520 public final class StringHelper {
3621
3722 private static final int ALIAS_TRUNCATE_LENGTH = 10;
5035 public static int lastIndexOfLetter(String string) {
5136 for ( int i=0; i<string.length(); i++ ) {
5237 char character = string.charAt(i);
53 if ( !Character.isLetter(character) /*&& !('_'==character)*/ ) return i-1;
38 if ( !Character.isLetter(character) && !('_'==character) ) return i-1;
5439 }
5540 return string.length()-1;
5641 }
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6 package org.hibernate.annotations.common.util.impl;
7
8 import org.jboss.logging.BasicLogger;
9 import org.jboss.logging.annotations.Cause;
10 import org.jboss.logging.annotations.LogMessage;
11 import org.jboss.logging.annotations.Message;
12 import org.jboss.logging.annotations.MessageLogger;
13
14 import static org.jboss.logging.Logger.Level.ERROR;
15 import static org.jboss.logging.Logger.Level.INFO;
16
17 /**
18 * @author Emmanuel Bernard <emmanuel@hibernate.org>
19 */
20 @MessageLogger(projectCode = "HCANN")
21 public interface Log extends BasicLogger {
22
23 @LogMessage(level = INFO)
24 @Message(id = 1, value = "Hibernate Commons Annotations {%1$s}")
25 void version(String version);
26
27 @LogMessage(level = ERROR)
28 @Message(id = 2, value = "An assertion failure occurred (this may indicate a bug in Hibernate)")
29 void assertionFailure(@Cause Throwable t);
30 }
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6 package org.hibernate.annotations.common.util.impl;
7
8 import org.jboss.logging.Logger;
9
10 /**
11 * A factory class for class loggers. Allows a creation of loggers after the DRY principle.
12 *
13 * @author Hardy Ferentschik
14 * @author Emmanuel Bernard <emmanuel@hibernate.org>
15 */
16 public class LoggerFactory {
17 public static Log make(String category) {
18 return Logger.getMessageLogger( Log.class, category );
19 }
20
21 public static Logger logger(Class caller) {
22 return Logger.getLogger( caller.getName() );
23 }
24 }
25
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.annotationfactory;
17
28 import junit.framework.TestCase;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.annotationfactory;
17
28 import java.lang.reflect.Method;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6
07 /**
18 *
29 */
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import java.util.List;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import java.util.List;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import junit.framework.TestCase;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import java.io.Serializable;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import java.util.LinkedList;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6
07 //$Id: $
18 package org.hibernate.annotations.common.test.reflection.java;
29
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import static java.lang.annotation.ElementType.*;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java;
17
28 import junit.framework.TestCase;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.lang.reflect.ParameterizedType;
1016
1117 public class ApproximatingTypeEnvironmentTest extends TestCase {
1218
13 TypeEnvironmentFactory teFactory = new TypeEnvironmentFactory();
14 TypeEnvironment unboundContext = teFactory.getEnvironment( BigBlob.class );
15 TypeEnvironment approximatingUnboundContext = teFactory.toApproximatingEnvironment( unboundContext );
19 TypeEnvironment unboundContext = TypeEnvironmentFactory.getEnvironment( BigBlob.class );
20 TypeEnvironment approximatingUnboundContext = TypeEnvironmentFactory.toApproximatingEnvironment( unboundContext );
1621
17 TypeEnvironment boundContext = teFactory.getEnvironment( SonOfBlob.class );
18 TypeEnvironment approximatingBoundContext = teFactory.toApproximatingEnvironment( boundContext );
22 TypeEnvironment boundContext = TypeEnvironmentFactory.getEnvironment( SonOfBlob.class );
23 TypeEnvironment approximatingBoundContext = TypeEnvironmentFactory.toApproximatingEnvironment( boundContext );
1924
2025 public void testDoesNothingOnClasses() throws SecurityException {
2126 assertEquals( String[].class, approximatingUnboundContext.bind( String[].class ) );
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.util.Collection;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.util.List;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.io.Serializable;
0 //$Id: Language.java 11282 2007-03-14 22:05:59Z epbernard $
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6
7 //$Id$
18 package org.hibernate.annotations.common.test.reflection.java.generics;
29
310 /**
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.util.Set;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 /**
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.util.List;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import static java.lang.annotation.ElementType.*;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.lang.reflect.ParameterizedType;
1521 public class TypeEnvironmentFactoryTest extends TestCase {
1622
1723 public void testBindsGenericsToSuperclassEnvironment() throws SecurityException, NoSuchMethodException {
18 TypeEnvironmentFactory env = new TypeEnvironmentFactory();
19 Type type = Grandpa.class.getMethod( "returnsGeneric", new Class[0] ).getGenericReturnType();
24 Type type = Grandpa.class.getMethod( "returnsGeneric" ).getGenericReturnType();
2025
21 Type asSeenFromGrandpa = env.getEnvironment( Grandpa.class ).bind( type );
26 Type asSeenFromGrandpa = TypeEnvironmentFactory.getEnvironment( Grandpa.class ).bind( type );
2227 assertTrue( asSeenFromGrandpa instanceof TypeVariable );
2328 assertEquals( "T", asSeenFromGrandpa.toString() );
2429
25 Type asSeenFromDad = env.getEnvironment( Dad.class ).bind( type );
30 Type asSeenFromDad = TypeEnvironmentFactory.getEnvironment( Dad.class ).bind( type );
2631 assertTrue( asSeenFromDad instanceof ParameterizedType );
2732 assertEquals( "java.util.List<T>", asSeenFromDad.toString() );
2833
29 ParameterizedType asSeenFromSon = (ParameterizedType) env.getEnvironment( Son.class ).bind( type );
34 ParameterizedType asSeenFromSon = (ParameterizedType) TypeEnvironmentFactory.getEnvironment( Son.class ).bind( type );
3035 assertType_isCollectionOfClass_withElementsOfClass( asSeenFromSon, List.class, String.class );
3136 }
3237
38 @SuppressWarnings("unchecked")
3339 public void testBindsGenericsToOwnerEnvironment() throws SecurityException, NoSuchMethodException {
34 TypeEnvironmentFactory env = new TypeEnvironmentFactory();
35
36 Type friendType = Dad.class.getMethod( "getFriend", new Class[0] ).getGenericReturnType();
37 ParameterizedType friendTypeAsSeenFromDad = (ParameterizedType) env.getEnvironment( Dad.class ).bind(
40 Type friendType = Dad.class.getMethod( "getFriend" ).getGenericReturnType();
41 ParameterizedType friendTypeAsSeenFromDad = (ParameterizedType) TypeEnvironmentFactory.getEnvironment( Dad.class ).bind(
3842 friendType
3943 );
4044
4145 Class friendClass = (Class) friendTypeAsSeenFromDad.getRawType();
42 Type returnType = friendClass.getMethod( "embeddedProperty", new Class[0] ).getGenericReturnType();
46 Type returnType = friendClass.getMethod( "embeddedProperty" ).getGenericReturnType();
4347
44 ParameterizedType boundType = (ParameterizedType) env.getEnvironment( friendTypeAsSeenFromDad ).bind(
48 ParameterizedType boundType = (ParameterizedType) TypeEnvironmentFactory.getEnvironment( friendTypeAsSeenFromDad ).bind(
4549 returnType
4650 );
4751 assertType_isCollectionOfClass_withElementsOfClass( boundType, Set.class, Integer.class );
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics;
17
28 import java.lang.reflect.Type;
915
1016 public class TypeUtilsTest extends TestCase {
1117
12 TypeEnvironmentFactory env = new TypeEnvironmentFactory();
13 TypeEnvironment dadContext = env.getEnvironment( Dad.class );
14 TypeEnvironment sonContext = env.getEnvironment( Son.class );
18 TypeEnvironment dadContext = TypeEnvironmentFactory.getEnvironment( Dad.class );
19 TypeEnvironment sonContext = TypeEnvironmentFactory.getEnvironment( Son.class );
1520
1621 public void testAClassIsAlwaysFullyResolved() throws Exception {
1722 assertTrue( TypeUtils.isResolved( Dad.class ) );
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6
07 //$Id: $
18 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
29
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6
07 //$Id: $
18 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
29
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
6
07 //$Id: $
18 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
29
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
17
28 public class Dummy {
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
17
28 import org.hibernate.annotations.common.test.reflection.java.generics.deep.Dummy;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
17
28 import org.hibernate.annotations.common.test.reflection.java.generics.deep.Dummy;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
17
28 import org.hibernate.annotations.common.test.reflection.java.generics.deep.Dummy;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
17
28 import org.hibernate.annotations.common.test.reflection.java.generics.deep.DummySubclass;
0 /*
1 * Hibernate, Relational Persistence for Idiomatic Java
2 *
3 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
4 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
5 */
06 package org.hibernate.annotations.common.test.reflection.java.generics.deep;
17
28 import org.hibernate.annotations.common.test.reflection.java.generics.deep.DummySubclass;
0
1 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
2 log4j.appender.stdout.Target=System.out
3 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
4 log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
5
6 log4j.rootLogger=info, stdout
7